paypal支付交易数据

paypal支付交易成功后返回的对象中就有交易信息(包括支付交易ID,支付金额,支付人信息,收款人信息等),同时如果你开启了消息通知paypal会同时给你推送一条差不多内容的交易信息。

支付成功返回数据:

我们在调paypal支付接口(execute)接口支付成功或者失败paypal返回的数据。

id:为本次的数据ID,唯一。

payer:付款人的信息。

transations:支付交易信息。

transations.amount:支付金额信息,总价,税费,运费等。

transations.item_list:商品信息。

transations.shipping_address:收货地址信息。

transations.related_resources:里面就是收款人的信息。

transations.related_resources.state:这个状态就是收款人的交易状态,只要是completed就表示我们收到了钱,钱到账了就什么都好说了,交易成功。

{
    "id": "PAY-1BV5911839643144YKSCUA7Q",
    "create_time": "2014-12-08T06:09:02Z",
    "update_time": "2014-12-08T06:10:51Z",
    "state": "approved",
    "intent": "sale",
    "payer": {
        "payment_method": "paypal",
        "payer_info": {
            "email": "[email protected]",
            "first_name": "Test",
            "last_name": "Buyer",
            "payer_id": "JARYJK2TES6C6",
            "shipping_address": {
                "line1": "NO 1 Nan Jin Road",
                "city": "Shanghai",
                "state": "Shanghai",
                "postal_code": "200000",
                "country_code": "CN",
                "recipient_name": "Buyer Test"
            }
        }
    },
    "transactions": [
        {
            "amount": {
                "total": "20.00",
                "currency": "USD",
                "details": {
                    "subtotal": "17.50",
                    "tax": "1.30",
                    "shipping": "1.20"
                }
            },
            "description": "Payment description",
            "item_list": {
                "items": [
                    {
                        "name": "Ground Coffee 40 oz",
                        "price": "7.50",
                        "currency": "USD",
                        "quantity": "1"
                    },
                    {
                        "name": "Granola bars",
                        "price": "2.00",
                        "currency": "USD",
                        "quantity": "5"
                    }
                ],
                "shipping_address": {
                    "recipient_name": "Buyer Test",
                    "line1": "NO 1 Nan Jin Road",
                    "city": "Shanghai",
                    "state": "Shanghai",
                    "postal_code": "200000",
                    "country_code": "CN"
                }
            },
            "related_resources": [
                {
                    "sale": {
                        "id": "74V52932AB811673C",
                        "create_time": "2014-12-08T06:09:02Z",
                        "update_time": "2014-12-08T06:10:51Z",
                        "amount": {
                            "total": "20.00",
                            "currency": "USD"
                        },
                        "payment_mode": "INSTANT_TRANSFER",
                        "state": "completed",
                        "protection_eligibility": "ELIGIBLE",
                        "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
                        "parent_payment": "PAY-1BV5911839643144YKSCUA7Q",
                        "links": [
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/sale/74V52932AB811673C",
                                "rel": "self",
                                "method": "GET"
                            },
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/sale/74V52932AB811673C/refund",
                                "rel": "refund",
                                "method": "POST"
                            },
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1BV5911839643144YKSCUA7Q",
                                "rel": "parent_payment",
                                "method": "GET"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "links": [
        {
            "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1BV5911839643144YKSCUA7Q",
            "rel": "self",
            "method": "GET"
        }
    ]
}

同时服务器会收到ipn消息, 类似:

支付成功后paypal会同时往我们卖家账号那里配置的消息通知url推送一条消息数据,数据和支付成功大致一样。

由于paypal推送消息不止一次,正常情况下如果是 completed并且用户收到信息就不会再推了,如果推送失败或者交易状态发生改变,比如出现资金冻结,发起退款等事情的时候,paypal的就会有多次推送了,那么我们要怎样判断是第一次推送还是多次推送呢?

查看数据我们发现数据中有交易号txn_id,如果出现多次推送就会多出一个属性parent_txn_id,这个就是原始交易ID,所以我们可以判断有没有这个属性,这个属性有没有值来确定是第一次还是第二次推送。

array (
  'act' => 'ipn',
  'mc_gross' => '20.00',
  'invoice' => '548531d624f59',
  'protection_eligibility' => 'Eligible',
  'address_status' => 'unconfirmed',
  'item_number1' => '',
  'tax' => '1.30',
  'item_number2' => '',
  'payer_id' => 'JARYJK2TES6C6',
  'address_street' => 'NO 1 Nan Jin Road',
  'payment_date' => '21:04:35 Dec 07, 2014 PST',
  'payment_status' => 'Completed',
  'charset' => 'gb2312',
  'address_zip' => '200000',
  'mc_shipping' => '1.20',
  'mc_handling' => '0.00',
  'first_name' => 'Test',
  'mc_fee' => '0.98',
  'address_country_code' => 'CN',
  'address_name' => 'Buyer Test',
  'notify_version' => '3.8',
  'custom' => '',
  'payer_status' => 'unverified',
  'address_country' => 'China',
  'num_cart_items' => '2',
  'mc_handling1' => '0.00',
  'mc_handling2' => '0.00',
  'address_city' => 'Shanghai',
  'verify_sign' => 'AomRS5l2W2xlt2An.GaSrAzpCl-NACIvh3Pz0HtrSBZzfcIeqDPGrXSk',
  'payer_email' => '[email protected]',
  'mc_shipping1' => '0.00',
  'mc_shipping2' => '0.00',
  'tax1' => '0.00',
  'tax2' => '0.00',
  'txn_id' => '5CS19517SJ894934R',
  'payment_type' => 'instant',
  'last_name' => 'Buyer',
  'address_state' => 'Shanghai',
  'item_name1' => 'Ground Coffee 40 oz',
  'receiver_email' => '[email protected]',
  'item_name2' => 'Granola bars',
  'payment_fee' => '0.98',
  'quantity1' => '1',
  'quantity2' => '5',
  'receiver_id' => '937CP9PSMDS2A',
  'txn_type' => 'cart',
  'mc_gross_1' => '7.50',
  'mc_currency' => 'USD',
  'mc_gross_2' => '10.00',
  'residence_country' => 'CN',
  'test_ipn' => '1',
  'transaction_subject' => '',
  'payment_gross' => '20.00',
  'ipn_track_id' => 'a9059421a1dd7',
)




你可能感兴趣的:(paypal)