dev #14490 WPA CoffeeLike добавление в wallet вместо установки для iOS
This commit is contained in:
parent
425ef99af2
commit
30854f4cb9
@ -4,7 +4,7 @@ import {
|
|||||||
HostListener,
|
HostListener,
|
||||||
OnInit,
|
OnInit,
|
||||||
Renderer2,
|
Renderer2,
|
||||||
Inject,
|
Inject,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { lastValueFrom } from 'rxjs';
|
import { lastValueFrom } from 'rxjs';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
@ -26,11 +26,11 @@ export class DownloadAppDirective implements OnInit {
|
|||||||
public renderer: Renderer2,
|
public renderer: Renderer2,
|
||||||
private el: ElementRef,
|
private el: ElementRef,
|
||||||
private _snackBar: MatSnackBar,
|
private _snackBar: MatSnackBar,
|
||||||
private appleWallet: AppleWalletService,
|
private appleWallet: AppleWalletService,
|
||||||
private cookiesService: CookiesService,
|
private cookiesService: CookiesService,
|
||||||
@Inject(DOCUMENT) private document: Document,
|
@Inject(DOCUMENT) private document: Document,
|
||||||
private jsonrpc: JsonrpcService,
|
private jsonrpc: JsonrpcService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.getTypeDevice();
|
this.getTypeDevice();
|
||||||
@ -68,9 +68,10 @@ export class DownloadAppDirective implements OnInit {
|
|||||||
if (event) {
|
if (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
await this.addCardToWallet();
|
||||||
|
return;
|
||||||
|
|
||||||
if (this.deviceType === 'ios') {
|
if (this.deviceType === 'ios') {
|
||||||
await this.addCardToWallet();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!this.deferredPrompt) {
|
if (!this.deferredPrompt) {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@ -93,29 +94,35 @@ export class DownloadAppDirective implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async addCardToWallet() {
|
async addCardToWallet() {
|
||||||
const token = this.cookiesService.getItem('token');
|
const token = this.cookiesService.getItem('token');
|
||||||
const accountData = (
|
try {
|
||||||
await lastValueFrom(
|
const accountData = (
|
||||||
this.jsonrpc.rpc(
|
await lastValueFrom(
|
||||||
{
|
this.jsonrpc.rpc(
|
||||||
method: 'getTokenData',
|
{
|
||||||
params: [],
|
method: 'getTokenData',
|
||||||
},
|
params: [],
|
||||||
RpcService.authService,
|
},
|
||||||
true
|
RpcService.authService,
|
||||||
|
true
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
).data;
|
||||||
).data;
|
|
||||||
if (token && accountData.user_id) {
|
if (token && accountData.user_id) {
|
||||||
this.appleWallet.generateCard(token, accountData.user_id).subscribe({
|
this.appleWallet.generateCard(token, accountData.user_id).subscribe({
|
||||||
next: (res: any) => {
|
next: (res: any) => {
|
||||||
this.document.location.href = res.url;
|
this.document.location.href = res.url;
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
console.log('Error: ', err);
|
console.log('Error: ', err);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export class GuestCardComponent implements OnInit {
|
|||||||
public customerInfo!: any;
|
public customerInfo!: any;
|
||||||
public purchases!: Purchase[];
|
public purchases!: Purchase[];
|
||||||
public lastPurchase!: Purchase;
|
public lastPurchase!: Purchase;
|
||||||
public Math: Math = Math;
|
public Math: Math = Math;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _bottomSheet: MatBottomSheet,
|
private _bottomSheet: MatBottomSheet,
|
||||||
@ -31,11 +31,11 @@ export class GuestCardComponent implements OnInit {
|
|||||||
private router: Router,
|
private router: Router,
|
||||||
private wpJsonService: WpJsonService,
|
private wpJsonService: WpJsonService,
|
||||||
public loyaltyProgram: LoyaltyProgramService
|
public loyaltyProgram: LoyaltyProgramService
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const token = this.cookiesService.getItem('token');
|
const token = this.cookiesService.getItem('token');
|
||||||
this.loyaltyProgram.purchaseData.$loading = true;
|
this.loyaltyProgram.purchaseData.$loading = true;
|
||||||
this.wpJsonService
|
this.wpJsonService
|
||||||
.getCustomerInfo(
|
.getCustomerInfo(
|
||||||
environment.systemId,
|
environment.systemId,
|
||||||
@ -45,17 +45,18 @@ export class GuestCardComponent implements OnInit {
|
|||||||
.subscribe({
|
.subscribe({
|
||||||
next: (value) => {
|
next: (value) => {
|
||||||
this.customerInfo = value.customer_info;
|
this.customerInfo = value.customer_info;
|
||||||
|
|
||||||
this.cookiesService.setCookie('phone-number', this.customerInfo?.phone?.substr(2))
|
this.cookiesService.setCookie('phone-number', this.customerInfo?.phone?.substr(2))
|
||||||
this.getPurchases().subscribe((value) => {
|
this.getPurchases().subscribe((value) => {
|
||||||
this.purchases = this.loyaltyProgram.filterPurchases(value[this.customerInfo?.id])
|
this.purchases = this.loyaltyProgram.filterPurchases(value[this.customerInfo?.id])
|
||||||
this.lastPurchase = this.loyaltyProgram.getLastPurchase(this.purchases)
|
this.lastPurchase = this.loyaltyProgram.getLastPurchase(this.purchases)
|
||||||
|
|
||||||
this.loyaltyProgram.setLastPurchases(this.purchases)
|
this.loyaltyProgram.setLastPurchases(this.purchases)
|
||||||
this.loyaltyProgram.setCurrentPurchases(this.purchases)
|
this.loyaltyProgram.setCurrentPurchases(this.purchases)
|
||||||
|
|
||||||
const currentAmount = this.loyaltyProgram.purchaseData.currentAmount || 0
|
const currentAmount = this.loyaltyProgram.purchaseData.currentAmount || 0
|
||||||
this.loyaltyProgram.setCurrentLvl(currentAmount)
|
this.loyaltyProgram.setCurrentLvl(currentAmount)
|
||||||
// this.currentLvlPeriod = this.lvlPeriods.find((item) => item.start <= currentAmount && currentAmount <= (item.end || Infinity))!
|
|
||||||
this.loyaltyProgram.purchaseData.$loading = false;
|
this.loyaltyProgram.purchaseData.$loading = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -69,7 +70,7 @@ export class GuestCardComponent implements OnInit {
|
|||||||
|
|
||||||
deleteToken(): void {
|
deleteToken(): void {
|
||||||
this.cookiesService.logout();
|
this.cookiesService.logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
logout() {
|
logout() {
|
||||||
const bottomSheet = this._bottomSheet.open(ExitComponent);
|
const bottomSheet = this._bottomSheet.open(ExitComponent);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user