feat(MED-97): update cart flow for using benefits

This commit is contained in:
2025-09-26 13:24:09 +03:00
parent 56f84a003c
commit db38e602aa
15 changed files with 419 additions and 81 deletions

View File

@@ -253,6 +253,37 @@ export async function setShippingMethod({
.catch(medusaError);
}
export async function initiateMultiPaymentSession(
cart: HttpTypes.StoreCart,
benefitsAmount: number,
) {
const headers = {
...(await getAuthHeaders()),
};
return sdk.client.fetch<unknown>(`/store/multi-payment`, {
method: 'POST',
body: { cartId: cart.id, benefitsAmount },
headers,
})
.then(async (response) => {
console.info('Payment session initiated:', response);
const cartCacheTag = await getCacheTag('carts');
revalidateTag(cartCacheTag);
return response as {
montonioPaymentSessionId: string | null;
companyBenefitsPaymentSessionId: string | null;
totalByBenefits: number;
totalByMontonio: number;
isFullyPaidByBenefits: boolean;
};
})
.catch((e) => {
console.error('Error initiating payment session:', e, JSON.stringify(Object.keys(e)));
return medusaError(e);
});
}
export async function initiatePaymentSession(
cart: HttpTypes.StoreCart,
data: HttpTypes.StoreInitializePaymentSession,