我参加聚会有点晚了,但我在 PayPal 文档中找到了这个
PayPal 付款涉及以下 3 个步骤:
- 指定付款信息以创建付款。
- 获得付款批准。
- 向 PayPal 用户的帐户执行付款。
1) 将intent设置为sale,将payment_method设置为paypal。
包括重定向 URL。用户在批准或取消付款时会被重定向到这些 URL。
curl https://api.sandbox.paypal.com/v1/payments/payment \
-v \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer accessToken' \
-d '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://return_URL_here",
"cancel_url":"http://cancel_URL_here"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment transaction description."
}
]
}
回复:
{
"id":"PAY-6RV70583SB702805EKEYSZ6Y",
"create_time":"2013-03-01T22:34:35Z",
"update_time":"2013-03-01T22:34:36Z",
"state":"created",
"intent":"sale",
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD",
"details":{
"subtotal":"7.47"
}
},
"description":"This is the payment transaction description."
}
],
"links":[
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y",
"rel":"self",
"method":"GET"
},
{
"href":"https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=EC-60U79048BN7719609",
"rel":"approval_url",
"method":"REDIRECT"
},
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y/execute",
"rel":"execute",
"method":"POST"
}
]
}
2) 获得付款批准
请注意上面示例中的 HATEOAS 链接。将用户引导至 PayPal 网站上的approval_url,以便用户批准付款。用户必须先批准付款,然后您才能执行和完成销售。
3) 执行付款
当用户批准付款时,PayPal 将用户重定向到指定的 return_url
付款创建时间。付款人 ID 和付款 ID 附加到返回 URL,如 PayerID 和 paymentId:
http://return_url?paymentId=PAY-6RV70583SB702805EKEYSZ6Y&token=EC-60U79048BN7719609&PayerID=7E7MGXCWTTKK2
执行支付时不需要附加到返回 URL 的令牌值。
要在用户批准后执行付款,请拨打/payment/execute/ 电话。在请求正文中,使用附加到返回 URL 的 payer_id 值。在标头中,使用您在创建付款时使用的访问令牌。
curl https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y/execute/ \
-v \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer accessToken' \
-d '{ "payer_id" : "7E7MGXCWTTKK2" }'
注意:付款完成后,称为销售。然后,您可以查看销售情况并进行退款。
希望对你有帮助!