Skip to content

Commit

Permalink
Use customer default payment method to fetch service estimations
Browse files Browse the repository at this point in the history
  • Loading branch information
ormiz committed Jun 24, 2024
1 parent eb23fd6 commit 5993138
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/client/Locomotion/src/context/newRideContext/api.js
Original file line number Diff line number Diff line change
@@ -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 });

Check failure on line 5 in examples/client/Locomotion/src/context/newRideContext/api.js

View workflow job for this annotation

GitHub Actions / lint

Expected a line break after this opening brace

Check failure on line 5 in examples/client/Locomotion/src/context/newRideContext/api.js

View workflow job for this annotation

GitHub Actions / lint

Expected a line break before this closing brace
return data;
} catch (e) {
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion examples/client/Locomotion/src/context/payments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 5993138

Please sign in to comment.