zmp-sdk 2.18.1 → 2.19.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19808,6 +19808,7 @@
19808
19808
  GET_ACCESS_TOKEN: 'https://h5.zalo.me/openapi/access_token',
19809
19809
  GET_ACCESS_TOKEN_V3: 'https://oauth.zaloapp.com/v3/access_token',
19810
19810
  GET_LIST_USER_INFO: 'https://graph.zalo.me/v2.0/me/friends/list',
19811
+ CREATE_ORDER: 'https://payment-mini.zalo.me/api/order/create',
19811
19812
  };
19812
19813
  const STORAGE_LIMIT = 5 * MB;
19813
19814
  const NETWORK_TYPE = (isAndroid) => ({
@@ -20266,7 +20267,12 @@
20266
20267
  HIDE_HOME: 0
20267
20268
  };
20268
20269
  const SHOW_ACTION_BAR = 5;
20269
- const HIDE_ACTION_BAR = 6;
20270
+ const HIDE_ACTION_BAR = 6;
20271
+ const PAYMENT_APIS = {
20272
+ CREATE_ORDER: 'https://payment-mini.zalo.me/api/order/create',
20273
+ GET_TRANSACTION: 'https://payment-mini.zalo.me/api/transaction',
20274
+ };
20275
+ const PAYMENT_H5_URL = 'https://payment-mini.zalo.me';
20270
20276
 
20271
20277
  class CommonError {
20272
20278
  constructor(code, msg, api) {
@@ -20403,7 +20409,7 @@
20403
20409
  missingParam: (params) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `Missing required argument: ${params}`),
20404
20410
  wrongTypeParam: (arg, expected, got) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `Wrong type of parameter '${arg}'. Expected ${expected}, but got ${got}`),
20405
20411
  cannotGetShareInfo: () => new CommonError(RESPONSE_CODE.INTERNAL_SERVER_ERROR, `Can not get app info to share`),
20406
- lengthInvalid: (arg) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `${arg} length is invalid.`)
20412
+ lengthInvalid: (arg) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `${arg} length is invalid.`),
20407
20413
  }
20408
20414
  };
20409
20415
 
@@ -20776,7 +20782,7 @@
20776
20782
  }
20777
20783
  if (lodash.isNumber(option === null || option === void 0 ? void 0 : option.maxLength)) {
20778
20784
  return {
20779
- error: (lodash.isString(data) || lodash.isArray(data)) && data.length > (option === null || option === void 0 ? void 0 : option.maxLength),
20785
+ error: lodash.isString(data) && data.length > (option === null || option === void 0 ? void 0 : option.maxLength),
20780
20786
  errorMessage: `data length must <= ${option === null || option === void 0 ? void 0 : option.maxLength}`
20781
20787
  };
20782
20788
  }
@@ -21616,7 +21622,7 @@
21616
21622
  }
21617
21623
  _ZJSBridgeProvider_bridge = new WeakMap();
21618
21624
 
21619
- var version = "2.18.1";
21625
+ var version = "2.19.0-rc.1";
21620
21626
 
