createOrder之后贝宝结帐redirectUrl

时间:2019-04-01 07:35:28

标签: javascript

我尝试将Javascript中的新的paypal方法用于结帐按钮,但是付款完成后,我将无法重定向用户。

这是我的代码:

    paypal.Buttons({
        // Set up the transaction
        createOrder: function(data, actions) {
            return actions.order.create({
 application_context: {
                                        return_url: 'https://url.com/ok.php',
                    cancel_url: 'https://url.com/nok.php',
                                        brand_name: "AKAZ",
                                        locale: "fr-FR",
                                        user_action: "CONTINUE"
                                    },
                purchase_units: [{
                    amount: {
                        value: '175.20'
                    }
                }]
            });
        },
        onApprove: function(data, actions) {
            return actions.payment.execute().then(function() {
                    actions.redirect();
                }
            );
        },
        onCancel: function (data, action) {
            return actions.payment.execute().then(function() {
                    actions.redirect();
                }
            );
        }
    }).render('#paypal-button-container');

1 个答案:

答案 0 :(得分:0)

<script
    src="https://www.paypal.com/sdk/js?client-id=SB_CLIENT_ID">
  </script>

<script>paypal.Buttons().render('body');</script>

在确认之前:

<!DOCTYPE html>标签可实现最佳浏览器兼容性。 页面上的<meta http-equiv="X-UA-Compatible" content="IE=edge" />元标记可实现最佳Internet Explorer兼容性。  <meta name="viewport" content="width=device-width, initial-scale=1">标记到页面上,以确保在移动设备上实现最佳呈现。

检查完整参数

{
  "intent": "CAPTURE",
  "application_context": {
    "return_url": "https://example.com",
    "cancel_url": "https://example.com",
    "brand_name": "EXAMPLE INC",
    "locale": "en-US",
    "landing_page": "BILLING",
    "shipping_preference": "SET_PROVIDED_ADDRESS",
    "user_action": "CONTINUE"
  },
  "purchase_units": [
    {
      "reference_id": "PUHF",
      "description": "Sporting Goods",

      "custom_id": "CUST-HighFashions",
      "soft_descriptor": "HighFashions",
      "amount": {
        "currency_code": "USD",
        "value": "230.00",
        "breakdown": {
          "item_total": {
            "currency_code": "USD",
            "value": "180.00"
          },
          "shipping": {
            "currency_code": "USD",
            "value": "30.00"
          },
          "handling": {
            "currency_code": "USD",
            "value": "10.00"
          },
          "tax_total": {
            "currency_code": "USD",
            "value": "20.00"
          },
          "shipping_discount": {
            "currency_code": "USD",
            "value": "10"
          }
        }
      },
      "items": [
        {
          "name": "T-Shirt",
          "description": "Green XL",
          "sku": "sku01",
          "unit_amount": {
            "currency_code": "USD",
            "value": "90.00"
          },
          "tax": {
            "currency_code": "USD",
            "value": "10.00"
          },
          "quantity": "1",
          "category": "PHYSICAL_GOODS"
        },
        {
          "name": "Shoes",
          "description": "Running, Size 10.5",
          "sku": "sku02",
          "unit_amount": {
            "currency_code": "USD",
            "value": "45.00"
          },
          "tax": {
            "currency_code": "USD",
            "value": "5.00"
          },
          "quantity": "2",
          "category": "PHYSICAL_GOODS"
        }
      ],
      "shipping": {
        "method": "United States Postal Service",
        "address": {
          "name": {
            "give_name":"John",
            "surname":"Doe"
          },
          "address_line_1": "123 Townsend St",
          "address_line_2": "Floor 6",
          "admin_area_2": "San Francisco",
          "admin_area_1": "CA",
          "postal_code": "94107",
          "country_code": "US"
        }
      }
    }
  ]
}

阅读Paypal文档