From 0ae4b54bd83cb0b85090c0c38548294674a57c37 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Fri, 4 Aug 2023 10:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ios=E5=86=85=E8=B4=AD?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JCWallet.d.ts | 1 + src/api/PayApi.ts | 5 +++++ src/config/cfg_421613_dev.js | 5 +++++ src/services/NativeSvr.ts | 6 ++++++ src/services/PaySvr.ts | 22 +++++++++++++++++++++- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/JCWallet.d.ts b/src/JCWallet.d.ts index 004acdd..e17eb20 100644 --- a/src/JCWallet.d.ts +++ b/src/JCWallet.d.ts @@ -34,6 +34,7 @@ declare namespace jsb { export function beginBuy(id: number, productId: string, orderId: string): string; export function queryPurchase(id: number): string; export function queryProducts(id: number, str: string): string; + export function finishTransaction(id: number, str: string); export function walletSecKey(id: string, openid: string, key_master: string, salt: string, pass: string): string; export function prepareWallet(id: string, openid: string, key_master: string, salt: string, pass: string): string; } diff --git a/src/api/PayApi.ts b/src/api/PayApi.ts index 8d02ede..cb79ef2 100644 --- a/src/api/PayApi.ts +++ b/src/api/PayApi.ts @@ -28,3 +28,8 @@ export function verifyGooglePay(data: any) { const url = `${PAY_API_HOST}/pay/google/verify`; return POST_JSON(url, data); } + +export function verifyApplePay(data: any) { + const url = `${PAY_API_HOST}/pay/apple/verify`; + return POST_JSON(url, data); +} diff --git a/src/config/cfg_421613_dev.js b/src/config/cfg_421613_dev.js index b6ddb66..60a1f9a 100644 --- a/src/config/cfg_421613_dev.js +++ b/src/config/cfg_421613_dev.js @@ -47,6 +47,11 @@ module.exports = { decimal: 6, thirdparty: 1, }, + { + address: '0xEbC170185ad614C05Af38C820020b70E458717F5', + name: 'gacha', + type: 'erc721', + }, ], contracts: { minterFactory: '0x1A27515c35a92Fb276c2670fa27C85ffAd75D094', diff --git a/src/services/NativeSvr.ts b/src/services/NativeSvr.ts index 469a1e2..6c12fcc 100644 --- a/src/services/NativeSvr.ts +++ b/src/services/NativeSvr.ts @@ -93,4 +93,10 @@ export class NativeSvr { jsb.queryProducts(id, productIds); return this._subscribeToCallResponse(id); } + + public finishTransaction(transactionId: string) { + let id = payloadId(); + jsb.finishTransaction(id, transactionId); + return this._subscribeToCallResponse(id); + } } diff --git a/src/services/PaySvr.ts b/src/services/PaySvr.ts index 0d44ae2..9cf8d30 100644 --- a/src/services/PaySvr.ts +++ b/src/services/PaySvr.ts @@ -1,4 +1,4 @@ -import { queryFiatList, queryTokenUsdPrice, reqAlchemyPrePay, verifyGooglePay } from '../api/PayApi'; +import { queryFiatList, queryTokenUsdPrice, reqAlchemyPrePay, verifyApplePay, verifyGooglePay } from '../api/PayApi'; import { ZError } from '../common/ZError'; import { singleton } from '../decorator/singleton.decorator'; import { IPayData } from '../types/data.types'; @@ -126,8 +126,28 @@ export class PaySvr { return str; } + public async queryIOSPurchases() { + let result = await new NativeSvr().queryPurchase(); + let data = JSON.parse(result + ''); + console.log('query purchase result:: ' + data); + if (data.length === 0) { + throw new ZError(10, 'no records'); + } + let res = await verifyApplePay({ list: data }); + if (res.errcode) { + throw new ZError(res.errcode, res.errmsg); + } + if (res.data.length > 0) { + for (let i = 0; i < res.data.length; i++) { + await new NativeSvr().finishTransaction(res.data[i]); + } + } + return data; + } + public async beginIOSPurchase(productId: string, orderId: string) { let result = await new NativeSvr().buyProduct(productId, orderId); + return result; } // end of iOS purchase }