12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- const Global = require("Global");
- const ENVIRONMENT_TYPE = { STAGE: 1, PRODUCTION: 2};
- class PaytmUtil {
- constructor() {
- this.environment = ENVIRONMENT_TYPE.PRODUCTION;
- }
- pay({midId, orderId, txnTokenId, callBackUrl}, txnAmountId) {
- let jsCallBackName = "Paytm_Callback";
- cc.game.once(jsCallBackName, this.onPayResult.bind(this));
- Global.print(`PaytmUtil:: onPaySuccess: 跳转支付(${midId}, ${orderId}, ${txnTokenId}, ${callBackUrl}, ${txnAmountId})`);
- cc.vv.reflection.changeOrientation("Portrait");
- cc.vv.reflection.payByPaytm(
- midId.toString(),
- orderId.toString(),
- txnTokenId.toString(),
- txnAmountId.toString(),
- callBackUrl.toString(),
- jsCallBackName.toString()
- );
- }
- onPayResult(code, ...data) {
- Global.print("PaytmUtil:: onPayResult: paytm支付返回Code:" + code);
- cc.vv.reflection.changeOrientation("Landscape");
- switch(code) {
- case 0: this.onPaySuccess(...data);break;
- case 1: this.onNetworkNotAvailable();break;
- case 2: this.onErrorProceed(...data);break;
- case 3: this.onClientAuthenticationFailed(...data);break;
- case 4: this.onSomeUIErrorOccurred(...data);break;
- case 5: this.onErrorLoadingWebPage(...data);break;
- case 6: this.onBackPressedCancelTransaction();break;
- case 7: this.onTransactionCancel(...data);break;
- }
- }
- onPaySuccess(data) {
- Global.print("PaytmUtil:: onPaySuccess: 支付成功");
- }
- onNetworkNotAvailable() {
- Global.print("PaytmUtil:: onNetworkNotAvailable: 网络无法连接");
- }
- onErrorProceed(data) {
- Global.print("PaytmUtil:: onErrorProceed: 支付发生错误");
- }
- onClientAuthenticationFailed(data) {
- Global.print("PaytmUtil:: onClientAuthenticationFailed: 用户验证失败");
- }
- onSomeUIErrorOccurred(data) {
- Global.print("PaytmUtil:: onSomeUIErrorOccurred: 发生未知错误");
- }
- onErrorLoadingWebPage(i, s, s1) {
- Global.print("PaytmUtil:: onErrorLoadingWebPage: 载入页面时发生错误");
- }
- onBackPressedCancelTransaction() {
- Global.print("PaytmUtil:: onBackPressedCancelTransaction: 取消支付");
- }
- onTransactionCancel(s, data) {
- Global.print("PaytmUtil:: onTransactionCancel: 取消支付");
- }
- }
- module.exports = new PaytmUtil();
|