PayPal
Process using PayPal with a Headless Site
Why use the Order API
If you are using Vrio fully headless, you can still create orders and process them using PayPal.
There are many different combinations to accomplish this, at the bottom you will see multiple recipe's to see different examples. In this guide, we are explaining the most common method which will allow the most flexibility.
Create a Cart
First you will need to create a cart using the POST /carts API endpoint. This cart will be referenced in order to create a PayPal token in the next step. Here you will need to pass the campaign_id and the offers array. This will return a cart_token to be used in step 2.
Get Paypal Token
In the response from #1, you will use the POST /carts/{cart_token}
/payment_tokens API endpoint. You will pass the cart_token from step 1, the payment_method_id (6 for PayPal), and the redirect URL for the user to be directed to after they finish the PayPal form.
The redirect_url is a page that you will host. After the User has verified with Paypal, this is where you will redirect the user to to complete the flow and post the token to Vrio in the next step.
In the response on this call, Vrio will return 2 values.
- post_data This value is returned from PayPal that will contain the URL to direct the user to. Once they are finished with this step, the user will redirect back to the redirect_url that you provided in this call.
- payment_token_id This value you will use in the next step that will allow you to get all the customer information. Is it used in the next step.
Get Customer Details
This step is needed to collect the customer information from PayPal ( email, name, address, etc.. ). Use the
GET /carts/{cart_token}
/payment_tokens/{payment_token_id}
.
You need to pass the cart_token from step 1, and the payment_token_id from step 2. Also, when using multiple PayPals, make sure you get the merchant_id from this response as well, it will be needed for step 4. This will allow you to get all needed customer details for the final step
Process Order
Once you have all this information, you will place the order the same way you would do for a credit card using the POST /orders, but instead of credit card information, you will pass the payment_token the previous step, along with the payment_method_id=6 and the merchant_id from step 3.
NOTE : it is not required, but its recommend passing the cart_token from step 1 when processing the order. This will allow us to tie the cart to the order for reporting.
See it in Action
Check out our recipe below
<block:tutorial-tile>
{{
"backgroundColor": "#018FF4",
"emoji": "🦉",
"id": "659f4dae69e492006df1b3a4",
"link": "https://api.vrio.com/v1.0/recipes/headless-paypal",
"slug": "headless-paypal",
"title": "Headless Paypal"
}}
</block:tutorial-tile>
Updated 21 days ago