Hello @leoshelp ,
Thank you for posting to the PayPal Sandbox Community.
v1 payments is deprecated, and was replaced by v2 orders api, which is probably part of the issue you are facing with testing. The replacement was v2 orders api, which has the ability to process both PayPal and Credit Cards. So in the create order api call the payment_source declares paypal or card, and the experience_context includes the return_url.
We do have a Python example for our Create order api available. Since v1 payments is deprecated, it may be impacting the return_url.
Here is the documentation for v2 orders api:
https://developer.paypal.com/docs/api/orders/v2/#orders_create
I copied the Python code from the above documentation: The access_token is an example, you will still need to request an access_token the same way that you have been. You can update the shipping_preference to GET_FROM_FILE to get the shipping address from PayPal or NO_SHIPPING which will remove the shipping address from the transaction. The return_url is part of the payment_source object, so that is where you declare it.
import requests
headers = {
'Content-Type': 'application/json',
'PayPal-Request-Id': '7b92603e-77ed-4896-8e78-5dea2050476a',
'Authorization': 'Bearer 6V7rbVwmlM1gFZKW_8QtzWXqpcwQ6T5vhEGYNJDAAdn3paCgRpdeMdVYmWzgbKSsECednupJ3Zx5Xd-g',
}
data = '{ "intent": "CAPTURE", "purchase_units": [ { "reference_id": "d9f80740-38f0-11e8-b467-0ed5f89f718b", "amount": { "currency_code": "USD", "value": "100.00" } } ], "payment_source": { "paypal": { "experience_context": { "payment_method_preference": "IMMEDIATE_PAYMENT_REQUIRED", "brand_name": "EXAMPLE INC", "locale": "en-US", "landing_page": "LOGIN", "shipping_preference": "SET_PROVIDED_ADDRESS", "user_action": "PAY_NOW", "return_url": "https://example.com", "cancel_url": "https://example.com/cancelUrl" } } } }'
response = requests.post('https://api-m.sandbox.paypal.com/v2/checkout/orders', headers=headers, data=data)
After you create the order, you should receive the url link for the buyer to approve the payment in the response (for PayPal Transactions).
Once the buyer approves the payment, they will be returned to the return url of your choice. then you send the Capture payment for order api call:
https://developer.paypal.com/docs/api/orders/v2/#orders_capture (below example has an order id in it, you would pass in the order id that is returned in the create order api call)
import requests
headers = {
'Content-Type': 'application/json',
'PayPal-Request-Id': '7b92603e-77ed-4896-8e78-5dea2050476a',
'Authorization': 'Bearer access_token6V7rbVwmlM1gFZKW_8QtzWXqpcwQ6T5vhEGYNJDAAdn3paCgRpdeMdVYmWzgbKSsECednupJ3Zx5Xd-g',
}
response = requests.post('https://api-m.sandbox.paypal.com/v2/checkout/orders/5O190127TN364715T/capture', headers=headers)
Thank you,
Jennifer
MTS
PayPal
... View more