接入流程文档见:https://blog.csdn.net/change_on/article/details/73881791
支付回调文档见:https://www.freesion.com/article/34141340978/
paypal官方文档:
预下单:https://developer.paypal.com/docs/api/payments/v1/#payment_create
IPN支付回调:https://developer.paypal.com/api/nvp-soap/ipn/IPNIntro/#id08CKFJ00JYK
刚开始看文档以为paypal和支付宝一样,准备使用接收回调的方式处理支付结果的,测试中发现需要调用executePayment接口才能收到回调通知,这样的话不需用到退款等功能的话就没必要接入支付回调了。
在支付成功接口里面处理处理自己的逻辑就行了。
获取关键字段
JSONArray transactions = result.getJSONArray("transactions");
JSONObject transaction = transactions.getJSONObject(0);
JSONObject amountObj = transaction.getJSONObject("amount");
JSONArray relatedResources = transaction.getJSONArray("related_resources");
JSONObject sale = relatedResources.getJSONObject(0).getJSONObject("sale");
String outOrderIdStr = transaction.getString("custom");// 自己业务的订单号
String totalAmountStr = amountObj.getString("total");// 支付金额
String totalCurrencyStr = transaction.getString("currency");// 支付货币
String payChannelId = sale.getString("id");// 支付渠道订单号
executePayment接口返回结果
{
"update_time": "2023-03-16T14:10:10Z",
"create_time": "2023-03-16T14:06:59Z",
"links": [{
"method": "GET",
"rel": "self",
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAYID-MQJSFAY41A60628MN734274A"
}],
"id": "PAYID-MQJSFAY41A60628MN734274A",
"state": "approved",
"transactions": [{
"payee": {
"merchant_id": "ZTV2ES9L5E5PN",
"email": "xx@cmge.com"
},
"amount": {
"total": "0.10",
"currency": "USD",
"details": {
"insurance": "0.00",
"shipping": "0.00",
"shipping_discount": "0.00",
"subtotal": "0.10",
"discount": "0.00",
"handling_fee": "0.00"
}
},
"related_resources": [{
"sale": {
"parent_payment": "PAYID-MQJSFAY41A60628MN734274A",
"amount": {
"total": "0.10",
"currency": "USD",
"details": {
"insurance": "0.00",
"shipping": "0.00",
"shipping_discount": "0.00",
"subtotal": "0.10",
"discount": "0.00",
"handling_fee": "0.00"
}
},
"payment_mode": "INSTANT_TRANSFER",
"update_time": "2023-03-16T14:10:10Z",
"create_time": "2023-03-16T14:10:10Z",
"protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"transaction_fee": {
"currency": "USD",
"value": "0.10"
},
"protection_eligibility": "ELIGIBLE",
"links": [{
"method": "GET",
"rel": "self",
"href": "https://api.sandbox.paypal.com/v1/payments/sale/8NU85203XK009112F"
}, {
"method": "POST",
"rel": "refund",
"href": "https://api.sandbox.paypal.com/v1/payments/sale/8NU85203XK009112F/refund"
}, {
"method": "GET",
"rel": "parent_payment",
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAYID-MQJSFAY41A60628MN734274A"
}],
"id": "8NU85203XK009112F",
"state": "completed"
}
}],
"item_list": {
"shipping_address": {
"country_code": "US",
"city": "San Jose",
"state": "CA",
"recipient_name": "liu nen",
"postal_code": "95131",
"line1": "1 Main St"
}
},
"custom": "217255803227471874",
"description": "goodname"
}],
"failed_transactions": [],
"intent": "sale",
"payer": {
"payment_method": "paypal",
"status": "VERIFIED",
"payer_info": {
"country_code": "US",
"last_name": "nen",
"payer_id": "CRECMZWEPZXA6",
"shipping_address": {
"country_code": "US",
"city": "San Jose",
"state": "CA",
"recipient_name": "liu nen",
"postal_code": "95131",
"line1": "1 Main St"
},
"first_name": "liu",
"email": "xx@qq.com"
}
},
"cart": "4WX621310W422174Y"
}
写笔记时看到这篇文章,感觉也不错,记录一下