Skip to content

Commit

Permalink
fix(payment): PAYMENTS-4886 Disable vaulting if isPaymentDataSubmitte…
Browse files Browse the repository at this point in the history
…d is true

When we start the payment process from the cart we can't offer vaulting
functionality and the customer has already picked their payment method,
we should not show the dropdown or options to vault instruments.
  • Loading branch information
icatalina committed Oct 30, 2019
1 parent 44f6c9b commit b816ad6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
22 changes: 16 additions & 6 deletions src/app/payment/paymentMethod/HostedPaymentMethod.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ describe('HostedPaymentMethod', () => {

const component = mount(<HostedPaymentMethodTest { ...defaultProps } />);

expect(component.find(storedInstrumentModule.AccountInstrumentFieldset).length)
.toBe(1);
expect(component.find(storedInstrumentModule.AccountInstrumentFieldset))
.toHaveLength(1);
});

it('does not show instruments fieldset when there are no stored instruments', () => {
Expand All @@ -179,6 +179,16 @@ describe('HostedPaymentMethod', () => {
.toHaveLength(0);
});

it('does not show instruments fieldset when starting from the cart', () => {
jest.spyOn(checkoutState.data, 'isPaymentDataSubmitted')
.mockReturnValue(true);

const component = mount(<HostedPaymentMethodTest { ...defaultProps } />);

expect(component.find(storedInstrumentModule.AccountInstrumentFieldset))
.toHaveLength(0);
});

it('shows save account checkbox when there are no stored instruments', () => {
jest.spyOn(checkoutState.data, 'getInstruments')
.mockReturnValue([]);
Expand Down Expand Up @@ -207,8 +217,8 @@ describe('HostedPaymentMethod', () => {
it('does not render the dropdown', () => {
const component = mount(<HostedPaymentMethodTest { ...defaultProps } />);

expect(component.find(storedInstrumentModule.AccountInstrumentFieldset).length)
.toBe(0);
expect(component.find(storedInstrumentModule.AccountInstrumentFieldset))
.toHaveLength(0);
});

it('does not prompt to save the instrument', () => {
Expand All @@ -220,8 +230,8 @@ describe('HostedPaymentMethod', () => {
{ ...defaultProps }
/>);

expect(component.find('.form-field--saveInstrument').length)
.toBe(0);
expect(component.find('.form-field--saveInstrument'))
.toHaveLength(0);
});
});
});
Expand Down
16 changes: 9 additions & 7 deletions src/app/payment/paymentMethod/HostedPaymentMethod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ function mapFromCheckoutProps(): MapToProps<
const filterTrustedInstruments = memoizeOne((instruments: AccountInstrument[] = []) => instruments.filter(({ trustedShippingAddress }) => trustedShippingAddress));

return (context, props) => {

const {
formik: { values },
isUsingMultiShipping = false,
Expand All @@ -191,6 +190,7 @@ function mapFromCheckoutProps(): MapToProps<
getCustomer,
getInstruments,
isPaymentDataRequired,
isPaymentDataSubmitted,
},
statuses: {
isLoadingInstruments,
Expand All @@ -214,12 +214,14 @@ function mapFromCheckoutProps(): MapToProps<
return {
instruments: trustedInstruments,
isNewAddress: trustedInstruments.length === 0 && currentMethodInstruments.length > 0,
isInstrumentFeatureAvailable: features['PAYMENTS-4579.braintree_paypal_vaulting'] && isInstrumentFeatureAvailable({
config,
customer,
isUsingMultiShipping,
paymentMethod: method,
}),
isInstrumentFeatureAvailable: features['PAYMENTS-4579.braintree_paypal_vaulting']
&& !isPaymentDataSubmitted(method.id, method.gateway)
&& isInstrumentFeatureAvailable({
config,
customer,
isUsingMultiShipping,
paymentMethod: method,
}),
isLoadingInstruments: isLoadingInstruments(),
isPaymentDataRequired: isPaymentDataRequired(values.useStoreCredit),
loadInstruments: checkoutService.loadInstruments,
Expand Down

0 comments on commit b816ad6

Please sign in to comment.