21621
21627
  class Basics {
21622
21628
  /**
@@ -23405,15 +23411,8 @@
23405
23411
  let reqData = {};
23406
23412
  switch (object.type) {
23407
23413
  case 'image':
23408
- let photoUrls = [];
23409
- if (Array.isArray(object.data.imageUrls) && object.data.imageUrls.length > 0) {
23410
- photoUrls = object.data.imageUrls;
23411
- }
23412
- else {
23413
- photoUrls.push(object.data.imageUrl);
23414
- }
23415
23414
  reqData = {
23416
- photoUrls: photoUrls,
23415
+ photoUrls: object.data.imageUrls,
23417
23416
  caption: object.data.caption
23418
23417
  };
23419
23418
  break;
@@ -24277,6 +24276,23 @@
24277
24276
  urls: []
24278
24277
  });
24279
24278
  }
24279
+ createOrder(object) {
24280
+ const result = { orderId: "" };
24281
+ return Promise.resolve(result);
24282
+ }
24283
+ ;
24284
+ checkTransaction(object) {
24285
+ const result = {
24286
+ msg: '',
24287
+ appId: '',
24288
+ merchantAppId: '',
24289
+ id: '',
24290
+ resultCode: 0,
24291
+ transTime: 0,
24292
+ createdAt: '',
24293
+ };
24294
+ return Promise.resolve(result);
24295
+ }
24280
24296
  }
24281
24297
  _MockSDKService_appId = new WeakMap(), _MockSDKService_appConfig = new WeakMap(), _MockSDKService_zOAuth = new WeakMap(), _MockSDKService_accessToken = new WeakMap(), _MockSDKService_cache = new WeakMap(), _MockSDKService_loggedId = new WeakMap();
24282
24298
 
@@ -24365,22 +24381,13 @@
24365
24381
  isMeetCondition = Object.keys(condition).every((key) => lodash.get(argument, key) === condition[key]);
24366
24382
  }
24367
24383
  if (isMeetCondition) {
24368
- fields.forEach((item) => {
24369
- const isInValidField = (field) => {
24370
- let isInValid = false;
24371
- if (lodash.isEmpty(lodash.get(argument, field))) {
24372
- if (!lodash.isUndefined(lodash.get(defaultValue, field))) {
24373
- lodash.set(arguments[parameterIndex], field, lodash.get(defaultValue, field));
24374
- }
24375
- isInValid = true;
24384
+ fields.forEach((field) => {
24385
+ if (lodash.isEmpty(lodash.get(argument, field))) {
24386
+ if (!lodash.isUndefined(lodash.get(defaultValue, field))) {
24387
+ lodash.set(arguments[parameterIndex], field, lodash.get(defaultValue, field));
24376
24388
  }
24377
- return isInValid;
24378
- };
24379
- if (Array.isArray(item) && item.length > 0 && item.every(isInValidField)) {
24380
- throw apiResponse.error.missingParam(item.join(' or '));
24381
- }
24382
- else if (lodash.isString(item) && isInValidField(item)) {
24383
- throw apiResponse.error.missingParam(item);
24389
+ else
24390
+ throw apiResponse.error.missingParam(field);
24384
24391
  }
24385
24392
  });
24386
24393
  }
@@ -24391,6 +24398,195 @@
24391
24398
  return descriptor;
24392
24399
  };
24393
24400
 
24401
+ var _PaymentService_appId;
24402
+ class PaymentService {
24403
+ constructor() {
24404
+ _PaymentService_appId.set(this, APP_ID);
24405
+ }
24406
+ static getInstance() {
24407
+ if (!PaymentService.instance) {
24408
+ PaymentService.instance = new PaymentService();
24409
+ }
24410
+ return PaymentService.instance;
24411
+ }
24412
+ /**
24413
+ * Tạo đơn hàng
24414
+ *
24415
+ * @async
24416
+ * @function createOrder
24417
+ * @category PaymentService
24418
+ * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
24419
+ */
24420
+ createOrder(sdk, object) {
24421
+ return __awaiter(this, void 0, void 0, function* () {
24422
+ const miniAppId = __classPrivateFieldGet(this, _PaymentService_appId, "f");
24423
+ const inputData = new URLSearchParams();
24424
+ inputData.append('amount', object.amount.toString());
24425
+ inputData.append('item', encodeURIComponent(JSON.stringify(object.item)));
24426
+ inputData.append('appId', miniAppId);
24427
+ if (object.desc) {
24428
+ inputData.append('desc', encodeURIComponent(object.desc));
24429
+ }
24430
+ if (object.extradata) {
24431
+ inputData.append('extradata', encodeURIComponent(JSON.stringify(object.extradata)));
24432
+ }
24433
+ if (object.method) {
24434
+ inputData.append('method', object.method);
24435
+ }
24436
+ const postConfig = {
24437
+ headers: {
24438
+ 'Content-Type': 'application/x-www-form-urlencoded',
24439
+ 'authorization': `Bearer `
24440
+ }
24441
+ };
24442
+ try {
24443
+ const accessToken = yield sdk.getAccessToken({
24444
+ fail: (error) => {
24445
+ throw apiResponse.error.loginRequired;
24446
+ }
24447
+ });
24448
+ postConfig.headers.authorization = `Bearer ${accessToken}`;
24449
+ const res = yield axios.post(PAYMENT_APIS.CREATE_ORDER, inputData, postConfig);
24450
+ const resData = res.data;
24451
+ if (!resData.data || resData.err !== 0) {
24452
+ throw new Error(resData.msg);
24453
+ }
24454
+ const orderId = resData.data.id;
24455
+ const version = window.APP_VERSION;
24456
+ const env = window.APP_ENV;
24457
+ const params = {
24458
+ miniAppId,
24459
+ accessToken: accessToken || '',
24460
+ orderId,
24461
+ };
24462
+ if (version) {
24463
+ params.version = version;
24464
+ }
24465
+ if (env) {
24466
+ params.env = env;
24467
+ }
24468
+ if (object.method) {
24469
+ params.method = object.method;
24470
+ }
24471
+ const buildURLQuery = QueryString.encode(params);
24472
+ const h5Url = new URL(`?${buildURLQuery}`, PAYMENT_H5_URL).toString();
24473
+ yield sdk.openWebview({
24474
+ url: h5Url,
24475
+ fail: (err) => {
24476
+ throw err;
24477
+ }
24478
+ });
24479
+ return { orderId };
24480
+ }
24481
+ catch (err) {
24482
+ throw err;
24483
+ }
24484
+ });
24485
+ }
24486
+ /**
24487
+ * Lấy thông tin transaction
24488
+ *
24489
+ * @async
24490
+ * @function checkTransaction
24491
+ * @category PaymentService
24492
+ * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
24493
+ */
24494
+ checkTransaction(sdk, object) {
24495
+ return __awaiter(this, void 0, void 0, function* () {
24496
+ try {
24497
+ let { data: inputData } = object;
24498
+ let id;
24499
+ if (!inputData) {
24500
+ inputData = sdk.getRouteParams();
24501
+ }
24502
+ if (typeof inputData === 'object') {
24503
+ id = inputData.appTransID || inputData.orderId || inputData.apptransid;
24504
+ }
24505
+ if (typeof inputData === 'string') {
24506
+ const orderId = QueryString.getParameterByName("orderId", inputData);
24507
+ const appTransID = QueryString.getParameterByName("appTransID", inputData) || QueryString.getParameterByName("apptransid", inputData);
24508
+ id = orderId || appTransID;
24509
+ }
24510
+ const res = yield axios.get(PAYMENT_APIS.GET_TRANSACTION, {
24511
+ params: {
24512
+ transId: id,
24513
+ appId: __classPrivateFieldGet(this, _PaymentService_appId, "f")
24514
+ }
24515
+ });
24516
+ const resData = res.data;
24517
+ if (!resData.data || resData.err !== 0) {
24518
+ throw new Error(resData.msg);
24519
+ }
24520
+ const data = resData.data || {};
24521
+ const transaction = {
24522
+ msg: data.resultMessage,
24523
+ appId: data.appId,
24524
+ orderId: data.orderId,
24525
+ resultCode: data.resultCode,
24526
+ transTime: data.transTime,
24527
+ createdAt: data.createAt
24528
+ };
24529
+ return transaction;
24530
+ }
24531
+ catch (err) {
24532
+ throw err;
24533
+ }
24534
+ });
24535
+ }
24536
+ }
24537
+ _PaymentService_appId = new WeakMap();
24538
+
24539
+ var _PaymentCreator_instance, _PaymentCreator_sdk;
24540
+ class PaymentCreator {
24541
+ constructor(sdk) {
24542
+ _PaymentCreator_instance.set(this, void 0);
24543
+ _PaymentCreator_sdk.set(this, void 0);
24544
+ __classPrivateFieldSet(this, _PaymentCreator_instance, this.getInstance(), "f");
24545
+ __classPrivateFieldSet(this, _PaymentCreator_sdk, sdk, "f");
24546
+ }
24547
+ /**
24548
+ * Tạo đơn hàng
24549
+ *
24550
+ * @async
24551
+ * @function createOrder
24552
+ * @category Payment
24553
+ * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
24554
+ */
24555
+ createOrder(object) {
24556
+ return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").createOrder(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
24557
+ }
24558
+ /**
24559
+ * Lấy thông tin transaction
24560
+ *
24561
+ * @async
24562
+ * @function checkTransaction
24563
+ * @category Payment
24564
+ * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
24565
+ */
24566
+ checkTransaction(object) {
24567
+ return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").checkTransaction(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
24568
+ }
24569
+ }
24570
+ _PaymentCreator_instance = new WeakMap(), _PaymentCreator_sdk = new WeakMap();
24571
+ __decorate([
24572
+ handleError,
24573
+ validate,
24574
+ __param(0, checkType('object', {
24575
+ 'amount': checkData(['string', 'number']),
24576
+ 'desc': checkData('string'),
24577
+ 'method?': checkData('string', { values: ['MOMO', 'ZALOPAY', 'MOMO_SANDBOX', 'ZALOPAY_SANDBOX', 'CC', 'CC_SANDBOX', 'ATM', 'ATM_SANDBOX'] })
24578
+ }))
24579
+ ], PaymentCreator.prototype, "createOrder", null);
24580
+ __decorate([
24581
+ handleError,
24582
+ validate
24583
+ ], PaymentCreator.prototype, "checkTransaction", null);
24584
+ class ZaloMiniAppPaymentCreator extends PaymentCreator {
24585
+ getInstance() {
24586
+ return PaymentService.getInstance();
24587
+ }
24588
+ }
24589
+
24394
24590
  var _SDKCreator_sdkService;
