diff --git a/libs/payments/cart/src/lib/checkout.service.spec.ts b/libs/payments/cart/src/lib/checkout.service.spec.ts index 4a88705370..c7424510df 100644 --- a/libs/payments/cart/src/lib/checkout.service.spec.ts +++ b/libs/payments/cart/src/lib/checkout.service.spec.ts @@ -514,6 +514,7 @@ describe('CheckoutService', () => { promotionCode: mockPromotionCode, priceId: mockPriceId, }); + jest.spyOn(customerManager, 'update').mockResolvedValue(mockCustomer); jest.spyOn(invoiceManager, 'processPayPalInvoice').mockResolvedValue(); jest.spyOn(invoiceManager, 'retrieve').mockResolvedValue(mockInvoice); jest.spyOn(paypalBillingAgreementManager, 'cancel').mockResolvedValue(); diff --git a/libs/payments/cart/src/lib/checkout.service.ts b/libs/payments/cart/src/lib/checkout.service.ts index bb2e413525..353448b467 100644 --- a/libs/payments/cart/src/lib/checkout.service.ts +++ b/libs/payments/cart/src/lib/checkout.service.ts @@ -14,6 +14,7 @@ import { InvoiceManager, PaymentMethodManager, PromotionCodeManager, + STRIPE_CUSTOMER_METADATA, StripeSubscription, SubplatInterval, SubscriptionManager, @@ -280,7 +281,12 @@ export class CheckoutService { status: 'active', endedAt: null, }); - // TODO: set billingAgreementId on customer metadata (existing is updateCustomerPaypalAgreement) + + await this.customerManager.update(customer.id, { + metadata: { + [STRIPE_CUSTOMER_METADATA.PAYPAL_AGREEMENT]: billingAgreementId, + }, + }); if (!subscription.latest_invoice) { throw new CheckoutError('latest_invoice does not exist on subscription'); diff --git a/libs/payments/stripe/src/lib/stripe.types.ts b/libs/payments/stripe/src/lib/stripe.types.ts index f0c1d86c80..1817b208f9 100644 --- a/libs/payments/stripe/src/lib/stripe.types.ts +++ b/libs/payments/stripe/src/lib/stripe.types.ts @@ -17,6 +17,10 @@ export interface TaxAmount { amount: number; } +export enum STRIPE_CUSTOMER_METADATA { + PAYPAL_AGREEMENT = 'paypalAgreementId', +} + export enum STRIPE_PRICE_METADATA { APP_STORE_PRODUCT_IDS = 'appStoreProductIds', PLAY_SKU_IDS = 'playSkuIds',