paypal - 使用 Express Checkout 定期付款

标签 paypal paypal-subscriptions

TL;DR:我正在尝试实现对我的商店的订阅,但“paypalobjects.com/api/checkout.js”重定向到“sandbox.paypal.com/webapps/hermes/error”。定期付款按预期工作。我正在使用 Express Checkout 高级服务器集成。

我的 Paypal.Button:

paypal.Button.render({

        env: 'sandbox', // Optional: specify 'sandbox' environment

        payment: function(resolve, reject) {


            const token = localStorage.getItem('_token').split(' ')[1];
            if(!subscribe){
              var CREATE_PAYMENT_URL = `/store/${store}/paypal/create-payment/${orderId}?token=${token}`;
            }else{
              var CREATE_PAYMENT_URL = `/store/${store}/subscribe/paypal/create-payment/${orderId}?token=${token}`;
            }

            paypal.request.post(CREATE_PAYMENT_URL)
                .then(function(data) { resolve(data.id); })
                .catch(function(err) { console.log(err); });
        },

        onAuthorize: function(data) {

            const token = localStorage.getItem('_token').split(' ')[1];
              if(!subscribe){
                var EXECUTE_PAYMENT_URL = `/store/${store}/paypal/execute-payment?token=${token}`;
              }else{
                var EXECUTE_PAYMENT_URL = `/store/${store}/subscribe/paypal/execute-payment?token=${token}`;
              }


            paypal.request.post(EXECUTE_PAYMENT_URL,
                    { paymentID: data.paymentID, payerID: data.payerID })

                .then(function(data) {

                })
                .catch(function(err) { console.log("error " + err);});
        },
        onCancel: function(data){

          cancel();
          this.destroy();
        },
        onError: function (err) {
          console.log("ERROR OCCURRED!");
          console.log(err);
        }

  }, '#paypal-button');

不太相关,但我的后端看起来像这样(带有测试数据):

public function createPaypalOrder(Request $request, $store, $orderId){

      $order = Order::with(['user', 'whitelabel'])->where('id', $orderId)->first();


      $amout = array(
        'value' => (string) $order->price/100,
        'currency' => 'NOK',
      );

      $shippingandtax = array(
        'value' => '0',
        'currency' => 'NOK',
      );

      $charge_models = array([
        'type'=> 'SHIPPING',
        'amount'=> $shippingandtax,
      ],
      [
        'type'=> 'TAX',
        'amount'=> $shippingandtax,
      ]);

      $payment_definitions_creation = array();
      array_push($payment_definitions_creation,[
        'name' => 'Regular Payment Definition',
        'type' => 'REGULAR',
        'frequency' => 'MONTH',
        'frequency_interval'=> '2',
        'amount' => $amout,
        'cycles' => '12',
        'charge_models' => $charge_models
      ]);

      $format = Config::get('constants.FRONTEND_URL')[env('APP_ENV')];
      $redirectBase = sprintf($format, $order->whitelabel->subdomain, 'orders/?order=' . $order->id);


      $merchant_preferences_temp = array(
        'value' => '0',
        'currency' => 'NOK'
      );
      $merchant_preferences = array(
          "setup_fee" => $merchant_preferences_temp,
          'return_url' => "http://www.vg.no",
          'cancel_url' => "http://www.yahoo.no",
          'auto_bill_amount' => 'YES',
          'initial_fail_amount_action' => 'CONTINUE',
          'max_fail_attempts' => '0'
      );

      $payment_definitions = array();
      array_push($payment_definitions, $payment_definitions_creation);

      $name = 'Monthly subscription to ' . (string)$order->whitelabel->title;
      $body = array(
        'name' => $name,
        'description' => 'Subscribtion.',
        'type' => 'fixed',
        'payment_definitions' => $payment_definitions_creation,
        "merchant_preferences"=> $merchant_preferences,
      );


      $token = $this->getPaypalToken($order);

      $client = new \GuzzleHttp\Client();
      $response = $client->post('https://api.sandbox.paypal.com/v1/payments/billing-plans', [
        'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $token],
        'json' => $body,
      ]);

      $paypalOrderCreation = json_decode($response->getBody());

      // add stuff to db
      $order->setTransactionId($paypalOrderCreation->id);
      return json_encode($paypalOrderCreation);

    }

我的后端返回来自 paypal 的有效响应,其中包含订单 ID 和状态“已创建”。 (还有很多其他数据……)

{"id":"P-0SE01606VF925501Y2UAKG3Y","state":"CREATED","name":"Monthly subscription to Paypal","description":"Subscribtion.","type":"FIXED","payment_definitions":[{"id":"PD-35U317461H38251442UAKG4A","name":"Regular Payment Definition","type":"REGULAR","frequency":"Month","amount":{"currency":"NOK","value":"500"},"cycles":"12","charge_models":[{"id":"CHM-7T021625H451740052UAKG4A","type":"SHIPPING","amount":{"currency":"NOK","value":"0"}},{"id":"CHM-313690493W320615U2UAKG4A","type":"TAX","amount":{"currency":"NOK","value":"0"}}],"frequency_interval":"2"}],"merchant_preferences":{"setup_fee":{"currency":"NOK","value":"0"},"max_fail_attempts":"0","return_url":"http:\/\/www.vg.no","cancel_url":"http:\/\/www.yahoo.no","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2017-01-25T09:41:45.967Z","update_time":"2017-01-25T09:41:45.967Z","links":[{"href":"https:\/\/api.sandbox.paypal.com\/v1\/payments\/billing-plans\/P-0SE01606VF925501Y2UAKG3Y","rel":"self","method":"GET"}]}

现在我的问题是,当我的 paypal.button 收到此响应时,它会处理信息并将我重定向到“sandbox.paypal.com/webapps/hermes/error”,这有点难以调试。

谢谢:)

最佳答案

问题是 Paypal 的内部问题。现在可以使用了。

关于paypal - 使用 Express Checkout 定期付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41848386/

相关文章:

android - Paypal Android SDK 可以询问送货地址吗?

java - 单击按钮后如何将Paypal集成到付款用户?

php - 您用于进入Pay​​Pal系统的链接无效。请检查链接并重试

Paypal 和定期付款通知

javascript - 如何使用 PayPal 的 javascript 订阅按钮在付款后重定向

java - 使用 Paypal API 问题

vb.net - 申请在线支付

php - PayPal 自适应支付错误 540031

paypal - 定期付款试用什么时候结束?

paypal - 如何将网站中的用户名链接到 PayPal 信息电子邮件?