NOTE: Place this file inside your Magento pub/ directory to avoid CORS restrictions.
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.
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'.
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.
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.
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.
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.
The result parameter will contain data from the processed event and the confirmation token created with the Stripe API.