[accelerator] avoid premature square setup call

This commit is contained in:
nymkappa 2024-07-25 21:49:48 +02:00
parent 481859bc8f
commit d3e3650cac
No known key found for this signature in database
GPG Key ID: 92358FC85D9645DE

View File

@ -90,7 +90,6 @@ export class AccelerateCheckout implements OnInit, OnDestroy {
auth: IAuth | null = null;
// accelerator stuff
square: { appId: string, locationId: string};
accelerationUUID: string;
accelerationSubscription: Subscription;
difficultySubscription: Subscription;
@ -113,7 +112,6 @@ export class AccelerateCheckout implements OnInit, OnDestroy {
loadingCashapp = false;
loadingApplePay = false;
loadingGooglePay = false;
cashappError = false;
cashappSubmit: any;
payments: any;
cashAppPay: any;
@ -170,13 +168,6 @@ export class AccelerateCheckout implements OnInit, OnDestroy {
this.moveToStep('summary');
}
this.servicesApiService.setupSquare$().subscribe(ids => {
this.square = {
appId: ids.squareAppId,
locationId: ids.squareLocationId
};
});
this.conversionsSubscription = this.stateService.conversions$.subscribe(
async (conversions) => {
this.conversions = conversions;
@ -443,20 +434,27 @@ export class AccelerateCheckout implements OnInit, OnDestroy {
}
async initSquare(): Promise<void> {
try {
//@ts-ignore
this.payments = window.Square.payments(this.square.appId, this.square.locationId)
const urlParams = new URLSearchParams(window.location.search);
if (this._step === 'cashapp' || urlParams.get('cash_request_id')) {
await this.requestCashAppPayment();
} else if (this._step === 'applepay') {
await this.requestApplePayPayment();
} else if (this._step === 'googlepay') {
await this.requestGooglePayPayment();
}
this.servicesApiService.setupSquare$().subscribe({
next: async (ids) => {
//@ts-ignore
this.payments = window.Square.payments(ids.squareAppId, ids.squareLocationId)
const urlParams = new URLSearchParams(window.location.search);
if (this._step === 'cashapp' || urlParams.get('cash_request_id')) {
await this.requestCashAppPayment();
} else if (this._step === 'applepay') {
await this.requestApplePayPayment();
} else if (this._step === 'googlepay') {
await this.requestGooglePayPayment();
}
},
error: () => {
console.debug('Error loading Square Payments');
this.accelerateError = 'cannot_setup_square';
}
});
} catch (e) {
console.debug('Error loading Square Payments', e);
this.cashappError = true;
return;
this.accelerateError = 'cannot_setup_square';
}
}