After you
# step 0: get token
curl --request POST --compressed --silent 'https://api-m.sandbox.paypal.com/v1/oauth2/token' --header 'accept: application/json' --header 'accept-language: en_us' --user '<clientid>:<secret>' --data 'grant_type=client_credentials'
# step 1: create the order (use the token from step 0)
curl --request POST --compressed --silent 'https://api-m.sandbox.paypal.com/v2/checkout/orders' --header 'content-type: application/json' --header 'authorization: bearer <token>' \
--data '{
"intent": "CAPTURE",
"purchase_units": [{"amount": {"value":"10.00", "currency_code":"USD"},
"description": "hello",
"application_context": {"brand_name":"mybrand", "shipping_preference":"NO_SHIPPING", "return_url":""}}]
}'
you show the user the approval page, where he can enter his credentials and approve the payment:
# step 2: show the user the approval page
https://www.sandbox.paypal.com/checkoutnow?<order_id>
I'm trying to implement step 2 in the client, with Javascript, without redirects (ie. without passing a return_url to /checkout/orders in step 1), and without using the PayPal buttons that come with the JS SDK.
This means you open a new window
window.open('https://www.sandbox.paypal.com/checkoutnow?<order_id>')
and let the user do his thing.
I've got everything working well, except the part that closes the approval window in step 2.
After the user logs in and approves the order in the newly created window, how can I automatically close it?