预充不能在razorpay中使用

时间:2018-07-02 06:16:06

标签: php payment-gateway razorpay

$data = [
        "key"               => $api_key,
        "amount"            => $amount,
        "name"              => "DJ Tiesto",
        "description"       => "Tron Legacy",
        "image"             => "logo.png",
        "prefill"           => [
                                    "name"     => "Daft Punk",
                                    "email"    => "customer@merchant.com",
                                    "contact"  => "9999999999",
                               ],
        "notes"             => [
                                    "address"           => "Hello World",
                                    "merchant_order_id" => "12312321",
                               ],
        "theme"             => [
                                    "color"    => "#F37254"
                               ],
        "order_id"          => $razorpayOrderId,
    ];

我正在尝试将razorpay与php集成在一起,一切正常,但是在预填充中,我得到了默认值。如何将该值更改为自定义值?

2 个答案:

答案 0 :(得分:2)

在预填充中,您将获得在预填充对象中给定的值。就像您传递了$ amount和$ razorpayOrderId一样,您可以使用$ name和$ email等,这可能是您从文本框或类似内容中获得的值。将这些名称和电子邮件存储在变量中,然后将其传递到预填充中。

答案 1 :(得分:0)

您可以轻松地通过从数据库获取这些值来更改默认值,或者像我在php中所做的那样通过ulr参数传递这些值。

通过url参数或发布请求获取订单ID

$ orderid = $ _GET ['orderid'];

  

运行php mysql查询以根据订单ID(i从数据库中获取数据   已使用2个表格进行付款,而另一个则用于   用户详细信息)

$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'];
  

现在在您的数据数组中,在数据数组中添加以上变量

$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,
    ];
  

,现在进入结帐/自动页面,从中获取值   数据数组并存储在data属性中,如下所示:

<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>