Skip to content

Commit

Permalink
USF-1323: Added new checkout API functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-matthews committed Nov 8, 2024
1 parent ff60cb2 commit dfab823
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/content/docs/dropins/checkout/checkout-functions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,38 @@ import OptionsTable from '@components/OptionsTable.astro';

This topic provides the details and instructions you need to use the functions provided by the Checkout dropin.

## authenticateCustomer

The `authenticateCustomer` function manages the authentication state of a customer, either by fetching customer data using the [`getCustomer`](#getcustomer) function when authenticated or resetting the customer data when not authenticated.

```ts
export const authenticateCustomer: () => Promise<void>
```
### Returns
The function does not return any value explicitly; it performs side effects by fetching data and logging errors.
### Usage
See the following example for usage details:
```ts
import { authenticateCustomer } from '@/checkout/api/authenticateCustomer';

async function authenticate() {
try {
await authenticateCustomer();
console.log('Customer authenticated successfully.');
} catch (error) {
console.error('Error authenticating customer:', error);
}
}
```

## estimateShippingMethods

This function fetches and displays available shipping methods based on a customer's address information. It can take a combination of fields as `criteria`: country, region, region identifier, and postal code.
The `estimateShippingMethods` function fetches and displays available shipping methods based on a customer's address information. It can take a combination of fields as `criteria`: country, region, region identifier, and postal code.

It uses a utility function to call an [`estimateShippingMethods`](https://developer.adobe.com/commerce/webapi/graphql/schema/cart/mutations/estimate-shipping-methods/) mutation.

Expand Down Expand Up @@ -660,4 +689,26 @@ setShippingMethodsOnCart([
method_code: 'flatrate',
},
]);
```

## synchronizeCheckout

The `synchronizeCheckout` function synchronizes the checkout state with the current cart information. It ensures that the checkout process is properly initialized, reset, or updated based on the cart data. It uses the [`getCart`](#getcart) function to fetch the necessary cart details.

```ts
export const synchronizeCheckout: () => void
```
### Returns
The function does not return any value explicitly; it performs side effects by fetching data and logging errors.
### Usage
See the following example for usage details:
```ts
import { synchronizeCheckout } from '@/checkout/api/synchronizeCheckout';

synchronizeCheckout('IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG');
```

0 comments on commit dfab823

Please sign in to comment.