diff --git a/src/modules/billing/billing.controller.ts b/src/modules/billing/billing.controller.ts index 4a0c6bc..df36d2d 100644 --- a/src/modules/billing/billing.controller.ts +++ b/src/modules/billing/billing.controller.ts @@ -22,6 +22,7 @@ export class BillingController { payload.projectId!, payload.planId, payload.countryCode, + payload.postalCode, ); return { status: 'successful', diff --git a/src/modules/billing/billing.service.ts b/src/modules/billing/billing.service.ts index e2d69d4..9b5c773 100644 --- a/src/modules/billing/billing.service.ts +++ b/src/modules/billing/billing.service.ts @@ -26,7 +26,12 @@ export class BillingService { @Inject() private readonly configService: ConfigService, ) {} - async upgradePlan(projectId: number, planId: number, countryCode: string): Promise { + async upgradePlan( + projectId: number, + planId: number, + countryCode: string, + postalCode: string, + ): Promise { // get project const project = await this.projectRepository.getProjectById(projectId); if (project === null) { @@ -99,6 +104,7 @@ export class BillingService { email: adminUser!.emailAddress, name: project.name, countryCode, + postalCode, }, subscription: { priceId: plan.metadata.paddleData.priceId, diff --git a/src/modules/billing/dto/generate-payment-link.dto.ts b/src/modules/billing/dto/generate-payment-link.dto.ts index 8703da9..4e6f2f6 100644 --- a/src/modules/billing/dto/generate-payment-link.dto.ts +++ b/src/modules/billing/dto/generate-payment-link.dto.ts @@ -15,4 +15,9 @@ export class GeneratePaymentLinkDto { message: 'Country code not provided', }) countryCode: string; + + @IsNotEmpty({ + message: 'Postal code not provided', + }) + postalCode: string; } diff --git a/src/modules/http/paddle-http-client/client.ts b/src/modules/http/paddle-http-client/client.ts index f94c76c..4e7704b 100644 --- a/src/modules/http/paddle-http-client/client.ts +++ b/src/modules/http/paddle-http-client/client.ts @@ -50,7 +50,11 @@ export class PaddleHttpClient extends BaseHttpClient { const addresses = await this.listCustomerAddress(customer.id); address = addresses?.find((x) => x.country_code === request.customer.countryCode); if (address === null || address === undefined) { - address = await this.createCustomerAddress(customer.id, request.customer.countryCode); + address = await this.createCustomerAddress( + customer.id, + request.customer.countryCode, + request.customer.postalCode, + ); } // create transaction const response = await this.request>({ @@ -243,12 +247,14 @@ export class PaddleHttpClient extends BaseHttpClient { private async createCustomerAddress( customerId: string, countryCode: string, + postalCode: string, ): Promise { const response = await this.request>({ url: `customers/${customerId}/addresses`, method: 'POST', data: { country_code: countryCode, + postal_code: postalCode, }, }); diff --git a/src/modules/http/paddle-http-client/types.ts b/src/modules/http/paddle-http-client/types.ts index 8be265c..4fb95a3 100644 --- a/src/modules/http/paddle-http-client/types.ts +++ b/src/modules/http/paddle-http-client/types.ts @@ -34,6 +34,7 @@ export type CreateTransactionRequest = { email: string; name: string; countryCode: string; + postalCode: string; }; subscription: { priceId: string;