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) => {