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/