'Store custom metadata with Paypal transaction
I am extending an application that is currently having stripe as a Payment processor. The architecture is implemented in such a way that I am not storing any of the transaction and customer information in the application database in order to meet the compliances. So all of data is being stored in Stripe as transaction metadata.
Now I need to extend the application to add Paypal Payment Gateways, but after going through the documentation I can't find a metadata option available in the PayPal Transaction API just like its there in Stripe.
I have tried PayPal's create order API with metadata as suggested in v1 https://developer.paypal.com/docs/business/checkout/server-side-api-calls/create-order/
createOrder: function(data, actions) {
return actions.order.create({
metadata:{
"cid":1233,
"dgn":"AH-GHGJTTHHHJ",
"ct":"X-HGD898989","tfn":"xyz params",
"type":"2",
"lo":"lorem ipsum is a dummy text and hope it works"
},
purchase_units: [
{
"description":'xyz P30 Pro mobile',
"amount":{"currency_code":"USD","value":199}
}]
});
},
But on retrieving the transaction by TX_ID i donot get the metadata object back.
So anyone who faced this challenge in the past and can suggest a workaround to achieve this with payPal will be highly appricated.
Solution 1:[1]
Apart from a unique (never used before for a completed payment) invoice_id
for the transaction, the only custom metadata field in PayPal is custom_id
, documented here: https://developer.paypal.com/docs/api/orders/v2/#orders-create-request-body
If you need additional fields, store them locally based on your own order/invoice ID or the resulting PayPal Transaction ID and look them up later as needed. Your most sensitive data with compliance issues might possibly go into custom_id
as a serialized JSON string, if it is small enough (127 chars)
Purchase item information can go in an "items" array, which requires the amount have a "breakdown" object. See the example within the docs,
createOrder: function(data, actions) {
return actions.order.create({
"purchase_units": [{
"amount": {
"currency_code": "USD",
"value": "100",
"breakdown": {
"item_total": { /* Required when including the `items` array */
"currency_code": "USD",
"value": "100"
}
}
},
"items": [
{
"name": "First Product Name", /* Shows within upper-right dropdown during payment approval */
"description": "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
"unit_amount": {
"currency_code": "USD",
"value": "50"
},
"quantity": "2"
},
]
}]
});
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |