# Three 3 secure flow This document will cover the flow of the three d secure checkout option ```mermaid sequenceDiagram autonumber participant Usr as User participant Clnt as Client participant Core as Core API participant PayG as PaymentGateway participant Adm as Admin Usr ->> Clnt : Adds items to Cart Clnt ->> Core : Shopping Cart Create Core ->> Clnt : Shopping Cart Usr ->> Clnt : Place order Clnt ->> Core : Online Order Create Core ->> Adm : Online Order Create Adm ->> Core : Online Order Created Core ->> PayG : Authorize Payment PayG ->> Core : Authorization Response - 3ds required Core ->> Adm : Payment Create Adm ->> Adm : Add Payment details to Order Core ->> Core : Set Order Status to awaiting_payment Core ->> Clnt : 3d secure link Clnt ->> Usr : 3d secure form Usr ->> Usr : Completes 3d secure form Clnt ->> Core : Complete order Core ->> Adm : Check Payment Status Adm ->> PayG : Check Payment Status PayG ->> Adm : Return Payment Status Adm ->> Adm : Set Order Status to authorized/declined Adm ->> Adm : Enqueues Order Processing Adm ->> Core : Payment Status Response Core ->> Clnt : Order Response Result ``` ## Create Order Endpoint: `POST /api/v2/orders` Creates the order ***Note*** - The orders with 3ds cards will stay blocked on `POST /api/v1/orders` because of backwards compatibility ### Parameters **Request body** ``` { "order": { "placed_via": "androidapp", "anonymous_id": "ad43bfe6-4e72-4566-9a34-2eb67490d789", "customer_origin": "marketplace", "shop_id": 191, "delivery_address": "33-02 35Th Ave", "delivery_city": "Queens", "delivery_postcode": "11106", "delivery_state": "NY", "delivery_telephone": "8042221111", "shipping_type": "delivery", "coupon_ids": [ 133290 ], "order_items_attributes": [ { "products_quantity": 1, "products_type_id": "4373636", "selection_ids": [ "36627751" ] }, { "products_quantity": 1, "products_type_id": "4373636", "selection_ids": [] } ], "payment_method_id": "5807", "tip_amount": "3.90", "payment_method": "credit", "customers_id": 16153583, "email": "emilija.t@slicelife.com", "delivery_first_name": "Emilija", "delivery_last_name": "Talevska Stojkovski", "delivery_name": "Emilija Talevska Stojkovski" }, "include_order_fees": true } ``` *The parameters stay the same as till now* ### Response If the payment is 3ds, the response is ``` { "order": { "uuid": "64b7bf41-92b2-4bbb-89ad-732007317502", "three_d_secure_link": "https://hooks.stripe.com/redirect/authenticate/src_0Lhuk8Fvs2hGANMszIiG4tAq?client_secret=src_client_secret_XHhNyeoZG6A6O75qvgaKhRlp&source_redirect_slug=test_YWNjdF8wWEhjRnZzMmhHQU5NczJXTzRiQixfTVFtSVo0WUM2UHpkNU1LQkYyOEtpQ0dqZHp0eDVXRA0100YBIM8yjt" } } ``` otherwise (the response stays the same, it returns the order) ``` { "order": { "id": 112857, "uuid": "c1ffb289-f011-4002-bc9b-175ca73543c6", "shipping_type": "delivery", "date_purchased": "2022-09-29T08:02:51.000-04:00", "delivery_address": "33-02 35Th Ave", "delivery_city": "Queens", "delivery_postcode": "11106", "delivery_state": "NY", "latitude": "40.7571861", "longitude": "-73.9268541", "delivery_telephone": "8042221111", "delivery_first_name": "Emilija", "delivery_last_name": "Talevska Stojkovski", "delivery_name": "Emilija Talevska Stojkovski", "payment_method": "credit", "email": "emilija.t@slicelife.com", "confirmed_at": null, "user_confirmed_delivered_at": null, "voided_at": null, "payment_status": "authorized", "progress_step": null, "promo_code_discount_amount": "0", "promo_code_tag": null, "service_fee_amount": "0.96", "slice_credit_discount": 0.0, "total_coupon_discount_amount": -5.0, "total": "46.21", "subtotal": "39.0", "tax": "3.45", "tip": "3.9", "shop_id": 191, "shop_name": "Napoli Pizza & Pasta", "shop_web_slug": "ny/astoria/11106/napoli-pizza-pasta", "shop_address": "33-02 35th Ave", "shop_city": "Astoria", "shop_state": "NY", "shop_zipcode": "11106", "shop_phone": "7185550156", "shop_latitude": "40.7571861", "shop_longitude": "-73.9268541", "shop_logo": "https://shop-logos.imgix.net/shops/191/original/191b.png", "shop_timezone": "EST", "invalid_selections": false, "min_eta_timestamp": "2022-09-29T08:44:51.000-04:00", "max_eta_timestamp": "2022-09-29T08:59:51.000-04:00", "eta_max": 57, "eta_min": 42, "placed_via": "androidapp", "coupons": [ { "id": 133290, "shop_id": 191, "name": "Test minimum amount", "description": "Test minimum amount", "discount_amount": "5", "pricing_type": "flat_discount", "parameters": {}, "coupon_conditions": [ { "id": 161354, "condition_type": "order_subtotal", "raw_parameters": "20", "customer_text": "Test minimum amount", "parameters": { "minimum_order_subtotal": 20 } } ] } ], "order_items": [ { "products_final_price": "18.5", "products_quantity": 1, "products_id": 2308333, "product_name": "Bolognese Pizza", "product_type_name": "Large (8 Slices)", "product_type_price": "18.5", "products_type_id": 4373636, "product_description": "With meatballs.", "order_item_selections": [ { "name": "Extra Cheese", "price": "2.0", "selection_id": 36627751, "addon_id": 3879185, "addon_name": "Whole Pizza Toppings" } ] }, { "products_final_price": "18.5", "products_quantity": 1, "products_id": 2308333, "product_name": "Bolognese Pizza", "product_type_name": "Large (8 Slices)", "product_type_price": "18.5", "products_type_id": 4373636, "product_description": "With meatballs.", "order_item_selections": [] } ], "user_facing_line_items": [ { "name": "Tax", "value": "$3.45" }, { "name": "Fee", "value": "$0.96" }, { "name": "Delivery Fee", "value": "$3.90" }, { "name": "Tip", "value": "$3.90" }, { "name": "Coupon Discount", "value": "-$5.00" } ], "adjustments": [ { "order_id": 112857, "amount": "3.9", "category": "tip", "tag": "tip", "description": "Tip" }, { "order_id": 112857, "amount": "3.9", "category": "delivery_fee", "tag": "delivery_fee", "description": "Delivery Fee" }, { "order_id": 112857, "amount": "-5.0", "category": "coupon_discount", "tag": "coupon_discount", "description": "Test minimum amount" }, { "order_id": 112857, "amount": "0.09", "category": "consumer_fee_tax", "tag": "tax", "description": "Tax" }, { "order_id": 112857, "amount": "3.36", "category": "tax", "tag": "tax", "description": "Tax" } ], "transactions": [ {} ], "order_option_types": [] } } ``` ### Error response format ``` { "messages": [ "Sorry, your payment was declined. Please try again." ], "error": "Unprocessable Entity", "status": 422, "meta": { "errors": {} } } ``` ### Status / Error 422 / Unprocessable Entity ## Complete Order Endpoint: `PUT /api/v1/orders/{{uuid}}/complete` Complete order after 3ds flow is done on client ### Parameters **Request body** *No body* **is_canceled** - optional If the user cancel the 3ds window, you can pass this parameter with value `true` in order to cancel the payment (in stripe) and decline the order. If skiped or `false` is passed, this param is ignored ### Response Returns the order (as you would get on `POST /api/v1/orders`) ``` { "order": { "id": 112857, "uuid": "c1ffb289-f011-4002-bc9b-175ca73543c6", "shipping_type": "delivery", "date_purchased": "2022-09-29T08:02:51.000-04:00", "delivery_address": "33-02 35Th Ave", "delivery_city": "Queens", "delivery_postcode": "11106", "delivery_state": "NY", "latitude": "40.7571861", "longitude": "-73.9268541", "delivery_telephone": "8042221111", "delivery_first_name": "Emilija", "delivery_last_name": "Talevska Stojkovski", "delivery_name": "Emilija Talevska Stojkovski", "payment_method": "credit", "email": "emilija.t@slicelife.com", "confirmed_at": null, "user_confirmed_delivered_at": null, "voided_at": null, "payment_status": "authorized", "progress_step": null, "promo_code_discount_amount": "0", "promo_code_tag": null, "service_fee_amount": "0.96", "slice_credit_discount": 0.0, "total_coupon_discount_amount": -5.0, "total": "46.21", "subtotal": "39.0", "tax": "3.45", "tip": "3.9", "shop_id": 191, "shop_name": "Napoli Pizza & Pasta", "shop_web_slug": "ny/astoria/11106/napoli-pizza-pasta", "shop_address": "33-02 35th Ave", "shop_city": "Astoria", "shop_state": "NY", "shop_zipcode": "11106", "shop_phone": "7185550156", "shop_latitude": "40.7571861", "shop_longitude": "-73.9268541", "shop_logo": "https://shop-logos.imgix.net/shops/191/original/191b.png", "shop_timezone": "EST", "invalid_selections": false, "min_eta_timestamp": "2022-09-29T08:44:51.000-04:00", "max_eta_timestamp": "2022-09-29T08:59:51.000-04:00", "eta_max": 57, "eta_min": 42, "placed_via": "androidapp", "coupons": [ { "id": 133290, "shop_id": 191, "name": "Test minimum amount", "description": "Test minimum amount", "discount_amount": "5", "pricing_type": "flat_discount", "parameters": {}, "coupon_conditions": [ { "id": 161354, "condition_type": "order_subtotal", "raw_parameters": "20", "customer_text": "Test minimum amount", "parameters": { "minimum_order_subtotal": 20 } } ] } ], "order_items": [ { "products_final_price": "18.5", "products_quantity": 1, "products_id": 2308333, "product_name": "Bolognese Pizza", "product_type_name": "Large (8 Slices)", "product_type_price": "18.5", "products_type_id": 4373636, "product_description": "With meatballs.", "order_item_selections": [ { "name": "Extra Cheese", "price": "2.0", "selection_id": 36627751, "addon_id": 3879185, "addon_name": "Whole Pizza Toppings" } ] }, { "products_final_price": "18.5", "products_quantity": 1, "products_id": 2308333, "product_name": "Bolognese Pizza", "product_type_name": "Large (8 Slices)", "product_type_price": "18.5", "products_type_id": 4373636, "product_description": "With meatballs.", "order_item_selections": [] } ], "user_facing_line_items": [ { "name": "Tax", "value": "$3.45" }, { "name": "Fee", "value": "$0.96" }, { "name": "Delivery Fee", "value": "$3.90" }, { "name": "Tip", "value": "$3.90" }, { "name": "Coupon Discount", "value": "-$5.00" } ], "adjustments": [ { "order_id": 112857, "amount": "3.9", "category": "tip", "tag": "tip", "description": "Tip" }, { "order_id": 112857, "amount": "3.9", "category": "delivery_fee", "tag": "delivery_fee", "description": "Delivery Fee" }, { "order_id": 112857, "amount": "-5.0", "category": "coupon_discount", "tag": "coupon_discount", "description": "Test minimum amount" }, { "order_id": 112857, "amount": "0.09", "category": "consumer_fee_tax", "tag": "tax", "description": "Tax" }, { "order_id": 112857, "amount": "3.36", "category": "tax", "tag": "tax", "description": "Tax" } ], "transactions": [ {} ], "order_option_types": [] } } ``` ### Error response format ``` { "messages": [ "Sorry, your payment was declined. Please try again." ], "error": "Unprocessable Entity", "status": 422, "meta": { "errors": {} } } ``` ### Status / Error 422 / Unprocessable Entity