From 59931388477214946c58f414ce8e49b8a40f548a Mon Sep 17 00:00:00 2001 From: Or Date: Mon, 24 Jun 2024 11:11:56 +0300 Subject: [PATCH] Use customer default payment method to fetch service estimations --- .../client/Locomotion/src/context/newRideContext/api.js | 4 ++-- .../client/Locomotion/src/context/newRideContext/index.tsx | 3 ++- examples/client/Locomotion/src/context/payments/index.js | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/client/Locomotion/src/context/newRideContext/api.js b/examples/client/Locomotion/src/context/newRideContext/api.js index c212a9373..76f8e8b42 100644 --- a/examples/client/Locomotion/src/context/newRideContext/api.js +++ b/examples/client/Locomotion/src/context/newRideContext/api.js @@ -1,8 +1,8 @@ import network from '../../services/network'; -export const createServiceEstimations = async (stopPoints, scheduledTo, businessAccountId) => { +export const createServiceEstimations = async (stopPoints, scheduledTo, businessAccountId, paymentMethodId) => { try { - const { data } = await network.post('api/v1/services/service-estimations', { stopPoints, scheduledTo, businessAccountId }); + const { data } = await network.post('api/v1/services/service-estimations', { stopPoints, scheduledTo, businessAccountId, paymentMethodId }); return data; } catch (e) { console.error(e); diff --git a/examples/client/Locomotion/src/context/newRideContext/index.tsx b/examples/client/Locomotion/src/context/newRideContext/index.tsx index fa342e414..8e55a1a06 100644 --- a/examples/client/Locomotion/src/context/newRideContext/index.tsx +++ b/examples/client/Locomotion/src/context/newRideContext/index.tsx @@ -440,8 +440,9 @@ const RidePageContextProvider = ({ children }: { const unixScheduledTo = moment.unix(Number(ride.scheduledTo) / 1000); scheduledTime = await getLocationTimezoneTime(formattedStopPoints[0].lat, formattedStopPoints[0].lng, unixScheduledTo); } + const defaultPaymentMethodId = getClientDefaultMethod()?.id; const { estimations, services } = await rideApi - .createServiceEstimations(formattedStopPoints, scheduledTime, relevantBusinessAccountId); + .createServiceEstimations(formattedStopPoints, scheduledTime, relevantBusinessAccountId, defaultPaymentMethodId); const tags = getEstimationTags(estimations); const formattedEstimations = formatEstimations(services, estimations, tags); diff --git a/examples/client/Locomotion/src/context/payments/index.js b/examples/client/Locomotion/src/context/payments/index.js index 1e184f37e..660431671 100644 --- a/examples/client/Locomotion/src/context/payments/index.js +++ b/examples/client/Locomotion/src/context/payments/index.js @@ -108,12 +108,16 @@ const usePayments = () => { && paymentMethods.some(pm => !pm.isExpired); const getClientDefaultMethod = (enableCash) => { + if (customer.defaultPaymentMethodId) { + return customer.defaultPaymentMethodId; + } if (paymentMethods && paymentMethods.length) { - return (paymentMethods || []).find(pm => pm.isDefault) || paymentMethods[0]; + return paymentMethods.find(pm => pm.isDefault) || paymentMethods[0]; } if (enableCash) { return cashPaymentMethod; } + return null; }; const createPaymentMethod = async (paymentMethodId) => {