diff --git a/package.json b/package.json index 0ffad9f..b685233 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@internxt/sdk", "author": "Internxt ", - "version": "1.16.0", + "version": "1.16.1", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/drive/payments/index.ts b/src/drive/payments/index.ts index 8f68b9c..4e6cb8c 100644 --- a/src/drive/payments/index.ts +++ b/src/drive/payments/index.ts @@ -5,16 +5,12 @@ import AppError from '../../shared/types/errors'; import { Tier } from './types/tiers'; import { AvailableProducts, - CreateCheckoutSessionPayload, - CreatedSubscriptionData, - CreatePaymentSessionPayload, + CouponCodeData, CustomerBillingInfo, DisplayPrice, - FreeTrialAvailable, Invoice, InvoicePayload, PaymentMethod, - ProductData, RedeemCodePayload, UpdateSubscriptionPaymentMethod, UserSubscription, @@ -36,83 +32,6 @@ export class Payments { this.apiSecurity = apiSecurity; } - public createCustomer( - name: string, - email: string, - country?: string, - companyVatId?: string, - ): Promise<{ customerId: string; token: string }> { - return this.client.post('/create-customer', { name, email, country, companyVatId }, this.headers()); - } - - public createSubscription( - customerId: string, - priceId: string, - token: string, - quantity: number, - currency?: string, - promoCodeId?: string, - ): Promise { - return this.client.post( - '/create-subscription', - { - customerId, - priceId, - token, - quantity, - currency, - promoCodeId, - }, - this.headers(), - ); - } - - public createPaymentIntent( - customerId: string, - amount: number, - planId: string, - token: string, - currency?: string, - promoCodeName?: string, - ): Promise<{ clientSecret: string; id: string; invoiceStatus?: string }> { - const query = new URLSearchParams(); - query.set('customerId', customerId); - query.set('amount', String(amount)); - query.set('planId', planId); - query.set('token', token); - if (currency !== undefined) query.set('currency', currency); - if (promoCodeName !== undefined) query.set('promoCodeName', promoCodeName); - return this.client.get(`/payment-intent?${query.toString()}`, this.headers()); - } - - /** - * Fetches the existing products and its details - */ - public getProducts(): Promise { - return this.client.get('/v3/stripe/products', this.headers()); - } - - /** - * Creates and returns a new session identifier for the client to go to payment platform - * @param payload - */ - public createSession(payload: CreatePaymentSessionPayload): Promise<{ - id: string; - }> { - return this.client.post( - '/v2/stripe/session', - { - test: payload.test, - lifetime_tier: payload.lifetime_tier, - mode: payload.mode, - priceId: payload.priceId, - successUrl: payload.successUrl, - canceledUrl: payload.canceledUrl, - }, - this.headers(), - ); - } - public getSetupIntent(userType?: UserType): Promise<{ clientSecret: string }> { const query = new URLSearchParams(); if (userType) query.set('userType', userType); @@ -140,15 +59,6 @@ export class Payments { return this.client.get(`/invoices?${query.toString()}`, this.headers()); } - public isCouponUsedByUser({ couponCode }: { couponCode: string }): Promise<{ - couponUsed: boolean; - }> { - const query = new URLSearchParams(); - if (couponCode !== undefined) query.set('code', couponCode); - - return this.client.get(`/coupon-in-use?${query.toString()}`, this.headers()); - } - public getPromoCodesUsedByUser(): Promise<{ usedCoupons: string[] }> { return this.client.get('/customer/redeemed-promotion-codes', this.headers()); } @@ -164,6 +74,20 @@ export class Payments { }); } + public async fetchPromotionCodeByName(priceId: string, promotionCodeName: string): Promise { + const promotionCode = await this.client.get<{ codeId: string; amountOff: number; percentOff: number }>( + `/promo-code-by-name?priceId=${priceId}&promotionCode=${promotionCodeName}`, + this.headers(), + ); + + return { + codeId: promotionCode.codeId, + codeName: promotionCodeName, + amountOff: promotionCode.amountOff, + percentOff: promotionCode.percentOff, + }; + } + public async getPrices(currency?: string, userType?: UserType): Promise { const query = new URLSearchParams(); if (currency !== undefined) query.set('currency', currency); @@ -171,14 +95,6 @@ export class Payments { return this.client.get(`/prices?${query.toString()}`, this.headers()); } - public requestPreventCancellation(): Promise { - return this.client.get('/request-prevent-cancellation', this.headers()); - } - - public preventCancellation(): Promise { - return this.client.put('/prevent-cancellation', {}, this.headers()); - } - public applyRedeemCode(payload: RedeemCodePayload): Promise { return this.client.post('/licenses', { code: payload.code, provider: payload.provider }, this.headers()); } @@ -217,10 +133,6 @@ export class Payments { return this.client.delete(`/subscriptions?${query.toString()}`, this.headers()); } - public createCheckoutSession(payload: CreateCheckoutSessionPayload): Promise<{ sessionId: string }> { - return this.client.post('/checkout-session', { ...payload }, this.headers()); - } - public updateCustomerBillingInfo(payload: CustomerBillingInfo): Promise { return this.client.patch('/billing', { ...payload }, this.headers()); } diff --git a/src/drive/payments/types/types.ts b/src/drive/payments/types/types.ts index 63d5430..293e23b 100644 --- a/src/drive/payments/types/types.ts +++ b/src/drive/payments/types/types.ts @@ -221,3 +221,10 @@ export type AvailableProducts = { backups: boolean; }; }; + +export interface CouponCodeData { + codeId: string; + codeName: string; + amountOff?: number; + percentOff?: number; +} diff --git a/src/payments/checkout.ts b/src/payments/checkout.ts index 47eb53a..00b7afa 100644 --- a/src/payments/checkout.ts +++ b/src/payments/checkout.ts @@ -93,7 +93,6 @@ export class Checkout { currency, captchaToken, promoCodeId, - quantity, }: CreateSubscriptionPayload): Promise { return this.client.post( '/checkout/subscription', @@ -104,7 +103,6 @@ export class Checkout { currency, captchaToken, promoCodeId, - quantity, }, this.authHeaders(), ); diff --git a/src/payments/types/index.ts b/src/payments/types/index.ts index d97933b..0a4c519 100644 --- a/src/payments/types/index.ts +++ b/src/payments/types/index.ts @@ -19,7 +19,6 @@ export interface CreateSubscriptionPayload { captchaToken: string; currency?: string; promoCodeId?: string; - quantity?: number; } export interface CreatePaymentIntentPayload { @@ -64,8 +63,6 @@ export type Price = { decimalAmount: number; type: UserType; product: string; - minimumSeats?: number; - maximumSeats?: number; }; export type Taxes = { diff --git a/test/drive/payments/index.test.ts b/test/drive/payments/index.test.ts index 21d9bc2..80fcc30 100644 --- a/test/drive/payments/index.test.ts +++ b/test/drive/payments/index.test.ts @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import { Payments } from '../../../src/drive'; -import { CreatePaymentSessionPayload, StripeSessionMode, UserType } from '../../../src/drive/payments/types/types'; +import { UserType } from '../../../src/drive/payments/types/types'; import { ApiSecurity, AppDetails } from '../../../src/shared'; import { headersWithToken } from '../../../src/shared/headers'; import { HttpClient } from '../../../src/shared/http/client'; @@ -10,26 +10,6 @@ describe('payments service', () => { vi.restoreAllMocks(); }); - describe('get products', () => { - it('should call with right params & return data', async () => { - // Arrange - const callStub = vi.spyOn(HttpClient.prototype, 'get').mockResolvedValue({ - content: 'true', - }); - - const { client, headers } = clientAndHeadersWithToken({}); - - // Act - const body = await client.getProducts(); - - // Assert - expect(callStub).toHaveBeenCalledWith('/v3/stripe/products', headers); - expect(body).toEqual({ - content: 'true', - }); - }); - }); - describe('getInvoices', () => { it('should call with right params & return data', async () => { const callStub = vi.spyOn(HttpClient.prototype, 'get').mockResolvedValue([ @@ -100,57 +80,6 @@ describe('payments service', () => { }); }); }); - - describe('create payment session', () => { - it('should call with right params & return data', async () => { - // Arrange - const callStub = vi.spyOn(HttpClient.prototype, 'post').mockResolvedValue({ - id: 'ident', - }); - const { client, headers } = clientAndHeadersWithToken({}); - const payload: CreatePaymentSessionPayload = { - canceledUrl: '', - lifetime_tier: undefined, - mode: StripeSessionMode.Payment, - priceId: '', - successUrl: '', - test: false, - }; - - // Act - const body = await client.createSession(payload); - - // Assert - expect(callStub).toHaveBeenCalledWith( - '/v2/stripe/session', - { - test: payload.test, - lifetime_tier: payload.lifetime_tier, - mode: payload.mode, - priceId: payload.priceId, - successUrl: payload.successUrl, - canceledUrl: payload.canceledUrl, - }, - headers, - ); - expect(body).toEqual({ - id: 'ident', - }); - }); - }); - - describe('Get user used promotional codes', () => { - it('When requesting a user redeemed promo codes, it returns the correct data with the right parameters', async () => { - const response = { usedCoupons: ['PROMO_CODE', 'PROMO_CODE_1'] }; - const callStub = vi.spyOn(HttpClient.prototype, 'get').mockResolvedValue(response); - const { client, headers } = clientAndHeadersWithToken({}); - - const body = await client.getPromoCodesUsedByUser(); - - expect(callStub).toHaveBeenCalledWith('/customer/redeemed-promotion-codes', headers); - expect(body).toEqual(response); - }); - }); }); function clientAndHeadersWithToken({