diff --git a/libs/payments/paypal/src/lib/paypal.manager.spec.ts b/libs/payments/paypal/src/lib/paypal.manager.spec.ts index 80b4b38887..648e155ff7 100644 --- a/libs/payments/paypal/src/lib/paypal.manager.spec.ts +++ b/libs/payments/paypal/src/lib/paypal.manager.spec.ts @@ -62,6 +62,29 @@ describe('PaypalManager', () => { } }); + describe('cancelBillingAgreement', () => { + it('cancels a billing agreement', async () => { + const billingAgreementId = faker.string.sample(); + + paypalClient.baUpdate = jest + .fn() + .mockResolvedValueOnce(NVPBAUpdateTransactionResponseFactory()); + + const result = await paypalManager.cancelBillingAgreement( + billingAgreementId + ); + expect(result).toBeUndefined(); + expect(paypalClient.baUpdate).toBeCalledWith({ + billingAgreementId, + cancel: true, + }); + }); + + it('throws an error', async () => { + expect(paypalManager.cancelBillingAgreement).rejects.toThrowError(); + }); + }); + describe('getBillingAgreement', () => { it('returns agreement details (active status)', async () => { const billingAgreementId = faker.string.sample(); diff --git a/libs/payments/paypal/src/lib/paypal.manager.ts b/libs/payments/paypal/src/lib/paypal.manager.ts index 3aa0c309fe..5db20b0ffa 100644 --- a/libs/payments/paypal/src/lib/paypal.manager.ts +++ b/libs/payments/paypal/src/lib/paypal.manager.ts @@ -23,6 +23,13 @@ export class PayPalManager { private paypalCustomerManager: PaypalCustomerManager ) {} + /** + * Cancels a billing agreement. + */ + async cancelBillingAgreement(billingAgreementId: string): Promise { + await this.client.baUpdate({ billingAgreementId, cancel: true }); + } + /** * Get Billing Agreement details by calling the update Billing Agreement API. * Parses the API call response for country code and billing agreement status