增加ios内购相关

This commit is contained in:
CounterFire2023 2023-08-04 10:07:30 +08:00
parent 4341ccfeff
commit 0ae4b54bd8
5 changed files with 38 additions and 1 deletions

1
src/JCWallet.d.ts vendored
View File

@ -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;
}

View File

@ -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);
}

View File

@ -47,6 +47,11 @@ module.exports = {
decimal: 6,
thirdparty: 1,
},
{
address: '0xEbC170185ad614C05Af38C820020b70E458717F5',
name: 'gacha',
type: 'erc721',
},
],
contracts: {
minterFactory: '0x1A27515c35a92Fb276c2670fa27C85ffAd75D094',

View File

@ -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);
}
}

View File

@ -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
}