From e558fcabc0bbf4983e6702a4abaa580b6091c383 Mon Sep 17 00:00:00 2001 From: Kataev Denis Date: Tue, 11 Oct 2022 09:55:01 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#12797=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bonus-program.component.html | 1 + .../bonus-program.component.scss | 19 +++++++--- .../bonus-program/bonus-program.component.ts | 36 ++++++++++++++++++- src/app/services/apple-wallet.service.ts | 22 ++++++++++++ src/environments/environment.ts | 3 ++ 5 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 src/app/services/apple-wallet.service.ts diff --git a/src/app/pages/account/bonus-program/bonus-program.component.html b/src/app/pages/account/bonus-program/bonus-program.component.html index 25510fa..1d0d03c 100644 --- a/src/app/pages/account/bonus-program/bonus-program.component.html +++ b/src/app/pages/account/bonus-program/bonus-program.component.html @@ -47,4 +47,5 @@ + diff --git a/src/app/pages/account/bonus-program/bonus-program.component.scss b/src/app/pages/account/bonus-program/bonus-program.component.scss index 60f65d6..623bb5d 100644 --- a/src/app/pages/account/bonus-program/bonus-program.component.scss +++ b/src/app/pages/account/bonus-program/bonus-program.component.scss @@ -3,14 +3,14 @@ display: flex; flex-direction: column; - &>h2 { + & > h2 { font-style: normal; font-weight: 700; font-size: 20px; line-height: 24px; } - &>p { + & > p { font-style: normal; font-weight: 400; font-size: 15px; @@ -154,12 +154,12 @@ } &.active_back { - >.card-content__front { + > .card-content__front { transform: rotateY(180deg); opacity: 0; } - >.card-content__back { + > .card-content__back { opacity: 1; transform: rotateY(0deg); } @@ -196,5 +196,14 @@ font-size: 12px; margin-bottom: 8px; } + + .add-to-wallet { + margin-top: 12px; + height: 36px; + border-radius: 8px; + background: #09467f; + border-color: #09467f; + color: #fff; + } } -} \ No newline at end of file +} diff --git a/src/app/pages/account/bonus-program/bonus-program.component.ts b/src/app/pages/account/bonus-program/bonus-program.component.ts index c663676..15084f5 100644 --- a/src/app/pages/account/bonus-program/bonus-program.component.ts +++ b/src/app/pages/account/bonus-program/bonus-program.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Inject, OnInit } from '@angular/core'; import { lastValueFrom } from 'rxjs'; import { orderStatuses, PageList, PageListWithBonus } from 'src/app/app.constants'; import { BonusProgramAccount, Page, Purchase, Transaction } from 'src/app/interface/data'; @@ -6,6 +6,10 @@ import { JsonrpcService, RpcService } from 'src/app/services/jsonrpc.service'; import * as moment from 'moment-timezone'; import * as barcode from 'jsbarcode'; import { environment } from 'src/environments/environment'; +import { AppleWalletService } from 'src/app/services/apple-wallet.service'; +import { CookiesService } from 'src/app/services/cookies.service'; +import { DOCUMENT } from '@angular/common'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; @Component({ selector: 'app-bonus-program', @@ -22,13 +26,25 @@ export class BonusProgramComponent implements OnInit { readonly pageList = environment.hasBonusProgram ? PageListWithBonus : PageList; public currentPage: Page = this.pageList[1]; public userName: string = ''; + public deviceType: 'ios' | 'android' | null = null; constructor( private jsonrpc: JsonrpcService, + private appleWallet: AppleWalletService, + private cookiesService: CookiesService, + @Inject(DOCUMENT) private document: Document, + private http: HttpClient, ) { } ngOnInit(): void { this.getAccountData(); + this.getTypeDevice() + } + + getTypeDevice() { + const userAgent = window.navigator.userAgent.toLowerCase() + const ios = /iphone|ipod|ipad/.test( userAgent ); + this.deviceType = ios ? 'ios' : 'android' } async getAccountData(): Promise{ @@ -101,4 +117,22 @@ export class BonusProgramComponent implements OnInit { }); } + + addCardToWallet(e: any) { + e.preventDefault() + const token = this.cookiesService.getItem('token') + if (token) { + this.appleWallet.generateCard(token).subscribe({ + next: (res: any) => { + this.document.location.href = res.url + }, + error: (err) => { + console.log('Error: ', err); + + } + }) + } + + } + } diff --git a/src/app/services/apple-wallet.service.ts b/src/app/services/apple-wallet.service.ts new file mode 100644 index 0000000..360cda3 --- /dev/null +++ b/src/app/services/apple-wallet.service.ts @@ -0,0 +1,22 @@ +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { environment } from 'src/environments/environment'; + +@Injectable({ + providedIn: 'root', +}) +export class AppleWalletService { + private url: string = environment.appleWalletEndpoint; + constructor( + private http: HttpClient, + ) {} + + generateCard(token: string) { + let headers = new HttpHeaders(); + headers = headers.set('Authorization', environment.appleWalletSecret); + const options = { + headers: headers, + }; + return this.http.get(`${this.url}/client/${environment.clientName}/passUrl/${token}`, options) + } +} diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 7802e04..e857a70 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -18,4 +18,7 @@ export const environment = { measurementId: 'G-RQF97ZK7R1', }, version: packageJson.version, + appleWalletEndpoint: 'https://ru-academy.online/apns/api', + appleWalletSecret: 'Token Z_vtuf_flvby!', + clientName: 'fashionlogica' };