Get details (parent payment) of a refund

左心房为你撑大大i 提交于 2019-12-11 03:07:28

问题


How is it possible to get the parent payment of a refund, which was notified to me by PayPal?

I got this notification (webhook) from PayPal:

{
  "create_time": "2015-02-20T10:56:36Z",
  "event_type": "PAYMENT.SALE.REFUNDED",
  "id": "WH-XXX-XXX",
  "links": [
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-XXX-XXX",
      "method": "GET",
      "rel": "self"
    },
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-XXX-XXX/resend",
      "method": "POST",
      "rel": "resend"
    }
  ],
  "resource": {
    "amount": {
      "currency": "EUR",
      "details": {
        "subtotal": "-XX.XX",
        "tax": "XX.XX"
      },
      "total": "-XX.XX"
    },
    "create_time": "2015-02-20T10:55:10Z",
    "id": "XXX",
    "links": [
      {
        "href": "https://10.73.133.169:17881/v1/payments/refund/XXX",
        "method": "GET",
        "rel": "self"
      }
    ],
    "state": "completed"
  },
  "resource_type": "sale",
  "summary": "A EUR XX.XX EUR sale payment was refunded"
}

If i take the resource -> id and do the following request with the PayPal PHP-SDK, i get a refund object but without the "parent_payment" field (documented here: https://developer.paypal.com/docs/api/#look-up-a-refund)

PayPal\Api\Refund::get($id, $api);

Every other call like..

PayPal\Api\Sale::get($id, $api);

or

PayPal\Api\Transaction::get($id, $api);

or

PayPal\Api\Payment::get($id, $api);

fails!

What is wrong with my notifications or the methods i am using?

UPDATE: Here is my response from the Refund::get() lookup:

{
  "id": "XXX",
  "create_time": "2015-02-20T10:55:10Z",
  "state": "completed",
  "amount": {
    "total": "-XX.XX",
    "currency": "EUR",
    "details": {
      "subtotal": "-XX.XX",
      "tax": "XX.XX"
    }
  },
  "links": [
    {
      "href": "https://api.paypal.com/v1/payments/refund/XXX",
      "rel": "self",
      "method": "GET"
    }
  ]
}

回答1:


Generally, when you do a lookup on Refund, you will get a response, that includes parent_payment that should have the PaymentID that could be used to retrieve the payment object.

This is how the response would look like:

Refund:get()

{
"id": "3KJ86032KA0123648",
"create_time": "2015-02-23T22:25:31Z",
"update_time": "2015-02-23T22:25:31Z",
"state": "completed",
"amount": {
    "total": "-0.01",
    "currency": "USD"
},
"sale_id": "4JE73984NP0170710",
"parent_payment": "PAY-0J694581CG996145EKTV2RWA",
"links": [
    {
        "href": "https://api.sandbox.paypal.com/v1/payments/refund/3KJ86032KA0123648",
        "rel": "self",
        "method": "GET"
    },
    {
        "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-0J694581CG996145EKTV2RWA",
        "rel": "parent_payment",
        "method": "GET"
    },
    {
        "href": "https://api.sandbox.paypal.com/v1/payments/sale/4JE73984NP0170710",
        "rel": "sale",
        "method": "GET"
    }
]

}

Payment:get();

{
    "id": "PAY-1XX00578GL815852KKTV2RGI",
    "create_time": "2015-02-23T22:24:25Z",
    "update_time": "2015-02-23T22:24:28Z",
    "state": "approved",
    "intent": "sale",
    "payer": {
        "payment_method": "credit_card",
        "funding_instruments": [
            {
                "credit_card": {
                    "type": "visa",
                    "number": "xxxxxxxxxxxx2259",
                    "expire_month": "11",
                    "expire_year": "2019",
                    "first_name": "Joe",
                    "last_name": "Shopper"
                }
            }
        ]
    },
    "transactions": [
        {
            "amount": {
                "total": "20.00",
                "currency": "USD",
                "details": {
                    "subtotal": "17.50",
                    "tax": "1.30",
                    "shipping": "1.20"
                }
            },
            "description": "Payment description",
            "invoice_number": "54eba89962365",
            "item_list": {
                "items": [
                    {
                        "name": "Ground Coffee 40 oz",
                        "price": "7.50",
                        "currency": "USD",
                        "quantity": "1",
                        "description": "Ground Coffee 40 oz",
                        "tax": "0.30"
                    },
                    {
                        "name": "Granola bars",
                        "price": "2.00",
                        "currency": "USD",
                        "quantity": "5",
                        "description": "Granola Bars with Peanuts",
                        "tax": "0.20"
                    }
                ]
            },
            "related_resources": [
                {
                    "sale": {
                        "id": "40F92773GL716624V",
                        "create_time": "2015-02-23T22:24:25Z",
                        "update_time": "2015-02-23T22:24:28Z",
                        "amount": {
                            "total": "20.00",
                            "currency": "USD"
                        },
                        "state": "partially_refunded",
                        "parent_payment": "PAY-1XX00578GL815852KKTV2RGI",
                        "links": [
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/sale/40F92773GL716624V",
                                "rel": "self",
                                "method": "GET"
                            },
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/sale/40F92773GL716624V/refund",
                                "rel": "refund",
                                "method": "POST"
                            },
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1XX00578GL815852KKTV2RGI",
                                "rel": "parent_payment",
                                "method": "GET"
                            }
                        ]
                    }
                },
                {
                    "refund": {
                        "id": "50V96618DN7676452",
                        "create_time": "2015-02-23T22:24:28Z",
                        "update_time": "2015-02-23T22:24:28Z",
                        "state": "completed",
                        "amount": {
                            "total": "-0.01",
                            "currency": "USD"
                        },
                        "sale_id": "40F92773GL716624V",
                        "parent_payment": "PAY-1XX00578GL815852KKTV2RGI",
                        "links": [
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/refund/50V96618DN7676452",
                                "rel": "self",
                                "method": "GET"
                            },
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1XX00578GL815852KKTV2RGI",
                                "rel": "parent_payment",
                                "method": "GET"
                            },
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/sale/40F92773GL716624V",
                                "rel": "sale",
                                "method": "GET"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "links": [
        {
            "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1XX00578GL815852KKTV2RGI",
            "rel": "self",
            "method": "GET"
        }
    ]
}


来源:https://stackoverflow.com/questions/28676798/get-details-parent-payment-of-a-refund

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!