From 0609d80de028795372dcea6045a7555a3a7b4128 Mon Sep 17 00:00:00 2001 From: Patrick Duvall Date: Fri, 27 Sep 2024 12:57:56 -0600 Subject: [PATCH] [EE-4326] Add destroy method for AlternatePaymentMethod class --- .../alternative-payment-methods.js | 5 +++++ .../alternative-payment-methods/gateways/adyen.js | 5 +++++ .../alternative-payment-methods.test.js | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/lib/recurly/alternative-payment-methods/alternative-payment-methods.js b/lib/recurly/alternative-payment-methods/alternative-payment-methods.js index 6ba67bef..e2d462c8 100644 --- a/lib/recurly/alternative-payment-methods/alternative-payment-methods.js +++ b/lib/recurly/alternative-payment-methods/alternative-payment-methods.js @@ -120,6 +120,11 @@ class AlternativePaymentMethods extends Emitter { }); } + async destroy () { + this.gatewayStrategy.destroy(); + } + + async selectGatewayStrategy (gatewayType) { const gatewayClass = GATEWAYS[gatewayType]; diff --git a/lib/recurly/alternative-payment-methods/gateways/adyen.js b/lib/recurly/alternative-payment-methods/gateways/adyen.js index 06a20558..667f3895 100644 --- a/lib/recurly/alternative-payment-methods/gateways/adyen.js +++ b/lib/recurly/alternative-payment-methods/gateways/adyen.js @@ -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; diff --git a/test/unit/alternative-payment-methods/alternative-payment-methods.test.js b/test/unit/alternative-payment-methods/alternative-payment-methods.test.js index 075fa5d0..5cb402ec 100644 --- a/test/unit/alternative-payment-methods/alternative-payment-methods.test.js +++ b/test/unit/alternative-payment-methods/alternative-payment-methods.test.js @@ -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);