24395
24591
  class SDKCreator {
24396
24592
  constructor() {
@@ -24401,6 +24597,7 @@
24401
24597
  const stringifyEventName = event;
24402
24598
  return this.events.addListener(Events[stringifyEventName], fn, context);
24403
24599
  };
24600
+ this.payment = new ZaloMiniAppPaymentCreator(this);
24404
24601
  }
24405
24602
  /**
24406
24603
  * Login to call more action.
@@ -25034,7 +25231,7 @@
25034
25231
  __decorate([
25035
25232
  handleError,
25036
25233
  validate,
25037
- __param(0, required([['data.imageUrl', 'data.imageUrls']], { if: { type: 'image' } })),
25234
+ __param(0, required(['data.imageUrls'], { if: { type: 'image' } })),
25038
25235
  __param(0, required(['data.link'], { if: { type: 'link' } })),
25039
25236
  __param(0, required(['data.id'], { if: { type: 'oa' } })),
25040
25237
  __param(0, required(['data.gifUrl'], { if: { type: 'gif' } })),
@@ -25290,6 +25487,7 @@
25290
25487
  else {
25291
25488
  app = new MockSDKCreator();
25292
25489
  }
25490
+ app.payment;
25293
25491
  window.ZaloMiniAppSDK = app;
25294
25492
 
25295
25493
  // @ts-ignore
package/dist/index.es.js CHANGED
@@ -19805,6 +19805,7 @@ const APIS = {
19805
19805
  GET_ACCESS_TOKEN: 'https://h5.zalo.me/openapi/access_token',
19806
19806
  GET_ACCESS_TOKEN_V3: 'https://oauth.zaloapp.com/v3/access_token',
19807
19807
  GET_LIST_USER_INFO: 'https://graph.zalo.me/v2.0/me/friends/list',
19808
+ CREATE_ORDER: 'https://payment-mini.zalo.me/api/order/create',
19808
19809
  };
19809
19810
  const STORAGE_LIMIT = 5 * MB;
19810
19811
  const NETWORK_TYPE = (isAndroid) => ({
@@ -20263,7 +20264,12 @@ const ACTION_LEFT_BUTTON_TYPE = {
20263
20264
  HIDE_HOME: 0
20264
20265
  };
20265
20266
  const SHOW_ACTION_BAR = 5;
20266
- const HIDE_ACTION_BAR = 6;
20267
+ const HIDE_ACTION_BAR = 6;
20268
+ const PAYMENT_APIS = {
20269
+ CREATE_ORDER: 'https://payment-mini.zalo.me/api/order/create',
20270
+ GET_TRANSACTION: 'https://payment-mini.zalo.me/api/transaction',
20271
+ };
20272
+ const PAYMENT_H5_URL = 'https://payment-mini.zalo.me';
20267
20273
 
20268
20274
  class CommonError {
20269
20275
  constructor(code, msg, api) {
@@ -20400,7 +20406,7 @@ const apiResponse = {
20400
20406
  missingParam: (params) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `Missing required argument: ${params}`),
20401
20407
  wrongTypeParam: (arg, expected, got) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `Wrong type of parameter '${arg}'. Expected ${expected}, but got ${got}`),
20402
20408
  cannotGetShareInfo: () => new CommonError(RESPONSE_CODE.INTERNAL_SERVER_ERROR, `Can not get app info to share`),
20403
- lengthInvalid: (arg) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `${arg} length is invalid.`)
20409
+ lengthInvalid: (arg) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `${arg} length is invalid.`),
20404
20410
  }
20405
20411
  };
20406
20412
 
@@ -20773,7 +20779,7 @@ const checkData = (types, option) => (data) => {
20773
20779
  }
20774
20780
  if (lodash.isNumber(option === null || option === void 0 ? void 0 : option.maxLength)) {
20775
20781
  return {
20776
- error: (lodash.isString(data) || lodash.isArray(data)) && data.length > (option === null || option === void 0 ? void 0 : option.maxLength),
20782
+ error: lodash.isString(data) && data.length > (option === null || option === void 0 ? void 0 : option.maxLength),
20777
20783
  errorMessage: `data length must <= ${option === null || option === void 0 ? void 0 : option.maxLength}`
20778
20784
  };
20779
20785
  }
@@ -21613,7 +21619,7 @@ class ZJSBridgeProvider {
21613
21619
  }
21614
21620
  _ZJSBridgeProvider_bridge = new WeakMap();
21615
21621
 
21616
- var version = "2.18.1";
21622
+ var version = "2.19.0-rc.1";
21617
21623
 
21618
21624
  class Basics {
21619
21625
  /**
@@ -23402,15 +23408,8 @@ class Zalo {
23402
23408
  let reqData = {};
23403
23409
  switch (object.type) {
23404
23410
  case 'image':
23405
- let photoUrls = [];
23406
- if (Array.isArray(object.data.imageUrls) && object.data.imageUrls.length > 0) {
23407
- photoUrls = object.data.imageUrls;
23408
- }
23409
- else {
23410
- photoUrls.push(object.data.imageUrl);
23411
- }
23412
23411
  reqData = {
23413
- photoUrls: photoUrls,
23412
+ photoUrls: object.data.imageUrls,
23414
23413
  caption: object.data.caption
23415
23414
  };
23416
23415
  break;
@@ -24274,6 +24273,23 @@ class MockSDKService {
24274
24273
  urls: []
24275
24274
  });
24276
24275
  }
24276
+ createOrder(object) {
24277
+ const result = { orderId: "" };
24278
+ return Promise.resolve(result);
24279
+ }
24280
+ ;
24281
+ checkTransaction(object) {
24282
+ const result = {
24283
+ msg: '',
24284
+ appId: '',
24285
+ merchantAppId: '',
24286
+ id: '',
24287
+ resultCode: 0,
24288
+ transTime: 0,
24289
+ createdAt: '',
24290
+ };
24291
+ return Promise.resolve(result);
24292
+ }
24277
24293
  }
24278
24294
  _MockSDKService_appId = new WeakMap(), _MockSDKService_appConfig = new WeakMap(), _MockSDKService_zOAuth = new WeakMap(), _MockSDKService_accessToken = new WeakMap(), _MockSDKService_cache = new WeakMap(), _MockSDKService_loggedId = new WeakMap();
24279
24295
 
@@ -25494,22 +25510,13 @@ const validate = (target, propertyName, descriptor) => {
25494
25510
  isMeetCondition = Object.keys(condition).every((key) => lodash.get(argument, key) === condition[key]);
25495
25511
  }
25496
25512
  if (isMeetCondition) {
25497
- fields.forEach((item) => {
25498
- const isInValidField = (field) => {
25499
- let isInValid = false;
25500
- if (lodash.isEmpty(lodash.get(argument, field))) {
25501
- if (!lodash.isUndefined(lodash.get(defaultValue, field))) {
25502
- lodash.set(arguments[parameterIndex], field, lodash.get(defaultValue, field));
25503
- }
25504
- isInValid = true;
25513
+ fields.forEach((field) => {
25514
+ if (lodash.isEmpty(lodash.get(argument, field))) {
25515
+ if (!lodash.isUndefined(lodash.get(defaultValue, field))) {
25516
+ lodash.set(arguments[parameterIndex], field, lodash.get(defaultValue, field));
25505
25517
  }
25506
- return isInValid;
25507
- };
25508
- if (Array.isArray(item) && item.length > 0 && item.every(isInValidField)) {
25509
- throw apiResponse.error.missingParam(item.join(' or '));
25510
- }
25511
- else if (lodash.isString(item) && isInValidField(item)) {
25512
- throw apiResponse.error.missingParam(item);
25518
+ else
25519
+ throw apiResponse.error.missingParam(field);
25513
25520
  }
25514
25521
  });
25515
25522
  }
@@ -25520,6 +25527,195 @@ const validate = (target, propertyName, descriptor) => {
25520
25527
  return descriptor;
25521
25528
  };
25522
25529
 
25530
+ var _PaymentService_appId;
25531
+ class PaymentService {
25532
+ constructor() {
25533
+ _PaymentService_appId.set(this, APP_ID);
25534
+ }
25535
+ static getInstance() {
25536
+ if (!PaymentService.instance) {
25537
+ PaymentService.instance = new PaymentService();
25538
+ }
25539
+ return PaymentService.instance;
25540
+ }
25541
+ /**
25542
+ * Tạo đơn hàng
25543
+ *
25544
+ * @async
25545
+ * @function createOrder
25546
+ * @category PaymentService
25547
+ * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
25548
+ */
25549
+ createOrder(sdk, object) {
25550
+ return __awaiter(this, void 0, void 0, function* () {
25551
+ const miniAppId = __classPrivateFieldGet(this, _PaymentService_appId, "f");
25552
+ const inputData = new URLSearchParams();
25553
+ inputData.append('amount', object.amount.toString());
25554
+ inputData.append('item', encodeURIComponent(JSON.stringify(object.item)));
25555
+ inputData.append('appId', miniAppId);
25556
+ if (object.desc) {
25557
+ inputData.append('desc', encodeURIComponent(object.desc));
25558
+ }
25559
+ if (object.extradata) {
25560
+ inputData.append('extradata', encodeURIComponent(JSON.stringify(object.extradata)));
25561
+ }
25562
+ if (object.method) {
25563
+ inputData.append('method', object.method);
25564
+ }
25565
+ const postConfig = {
25566
+ headers: {
25567
+ 'Content-Type': 'application/x-www-form-urlencoded',
25568
+ 'authorization': `Bearer `
25569
+ }
25570
+ };
25571
+ try {
25572
+ const accessToken = yield sdk.getAccessToken({
25573
+ fail: (error) => {
25574
+ throw apiResponse.error.loginRequired;
25575
+ }
25576
+ });
25577
+ postConfig.headers.authorization = `Bearer ${accessToken}`;
25578
+ const res = yield axios.post(PAYMENT_APIS.CREATE_ORDER, inputData, postConfig);
25579
+ const resData = res.data;
25580
+ if (!resData.data || resData.err !== 0) {
25581
+ throw new Error(resData.msg);
25582
+ }
25583
+ const orderId = resData.data.id;
25584
+ const version = window.APP_VERSION;
25585
+ const env = window.APP_ENV;
25586
+ const params = {
25587
+ miniAppId,
25588
+ accessToken: accessToken || '',
25589
+ orderId,
25590
+ };
25591
+ if (version) {
25592
+ params.version = version;
25593
+ }
25594
+ if (env) {
25595
+ params.env = env;
25596
+ }
25597
+ if (object.method) {
25598
+ params.method = object.method;
25599
+ }
25600
+ const buildURLQuery = QueryString.encode(params);
25601
+ const h5Url = new URL(`?${buildURLQuery}`, PAYMENT_H5_URL).toString();
25602
+ yield sdk.openWebview({
25603
+ url: h5Url,
25604
+ fail: (err) => {
25605
+ throw err;
25606
+ }
25607
+ });
25608
+ return { orderId };
25609
+ }
25610
+ catch (err) {
25611
+ throw err;
25612
+ }
25613
+ });
25614
+ }
25615
+ /**
25616
+ * Lấy thông tin transaction
25617
+ *
25618
+ * @async
25619
+ * @function checkTransaction
25620
+ * @category PaymentService
25621
+ * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
25622
+ */
25623
+ checkTransaction(sdk, object) {
25624
+ return __awaiter(this, void 0, void 0, function* () {
25625
+ try {
25626
+ let { data: inputData } = object;
25627
+ let id;
25628
+ if (!inputData) {
25629
+ inputData = sdk.getRouteParams();
25630
+ }
25631
+ if (typeof inputData === 'object') {
25632
+ id = inputData.appTransID || inputData.orderId || inputData.apptransid;
25633
+ }
25634
+ if (typeof inputData === 'string') {
25635
+ const orderId = QueryString.getParameterByName("orderId", inputData);
25636
+ const appTransID = QueryString.getParameterByName("appTransID", inputData) || QueryString.getParameterByName("apptransid", inputData);
25637
+ id = orderId || appTransID;
25638
+ }
25639
+ const res = yield axios.get(PAYMENT_APIS.GET_TRANSACTION, {
25640
+ params: {
25641
+ transId: id,
25642
+ appId: __classPrivateFieldGet(this, _PaymentService_appId, "f")
25643
+ }
25644
+ });
25645
+ const resData = res.data;
25646
+ if (!resData.data || resData.err !== 0) {
25647
+ throw new Error(resData.msg);
25648
+ }
25649
+ const data = resData.data || {};
25650
+ const transaction = {
25651
+ msg: data.resultMessage,
25652
+ appId: data.appId,
25653
+ orderId: data.orderId,
25654
+ resultCode: data.resultCode,
25655
+ transTime: data.transTime,
25656
+ createdAt: data.createAt
25657
+ };
25658
+ return transaction;
25659
+ }
25660
+ catch (err) {
25661
+ throw err;
25662
+ }
25663
+ });
25664
+ }
25665
+ }
25666
+ _PaymentService_appId = new WeakMap();
25667
+
25668
+ var _PaymentCreator_instance, _PaymentCreator_sdk;
25669
+ class PaymentCreator {
25670
+ constructor(sdk) {
25671
+ _PaymentCreator_instance.set(this, void 0);
25672
+ _PaymentCreator_sdk.set(this, void 0);
25673
+ __classPrivateFieldSet(this, _PaymentCreator_instance, this.getInstance(), "f");
25674
+ __classPrivateFieldSet(this, _PaymentCreator_sdk, sdk, "f");
25675
+ }
25676
+ /**
25677
+ * Tạo đơn hàng
25678
+ *
25679
+ * @async
25680
+ * @function createOrder
25681
+ * @category Payment
25682
+ * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
25683
+ */
25684
+ createOrder(object) {
25685
+ return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").createOrder(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
25686
+ }
25687
+ /**
25688
+ * Lấy thông tin transaction
25689
+ *
25690
+ * @async
25691
+ * @function checkTransaction
25692
+ * @category Payment
25693
+ * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
25694
+ */
25695
+ checkTransaction(object) {
25696
+ return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").checkTransaction(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
25697
+ }
25698
+ }
25699
+ _PaymentCreator_instance = new WeakMap(), _PaymentCreator_sdk = new WeakMap();
25700
+ __decorate([
25701
+ handleError,
25702
+ validate,
25703
+ __param(0, checkType('object', {
25704
+ 'amount': checkData(['string', 'number']),
25705
+ 'desc': checkData('string'),
25706
+ 'method?': checkData('string', { values: ['MOMO', 'ZALOPAY', 'MOMO_SANDBOX', 'ZALOPAY_SANDBOX', 'CC', 'CC_SANDBOX', 'ATM', 'ATM_SANDBOX'] })
25707
+ }))
25708
+ ], PaymentCreator.prototype, "createOrder", null);
25709
+ __decorate([
25710
+ handleError,
25711
+ validate
25712
+ ], PaymentCreator.prototype, "checkTransaction", null);
25713
+ class ZaloMiniAppPaymentCreator extends PaymentCreator {
25714
+ getInstance() {
25715
+ return PaymentService.getInstance();
25716
+ }
25717
+ }
25718
+
25523
25719
  var _SDKCreator_sdkService;
