Step 1. Create and process the order on Sublytics
Run the doAdd
and doProcess
, or doAddProcess
endpoint in to create the order. And we will create the order on PayPal.
In doProcess
or doAddProcess
, need to pass the payment method id of 6 (Paypal) and the redirect_url
defining where to redirect the customer after they approves the transaction.
Example request for doAddProcess
## doAddProcess Paypal Request
curl -X "POST" "https://{your_sublytics_domain}/api/order/doAddProcess" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
--data-urlencode "user_id=XXXXX" \
--data-urlencode "user_password=XXXXX" \
--data-urlencode "email=customer@testorder.com" \
--data-urlencode "phone=1114000880" \
--data-urlencode "bill_fname=Test" \
--data-urlencode "bill_lname=User" \
--data-urlencode "bill_country=US" \
--data-urlencode "bill_address1=123 test Order" \
--data-urlencode "bill_address2=" \
--data-urlencode "bill_city=Test" \
--data-urlencode "bill_state=CO" \
--data-urlencode "bill_zipcode=18966" \
--data-urlencode "shipping_same=1" \
--data-urlencode "offers=[{\"offer_id\":89, \"order_offer_quantity\": 1,\"order_offer_price\":34.99}]" \
--data-urlencode "payment_method_id=6" \
--data-urlencode "campaign_id=2" \
--data-urlencode "redirect_url=http://myhostedsite.com/complete_paypal" \
--data-urlencode "connection_id=1"
Step 2 : Redirect the customer to the approve page
The response from the previous call contains the url where you need to redirect the customer to in order to approve the transaction in the post_data
attribute.
Response from doProcess or doAddProcess
## Response
{
"success": true,
"message": "Order successful",
"data": {
"transaction": {
"success": true,
"response_code": 101,
"response": "Success",
"gateway_response_id": "5GF201864P28XXXX",
"merchant_id": "71",
"merchant_descriptor": "",
"post_data": "https://www.sandbox.paypal.com/checkoutnow?token=5GF201864P28XXXX",
"gateway_response_description": "",
"gateway_hard_decline": "",
"transaction_id": 4437557,
"transaction_total": "34.99",
"customer_id": 237002,
"order_id": 840741,
"order": {
"id": "840741",
"customers_address_billing_id": "855782",
"customers_address_shipping_id": "855782",
"customer_card_id": "752771",
"order_offers": []
}
}
}
}
After the user completes the flow on PayPal, they will then be redirected to the url you passed in the initial request (redirect_url
), in all cases (approve and cancel). When the user is directed back to your hosted page, the query parameter of token
will be used to complete the order in Sublytics.
Example : redirect_url
?token=5GF201864P28XXXX&PayerID=UKE2LUXXXXXX&ba_token=BA-0N8326XXXXXXX
NOTE : If processing a $0 transaction with PayPal, we will just attempt to do a vault with PayPal. In these cases, the query parameter to look for will be approval_token_id
instead of a token.
Example redirect_url&approval_token_id=5GF201864P28XXXX&approval_session_id=4EP47002XXXXXXX
Step 3 : Capture the order by requesting order/doProcessPaypal
Finally you need to call order/doProcessPaypal
to capture the order in paypal passing the token from the redirect as transaction_token. If using multiple PayPal accounts, you will need to pass the merchant_id as well that was returned from step 1 in order to route it to the proper PayPal account.
Request for doProcessPaypal
curl -X "POST" "https://{your_sublytics_domain}/api/order/doProcessPaypal" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
--data-urlencode "user_id=XXXXX" \
--data-urlencode "user_password=XXXXX" \
--data-urlencode "order_id=840741" \
--data-urlencode "transaction_token=5GF201864P28XXXX" \
--data-urlencode "merchant_id=71" // required if multiple paypal accounts on the same campaign
Process upsells
You can then process more orders for that customer using the order/doAddProcess
endpoint and can simply pass the customer_card_id for the customer payment information similar to the initial call. For instance here we are using the customer_id, customer_address_billing_id, customer_address_shipping_id and customer_card_id returned from Sublytics that was returned from both the Step 1 and Step 3 API calls.
curl -X "POST" "https://{your_sublytics_domain}/api/order/doAddProcess" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
--data-urlencode "user_id=XXXXX" \
--data-urlencode "user_password=XXXXX" \
--data-urlencode "offers=[{\"offer_id\":308, \"order_offer_quantity\": 1}]" \
--data-urlencode "payment_method_id=6" \
--data-urlencode "campaign_id=2" \
--data-urlencode "connection_id=1" \
--data-urlencode "customer_id=237002" \
--data-urlencode "customer_card_id=752771" \
--data-urlencode "customers_address_billing_id=855782" \
--data-urlencode "customers_address_shipping_id=855782" \
--data-urlencode "merchant_id=71"