Skip to content

Commit

Permalink
Return Adyen checkout state for active payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
douglaslise committed Jul 27, 2023
1 parent 1f96eeb commit ea1d64f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion lib/recurly/alternative-payment-methods/gateways/adyen.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ class AdyenGateway extends Base {
}

get data () {
return this.state.data;
const methodState = this.state.data;
const componentState = this.webComponent?.activePaymentMethod?.data;

return { ...methodState, ...componentState };
}

async handleAction (action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe('Recurly.AlternativePaymentMethods', () => {
};

const { onChange } = window.AdyenCheckout.getCall(0).args[0];
onChange({ data: 'payment-method-state', isValid: true });
onChange({ data: { myState: 1 }, isValid: true });

paymentMethods.submit({ billingAddress });

Expand All @@ -264,7 +264,7 @@ describe('Recurly.AlternativePaymentMethods', () => {
countryCode: 'US',
locale: 'en-US',
channel: 'Web',
paymentMethodData: 'payment-method-state',
paymentMethodData: { myState: 1 },
gatewayType: 'adyen',
returnURL: 'https://merchant-website.test/completed',
billingAddress: billingAddress,
Expand All @@ -274,20 +274,20 @@ describe('Recurly.AlternativePaymentMethods', () => {
});

const validateTokenization = submit => {
it("make a POST /js/v1/payment_methods/token with the needed params", done => {
it('make a POST /js/v1/payment_methods/token with the needed params', done => {
sandbox.stub(recurly.request, 'post').resolves({ });
submit();

nextTick(() => assertDone(done, () => {
assert.equal(recurly.request.post.called, true);
assert.deepEqual(recurly.request.post.getCall(0).args[0].route, "/payment_methods/token");
assert.deepEqual(recurly.request.post.getCall(0).args[0].route, '/payment_methods/token');
assert.deepEqual(recurly.request.post.getCall(0).args[0].data, {
currency: 'USD',
amount: 100,
countryCode: 'US',
locale: 'en-US',
channel: 'Web',
paymentMethodData: 'boleto-state',
paymentMethodData: { myState: 2 },
gatewayType: 'adyen',
returnURL: 'https://merchant-website.test/completed',
billingAddress: undefined,
Expand Down Expand Up @@ -358,7 +358,7 @@ describe('Recurly.AlternativePaymentMethods', () => {

validateTokenization(() => {
const { onSubmit } = window.AdyenCheckout.getCall(0).args[0];
onSubmit({ data: 'boleto-state' });
onSubmit({ data: { myState: 2 } });
});
});

Expand All @@ -375,7 +375,7 @@ describe('Recurly.AlternativePaymentMethods', () => {
}));

const { onChange } = window.AdyenCheckout.getCall(0).args[0];
onChange({ data: 'boleto-state-2', isValid: true });
onChange({ data: { myState: 3 }, isValid: true });
});
});

Expand All @@ -388,8 +388,8 @@ describe('Recurly.AlternativePaymentMethods', () => {

validateTokenization(() => {
const { onChange } = window.AdyenCheckout.getCall(0).args[0];
onChange({ data: 'boleto-state-2' });
onChange({ data: 'boleto-state' });
onChange({ data: { myState: 3 } });
onChange({ data: { myState: 2 } });

paymentMethods.submit();
});
Expand All @@ -401,7 +401,7 @@ describe('Recurly.AlternativePaymentMethods', () => {
paymentMethods.start()
.finally(() => {
const { onChange } = window.AdyenCheckout.getCall(0).args[0];
onChange({ data: 'boleto-state' });
onChange({ data: { myState: 2 } });

paymentMethods.submit();
done();
Expand Down

0 comments on commit ea1d64f

Please sign in to comment.