Skip to content

Commit

Permalink
Merge pull request #901 from recurly/EE-4326
Browse files Browse the repository at this point in the history
Add destroy method for AlternatePaymentMethod class
  • Loading branch information
chrissrogers authored Sep 27, 2024
2 parents ce01b44 + 0994438 commit b8ed11a
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 @@ -71,6 +71,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 b8ed11a

Please sign in to comment.