changed how membership changes are communicated to the backend and fixed a couple of bugs related to that process
parent
df342fe288
commit
e9cd98af88
|
@ -117,7 +117,7 @@ export class ProfileService {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAccount(accountChanges: any) {
|
updateAccount(accountChanges: any) {
|
||||||
return this.http.patch(ACCOUNT_URL, {accountChanges}).pipe(
|
return this.http.patch(ACCOUNT_URL, accountChanges).pipe(
|
||||||
catchError(this.handleError)
|
catchError(this.handleError)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@ import { MediaChange, MediaObserver } from '@angular/flex-layout';
|
||||||
import { MatBottomSheet } from '@angular/material';
|
import { MatBottomSheet } from '@angular/material';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
import { AccountMembership } from '../../../../../shared/models/account-membership.model';
|
import { AccountMembership } from '@account/models/account-membership.model';
|
||||||
import { MembershipType } from '../../../../../shared/models/membership.model';
|
import { MembershipType } from '@account/models/membership.model';
|
||||||
import { ProfileService } from '../../../../../core/http/profile.service';
|
import { ProfileService } from '@account/http/profile.service';
|
||||||
import { PaymentComponent } from '../../views/payment/payment.component';
|
import { PaymentComponent } from '../../views/payment/payment.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -42,20 +42,24 @@ export class MembershipComponent implements OnDestroy {
|
||||||
if (selectedMembership) {
|
if (selectedMembership) {
|
||||||
if (this.accountMembership) {
|
if (this.accountMembership) {
|
||||||
// We have the user's credit card info but they decide to change plans
|
// 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 {
|
} else {
|
||||||
// No credit card info. Go to payment screen to collect
|
// No credit card info. Go to payment screen to collect
|
||||||
this.openBottomSheet();
|
this.openBottomSheet(membershipType);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Membership termination
|
// Membership termination
|
||||||
this.profileService.updateAccount({support: {membership: null}});
|
this.profileService.updateAccount(
|
||||||
|
{membership: {paymentMethod: 'Stripe', newMembership: false, membershipType: null}}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openBottomSheet() {
|
openBottomSheet(membershipType: string) {
|
||||||
const bottomSheetConfig = {
|
const bottomSheetConfig = {
|
||||||
data: {newAccount: false},
|
data: {newAccount: false, membershipType: membershipType},
|
||||||
disableClose: true,
|
disableClose: true,
|
||||||
restoreFocus: true
|
restoreFocus: true
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
|
|
||||||
import { ElementOptions, StripeCardComponent, StripeService } from 'ngx-stripe';
|
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';
|
import { VerifyCardDialogComponent } from './verify-card-dialog.component';
|
||||||
|
|
||||||
const twoSeconds = 2000;
|
const twoSeconds = 2000;
|
||||||
|
@ -32,7 +32,6 @@ export class PaymentComponent implements OnInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private membershipType: string;
|
|
||||||
private dialogRef: MatDialogRef<VerifyCardDialogComponent>;
|
private dialogRef: MatDialogRef<VerifyCardDialogComponent>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -57,7 +56,7 @@ export class PaymentComponent implements OnInit {
|
||||||
if (configData.newAccount) {
|
if (configData.newAccount) {
|
||||||
this.showStripeSuccess(result.token.id);
|
this.showStripeSuccess(result.token.id);
|
||||||
} else {
|
} else {
|
||||||
this.updateAccount(result.token.id);
|
this.updateAccount(configData.membershipType, result.token.id);
|
||||||
}
|
}
|
||||||
} else if (result.error) {
|
} else if (result.error) {
|
||||||
this.showStripeError(result.error.message);
|
this.showStripeError(result.error.message);
|
||||||
|
@ -73,10 +72,11 @@ export class PaymentComponent implements OnInit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAccount(stripeToken: string) {
|
updateAccount(membershipType: string, stripeToken: string) {
|
||||||
const newMembership = {
|
const newMembership = {
|
||||||
support: {
|
membership: {
|
||||||
membership: this.membershipType,
|
newMembership: true,
|
||||||
|
membershipType: membershipType,
|
||||||
paymentMethod: 'Stripe',
|
paymentMethod: 'Stripe',
|
||||||
paymentToken: stripeToken
|
paymentToken: stripeToken
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue