PaytmUtil.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const Global = require("Global");
  2. const ENVIRONMENT_TYPE = { STAGE: 1, PRODUCTION: 2};
  3. class PaytmUtil {
  4. constructor() {
  5. this.environment = ENVIRONMENT_TYPE.PRODUCTION;
  6. }
  7. pay({midId, orderId, txnTokenId, callBackUrl}, txnAmountId) {
  8. let jsCallBackName = "Paytm_Callback";
  9. cc.game.once(jsCallBackName, this.onPayResult.bind(this));
  10. Global.print(`PaytmUtil:: onPaySuccess: 跳转支付(${midId}, ${orderId}, ${txnTokenId}, ${callBackUrl}, ${txnAmountId})`);
  11. cc.vv.reflection.changeOrientation("Portrait");
  12. cc.vv.reflection.payByPaytm(
  13. midId.toString(),
  14. orderId.toString(),
  15. txnTokenId.toString(),
  16. txnAmountId.toString(),
  17. callBackUrl.toString(),
  18. jsCallBackName.toString()
  19. );
  20. }
  21. onPayResult(code, ...data) {
  22. Global.print("PaytmUtil:: onPayResult: paytm支付返回Code:" + code);
  23. cc.vv.reflection.changeOrientation("Landscape");
  24. switch(code) {
  25. case 0: this.onPaySuccess(...data);break;
  26. case 1: this.onNetworkNotAvailable();break;
  27. case 2: this.onErrorProceed(...data);break;
  28. case 3: this.onClientAuthenticationFailed(...data);break;
  29. case 4: this.onSomeUIErrorOccurred(...data);break;
  30. case 5: this.onErrorLoadingWebPage(...data);break;
  31. case 6: this.onBackPressedCancelTransaction();break;
  32. case 7: this.onTransactionCancel(...data);break;
  33. }
  34. }
  35. onPaySuccess(data) {
  36. Global.print("PaytmUtil:: onPaySuccess: 支付成功");
  37. }
  38. onNetworkNotAvailable() {
  39. Global.print("PaytmUtil:: onNetworkNotAvailable: 网络无法连接");
  40. }
  41. onErrorProceed(data) {
  42. Global.print("PaytmUtil:: onErrorProceed: 支付发生错误");
  43. }
  44. onClientAuthenticationFailed(data) {
  45. Global.print("PaytmUtil:: onClientAuthenticationFailed: 用户验证失败");
  46. }
  47. onSomeUIErrorOccurred(data) {
  48. Global.print("PaytmUtil:: onSomeUIErrorOccurred: 发生未知错误");
  49. }
  50. onErrorLoadingWebPage(i, s, s1) {
  51. Global.print("PaytmUtil:: onErrorLoadingWebPage: 载入页面时发生错误");
  52. }
  53. onBackPressedCancelTransaction() {
  54. Global.print("PaytmUtil:: onBackPressedCancelTransaction: 取消支付");
  55. }
  56. onTransactionCancel(s, data) {
  57. Global.print("PaytmUtil:: onTransactionCancel: 取消支付");
  58. }
  59. }
  60. module.exports = new PaytmUtil();