From Cart to Checkout
This guide assumes you have a active product already setup. Please see our guide on product for details on how to setup an active product. From cart to checkout is a 4 step process:
Create a cart
Add product to cart by creating line items
Submit customer's information
Pay for the cart by creating a payment
Step 1: Create a cart
When a customer visit your store you should create a cart for them so they can start shopping. In Freshcom, cart and order is the same resource, cart is simply an order with status cart
. When an order is first created it will always have the status cart
, so creating a initial cart is as simply as creating an empty order.
Once a cart is created, we recommend you to save its ID in the browser's locale storage or cookies, so that if they refresh the page or opens a new tab their cart does not get lost. As long as you have the cart ID you can retrieve the cart through Freshcom API.
Step 2: Add product to cart
Adding product to cart is simply creating a line item for the cart. This step assume you have a active product for customer to purchase. For details on how to setup product please see our guide on product.
When you create a line item for the cart, the sub total, taxes and grand total related attributes for the cart will be updated automatically.
Step 3: Submit customer's information
Submit the customer's information by simply updating the cart with the appropriate information.
Note that non of the attributes of the order resource is required when creating, but when updating the name, email and fulfillment method is required.
Step 4: Paying for the cart
Freshcom does not reinvent payment processing, instead we uses Stripe under the hood to process payments. Each Freshcom account is connected to its own Stripe account, and thus have its own keys for Stripe. Using your Stripe keys you can advantage of many Stripe product for collecting payment information like Stripe Element. At the moment Freshcom do not accept credit number directly you must use Stripe.js or Stripe Elements to create a token for the credit card first and use the token to create a payment in Freshcom. In short paying for a cart is a two step process:
Create a credit card token using Stripe.js or Stripe Elements
Create a payment using the token returned from Stripe
Please see the Stripe.js & Stripe Elements documentation on Stripe for how to obtain the token for credit card. The code below assume the token is already obtained.
Once a payment is created, the status of cart will be automatically be changed to opened
indicating a successful transition from cart to an open order.
Next Steps
Customize Payment AmountAuthorize PaymentLine Item StructureFulfillment & ReturnLast updated