Skip to content

Commit 02a03af

Browse files
committed
feat(billing): add postal code to upgrade plan and customer address creation
1 parent d725af7 commit 02a03af

5 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/modules/billing/billing.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class BillingController {
2222
payload.projectId!,
2323
payload.planId,
2424
payload.countryCode,
25+
payload.postalCode,
2526
);
2627
return {
2728
status: 'successful',

src/modules/billing/billing.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ export class BillingService {
2626
@Inject() private readonly configService: ConfigService,
2727
) {}
2828

29-
async upgradePlan(projectId: number, planId: number, countryCode: string): Promise<string> {
29+
async upgradePlan(
30+
projectId: number,
31+
planId: number,
32+
countryCode: string,
33+
postalCode: string,
34+
): Promise<string> {
3035
// get project
3136
const project = await this.projectRepository.getProjectById(projectId);
3237
if (project === null) {
@@ -99,6 +104,7 @@ export class BillingService {
99104
email: adminUser!.emailAddress,
100105
name: project.name,
101106
countryCode,
107+
postalCode,
102108
},
103109
subscription: {
104110
priceId: plan.metadata.paddleData.priceId,

src/modules/billing/dto/generate-payment-link.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ export class GeneratePaymentLinkDto {
1515
message: 'Country code not provided',
1616
})
1717
countryCode: string;
18+
19+
@IsNotEmpty({
20+
message: 'Postal code not provided',
21+
})
22+
postalCode: string;
1823
}

src/modules/http/paddle-http-client/client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ export class PaddleHttpClient extends BaseHttpClient {
5050
const addresses = await this.listCustomerAddress(customer.id);
5151
address = addresses?.find((x) => x.country_code === request.customer.countryCode);
5252
if (address === null || address === undefined) {
53-
address = await this.createCustomerAddress(customer.id, request.customer.countryCode);
53+
address = await this.createCustomerAddress(
54+
customer.id,
55+
request.customer.countryCode,
56+
request.customer.postalCode,
57+
);
5458
}
5559
// create transaction
5660
const response = await this.request<Record<string, unknown>>({
@@ -243,12 +247,14 @@ export class PaddleHttpClient extends BaseHttpClient {
243247
private async createCustomerAddress(
244248
customerId: string,
245249
countryCode: string,
250+
postalCode: string,
246251
): Promise<AddressResponse> {
247252
const response = await this.request<Record<string, unknown>>({
248253
url: `customers/${customerId}/addresses`,
249254
method: 'POST',
250255
data: {
251256
country_code: countryCode,
257+
postal_code: postalCode,
252258
},
253259
});
254260

src/modules/http/paddle-http-client/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type CreateTransactionRequest = {
3434
email: string;
3535
name: string;
3636
countryCode: string;
37+
postalCode: string;
3738
};
3839
subscription: {
3940
priceId: string;

0 commit comments

Comments
 (0)