paypal - 如何使用 Paypal 客户端 rest api 创建订阅付款?

标签 paypal payment-gateway paypal-rest-sdk

Client-side REST integration文档描述了如何为一个或多个项目创建快速结帐。

我如何使用它来创建订阅或定期付款?下面应该怎么修改?

 payment: function(data, actions) {
        return actions.payment.create({
            transactions: [
                {
                    amount: { total: '1.00', currency: 'USD' }
                }
            ]
        });
    },

我找到了一个类似的 Rest api for Node .不确定在 JS 上会怎样。

最佳答案

首先您需要创建一个计费计划:

billing_plan_attributes = {
                "name": PLAN_NAME_HERE,
                "description": PLAN_DESCRIPTION,
                "merchant_preferences": {
                    "auto_bill_amount": "yes", # yes if you want auto bill 
                    "cancel_url": "http://www.cancel.com", # redirect uri if user cancels payment
                    "initial_fail_amount_action": "continue",
                    "max_fail_attempts": "1",
                    "return_url": RETURN_URL,
                    "setup_fee": {
                        "currency": CURRENCY,
                        "value": VALUE # how much do you want to charge
                    }
                },
                "payment_definitions": [
                    {
                        "amount": {
                            "currency": request.form['currency'],
                            "value": request.form['amount']
                        },

                        "cycles": CYCLES, # how much time this subscription will charge user
                        "frequency": FREQ, # month, day
                        "frequency_interval": INTERVAL, # per month or per three month or so on
                        "name": NAME,
                        "type": TYPE
                    }
                ],
                "type": TYPE
            }
            billing_plan = BillingPlan(billing_plan_attributes)
            if billing_plan.create():
                print("success")

这里使用的属性具有字面意义。现在,由于您已经创建了一个计费计划,您需要为用户提供一些界面,以便他们可以订阅它。下面是一个示例代码:

billing_agreement = BillingAgreement({
            "name": "Organization plan name",
            "description": "Agreement for " + request.args.get('name', ''),
            "start_date": (datetime.now() + timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%SZ'),
            "plan": {
                "id": request.args.get('id', '')
            },
            "payer": {
                "payment_method": "paypal"
            },
            "shipping_address": {
                "line1": "StayBr111idge Suites",
                "line2": "Cro12ok Street",
                "city": "San Jose",
                "state": "CA",
                "postal_code": "95112",
                "country_code": "US"
            }
        })
        if billing_agreement.create():
            for link in billing_agreement.links:
                if link.rel == "approval_url":
                    approval_url = link.href

在最后一行中,您可以获得可以提供给用户的批准链接。 接下来,您必须设置一个端点,如果用户批准付款,它将作为回调 url。

billing_agreement_response = BillingAgreement.execute(payment_token)

payment_token 由 paypal 发送到您的回调 url。

关于paypal - 如何使用 Paypal 客户端 rest api 创建订阅付款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44605443/

相关文章:

paypal - 如何通过 OpenID Connect 获取 PayPal 用户的 payer_id?

paypal - 使用 Paypal 标准付款时是否需要先登录沙盒帐户

javascript - Cordova 和布伦特里 : PayPal login window is blank

CreateRecurringPaymentsProfile 中 Paypal API PROFILESTARTDATE 的 PHP 日期格式

payment-gateway - 使用信用卡和支付网关进行年龄验证

Paypal : Billing Plan + Agreement - basic Qs

php - 此交易无效。 Paypal PHP SDK

java - CCAvenue 集成无法正常工作错误 10002

php - 在 Paypal Payments Pro、Payments Advanced 和 Payflow Pro 之间进行选择

php - PayPal Rest SDK API - 获取 token