以下是 REST API 计费计划和计费协议的工作方式(包括 curl 调用示例):
首先,请确保您的 REST 应用已切换为订阅(您可以在 https://developer.paypal.com/webapps/developer/applications/myapps 检查您的 REST 应用设置)
1-) 创建计费计划
curl -k -v -H "Content-Type:application/json" -H "Authorization: Bearer ACCESS_TOKEN" -d '{"name":"Test REST Club Plan","description":"模板创建。 ","type":"fixed","payment_definitions":[{"name":"Regular Payments","type":"REGULAR","frequency":"MONTH","frequency_interval":"2","金额":{"价值":"100","货币":"美元"},"周期":"12","charge_models":[{"type":"SHIPPING","amount":{"价值":"10","currency":"USD"}},{"type":"TAX","amount":{"value":"12","currency":"USD"}}]}] ,"merchant_preferences":{"setup_fee":{"value":"1","currency":"USD"},"return_url":"http://returnurl","cancel_url":"http://cancelurl ","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE","max_fail_attempts":"0"}}' https://api.sandbox.paypal.com/v1/payments/billing-plans
PayPal 将返回一个以“P-”开头的计费方案 ID
2-) 激活计费计划
curl -k -v -H "Content-Type:application/json" -H "Authorization: Bearer ACCESS_TOKEN" -d '[{"path":"/","value":{"state":" ACTIVE"},"op":"replace"}]' https://api.sandbox.paypal.com/v1/payments/billing-plans/
3-) 创建结算协议
curl -k -v -H "Content-Type:application/json" -H "Authorization: Bearer ACCESS_TOKEN" -d '{"name":"Test REST Club Plan","description":"模板创建。 ","start_date":"2015-03-20T07:49:27-07:00","plan":{"id":"PLAN_ID_HERE"},"payer":{"payment_method":"paypal"}, "shipping_address":{"line1":"111 First Street","city":"Saratoga","state":"CA","postal_code":"95070","country_code":"US"}}' @ 987654324@
PayPal 将返回带有 EC 令牌的 Express Checkout 重定向 URL。例如。 https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-xxxxxxxxxxxxxxxxx
您需要通过该 URL 将您的客户重定向到 PayPal。结算协议获得授权后,客户将返回您的网站(步骤 1 中的 return_url)。
4-) 执行计费协议
curl -k -v -H "Content-Type:application/json" -H "Authorization: Bearer ACCESS_TOKEN" -d '{}' https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-TOKEN_HERE/agreement-execute