Skip to content

Commit

Permalink
[EE-4326] Add destroy method for AlternatePaymentMethod class
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Duvall committed Sep 27, 2024
1 parent d0b6dfd commit 0609d80
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class AlternativePaymentMethods extends Emitter {
});
}

async destroy () {
this.gatewayStrategy.destroy();
}


async selectGatewayStrategy (gatewayType) {
const gatewayClass = GATEWAYS[gatewayType];

Expand Down
5 changes: 5 additions & 0 deletions lib/recurly/alternative-payment-methods/gateways/adyen.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class AdyenGateway extends Base {
return this.webComponent;
}

async destroy () {
this.webComponent?.remove();
delete this.webComponent;
}

get data () {
const methodState = this.state.data;
const componentState = this.webComponent?.activePaymentMethod?.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ describe('Recurly.AlternativePaymentMethods', () => {
});
});

describe('destroy', () => {
it('removes the web component', done => {
paymentMethods = recurly.AlternativePaymentMethods(params);
paymentMethods.start()
.then(() => {
paymentMethods.destroy();
assert.equal(paymentMethods.webComponent, undefined);
})
.finally(done);
});
});

it("make a GET /js/v1/payment_methods/list with the needed params", (done) => {
sandbox.stub(recurly.request, 'get').resolves({ });
paymentMethods = recurly.AlternativePaymentMethods(params);
Expand Down

0 comments on commit 0609d80

Please sign in to comment.