首页 > 解决方案 > 如何在 laravel 中使用 jquery 在 paypal 中传递帐单地址或用户详细信息

问题描述

我正在使用 Braintree 付款进行 PayPal 付款度假集成,但我无法在 PayPal 上传递参数。

jQuery

<script type="text/javascript">
jQuery(document).ready(function(e) {
braintree.setup(
        // Replace this with a client token from your server
        " <?php print session('braintree_token')?>",
        "dropin", {
            container: "payment-form",
        });

});

<script type="text/javascript">
window.onload = function(e){

var paypal_public_key = document.getElementById('paypal_public_key').value;
var acount_type = document.getElementById('paypal_environment').value;
if(acount_type=='Test'){
  var paypal_environment = 'sandbox'
}else if(acount_type=='Live'){
  var paypal_environment = 'production'
}

   paypal.Button.render({
       enableBillingAddress: false,
  env: paypal_environment, // sandbox | production
  style: {
          label: 'checkout',
          size:  'small',    // small | medium | large | responsive
          shape: 'pill',     // pill | rect
          color: 'gold'      // gold | blue | silver | black
      },

  // PayPal Client IDs - replace with your own
  // Create a PayPal app: https://developer.paypal.com/developer/applications/create

  client: {
    sandbox:     paypal_public_key,
    production:  paypal_public_key
  },

  // Show the buyer a 'Pay Now' button in the checkout flow
  commit: true,

  // payment() is called when the button is clicked
  payment: function(data, actions) {
    var payment_currency = document.getElementById('payment_currency').value;
    var total_price = '<?php echo number_format((float)$total_price+0, 2, '.', '');?>';
      var billing_address = false;

    // Make a call to the REST api to create the payment
    return actions.payment.create({

      payment: {
        transactions: [
          {
            amount: {
                total: total_price,
                currency: payment_currency,
            },

          }
        ]
      }
    });
  },



  // onAuthorize() is called when the buyer approves the payment
  onAuthorize: function(data, actions) {

    // Make a call to the REST api to execute the payment
    return actions.payment.execute().then(function() {
         jQuery('#update_cart_form').prepend('<input type="hidden" name="nonce" value='+JSON.stringify(data)+'>');
      jQuery("#update_cart_form").submit();
    });
  }

}, '#paypal_button');

};

当我点击 PayPal 按钮时,它会重定向到 sandbox.paypal.com,这是正确的,但它不会隐藏帐单地址,它仍然处于启用状态,我通过了 false。所以,我的问题是如何使用 jquery 将参数传递给 PayPal 结帐,因为我需要传递一些有关客户的更多信息。那么如何实现这一点。请帮忙。

标签: jquerylaravelpaypal

解决方案


所有 PayPal 交易都使用账单地址。这是必需的。

enableBillingAddress 参数用于请求返回该信息。很少有卖家账户可以在设置为 true 的情况下处理付款,因此您应该忽略这一点。

如果您的目标是设置预填信息,则需要与其他字段一起设置,并且在用户登录时可能会被忽略,因为已登录的用户已经存储了自己的信息。


推荐阅读