Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modules/billing/billing.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class BillingController {
payload.projectId!,
payload.planId,
payload.countryCode,
payload.postalCode,
);
return {
status: 'successful',
Expand Down
8 changes: 7 additions & 1 deletion src/modules/billing/billing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ export class BillingService {
@Inject() private readonly configService: ConfigService,
) {}

async upgradePlan(projectId: number, planId: number, countryCode: string): Promise<string> {
async upgradePlan(
projectId: number,
planId: number,
countryCode: string,
postalCode: string,
): Promise<string> {
// get project
const project = await this.projectRepository.getProjectById(projectId);
if (project === null) {
Expand Down Expand Up @@ -99,6 +104,7 @@ export class BillingService {
email: adminUser!.emailAddress,
name: project.name,
countryCode,
postalCode,
},
subscription: {
priceId: plan.metadata.paddleData.priceId,
Expand Down
5 changes: 5 additions & 0 deletions src/modules/billing/dto/generate-payment-link.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ export class GeneratePaymentLinkDto {
message: 'Country code not provided',
})
countryCode: string;

@IsNotEmpty({
message: 'Postal code not provided',
})
postalCode: string;
}
8 changes: 7 additions & 1 deletion src/modules/http/paddle-http-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, unknown>>({
Expand Down Expand Up @@ -243,12 +247,14 @@ export class PaddleHttpClient extends BaseHttpClient {
private async createCustomerAddress(
customerId: string,
countryCode: string,
postalCode: string,
): Promise<AddressResponse> {
const response = await this.request<Record<string, unknown>>({
url: `customers/${customerId}/addresses`,
method: 'POST',
data: {
country_code: countryCode,
postal_code: postalCode,
},
});

Expand Down
1 change: 1 addition & 0 deletions src/modules/http/paddle-http-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type CreateTransactionRequest = {
email: string;
name: string;
countryCode: string;
postalCode: string;
};
subscription: {
priceId: string;
Expand Down
Loading