首页 文章

自定义PayPal市场(API)的“PayPal”按钮

提问于
浏览
0

我是第一次使用PayPal Marketplace API开发我的应用程序 .

在其他步骤中,我需要自定义"PayPal checkout"按钮 . 我是按照this page上的说明做到的 .

在功能“付款”(请参阅下面的原始代码段)中,我应该为CREATE_URL提供回调网址:

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

            // Set up a url on your server to create the payment
            var CREATE_URL = '/demo/checkout/api/paypal/order/create/';

            // Make a call to your server to set up the payment
            return paypal.request.post(CREATE_URL)
                .then(function(res) {
                    return res.id;
                });
            }
  • 通过阅读本文,我很困惑为什么CREATE_URL值不是以“http”或“https”开头的完整路径网址?我在html文件的后续段中有类似的EXECUTE_URL问题 .

  • 我的REST控制器应该期望什么类型的RequestBody?

  • 我的应用应该在“CREATE_URL”的网址上采取什么操作?我的直觉是调用Order API来创建一个订单(以及我的数据库中的其他内容) . 它是否正确?

1 回答

  • 1

    我可以一次解决一个问题:

    • 通过阅读本文,我很困惑为什么CREATE_URL值不是以"http"或"https"开头的完整路径url?我在html文件的后续段中有类似的EXECUTE_URL问题 .

    You don't have to have a full path URL (known as absolute path) because the path that you provide for CREATE_URL is on your own server. So the code where you have your button is on a page like exampleButton.html and when you click the button, it takes you to a script, such as var CREATE_URL = '/demo/checkout/api/paypal/order/create/'; which is an index page which will run the Create Order API method with the data that you pass. Here is another example implementing a payment button with checkout.js using a server side language.

    • 我的REST控制器应该期望什么类型的RequestBody?

    Your request body will receive the payment data from the JavaScript data parameter, which should be JSON format. You then pass this to the server side when you receive the POST data. An even simpler implementation is to use the client-side integration to create the order.

    • 我的应用应该在"CREATE_URL"的网址上采取什么操作?我的直觉是调用Order API来创建一个订单(以及我的数据库中的其他内容) . 它是否正确?

    Your app should automatically run the create order method. This script works with JavaScript promises, so will wait for a response, like getting a successful authorization (or failure) from the customer before attempting to execute the payment.

相关问题