25524
25720
  class SDKCreator {
25525
25721
  constructor() {
@@ -25530,6 +25726,7 @@ class SDKCreator {
25530
25726
  const stringifyEventName = event;
25531
25727
  return this.events.addListener(Events[stringifyEventName], fn, context);
25532
25728
  };
25729
+ this.payment = new ZaloMiniAppPaymentCreator(this);
25533
25730
  }
25534
25731
  /**
25535
25732
  * Login to call more action.
@@ -26163,7 +26360,7 @@ __decorate([
26163
26360
  __decorate([
26164
26361
  handleError,
26165
26362
  validate,
26166
- __param(0, required([['data.imageUrl', 'data.imageUrls']], { if: { type: 'image' } })),
26363
+ __param(0, required(['data.imageUrls'], { if: { type: 'image' } })),
26167
26364
  __param(0, required(['data.link'], { if: { type: 'link' } })),
26168
26365
  __param(0, required(['data.id'], { if: { type: 'oa' } })),
26169
26366
  __param(0, required(['data.gifUrl'], { if: { type: 'gif' } })),
@@ -26419,7 +26616,8 @@ if (platform.isZalo) {
26419
26616
  else {
26420
26617
  app = new MockSDKCreator();
26421
26618
  }
26619
+ const payment = app.payment;
26422
26620
  window.ZaloMiniAppSDK = app;
26423
26621
 
26424
26622
  export default app;
26425
- export { ChatType, Events, MediaPickerType, NativeCode, NetworkType, OrientationType, PlatformType, PostFeedType, ProfileType, SDKCreator, ShareSheetType, VibrateType };
26623
+ export { ChatType, Events, MediaPickerType, NativeCode, NetworkType, OrientationType, payment as Payment, PlatformType, PostFeedType, ProfileType, SDKCreator, ShareSheetType, VibrateType };