Place an order using the Express Checkout Element with a logged in customer

Configuration

To have a logged in customer when using GraphQL, you will have to get the customer token, and then using that token as a Bearer token for the Authorization parameter of each following request. The request will look like this:




After you get the token, you need to create a quote for the customer. With the following mutation you will create a quote if the user does not have a quote, or link a previously existing quote for the user if he created one.



Once the quote is created, you can start initializing the Express Checkout Element. For the initialization part, the ECE needs to have the configuration data, which contains things like the API keys, API version and configs for the buttons of the payment methods. Also, it needs the init parameters like availability countries, address requirements, shipping rates and styling options for the modals.

Get Stripe Configurations show

This will return configurations like API keys, API version and button configs from the admin. The location parameter can have the values 'product', 'cart' or 'minicart'.


    

Get ECE Params show

This endpoint will return a resolve payload, which will be used in the resolve function for add to cart event, and also an element options component, which are cosmetic settings for the modal which will appear.

The parameters are the location from which the ECE is being initialized and the product ID, if it is initialized from a product page.


    
Once the ECE is initialized, we assume that we are on a product page. Once you click on the payment method button, the product will be added to the basked in the background.

Add Product To Cart show

The parameters for the request are the following:

This is how the request components can be formatted. They will be kept in a JSON format and then added to the mutation, because based on the product type that you want to add, the structure can become more complex.

After selecting the product and other options if necessary, they will be passed to the mutation as its' parameter.


    
After the product is added to the basket, based on your addresses saved against the selected payment method, you will either be prompted to add a shipping address, or an address from the saved addresses will be selected automatically. Regardless of the situation, this will be handled by the 'shippingaddresschange' event of the ECE which calls the address changed endpoint.

Change the shipping address show

The newAddress parameter is taken from the event data

The result of the endpoint call will be used for resolving the processed event, which updates the totals on the ECE.


    
Once the shipping address is set, you will be able to select or change your shipping rate. This will be handled by the 'shippingratechange' event on the ECE, and it should call the rates changed endpoint.

Change the shipping rate show

The address parameter needs to be the latest address processed in the 'address changed' so it's recommended the address be saved when it is handled. You will have this address from the init process for the ECE, either from when you add the address manually or have one already saved in your selected payment method.

The shipping method parameter is also taken from the processed event.

The result of the endpoint call will be used for resolving the processed event, which updates the totals on the ECE.


    
After all the selections are made, when clicking the payment button, the 'confirm' event will be triggered. This event should use the place order endpoint.

Place Order show

The result parameter will contain data from the processed event and the confirmation token created with the Stripe API.