From e9cd98af88951f6f26c1e769633a837f1b06eaec Mon Sep 17 00:00:00 2001 From: Chris Veilleux Date: Tue, 26 Mar 2019 19:00:20 -0500 Subject: [PATCH] changed how membership changes are communicated to the backend and fixed a couple of bugs related to that process --- .../src/app/core/http/profile.service.ts | 2 +- .../cards/membership/membership.component.ts | 20 +++++++++++-------- .../views/payment/payment.component.ts | 12 +++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/projects/account/src/app/core/http/profile.service.ts b/projects/account/src/app/core/http/profile.service.ts index a611d23..475bd38 100644 --- a/projects/account/src/app/core/http/profile.service.ts +++ b/projects/account/src/app/core/http/profile.service.ts @@ -117,7 +117,7 @@ export class ProfileService { } updateAccount(accountChanges: any) { - return this.http.patch(ACCOUNT_URL, {accountChanges}).pipe( + return this.http.patch(ACCOUNT_URL, accountChanges).pipe( catchError(this.handleError) ); } diff --git a/projects/account/src/app/modules/profile/components/cards/membership/membership.component.ts b/projects/account/src/app/modules/profile/components/cards/membership/membership.component.ts index 4c82721..a5c748f 100644 --- a/projects/account/src/app/modules/profile/components/cards/membership/membership.component.ts +++ b/projects/account/src/app/modules/profile/components/cards/membership/membership.component.ts @@ -3,9 +3,9 @@ import { MediaChange, MediaObserver } from '@angular/flex-layout'; import { MatBottomSheet } from '@angular/material'; import { Subscription } from 'rxjs'; -import { AccountMembership } from '../../../../../shared/models/account-membership.model'; -import { MembershipType } from '../../../../../shared/models/membership.model'; -import { ProfileService } from '../../../../../core/http/profile.service'; +import { AccountMembership } from '@account/models/account-membership.model'; +import { MembershipType } from '@account/models/membership.model'; +import { ProfileService } from '@account/http/profile.service'; import { PaymentComponent } from '../../views/payment/payment.component'; @Component({ @@ -42,20 +42,24 @@ export class MembershipComponent implements OnDestroy { if (selectedMembership) { if (this.accountMembership) { // We have the user's credit card info but they decide to change plans - this.profileService.updateAccount({support: {membership: membershipType}}); + this.profileService.updateAccount( + {membership: {paymentMethod: 'Stripe', newMembership: false, membershipType: membershipType}} + ); } else { // No credit card info. Go to payment screen to collect - this.openBottomSheet(); + this.openBottomSheet(membershipType); } } else { // Membership termination - this.profileService.updateAccount({support: {membership: null}}); + this.profileService.updateAccount( + {membership: {paymentMethod: 'Stripe', newMembership: false, membershipType: null}} + ); } } - openBottomSheet() { + openBottomSheet(membershipType: string) { const bottomSheetConfig = { - data: {newAccount: false}, + data: {newAccount: false, membershipType: membershipType}, disableClose: true, restoreFocus: true }; diff --git a/projects/account/src/app/modules/profile/components/views/payment/payment.component.ts b/projects/account/src/app/modules/profile/components/views/payment/payment.component.ts index 4964789..3691bef 100644 --- a/projects/account/src/app/modules/profile/components/views/payment/payment.component.ts +++ b/projects/account/src/app/modules/profile/components/views/payment/payment.component.ts @@ -8,7 +8,7 @@ import { import { ElementOptions, StripeCardComponent, StripeService } from 'ngx-stripe'; -import { ProfileService } from '../../../../../core/http/profile.service'; +import { ProfileService } from '@account/http/profile.service'; import { VerifyCardDialogComponent } from './verify-card-dialog.component'; const twoSeconds = 2000; @@ -32,7 +32,6 @@ export class PaymentComponent implements OnInit { } } }; - private membershipType: string; private dialogRef: MatDialogRef; constructor( @@ -57,7 +56,7 @@ export class PaymentComponent implements OnInit { if (configData.newAccount) { this.showStripeSuccess(result.token.id); } else { - this.updateAccount(result.token.id); + this.updateAccount(configData.membershipType, result.token.id); } } else if (result.error) { this.showStripeError(result.error.message); @@ -73,10 +72,11 @@ export class PaymentComponent implements OnInit { ); } - updateAccount(stripeToken: string) { + updateAccount(membershipType: string, stripeToken: string) { const newMembership = { - support: { - membership: this.membershipType, + membership: { + newMembership: true, + membershipType: membershipType, paymentMethod: 'Stripe', paymentToken: stripeToken }