add google in-app purchase
This commit is contained in:
parent
2e1c76976d
commit
676e1176de
19
src/JCWallet.d.ts
vendored
19
src/JCWallet.d.ts
vendored
@ -31,20 +31,11 @@ declare namespace jsb {
|
||||
export function hashSvrPass(pass: string): string;
|
||||
export function walletEncrypt(str: string): string;
|
||||
export function walletDecrypt(str: string): 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;
|
||||
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 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;
|
||||
}
|
||||
|
||||
declare let window: Window;
|
||||
|
@ -1,17 +1,22 @@
|
||||
import { WALLET_API_HOST } from "../config/constants";
|
||||
import { GET_JSON, POST_JSON } from "../lib/Http";
|
||||
import { PAY_API_HOST } from '../config/constants';
|
||||
import { GET_JSON, POST_JSON } from '../lib/Http';
|
||||
|
||||
export function reqAlchemyPrePay(data: any) {
|
||||
const url = `${WALLET_API_HOST}/pay/alchemy/buy`;
|
||||
const url = `${PAY_API_HOST}/pay/alchemy/buy`;
|
||||
return POST_JSON(url, data);
|
||||
}
|
||||
|
||||
export function queryTokenUsdPrice(eth: string, chain: string, env: string) {
|
||||
const url = `${WALLET_API_HOST}/pay/alchemy/crypto_price`;
|
||||
const url = `${PAY_API_HOST}/pay/alchemy/crypto_price`;
|
||||
return POST_JSON(url, { token: eth, chain, env });
|
||||
}
|
||||
|
||||
export function queryFiatList() {
|
||||
const url = `${WALLET_API_HOST}/pay/alchemy/fait_list`;
|
||||
const url = `${PAY_API_HOST}/pay/alchemy/fait_list`;
|
||||
return GET_JSON(url);
|
||||
}
|
||||
|
||||
export function verifyGooglePay(data: any) {
|
||||
const url = `${PAY_API_HOST}/pay/google/verify`;
|
||||
return POST_JSON(url, data);
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
export const WALLET_STORAGE_KEY_NAME = "jc_wallet_data";
|
||||
export const WALLET_STORAGE_KEY_NAME = 'jc_wallet_data';
|
||||
|
||||
// export const WALLET_API_HOST = "https://wallet.cebggame.com";
|
||||
export const WALLET_API_HOST = "https://pay.cebggame.com";
|
||||
// export const WALLET_API_HOST = "http://192.168.100.185:3007";
|
||||
// export const WALLET_API_HOST = 'http://192.168.100.183:3007';
|
||||
// export const PAY_API_HOST = 'http://192.168.100.183:3007';
|
||||
export const WALLET_API_HOST = 'https://pay.cebggame.com';
|
||||
export const PAY_API_HOST = 'https://pay.cebggame.com/v1';
|
||||
|
||||
export const MAX_TRY_COUNT = 6;
|
||||
|
||||
@ -10,12 +12,12 @@ export const MAX_UPLOAD_COUNT = 10;
|
||||
|
||||
export const TX_CONFIRM_BLOCKS = 6;
|
||||
|
||||
export const NATIVE_PK_PREFIX = "0x000000000000000000000000";
|
||||
export const NATIVE_PK_PREFIX = '0x000000000000000000000000';
|
||||
|
||||
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
||||
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
|
||||
export const AVAILABLE_CHAINS = [80001, 421613, 137, 42161];
|
||||
|
||||
export const BASE_TOKEN_URI = "https://market.cebg.games/api/nft/info/";
|
||||
export const BASE_TOKEN_URI = 'https://market.cebg.games/api/nft/info/';
|
||||
|
||||
export const GAS_BOOST = 1.2;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { payloadId } from "@walletconnect/utils";
|
||||
import { createWalletEvents } from "../common/WalletEvent";
|
||||
import { singleton } from "../decorator/singleton.decorator";
|
||||
import { payloadId } from '@walletconnect/utils';
|
||||
import { createWalletEvents } from '../common/WalletEvent';
|
||||
import { singleton } from '../decorator/singleton.decorator';
|
||||
|
||||
@singleton
|
||||
export class NativeSvr {
|
||||
@ -75,4 +75,22 @@ export class NativeSvr {
|
||||
jsb.scanQRCode(id, title);
|
||||
return this._subscribeToCallResponse(id);
|
||||
}
|
||||
|
||||
public buyProduct(productId: string, orderId: string) {
|
||||
let id = payloadId();
|
||||
jsb.beginBuy(id, productId, orderId);
|
||||
return this._subscribeToCallResponse(id);
|
||||
}
|
||||
|
||||
public queryPurchase() {
|
||||
let id = payloadId();
|
||||
jsb.queryPurchase(id);
|
||||
return this._subscribeToCallResponse(id);
|
||||
}
|
||||
|
||||
public queryProducts(productIds: string) {
|
||||
let id = payloadId();
|
||||
jsb.queryProducts(id, productIds);
|
||||
return this._subscribeToCallResponse(id);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
import {
|
||||
queryFiatList,
|
||||
queryTokenUsdPrice,
|
||||
reqAlchemyPrePay,
|
||||
} from "../api/PayApi";
|
||||
import { singleton } from "../decorator/singleton.decorator";
|
||||
import { IPayData } from "../types/data.types";
|
||||
import { queryFiatList, queryTokenUsdPrice, reqAlchemyPrePay, verifyGooglePay } from '../api/PayApi';
|
||||
import { ZError } from '../common/ZError';
|
||||
import { singleton } from '../decorator/singleton.decorator';
|
||||
import { IPayData } from '../types/data.types';
|
||||
import { NativeSvr } from './NativeSvr';
|
||||
|
||||
@singleton
|
||||
export class PaySvr {
|
||||
@ -24,13 +22,13 @@ export class PaySvr {
|
||||
throw new Error(res.errmsg);
|
||||
}
|
||||
if (!res.data) {
|
||||
throw new Error("No data returned");
|
||||
throw new Error('No data returned');
|
||||
}
|
||||
const url = res.data.url;
|
||||
if (!url) {
|
||||
throw new Error("No url returned");
|
||||
throw new Error('No url returned');
|
||||
}
|
||||
console.log("pay url::", url);
|
||||
console.log('pay url::', url);
|
||||
// jsb.showWebPage(url);
|
||||
// jsb.openURL(url);
|
||||
return res.data;
|
||||
@ -40,34 +38,26 @@ export class PaySvr {
|
||||
const key = `gasprice_${chainId}`;
|
||||
if (!this.priceMap.has(key)) {
|
||||
let price = await new jc.wallet.web3.eth.getGasPrice();
|
||||
this.priceMap.set(key, price + "");
|
||||
this.priceMap.set(key, price + '');
|
||||
} else {
|
||||
setImmediate(async () => {
|
||||
let price = await new jc.wallet.web3.eth.getGasPrice();
|
||||
this.priceMap.set(key, price + "");
|
||||
this.priceMap.set(key, price + '');
|
||||
});
|
||||
}
|
||||
console.log("gas price", this.priceMap.get(key));
|
||||
console.log('gas price', this.priceMap.get(key));
|
||||
return this.priceMap.get(key);
|
||||
}
|
||||
|
||||
private async updateTokenPrice(
|
||||
chain: string,
|
||||
tokenName: string,
|
||||
env: string
|
||||
) {
|
||||
private async updateTokenPrice(chain: string, tokenName: string, env: string) {
|
||||
const key = `crypto_usd_${chain}_${tokenName}_${env}`;
|
||||
let priceData = await queryTokenUsdPrice(tokenName, chain, env);
|
||||
console.log("ETH price data", JSON.stringify(priceData));
|
||||
console.log('ETH price data', JSON.stringify(priceData));
|
||||
let price = priceData.data.price;
|
||||
this.priceMap.set(key, price + "");
|
||||
this.priceMap.set(key, price + '');
|
||||
}
|
||||
|
||||
public async queryTokenPrice(
|
||||
chain: string,
|
||||
tokenName: string,
|
||||
env: string = "release"
|
||||
) {
|
||||
public async queryTokenPrice(chain: string, tokenName: string, env: string = 'release') {
|
||||
chain = chain.toUpperCase();
|
||||
tokenName = tokenName.toUpperCase();
|
||||
const key = `crypto_usd_${chain}_${tokenName}_${env}`;
|
||||
@ -75,22 +65,58 @@ export class PaySvr {
|
||||
try {
|
||||
await this.updateTokenPrice(chain, tokenName, env);
|
||||
} catch (err) {
|
||||
console.log("ETH price err", err);
|
||||
console.log('ETH price err', err);
|
||||
}
|
||||
} else {
|
||||
setImmediate(async () => {
|
||||
try {
|
||||
await this.updateTokenPrice(chain, tokenName, env);
|
||||
} catch (err) {
|
||||
console.log("ETH price err", err);
|
||||
console.log('ETH price err', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
console.log("ETH price", this.priceMap.get(key));
|
||||
console.log('ETH price', this.priceMap.get(key));
|
||||
return this.priceMap.get(key);
|
||||
}
|
||||
|
||||
public async fetchFiatList() {
|
||||
return queryFiatList();
|
||||
}
|
||||
|
||||
// begin of google pay
|
||||
public async queryGoogleProducts(productIds: string[]) {
|
||||
let str = await new NativeSvr().queryProducts(productIds.join(','));
|
||||
return str;
|
||||
}
|
||||
|
||||
public async queryGooglePurchases() {
|
||||
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 verifyGooglePay({ list: data });
|
||||
if (res.errcode) {
|
||||
throw new ZError(res.errcode, res.errmsg);
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
public async buyGoogleProduct(productId: string, orderId: string) {
|
||||
let result = await new NativeSvr().buyProduct(productId, orderId);
|
||||
let data = JSON.parse(result + '');
|
||||
console.log('native buy result:: ' + data);
|
||||
if (data.length === 0) {
|
||||
throw new ZError(10, 'no records');
|
||||
}
|
||||
let res = await verifyGooglePay({ list: data });
|
||||
if (res.errcode) {
|
||||
throw new ZError(res.errcode, res.errmsg);
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
// end of google pay
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user