paypal支付接口开发笔记--Java版

接入流程文档见: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"
}

写笔记时看到这篇文章,感觉也不错,记录一下

https://blog.csdn.net/MrwanZH/article/details/109540847?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7ERate-1-109540847-blog-129717065.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7ERate-1-109540847-blog-129717065.pc_relevant_default&utm_relevant_index=2

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值