我正在使用Paypal和Paypal Webhooks。当在客户端进行付款时,我会在后端收到有关其付款的通知。
结果是,我收到2条关于相同付款的通知。一个的状态为PENDING
,另一个的状态为COMPLETED
。即使它们是同一笔付款的详细信息,其ID也不同。为什么会这样?
我之所以问是因为,我想将所有待处理,已完成,被拒绝的事务存储到数据库中。我需要一些独特的东西,以便可以更新交易状态。如果同一笔付款具有不同的ID,如何在数据库中将PENDING更新为COMPLETED?
PAYMENT.CAPTURE.PENDING WEBHOOK数据
{
"id": "WH-05T33772A52658430-32J33305NG495525W",
"create_time": "2019-08-06T07:25:05.456Z",
"resource_type": "capture",
"event_type": "PAYMENT.CAPTURE.PENDING",
"summary": "Payment pending for EUR 1.0 EUR",
"resource": {
"amount": {
"currency_code": "EUR",
"value": "1.00"
},
"seller_protection": {
"status": "ELIGIBLE",
"dispute_categories": [
"ITEM_NOT_RECEIVED",
"UNAUTHORIZED_TRANSACTION"
]
},
"update_time": "2019-08-06T07:25:00Z",
"create_time": "2019-08-06T07:25:00Z",
"final_capture": true,
"invoice_id": "6,7,1565076281554.6213",
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/payments/captures/2W106091AH697743F",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v2/payments/captures/2W106091AH697743F/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/0JA94285K3916615D",
"rel": "up",
"method": "GET"
}
],
"id": "2W106091AH697743F",
"status_details": {
"reason": "RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION"
},
"status": "PENDING"
},
"status": "SUCCESS",
"transmissions": [
{
"webhook_url": "https://giorgilagidze.com/api/payments/paypal/ipn",
"response_headers": {
"Transfer-Encoding": "chunked",
"X-Frame-Options": "SAMEORIGIN",
"X-RateLimit-Remaining": "56",
"Cache-Control": "no-cache, private",
"Server": "nginx/1.15.8",
"X-Content-Type-Options": "nosniff",
"Connection": "keep-alive",
"Vary": "Accept-Encoding",
"X-RateLimit-Limit": "60",
"X-XSS-Protection": "1; mode=block",
"Date": "Tue, 06 Aug 2019 07:26:16 GMT",
"Content-Type": "text/html; charset=UTF-8"
},
"transmission_id": "521fe300-b81b-11e9-bdaa-7b0f83d3d8cf",
"status": "SUCCESS",
"timestamp": "2019-08-06T07:25:09Z"
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-05T33772A52658430-32J33305NG495525W",
"rel": "self",
"method": "GET",
"encType": "application/json"
},
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-05T33772A52658430-32J33305NG495525W/resend",
"rel": "resend",
"method": "POST",
"encType": "application/json"
}
],
"event_version": "1.0",
"resource_version": "2.0"
}
CHECKOUT.ORDER.APWEBHOOK数据
{
"id": "WH-8L74536230699424S-3UL381024U924281P",
"create_time": "2019-08-06T07:25:02.923Z",
"resource_type": "checkout-order",
"event_type": "CHECKOUT.ORDER.APPROVED",
"summary": "An order has been approved by buyer",
"resource": {
"update_time": "2019-08-06T07:25:00Z",
"create_time": "2019-08-06T07:24:43Z",
"purchase_units": [
{
"reference_id": "default",
"amount": {
"currency_code": "EUR",
"value": "1.00"
},
"payee": {
"email_address": "gioskofield-facilitator@gmail.com",
"merchant_id": "M8FBTS3ZCRGCE"
},
"invoice_id": "6,7,1565076281554.6213",
"shipping": {
"name": {
"full_name": "test buyer"
},
"address": {
"address_line_1": "1 Main St",
"admin_area_2": "San Jose",
"admin_area_1": "CA",
"postal_code": "95131",
"country_code": "US"
}
},
"payments": {
"captures": [
{
"id": "2W106091AH697743F",
"status": "PENDING",
"status_details": {
"reason": "RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION"
},
"amount": {
"currency_code": "EUR",
"value": "1.00"
},
"final_capture": true,
"seller_protection": {
"status": "ELIGIBLE",
"dispute_categories": [
"ITEM_NOT_RECEIVED",
"UNAUTHORIZED_TRANSACTION"
]
},
"invoice_id": "6,7,1565076281554.6213",
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/payments/captures/2W106091AH697743F",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v2/payments/captures/2W106091AH697743F/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/0JA94285K3916615D",
"rel": "up",
"method": "GET"
}
],
"create_time": "2019-08-06T07:25:00Z",
"update_time": "2019-08-06T07:25:00Z"
}
]
}
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/0JA94285K3916615D",
"rel": "self",
"method": "GET"
}
],
"id": "0JA94285K3916615D",
"intent": "CAPTURE",
"payer": {
"name": {
"given_name": "test",
"surname": "buyer"
},
"email_address": "gioskofield-buyer@gmail.com",
"payer_id": "UCCQBA8S6GUR4",
"address": {
"country_code": "US"
}
},
"status": "COMPLETED"
},
"status": "SUCCESS",
"transmissions": [
{
"webhook_url": "https://giorgilagidze.com/api/payments/paypal/ipn",
"response_headers": {
"Transfer-Encoding": "chunked",
"X-Frame-Options": "SAMEORIGIN",
"X-RateLimit-Remaining": "60",
"Cache-Control": "no-cache, private",
"Server": "nginx/1.15.8",
"X-Content-Type-Options": "nosniff",
"Connection": "keep-alive",
"Vary": "Accept-Encoding",
"X-RateLimit-Limit": "60",
"X-XSS-Protection": "1; mode=block",
"Date": "Tue, 06 Aug 2019 07:26:17 GMT",
"Content-Type": "text/html; charset=UTF-8"
},
"transmission_id": "503d1940-b81b-11e9-bdaa-7b0f83d3d8cf",
"status": "SUCCESS",
"timestamp": "2019-08-06T07:25:06Z"
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-8L74536230699424S-3UL381024U924281P",
"rel": "self",
"method": "GET",
"encType": "application/json"
},
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-8L74536230699424S-3UL381024U924281P/resend",
"rel": "resend",
"method": "POST",
"encType": "application/json"
}
],
"event_version": "1.0",
"resource_version": "2.0"
}