@alipay/ams-checkout 0.0.1783252456-dev.2 → 0.0.1783323899-dev.0

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.
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
+ * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
+ */
1
8
  export declare const marmotMap: Record<string, string>;
2
9
  export declare const marmotConfigMap: Record<string, string>;
3
10
  export declare const v2AppMarmotMap: Record<string, string>;
@@ -5,7 +5,7 @@
5
5
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
6
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
7
  */
8
- import json from "../../package.json";
8
+
9
9
  export var marmotMap = {
10
10
  dev: 'http://page.alipay.net/page/antom-web-checkout/src/component-app',
11
11
  sit: 'http://page.test.alipay.net/page/antom-web-checkout/src/component-app',
@@ -30,7 +30,7 @@ export var v2AppMarmotMap = {
30
30
  light_sandbox: 'https://checkout.antom.com',
31
31
  prod: 'https://checkout.antom.com'
32
32
  };
33
- export var sdkVersion = json.version;
33
+ export var sdkVersion = "0.0.1783323899-dev.0";
34
34
 
35
35
  /**
36
36
  * @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
@@ -22,5 +22,6 @@ export declare enum ELEMENT_PAGE_URL {
22
22
  INSTRUCTION_GUIDE = "/elements/pages/instruction-guide/index.html",
23
23
  THREED_PAGE = "/elements/pages/threed-page/index.html",
24
24
  ELEMENT_AUTH = "/auth-element/pages/element_auth/index.html",
25
- ADDRESS = "/element-address/pages/address/index.html"
25
+ ADDRESS = "/element-address/pages/address/index.html",
26
+ NEW_ELEMENT_PAYMENT = "/elements2/pages/element_payment/index.html"
26
27
  }
@@ -26,5 +26,6 @@ export var ELEMENT_PAGE_URL = /*#__PURE__*/function (ELEMENT_PAGE_URL) {
26
26
  ELEMENT_PAGE_URL["THREED_PAGE"] = "/elements/pages/threed-page/index.html";
27
27
  ELEMENT_PAGE_URL["ELEMENT_AUTH"] = "/auth-element/pages/element_auth/index.html";
28
28
  ELEMENT_PAGE_URL["ADDRESS"] = "/element-address/pages/address/index.html";
29
+ ELEMENT_PAGE_URL["NEW_ELEMENT_PAYMENT"] = "/elements2/pages/element_payment/index.html";
29
30
  return ELEMENT_PAGE_URL;
30
31
  }({});
@@ -1,5 +1,5 @@
1
- import { AddressMountOptions, EventDataMap, EVENTNAME, ICommonApiResponse, IElementOptions, IPaymentApiResponse, LinkAuthMountOptions, PaymentMountOptions, SubmitFuncParams } from '../type';
2
- declare class ElementController {
1
+ import { AddressMountOptions, EventDataMap, EVENTNAME, ICommonApiResponse, IElementController, IElementOptions, IPaymentApiResponse, LinkAuthMountOptions, PaymentMountOptions, SubmitFuncParams } from '../type';
2
+ declare class ElementController implements IElementController {
3
3
  private options;
4
4
  private elementContainer;
5
5
  private serviceMap;
@@ -44,7 +44,7 @@ declare class ElementController {
44
44
  private getErrorFromResponse;
45
45
  private areAllContainersReady;
46
46
  private sendReady;
47
- updatePayment(paymentSessionData: any): Promise<unknown>;
47
+ updatePayment(paymentSessionData: string): Promise<boolean>;
48
48
  private destroyHandle;
49
49
  destroy(): void;
50
50
  private setControllerStatusOrView;
@@ -3,7 +3,10 @@ export declare class ElementComponent {
3
3
  private options;
4
4
  private controller;
5
5
  constructor(options: IElementOptions);
6
- updatePayment(paymentSessionData: any): Promise<unknown>;
6
+ /**
7
+ * @deprecated 不要使用,internal experiment方法
8
+ */
9
+ updatePayment(paymentSessionData: any): Promise<boolean>;
7
10
  mount(renderOptions: PaymentMountOptions, sdkSelector: string): Promise<import("./type").ICommonApiResponse>;
8
11
  validateFields(): Promise<{
9
12
  isValid: boolean;
@@ -1,16 +1,18 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
5
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
8
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
9
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
10
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ import { adjustSessionData, isElements2 } from "../../../modern/tools";
13
14
  import ElementController from "./elementController";
15
+ import { ModernElementController } from "./modernElementController";
14
16
  import { InvalidElementConfigError } from "./type";
15
17
  import { formatElementOption, validateElementOption } from "./util";
16
18
  export var ElementComponent = /*#__PURE__*/function () {
@@ -23,11 +25,23 @@ export var ElementComponent = /*#__PURE__*/function () {
23
25
  throw new InvalidElementConfigError(validate.errors);
24
26
  }
25
27
  this.options = formatElementOption(options);
26
- this.controller = new ElementController(options);
28
+
29
+ // 核心分流逻辑
30
+ if (isElements2(options.sessionData)) {
31
+ this.controller = new ModernElementController(_objectSpread(_objectSpread({}, this.options), {}, {
32
+ sessionData: adjustSessionData(this.options.sessionData)
33
+ }));
34
+ } else {
35
+ this.controller = new ElementController(this.options);
36
+ }
27
37
  }
38
+
39
+ /**
40
+ * @deprecated 不要使用,internal experiment方法
41
+ */
28
42
  _createClass(ElementComponent, [{
29
43
  key: "updatePayment",
30
- value: function () {
44
+ value: (function () {
31
45
  var _updatePayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(paymentSessionData) {
32
46
  return _regeneratorRuntime().wrap(function _callee$(_context) {
33
47
  while (1) switch (_context.prev = _context.next) {
@@ -47,6 +61,7 @@ export var ElementComponent = /*#__PURE__*/function () {
47
61
  // mount(renderOptions: LinkAuthMountOptions, sdkSelector: string): LinkAuthMountResult;
48
62
  // mount(renderOptions: AddressMountOptions, sdkSelector: string): AddressMountResult;
49
63
  // mount(renderOptions: PaymentMountOptions, sdkSelector: string);
64
+ )
50
65
  }, {
51
66
  key: "mount",
52
67
  value: function mount(renderOptions, sdkSelector) {
@@ -0,0 +1,19 @@
1
+ import type { IMerchantAppointParam } from "../../../../types";
2
+ import type { IPaymentApiResponse, PaymentMountOptions } from '../type';
3
+ import { EventCallbackCode } from '../type';
4
+ import type { PaymentSubmitResult, ErrorPayload } from "../../../../modern/tools";
5
+ export declare function adaptSubmitResult(result: PaymentSubmitResult): IPaymentApiResponse;
6
+ export declare function adaptErrorToEventCallback(error: ErrorPayload): {
7
+ code: EventCallbackCode;
8
+ message: string;
9
+ };
10
+ /**
11
+ * 将老架构的 appearance 格式转换为新架构格式
12
+ *
13
+ * 转换规则:
14
+ * 1. theme: kebab-case → camelCase(如 'nostalgic-gray' → 'nostalgicGray'),其余保持不变
15
+ * 2. variables: 直接透传(kebab-case CSS 变量 key-value)
16
+ * 3. card.showBrandIcon → displaySetting.showCardBrandIcon
17
+ * 4. layout: 直接透传
18
+ */
19
+ export declare function adaptAppearance(appearance?: PaymentMountOptions['appearance'], merchantAppointParam?: IMerchantAppointParam): any;
@@ -0,0 +1,73 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
7
+ import { EventCallbackCode } from "../type";
8
+ export function adaptSubmitResult(result) {
9
+ var _result$error;
10
+ return {
11
+ status: result.status || 'FAIL',
12
+ error: result.error ? {
13
+ code: result.error.code,
14
+ message: result.error.message,
15
+ needChangeSessionForRetry: (_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.needChangeSessionForRetry
16
+ } : undefined,
17
+ userCanceled3D: result.userCanceled3D,
18
+ session: result.paymentSession ? {
19
+ nextAction: {
20
+ applinkUrl: result.paymentSession.returnAppUrl,
21
+ normalUrl: result.paymentSession.returnUrl,
22
+ schemeUrl: result.paymentSession.returnAppScheme
23
+ }
24
+ } : undefined
25
+ };
26
+ }
27
+ export function adaptErrorToEventCallback(error) {
28
+ return {
29
+ code: error.code || EventCallbackCode.SDK_PAYMENT_ERROR,
30
+ message: error.message || ''
31
+ };
32
+ }
33
+
34
+ /**
35
+ * 将老架构的 appearance 格式转换为新架构格式
36
+ *
37
+ * 转换规则:
38
+ * 1. theme: kebab-case → camelCase(如 'nostalgic-gray' → 'nostalgicGray'),其余保持不变
39
+ * 2. variables: 直接透传(kebab-case CSS 变量 key-value)
40
+ * 3. card.showBrandIcon → displaySetting.showCardBrandIcon
41
+ * 4. layout: 直接透传
42
+ */
43
+ export function adaptAppearance(appearance, merchantAppointParam) {
44
+ var _appearance$card, _merchantAppointParam, _appearance$accordion;
45
+ if (!appearance) return undefined;
46
+ var result = {};
47
+
48
+ // Theme mapping: kebab-case → camelCase
49
+ if (appearance.theme) {
50
+ result.theme = appearance.theme;
51
+ }
52
+
53
+ // Variables: 直接透传
54
+ if (appearance.variables && _typeof(appearance.variables) === 'object') {
55
+ var filtered = _objectSpread({}, appearance.variables);
56
+ if (Object.keys(filtered).length > 0) {
57
+ result.variables = filtered;
58
+ }
59
+ }
60
+ result.displaySetting = {
61
+ showCardBrandIcon: !!((_appearance$card = appearance.card) !== null && _appearance$card !== void 0 && _appearance$card.showBrandIcon),
62
+ showCardCVV: !!(merchantAppointParam !== null && merchantAppointParam !== void 0 && (_merchantAppointParam = merchantAppointParam.storedCard) !== null && _merchantAppointParam !== void 0 && _merchantAppointParam.needCVV),
63
+ showPaymentMethodListWhenSingleOption: (merchantAppointParam === null || merchantAppointParam === void 0 ? void 0 : merchantAppointParam.singleOption) === 'list',
64
+ showRadioWhenAccordionLayout: !!((_appearance$accordion = appearance.accordion) !== null && _appearance$accordion !== void 0 && _appearance$accordion.showRadio)
65
+ };
66
+
67
+ // Layout: 直接透传
68
+ if (appearance.layout) {
69
+ var _appearance$layout$ty;
70
+ result.layout = ((_appearance$layout$ty = appearance.layout.type) === null || _appearance$layout$ty === void 0 ? void 0 : _appearance$layout$ty.toLowerCase()) || 'accordion';
71
+ }
72
+ return Object.keys(result).length > 0 ? result : undefined;
73
+ }
@@ -0,0 +1,133 @@
1
+ import type { IElementController, IElementOptions, ICommonApiResponse, IPaymentApiResponse, PaymentMountOptions, SubmitFuncParams, EventDataMap } from '../type';
2
+ import { EVENTNAME } from '../type';
3
+ type ModernElementStatus = 'initialized' | 'mounting' | 'mounted' | 'ready' | 'destroyed';
4
+ interface ModernElementControllerOptions extends IElementOptions {
5
+ /** Called after the controller status changes. */
6
+ onStatusChange?: (status: ModernElementStatus, previousStatus: ModernElementStatus) => void;
7
+ }
8
+ /**
9
+ * ModernElementController 使用 opensdk-core 的 HostBridge 实现新架构通信。
10
+ *
11
+ * Mount 流程(正确):
12
+ * 1. setup() — 解析 sessionData 获取 metaData,准备 HANDSHAKE 配置
13
+ * 2. 创建 iframe(先不设置 src,避免提前触发加载)
14
+ * 3. 先注册所有事件监听,再设置 iframe.src 和 appendChild 触发加载
15
+ * 4. setup() 与 waitForReadyHandshake() 并行执行
16
+ * 5. 两者都完成后,sendHandshake() 发送 HANDSHAKE 配置
17
+ * 6. 等待 HANDSHAKE_ACK → 设置 status = 'ready'
18
+ * 7. ready 后发送缓存的消息
19
+ */
20
+ export declare class ModernElementController implements IElementController {
21
+ private options;
22
+ private onStatusChange?;
23
+ private readonly scopeId;
24
+ private bridge;
25
+ private iframe;
26
+ private status;
27
+ private cachedSend;
28
+ private modalBridge;
29
+ private modalDestroy;
30
+ private _closeConfirmResolve;
31
+ private notRedirectAfterComplete;
32
+ private _sdkInitTime;
33
+ private _mountStartTime;
34
+ /** 商户传入的金额覆盖(Apple Pay 弹窗展示用,实际扣款由服务端控制) */
35
+ private _merchantAmount;
36
+ /** 商户传入的币种覆盖(Apple Pay 弹窗展示用) */
37
+ private _merchantCurrency;
38
+ /** 当前选中的支付方式类型(如 'APPLEPAY', 'CARD'),通过 paymentMethodChanged 事件更新 */
39
+ private currentPaymentMethodType;
40
+ constructor({ onStatusChange, ...options }: ModernElementControllerOptions);
41
+ mount(renderOptions: PaymentMountOptions, sdkSelector: string): Promise<ICommonApiResponse>;
42
+ /**
43
+ * setup() — 解析 sessionData 获取 metaData,发起 sdkQuery 获取渲染数据,准备 HANDSHAKE 配置
44
+ *
45
+ * 完整实现:
46
+ * 1. 解析 sessionData 获取 paymentSessionConfig
47
+ * 2. 初始化 request 全局配置(hostSign, env, sdkVersion)
48
+ * 3. 调用 sdkQuery 获取 renderData
49
+ * 4. 处理请求错误,将错误信息放入 renderDataError(不阻塞 mount 流程)
50
+ * 5. 从 renderData 中提取 preferredLocale
51
+ */
52
+ private setup;
53
+ /**
54
+ * 校验 renderData 数据格式,参照老逻辑 isLoadErrorPage 的三个校验维度:
55
+ * 1. success 字段 — 接口是否返回业务成功
56
+ * 2. 支付方式 — paymentMethods 或 savedPaymentMethods 必须存在且为非空数组
57
+ * 3. 金额视图 — orderAmountView 和 paymentAmountView 必须同时存在
58
+ *
59
+ * 当数据结构异常时,构造 ERR_DATA_STRUCT_UNRECOGNIZED 错误
60
+ */
61
+ private getLegacySdkQueryError;
62
+ private validateRenderData;
63
+ /**
64
+ * 注册所有 bridge 事件监听(必须在 iframe 加载前调用,避免丢失早期消息)
65
+ */
66
+ private bindBridgeEvents;
67
+ /**
68
+ * 处理 webapp 委托的 Apple Pay token 请求。
69
+ * Chrome 等非 Safari 浏览器内 iframe 无法拉起 Apple 二维码 modal(jsapi 注入需父域),
70
+ * 改由 SDK 域 new ApplePaySdk().startPay() 拉起 Apple modal,结果通过 bridge 回传。
71
+ */
72
+ private handleGetApplePayToken;
73
+ /**
74
+ * 处理 webapp 委托的 skipRenderPaymentMethod 拉起请求(fire-and-forget)。
75
+ * 走 plugin/applepay 标准链路:ApplePayBusSubscriber.onCreateComponent 自动注入
76
+ * onEventCallback,通过 BusManager.publish(SDKCallbackActionEnum.onEventCallback)
77
+ * 通知商户。SDK 端不需要 reply 给 webapp。
78
+ */
79
+ private handleHandlePayment;
80
+ /**
81
+ * 处理来自 webapp 的 beforeConfirm 请求(Apple Pay 授权后、扣款前)。
82
+ * onBeforeConfirm 由 submitPayment 闭包传入,不需要从 this 读取。
83
+ */
84
+ private handleBeforeConfirmInternal;
85
+ /**
86
+ * 等待 webapp 发送 READY_HANDSHAKE(表示 iframe 已加载并准备好握手),
87
+ * 收到后设置 bridge target 和安全源
88
+ */
89
+ private waitForReadyHandshake;
90
+ /**
91
+ * 发送 HANDSHAKE 配置给 webapp(setup 和 READY_HANDSHAKE 都完成后调用)
92
+ */
93
+ private sendHandshake;
94
+ /**
95
+ * 等待 webapp 返回 HANDSHAKE_ACK(确认握手完成)
96
+ */
97
+ private waitForHandshakeAck;
98
+ submitPayment(params: SubmitFuncParams): Promise<IPaymentApiResponse>;
99
+ validateFields(): Promise<{
100
+ isValid: boolean;
101
+ }>;
102
+ updatePayment(paymentSessionData: string): Promise<boolean>;
103
+ on<T extends EVENTNAME>(event: T, callback: (data: EventDataMap[T]) => void): void;
104
+ destroy(): void;
105
+ private cleanup;
106
+ private setStatus;
107
+ /**
108
+ * 带缓存的消息发送:当 status 不是 ready 时,缓存消息;ready 后由 flushCachedMessages 批量发送
109
+ */
110
+ private send;
111
+ /**
112
+ * 批量发送缓存的消息
113
+ */
114
+ private flushCachedMessages;
115
+ /**
116
+ * 处理 webapp 请求打开 modal 弹窗
117
+ *
118
+ * 流程(参照 BaseFactory 桥接流程):
119
+ * 1. 调用 openModal 工具函数创建 modal DOM(overlay + modal + iframe + 动画 + close icon + loading)
120
+ * 2. 为 modal 创建独立的 HostBridge 用于通信
121
+ * 3. iframe 加载后 setTarget 到 modal iframe 的 contentWindow
122
+ * 4. 监听 modal 的 READY_HANDSHAKE → 发送配置消息
123
+ * 5. 如果 payload 有 appearance,通过 TRANSFER_MODAL_APPEARANCE 消息发送
124
+ * 6. 如果 payload 有 closeConfirm,创建 MessageChannel port 用于确认关闭
125
+ */
126
+ private handleOpenModal;
127
+ /**
128
+ * 销毁 modal bridge、调用 openModal 返回的 destroy 方法清理 modal DOM
129
+ */
130
+ private handleCloseModal;
131
+ private buildIframeUrl;
132
+ }
133
+ export {};