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 }