Skip to content

Commit

Permalink
Added Wallet/Express pay type field (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Dart <jonathan.dart@boldcommerce.com>
  • Loading branch information
jdart and jdart-bold authored Nov 20, 2023
1 parent 7cb7d08 commit 6b0bac7
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/braintree/apple/braintreeOnPaymentAuthorizedApple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export async function braintreeOnPaymentAuthorizedApple(event: ApplePayPaymentAu
token: nonce,
gateway_public_id: gatewayPublicId,
currency: currencyCode,
amount: totalAmountDue
amount: totalAmountDue,
wallet_pay_type: 'applepay',
};

const paymentResult = await addPayment(payment, API_RETRY);
Expand Down
3 changes: 2 additions & 1 deletion src/braintree/google/braintreeOnPaymentAuthorizedGoogle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export async function braintreeOnPaymentAuthorizedGoogle(paymentData: PaymentDat
gateway_public_id: gatewayPublicId,
currency: currencyCode,
amount: totalAmountDue,
display_string: description
display_string: description,
wallet_pay_type: 'paywithgoogle',
};
const paymentResult = await addPayment(payment, API_RETRY);
if (!paymentResult.success) {
Expand Down
3 changes: 2 additions & 1 deletion src/paypal/paypalOnApprove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export async function paypalOnApprove(data: OnApproveData, actions: OnApproveAct
nonce: `${id}:${payer.payer_id}`, // TODO: Temporarily required - It is not in the API documentation, but required for Paypal Express
gateway_public_id: getPaypalGatewayPublicId(),
currency: currencyCode,
amount: totals.totalAmountDue
amount: totals.totalAmountDue,
wallet_pay_type: 'paypal',
} as IAddPaymentRequest;
const paymentResult = await addPayment(payment, API_RETRY);
if(!paymentResult.success){
Expand Down
1 change: 1 addition & 0 deletions src/paypal/ppcp_apple/ppcpOnPaymentAuthorizedApple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export async function ppcpOnPaymentAuthorizedApple(event: ApplePayPaymentAuthori
gateway_public_id: gatewayPublicId,
currency: currencyCode,
amount: totalAmountDue,
wallet_pay_type: 'applepay',
extra_payment_data: {
brand: token.paymentMethod.network,
last_digits: displayNameLast,
Expand Down
1 change: 1 addition & 0 deletions src/paypal/ppcp_buttons/ppcpOnApprove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export async function ppcpOnApprove(data: OnApproveData, actions: OnApproveActio
gateway_public_id: getPaypalGatewayPublicId(),
currency: currencyCode,
amount: totals.totalAmountDue,
wallet_pay_type: 'paypal',
extra_payment_data: {
orderId: data.orderID,
facilitatorAccessToken: data.facilitatorAccessToken,
Expand Down
4 changes: 3 additions & 1 deletion src/stripe/addStripePayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ export async function addStripePayment(event: IStripePaymentEvent, stripeGateway
const billingAddress = formatStripeBillingAddress(card, event.payerName, event.payerPhone);
await setBillingAddress(billingAddress, API_RETRY).then(async (billingResult) => {
if (billingResult.success) {
const walletPayType = window.ApplePaySession && ApplePaySession.canMakePayments() ? 'applepay' : 'paywithgoogle';
const payment: IAddPaymentRequest = {
token: token.id,
gateway_public_id: stripeGatewayId,
currency: card.currency,
amount: totalAmountDue
amount: totalAmountDue,
wallet_pay_type: walletPayType,
};
await addPayment(payment, API_RETRY).then(async (paymentResult) => {
if (paymentResult.success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ describe('testing braintreeOnPaymentAuthorizedApple function', () => {
token: nonce,
gateway_public_id: credentials.public_id,
currency: currencyMock.iso_code,
amount: applicationStateMock.order_total
amount: applicationStateMock.order_total,
wallet_pay_type: 'applepay',
};

await braintreeOnPaymentAuthorizedApple(eventParam as ApplePayPaymentAuthorizedEvent);
Expand Down
1 change: 1 addition & 0 deletions tests/paypal/paypalOnApprove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const paypalOrderResponseMock: OrderResponseBody = {
const paymentRequest = {
token: 'test_id:test_payer_id',
nonce: 'test_id:test_payer_id',
wallet_pay_type: 'paypal',
gateway_public_id: 'abc123',
currency: 'USD',
amount: 10000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ describe('testing ppcpOnPaymentAuthorizedApple function', () => {
gateway_public_id: credentials.public_id,
currency: currencyMock.iso_code,
amount: applicationStateMock.order_total,
wallet_pay_type: 'applepay',
extra_payment_data: {
brand: eventParam.payment.token.paymentMethod.network,
last_digits: '1111',
Expand Down
1 change: 1 addition & 0 deletions tests/paypal/ppcp_buttons/ppcpOnApprove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const paypalOrderResponseMock: OrderResponseBody = {
} as unknown as OrderResponseBody;
const paymentRequest = {
token: onApproveDataMock.orderID,
wallet_pay_type: 'paypal',
gateway_public_id: 'abc123',
currency: 'USD',
amount: 10000,
Expand Down
5 changes: 5 additions & 0 deletions tests/stripe/addStripePayment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const processOrderMock = mocked(processOrder, true);
const getTotalsMock = mocked(getTotals, true);
const getOrderInitialDataMock = mocked(getOrderInitialData, true);
const callGuestCustomerEndpointMock = mocked(callGuestCustomerEndpoint, true);
const canMakePaymentsMock = jest.fn();
const applePaySession = {canMakePayments: canMakePaymentsMock};

describe('testing stripe payment function', () => {

Expand Down Expand Up @@ -117,6 +119,7 @@ describe('testing stripe payment function', () => {
formatStripeBillingAddressMock.mockReturnValue(appState.addresses.billing);
getTotalsMock.mockReturnValue(totals);
getOrderInitialDataMock.mockReturnValue(orderInitialDataMock);
window.ApplePaySession = applePaySession;

});

Expand All @@ -126,6 +129,7 @@ describe('testing stripe payment function', () => {
setBillingAddressMock.mockReturnValueOnce(Promise.resolve(setBilling));
addPaymentMock.mockReturnValueOnce(Promise.resolve(addPayment));
processOrderMock.mockReturnValueOnce(Promise.resolve(processOrder));
canMakePaymentsMock.mockReturnValueOnce(false);

await addStripePayment(eventMock, 'test-id');
expect(completeMock).toBeCalled();
Expand All @@ -141,6 +145,7 @@ describe('testing stripe payment function', () => {
setBillingAddressMock.mockReturnValueOnce(Promise.resolve(successApi));
addPaymentMock.mockReturnValueOnce(Promise.resolve(successApi));
processOrderMock.mockReturnValueOnce(Promise.resolve(successApi));
canMakePaymentsMock.mockReturnValueOnce(true);
await addStripePayment(localEventMock, 'test-id');
expect(completeMock).toBeCalled();
expect(completeMock).toHaveBeenCalledWith('success');
Expand Down

0 comments on commit 6b0bac7

Please sign in to comment.