【问题标题】:How to create "CreatePayment" and "PaymentExecute" controller for PayPal REST api in laravel 5.4如何在 laravel 5.4 中为 PayPal REST api 创建“CreatePayment”和“PaymentExecute”控制器
【发布时间】:2018-03-19 18:22:37
【问题描述】:

我正在使用 Laravel 5.4 创建一个需要 PayPal 进行支付的应用程序,当我研究 PayPal 集成文档时,我发现 REST API 需要服务器端名称中的 2 个控制器“/demo/checkout/api/paypal/payment/ create/" 和 "/demo/checkout/api/paypal/payment/execute/",但是 PayPal 的文档很模糊,有谁知道它是什么以及它的例子吗?

这是我在前端的代码:

$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $("meta[name='csrf-token']").attr("content")
        }
    });

    paypal.Button.render({
      env: 'sandbox', // sandbox | production

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

      // payment() is called when the button is clicked
      payment: function() {

        // Set up a url on your server to create the payment
        var CREATE_URL = '{{route('paypal.createpayment')}}';

        // Make a call to your server to set up the payment
        return paypal.request({
          method: 'post',
          url: CREATE_URL,
          headers: {
            'x-csrf-token': $("meta[name='csrf-token']").attr("content")
          }
        }).then(function(res) {
          return res.paymentID;
        });
      },

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

        // Set up a url on your server to execute the payment
        var EXECUTE_URL = '/demo/checkout/api/paypal/payment/execute/';

        // Set up the data you need to pass to your server
        var data = {
          paymentID: data.paymentID,
          payerID: data.payerID
        };

        // Make a call to your server to execute the payment
        return paypal.request.post(EXECUTE_URL, data)
        .then(function (res) {
          window.alert('Payment Complete!');
        });
      }
    }, '#paypal-button-container');

【问题讨论】:

    标签: php rest paypal


    【解决方案1】:

    文档在此页面上,并带有多种编程语言的示例:https://developer.paypal.com/docs/api/quickstart/payments/#define-payment

    所以在第一次调用您的服务器时,您需要定义付款创建付款

    在第二次调用您的服务器时(在 onAuthorize 函数中调用),您需要执行付款

    【讨论】:

      猜你喜欢
      • 2017-09-20
      • 2018-02-16
      • 2015-08-02
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 2016-08-27
      • 2015-05-10
      • 2013-12-27
      相关资源
      最近更新 更多