Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #388 from beabee-communityrm/feat/billing-from-stripe
Browse files Browse the repository at this point in the history
feat: get billing address from Stripe
  • Loading branch information
wpf500 authored Apr 3, 2024
2 parents 9b20c82 + 0be11c1 commit e0dbcd6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
7 changes: 1 addition & 6 deletions src/api/controllers/SignupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,7 @@ export class SignupController {
}

// Merge additional data into the join form
if (
data.firstname ||
data.lastname ||
data.billingAddress ||
data.vatNumber
) {
if (data.firstname || data.lastname || data.vatNumber) {
Object.assign(joinFlow.joinForm, data);
await getRepository(JoinFlow).save(joinFlow);
}
Expand Down
8 changes: 1 addition & 7 deletions src/api/dto/SignupFlowDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export class StartSignupFlowDto implements CompleteUrls {

export class CompleteSignupFlowDto
extends CompleteJoinFlowDto
implements
Pick<JoinForm, "firstname" | "lastname" | "billingAddress" | "vatNumber">
implements Pick<JoinForm, "firstname" | "lastname" | "vatNumber">
{
@IsOptional()
@IsString()
Expand All @@ -53,11 +52,6 @@ export class CompleteSignupFlowDto
@IsString()
lastname?: string;

@IsOptional()
@ValidateNested()
@Type(() => UpdateAddressDto)
billingAddress?: UpdateAddressDto;

@IsOptional()
@IsString()
vatNumber?: string;
Expand Down
21 changes: 13 additions & 8 deletions src/core/providers/payment/StripeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,23 @@ export default class StripeProvider extends PaymentProvider<StripePaymentData> {
}

async updatePaymentMethod(flow: CompletedPaymentFlow): Promise<void> {
const paymentMethod = await stripe.paymentMethods.retrieve(flow.mandateId);
const address = paymentMethod.billing_details.address;

const customerData: Stripe.CustomerUpdateParams = {
invoice_settings: {
default_payment_method: flow.mandateId
},
...(flow.joinForm.billingAddress && {
address: {
line1: flow.joinForm.billingAddress.line1,
line2: flow.joinForm.billingAddress.line2 || "",
city: flow.joinForm.billingAddress.city,
postal_code: flow.joinForm.billingAddress.postcode
}
})
address: address
? {
line1: address.line1 || "",
...(address.city && { city: address.city }),
...(address.country && { country: address.country }),
...(address.line2 && { line2: address.line2 }),
...(address.postal_code && { postal_code: address.postal_code }),
...(address.state && { state: address.state })
}
: null
};

if (this.data.customerId) {
Expand Down
19 changes: 19 additions & 0 deletions src/migrations/1712163090314-RemoveJoinFormBillingAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class RemoveJoinFormBillingAddress1712163090314
implements MigrationInterface
{
name = "RemoveJoinFormBillingAddress1712163090314";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "join_flow" DROP COLUMN "joinFormBillingaddress"`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "join_flow" ADD "joinFormBillingaddress" jsonb`
);
}
}
3 changes: 0 additions & 3 deletions src/models/JoinForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export default class JoinForm implements PaymentForm, ReferralGiftForm {
@Column({ type: String, nullable: true })
lastname?: string | null;

@Column({ type: "jsonb", nullable: true })
billingAddress?: Address | null;

@Column({ type: String, nullable: true })
vatNumber?: string | null;

Expand Down

0 comments on commit e0dbcd6

Please sign in to comment.