接入顺序:
- Get Access Token
后端做,拿到服务的token
POST https://api.sandbox.paypal.com/v1/oauth2/token
header:{ "PayPal-Request-Id": "platform-1670382693555", "Authorization": "Basic QVRz****************************************************************************************************************************************************************************************************************akE="}
body :{
grant_type=client_credentials
}
- Create Order
后端做,计算金额 生成orderId
POST https://api.sandbox.paypal.com/v2/checkout/orders
header:{ "PayPal-Request-Id": "platform-1670382693941", "Content-Type": "application/json", "cache-control": "no-cache", "Authorization": "Bearer A21******************************************************************************************NPWQ"}
body:{ "intent": "CAPTURE", "purchase_units": [ { "reference_id": "PU1", "description": "Camera Shop", "invoice_id": "INV-CameraShop-1670382691590", "custom_id": "CUST-CameraShop", "amount": { "currency_code": "USD", "value": 300, "breakdown": { "item_total": { "currency_code": "USD", "value": 300 } } }, "items": [ { "name": "DSLR Camera", "description": "Black Camera - Digital SLR", "sku": "sku01", "unit_amount": { "currency_code": "USD", "value": 300 }, "quantity": "1", "category": "PHYSICAL_GOODS" } ] } ]}
- Order Details
可选
GET https://api.sandbox.paypal.com/v2/checkout/orders/2LS61083EB930562C
header:{ "PayPal-Request-Id": "platform-1670382702710", "Content-Type": "application/json", "Authorization": "Bearer A21******************************************************************************************NPWQ"}
- Patch Order
前端做 用户授权
PATCH https://api.sandbox.paypal.com/v2/checkout/orders/2LS61083EB930562C
header: { "PayPal-Request-Id": "platform-1670382703115", "Content-Type": "application/json", "Authorization": "Bearer A21******************************************************************************************NPWQ"}
body:[ { "op": "replace", "path": "/purchase_units/@reference_id=='PU1'/amount", "value": { "currency_code": "USD", "value": 350, "breakdown": { "item_total": { "currency_code": "USD", "value": 300 }, "shipping": { "currency_code": "USD", "value": 20 }, "tax_total": { "currency_code": "USD", "value": 30 } } } }]
- Immediate Capture
后端收钱
POST https://api.sandbox.paypal.com/v2/checkout/orders/2LS61083EB930562C/capture/
header:{ "PayPal-Request-Id": "platform-1670382706795", "Content-Type": "application/json", "Authorization": "Bearer A21******************************************************************************************NPWQ"}
发表回复