2

I am having an e-commerce site on which i have embedded an instamojo payment button. The amount specified in my instamojo dashboard is INR 200. I want to dynamically change the amount so that it is equal to the one defined in mongodb database. How can i achieve that without using REST API?

For eg : Instead of "Rs 200" or "Minimum Rs 200" on the instamojo payment gateway, I want the amount value to be equal to the value specified on my website for that particular product.

2 Answers2

1

I think there is no simple way like passing the price value as URL variable. You need use REST API or php library and generate a payment request via

try {
    $response = $api->paymentRequestCreate(array(
        "purpose" => "FIFA 16",
        "amount" => "3499",
        "send_email" => true,
        "email" => "foo@example.com",
        "redirect_url" => "http://www.example.com/handle_redirect.php"
        ));
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}
1
<?php
include 'database.php';//include database    
$pricesql="SELECT * FROM `price`";//this is price table which i can update  and this table contain 3 type of price
$response=mysqli_query($conn,$pricesql);
$price=mysqli_fetch_assoc($response);
$price_teacher= $price['price_teacher'];
$price_student= $price['price_student'];
$price_institute= $price['price_institute'];
     }
}
```
include 'src/instamojo.php';  
@$api = new Instamojo\Instamojo(test_d895d58336b76a4042ae3b70851, test_12bb1df4f178cbbbed8ddaa3d9b, 'https://test.instamojo.com/api/1.1/');
try {
    $response = $api->paymentRequestCreate(array(
        "purpose" => $product_name,
      "custom_fields"=>$cars,
        "amount" => $price,//here you can pass amount(remove my comment)
        "send_email" => true,
        "email" => $email,
        "buyer_name"=> $name,
        "phone"=>$phone,
        "send_sms"=> true,
        "allow_repeated_payments"=>false,
        "redirect_url" => "http://localhost/bteacher/thankyou.php"
        //"webhook"=>
        ));
    $pay_url = $response['longurl'];
    header("Location: $pay_url");
    exit();
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

?>

Jayakumar Thangavel
  • 1,884
  • 1
  • 22
  • 29
CYL TECH
  • 11
  • 1