I'm new to Paypal API. I wants to save a JSON on the PayPal so that I can get it as response after capturing PayPal order. I'm using PYTHON
Data I want to store is array of products.
products = [
{'id': 'id_1', 'price': 100, 'quantity': 2},
{'id': 'id_2', 'price': 50, 'quantity': 2}
]
After searching I came to know about application_context parameter in paypal. I'm storing my data in JSON like this and sending it to /v2/checkout/orders to get order ID
paypal_json = {"intent": "CAPTURE",
"purchase_units": [{"amount": {"currency_code": CURRENCY, "value": total_price}}],
'application_context': {"products": products}}
I'm trying to get application_context using PayPal API by this but it does not contain my application_context data.
PayPal Orders_Get API
access_token = generate_access_token()
headers = {"Authorization": f"Bearer {access_token}"}
response = requests.get(f"https://api-m.paypal.com/v2/checkout/orders/{order_id}", headers=headers)
print(response.json(), response.status_code) # it does not contain application_context
Right now I'm using client-side localStorage. But client can easily change that data after approval of order and data sent to me can be updated one for which client didn't even paid. And that will get stored in Database. That is why I need a secure way to store data related to order. I can use server to created order and store it in database with orderID of paypal and mark it as uncomplete until it is approved. But that will be waste of memory if client will not approve order.
That is why I wants to know how can i store my products data on PayPal and retrieve it after capturing of order. Can anyone please help me?
I have tried to send get request to PayPal API to get order data but it does not contain application_context which I added in JSON while creating PayPal order
The application_context parameter is deprecated, do not use it. Also even before it was deprecated, it was never used to store product information.
Product information belongs inside the items
array within each purchase_unit. See the create order API reference for details.
Item information will be visible during order approval, and stored in the transaction record in www.paypal.com . However, it is not returned in API calls.
You should store item information in your own database records.
To reconcile your own order records with PayPal captures, you can set an invoice_id
parameter for the purchase_unit. The invoice_id value should be unique, never before used for a captured transaction on that account. Duplicate capture attempts are blocked.