$data = [
"key" => $api_key,
"amount" => $amount,
"name" => "DJ Tiesto",
"description" => "Tron Legacy",
"image" => "logo.png",
"prefill" => [
"name" => "Daft Punk",
"email" => "[email protected]",
"contact" => "9999999999",
],
"notes" => [
"address" => "Hello World",
"merchant_order_id" => "12312321",
],
"theme" => [
"color" => "#F37254"
],
"order_id" => $razorpayOrderId,
];
I am trying to integrate razorpay with php everything is ok but in prefill, I get a default value. how can I change this value to custom value?
You can prefill the payment method for customers, based on their past payment preferences. For example, you can ensure when the customer opens the link, card appears selected as the payment method. You can prefill the bank name (If netbanking is the prefilled payment method)
You can set query parameters with callback_url to map it with entities at your end. An example of a valid callback URL: https://your-site.com/callback?cart_id=12345 .
By default, a customer can make a maximum payment of ₹5,00,000. You can increae this limit by raising a request with Razorpay Support.
In prefill you will get the value which you are given in the prefill object. Just like you passsed $amount and $razorpayOrderId you can use $name and $email etc which might be the value you get from textbox or something like that. Store those names and email in a variable and pass that into prefill.
you can easily change the default value by fetching those values from database or pass those values through ulr parameters as i have done in php.
get order id through url parameter or post request
$orderid = $_GET['orderid'];
run php mysql query to fetch data from database based on order id(i have used 2 table one for payment details and another one for userdetails)
$query = "SELECT ud.Name, ud.lname,
ud.MobileId,ud.EmailID,opd.pay_amount, opd.receipt, opd.transaction_id
FROM online_payment_details as opd
INNER JOIN userdetails as ud
ON opd.user_id=ud.UserID
WHERE order_id='$orderid';";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$name = $row['Name'].' '.$row['lname'];
$razorpayOrderId = $orderid;
$amount_pay = $row['pay_amount'];
$receipt = $row['receipt'];
$transaction_id = $row['transaction_id'];
$displayAmount = $amount_pay ;
$corporateName = '';
$email = $row['EmailID'];
$contact = $row['MobileId'];
now in your data array add above variables in data array
$data = [
"key" => $keyId,
"amount" => $amount_pay,
"name" => $name,
"description" => "",
"image" => "",
"prefill" => [
"name" => $corporateName,
"email" => $email,
"contact" => $contact,
],
"notes" => [
"address" => "Hello World",
"merchant_order_id" => $transaction_id,
],
"theme" => [
"color" => "#F37254"
],
"order_id" => $razorpayOrderId,
"receipt" => $receipt,
];
and now in checkout/automatic page in block fetch values from data array and store in data attribute as below
<script
src="https://checkout.razorpay.com/v1/checkout.js"
data-key="<?php echo $data['key']?>"
data-amount="<?php echo $data['amount']?>"
data-currency="INR"
data-name="<?php echo $data['name']?>"
data-image="<?php echo $data['image']?>"
data-description="<?php echo $data['description']?>"
data-prefill.name="<?php echo $data['prefill']['name']?>"
data-prefill.email="<?php echo $data['prefill']['email']?>"
data-prefill.contact="<?php echo $data['prefill']['contact']?>"
data-notes.shopping_order_id="<?php echo $data['receipt']?>"
data-order_id="<?php echo $data['order_id']?>"
<?php if ($displayCurrency !== 'INR') { ?> data-display_amount="<?php echo $data['display_amount']?>" <?php } ?>
<?php if ($displayCurrency !== 'INR') { ?> data-display_currency="<?php echo $data['display_currency']?>" <?php } ?>
>
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With