Skip to content

Commit

Permalink
Merge pull request #43 from beabee-communityrm/fix/complete-join-flow…
Browse files Browse the repository at this point in the history
…-no-contrib

fix: always complete join flow, even if no contribution
  • Loading branch information
wpf500 authored Aug 7, 2024
2 parents 1806a01 + fc5971a commit a95ad8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions apps/backend/src/api/controllers/ContactController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ export class ContactController {
}

const completedFlow = await PaymentFlowService.completeJoinFlow(joinFlow);
if (!completedFlow) {
throw new NotFoundError();
}

await PaymentService.updatePaymentMethod(target, completedFlow);

return joinFlow;
Expand Down
16 changes: 9 additions & 7 deletions packages/core/src/services/PaymentFlowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ class PaymentFlowService implements PaymentFlowProvider {
return await getRepository(JoinFlow).findOneBy({ paymentFlowId });
}

async completeJoinFlow(joinFlow: JoinFlow): Promise<CompletedPaymentFlow> {
async completeJoinFlow(
joinFlow: JoinFlow
): Promise<CompletedPaymentFlow | undefined> {
log.info("Completing join flow " + joinFlow.id);
const paymentFlow = await this.completePaymentFlow(joinFlow);
const paymentFlow =
joinFlow.joinForm.monthlyAmount > 0
? await this.completePaymentFlow(joinFlow)
: undefined;
await getRepository(JoinFlow).delete(joinFlow.id);
return paymentFlow;
}
Expand Down Expand Up @@ -161,13 +166,10 @@ class PaymentFlowService implements PaymentFlowProvider {
lastname: joinFlow.joinForm.lastname || ""
};

let completedPaymentFlow: CompletedPaymentFlow | undefined;
const completedPaymentFlow = await this.completeJoinFlow(joinFlow);
let deliveryAddress: Address | undefined;

// Only complete join flow for those with a contribution
// TODO: rework join flow to properly accommodate no contributions
if (joinFlow.joinForm.monthlyAmount !== 0) {
completedPaymentFlow = await this.completeJoinFlow(joinFlow);
if (completedPaymentFlow) {
const paymentData =
await this.getCompletedPaymentFlowData(completedPaymentFlow);

Expand Down

0 comments on commit a95ad8d

Please sign in to comment.