简介
stripe是用于支付的库,大量使用了代码混淆,react-stripe-elements中会依赖stripe.js
基础函数e
其定义为
function e(t) {
var n = o[t];
if (void 0 !== n)
return n.exports;
var a = o[t] = {
exports: {}
};
return r[t](a, a.exports, e),
a.exports
}
1、检查对象o中的属性t o[t],如果不为空,则返回o[t].exports
2、如果为空,则创建a, o[t]对象,其属性exports为空对象
3、调用函数r[t],传参为a,a.exports和函数自身e
4、返回a.exports
window.Stripe
ay = function (e, t) {
return function (e, t) {
try {
if ("string" != typeof e || 0 !== e.indexOf("pk_test_"))
return;
var n = JSON.stringify({
apiKey: e,
options: t
});
if (ny[n] || (ny[n] = {
count: 0,
hasWarned: !1
}), ny[n].hasWarned)
return;
ny[n].count++,
ny[n].count >= 10 ? (ny[n].hasWarned = !0, window.console && console.warn("[Stripe.js] It looks like Stripe() was called many times with the same API key and options. For best performance, create and share a single instance of the Stripe object. https://stripe.com/docs/js/initializing")) : null === ry && (ry = setTimeout((function () {
Object.keys(ny).forEach((function (e) {
ny[e].count = 0
})),
ry = null
}), 1e4))
} catch (e) {}
}
(e, t),
new ty((0, s.A)({
apiKey: e
}, t && "object" == typeof t ? t : {}), oy)
};
window.Stripe = ay
window.Stripe(apiKey, options)调用的是ay(apiKey, options),返回的是ty实例
new ty((0, s.A)({apiKey: e}, t && "object" == typeof t ? t : {}), oy)
//(0, s.A)({apiKey: e}, t && "object" == typeof t ? t : {}) 作用是将第二个对象的参数赋值给第一个
其中ey才是真正的实例类
var ty = ey;
ey的实例为

function e(t, n) {
var r = this;
(0, d.A)(this, e),
this._listenerRegistry = ge(),
this.elements = (0, I.UZ)((function (e) {
return new To(r._controller, r._listenerRegistry, {
stripeJsLoadTimestamp: Fh,
stripeCreateTimestamp: r._controller._createTimestamp
}, r._betas, r._mids(), r._developerToolsOptions, (0, s.A)((0, s.A)({}, r._locale ? {
locale: r._locale
}
: {}), e))
}), void 0, "elements"),
this.createToken = (0, I.kO)((function (e, t) {
var n = r._mids();
return "cvc_update" === e ? function (e, t) {
var n = (0, g.gJ)(t);
if (n && "cardCvc" === n._componentName) {
var r = n._implementation._frame.id;
return e.action.tokenizeCvcUpdate({
frameId: r
}).then(Gf)
}
throw new P.N2("You must provide a `cardCvc` Element to create a `cvc_update` token.")
}
(r._controller, t) : function (e, t) {
return function (n, r) {
var o = (0, g.gJ)(n);
if (o) {
var a = o._implementation._frame.id,
i = o._componentName,
c = Hf(r);
return e.action.tokenizeWithElement({
frameId: a,
elementName: i,
tokenData: c,
mids: t
}).then(Gf)
}
if ("string" == typeof n) {
var s = n,
l = Hf(r);
return e.action.tokenizeWithData({
elementName: null,
type: s,
tokenData: l,
mids: t
}).then(Gf)
}
throw new P.N2("You must provide a Stripe Element or a valid token type to create a Token.")
}
}
(r._controller, n)(e, t)
}), void 0, "createToken"),
this.createSource = (0, I.kO)((function (e, t) {
if ((0, M.x$)(Xh, "legacySourceMethodsDeprecated"))
throw Jh("stripe.createSource");
var n = (0, g.gJ)(e),
o = il(n ? t : e),
a = o || {
type: null,
data: {}
},
i = a.type,
c = a.data;
if (n) {
var s = n._implementation._frame.id,
l = n._componentName;
return !o && (0, E.G)(l) ? Uh.reject(new P.N2("Please provide Source creation parameters to createSource.")) : r._controller.action.createSourceWithElement({
frameId: s,
elementName: l,
type: i,
sourceData: c,
mids: r._mids()
}).then(cl)
}
return o ? i ? r._controller.action.createSourceWithData({
elementName: null,
type: i,
sourceData: c,
mids: r._mids()
}).then(cl) : Uh.reject(new P.N2("Please provide a source type to createSource.")) : Uh.reject(new P.N2("Please provide either an Element or Source creation parameters to createSource."))
}), void 0, "createSource"),
this.retrieveSource = (0, I.PB)((function (e) {
if ((0, M.x$)(Xh, "legacySourceMethodsDeprecated"))
throw Jh("stripe.retrieveSource");
var t = (0, g.tf)(ll, {
source: e
}, "retrieveSource"),
n = t.value;
return t.warnings.forEach((function (e) {
return r._controller.warn(e)
})),
r._controller.action.retrieveSource(n).then(cl)
}), void 0, "retrieveSource"),
this.paymentRequest = (0, I.Jm)((function (e, t) {
(0, Vt._y)(r._keyMode);
var n = t;
return No(r._controller, {
apiKey: r._apiKey,
accountId: r._stripeAccount
}, r._mids(), e, r._betas, n, r._listenerRegistry)
}), void 0, "paymentRequest"),
this.openLinkModal = (0, I.t$)((function () {
var e,
t = window.location.origin || (null === (e = (0, S.wS)(window.location.href)) || void 0 === e ? void 0 : e.origin),
n = t && (0, S.qZ)(t);
r._keyMode === Vt.ld.test && n && r._controller.action.openLinkModal()
}), void 0, "openLinkModal");
try {
var o = new qe.Dc,
a = Qh(t || {}),
i = a.validOptions,
c = a.warnings;
this._version = Xh,
this._stripeJsId = e.stripeJsId,
this._stripeObjId = "sobj-".concat((0, b.uR)());
var l = function (e) {
var t = e.apiKey,
n = e.context,
r = e.forceRollout,
o = e.isAffectedBrowser,
a = e.rolloutSlice,
i = e.log,
c = Q()(t),
l = {
apiKey: t,
hashedKey: c,
isAffectedBrowser: o,
context: n
},
u = function (e) {
var t = e.mechanism,
r = e.action;
o && i("legacy-deprecation-rollout", (0, s.A)((0, s.A)({}, l), {}, {
mechanism: t,
action: r,
state: [n, t, r].join("-")
}))
};
return r ? (u({
mechanism: uh,
action: o ? ch : sh
}), o) : "___TESTMODE_FORCE_UNSUPPORTED_BROWSER" === t || (-1 !== (0, C.SL)(ih, (function (e) {
return e === c
})) ? (u({
mechanism: lh,
action: o ? ch : sh
}), o) : -1 !== (0, C.SL)(ah, (function (e) {
return e === c
})) ? (u({
mechanism: lh,
action: sh
}), !1) : function (e, t) {
return t < 100
}
(0, a) ? (u({
mechanism: dh,
action: o ? ch : sh
}), o) : (u({
mechanism: ph,
action: sh
}), !1))
}
({
apiKey: i.apiKey,
context: "outer",
forceRollout: jh,
isAffectedBrowser: !window.Promise,
rolloutSlice: Math.floor(100 * Math.random()),
log: _h
});
if (l)
return this._apiKey = "", this._keyMode = "live", this._betas = [], this._isCheckout = !1, this._isHostedInvoicePage = !1, this._developerToolsOptions = Ir, new bh;
var u = i.apiKey,
p = i.stripeAccount,
m = i.apiVersion,
_ = i.locale,
f = i.developerTools,
h = i.__v2PrivateBeta,
y = i.__dashboard,
v = i.__privateApiUrl,
A = i.__checkoutSessionId,
k = i.__checkout,
T = i.__hosted3DS,
N = i.__hostedInvoicePage,
x = i.__privateSharedSessionContext,
O = i.__lazilyAttachController,
R = i.__hostedCaptcha,
L = i.betas,
q = (0, w.NH)(L || null),
D = q.validBetas,
U = q.betaWarning,
j = q.betaError;
if (j)
throw new P.N2(j);
U && c.push(U),
(0, Vt.Ld)(u),
null != k && k.mids && (e._ec = xe({
checkoutIds: k.mids,
stripeJsId: e.stripeJsId,
version: Xh
})),
this._apiKey = u.trim(),
this._keyMode = (0, Vt.Xf)(this._apiKey),
this._betas = D,
this._locale = (0, w.q3)(_, this._betas) || null;
var F = Wh(p);
this._stripeAccount = F || null,
this._developerToolsOptions = f,
this._isCheckout = !!k,
null != k && k.embeddedCheckoutRelays && (this._embeddedCheckoutRelays = k.embeddedCheckoutRelays),
null != k && k.embeddedCheckoutMessengerSend && (this._embeddedCheckoutMessengerSend = k.embeddedCheckoutMessengerSend),
this._isHostedInvoicePage = !!N;
var B = y ? ls.Dx : N ? ls.kU : void 0;
this._attachControllerGetter({
stripeCreateTimestamp: o,
apiVersion: m,
checkoutSessionId: A,
privateApiUrl: v,
privatePaymentUserAgentSuffix: B,
privateSharedSessionContext: x,
lazilyAttachController: O,
stripeAccount: F,
v2: h
}),
c.forEach((function (e) {
r._controller.warn(e),
r._controller.report("integration_warning", {
message: e,
method: "Stripe()"
})
})),
Dm(),
this._ensureHTTPOnlyLinkCookie(),
this._ensureHTTPS(),
this._ensureStripeHosted(n),
this._attachPaymentIntentMethods(this._betas, !!T, !!R),
this._attachLegacyPaymentIntentMethods(this._betas),
this._attachCheckoutMethods(this._betas),
this._attachEmbeddedCheckoutMethods(),
this._attachCustomCheckoutMethods(this._betas),
this._attachPrivateMethodsForCheckout(this._isCheckout),
this._attachPrivateMethodsForHostedInvoicePage(this._isHostedInvoicePage),
this._attachPrivateMethodsForConsumer(he),
this._attachCreateFinancialAccountDisclosure(),
this._attachCreateIssuingDisclosure(),
this._attachCreateTreasuryDisclosure(),
this._attachCreateRadarSession(),
this._attachGetters(),
this._attachIssuingCardMethods(this._betas),
this._attachIdentityMethods(),
this._attachLinkedAccountsMethods(this._betas),
this._attachAppInfo(),
this._attachStripeUpdate(),
this._attachLocalizeErrorMethod(),
this._attachCardBrandChoiceMethods(),
this._attachV2PrivateBetaMethods(h),
this._attachThreeDSecureStandaloneMethods(this._betas),
this._attachInitializePricing(this._betas),
!0 === ve && (0, yn.X1)(),
(0, yn.Gy)("init")
} catch (t) {
throw e._outerLogger || (e._outerLogger = function (e) {
return new Ch(e)
}
({
apiKey: this._apiKey,
stripeAccount: this._stripeAccount,
stripeJsId: e.stripeJsId,
version: Xh
})),
e._outerLogger.logError(t),
t instanceof P.N2 ? t : new Error("[Stripe.js] There was an issue with Stripe.js initialization")
}
}
其方法有
elements
elements:(0, I.UZ)(e, t, n)为
function (r) {
try {
return e.call(this, r)
} catch (e) {
return i(e, t || this && this._controller, !1, n)
}
}
当中的To为io

即为function t(e, r, o, a, i, c, u)
q.A为父类构造函数
function e() {
var t = this;
(0, a.A)(this, e),
this._emit = function (e) {
for (var n = arguments.length, o = new Array(n > 1 ? n - 1 : 0), a = 1; a < n; a++)
o[a - 1] = arguments[a];
var i = (0, r.A)(t._callbacks[e] || []);
return i.forEach((function (e) {
var t = e.fn;
if (t._isUserCallback)
try {
t.apply(void 0, o)
} catch (e) {
throw e._isUserError = !0,
e
}
else
t.apply(void 0, o)
})),
t
},
this._once = function (e, n) {
return t._on(e, (function r() {
t._off(e, r),
n.apply(void 0, arguments)
}), n)
},
this._removeAllListeners = function () {
return t._callbacks = {},
t
},
this._on = function (e, n, o) {
return t._callbacks[e] = [].concat((0, r.A)(t._callbacks[e] || []), [{
fn: n,
original: o
}
]),
t
},
this._validateUserOn = function () {},
this._userOn = function (e, n) {
if ("string" != typeof e)
throw new i.N2("When adding an event listener, the first argument should be a string event name.");
if ("function" != typeof n)
throw new i.N2("When adding an event listener, the second argument should be a function callback.");
return t._validateUserOn(e, n),
n._isUserCallback = !0,
t._on(e, n)
},
this._hasRegisteredListener = function (e) {
return (t._callbacks[e] || []).length > 0
},
this._off = function (e, n) {
if (n) {
for (var r, o = t._callbacks[e] || [], a = 0; a < o.length; a++)
if ((r = o[a]).fn === n || r.original === n) {
o.splice(a, 1);
break
}
} else
delete t._callbacks[e];
return t
},
this._callbacks = {};
var n = (0, c.Jm)(this._userOn),
o = (0, c.Jm)(this._off),
s = (0, c.Jm)(this._once),
l = (0, c.UZ)(this._hasRegisteredListener),
u = (0, c.UZ)(this._removeAllListeners),
d = (0, c.Tq)(this._emit);
this.on = this.addListener = this.addEventListener = n,
this.off = this.removeListener = this.removeEventListener = o,
this.once = s,
this.hasRegisteredListener = l,
this.removeAllListeners = u,
this.emit = d
}
(0, y.A)(t, e):设置t.prototype的原型链, 使用寄生式组件继承
var n = (0, v.A)(t):创建调用父类构造函数的函数
function r(e) {
var t = (0, a.A)();
return function () {
var n,
r = (0, o.A)(e);
if (t) {
var a = (0, o.A)(this).constructor;
n = Reflect.construct(r, arguments, a)
} else
n = r.apply(this, arguments);
return (0, i.A)(this, n)
}
}
上面(0, i.A)(this, n)的返回值是n
createToken
(0, I.kO)函数定义为
function (e, t, n) {
return function (r, o) {
var a = this;
try {
return e.call(this, r, o).catch((function (e) {
return i(e, t || a && a._controller, !0, n)
}))
} catch (e) {
return i(e, t || this && this._controller, !1, n)
}
}
}
即createToken对应的是function (r, o),内部调用 函数e,其定义为
function (e, t) {
var n = r._mids();
return "cvc_update" === e ? function (e, t) {
var n = (0, g.gJ)(t);
if (n && "cardCvc" === n._componentName) {
var r = n._implementation._frame.id;
return e.action.tokenizeCvcUpdate({
frameId: r
}).then(Gf)
}
throw new P.N2("You must provide a `cardCvc` Element to create a `cvc_update` token.")
}
(r._controller, t) : function (e, t) {
return function (n, r) {
var o = (0, g.gJ)(n);
if (o) {
var a = o._implementation._frame.id,
i = o._componentName,
c = Hf(r);
return e.action.tokenizeWithElement({
frameId: a,
elementName: i,
tokenData: c,
mids: t
}).then(Gf)
}
if ("string" == typeof n) {
var s = n,
l = Hf(r);
return e.action.tokenizeWithData({
elementName: null,
type: s,
tokenData: l,
mids: t
}).then(Gf)
}
throw new P.N2("You must provide a Stripe Element or a valid token type to create a Token.")
}
}
(r._controller, n)(e, t)
}
其中var n = r._mids()的返回为null或者对象
{
guid: this._guid,
muid: this._muid,
sid: this._sid
}
var o = (0, g.gJ)(n)中的g.gJ对应的函数为
function (e) {
var t = (0, r.pZ)(o, e, "");
return "error" === t.type ? null : t.value
}
//其中r.pZ对应函数
pe = function (e, t, n, r) {
var o = r || {},
i = o.path || [],
c = e(t, {
authenticatedOrigin: o.authenticatedOrigin || "",
element: o.element || "",
label: n
}, i);
return "valid" === c.type || "full" === c.errorType ? c : {
type: "error",
errorType: "full",
error: new a.N2(_(c.expected, c.actual, c.options, c.path))
}
}
//o对应为
var r = n(1649),
o = (0, r.z4)("an Element", {
_componentName: r.Yj,
_groupId: r.Yj,
_implementation: (0, r.cW)({
_frame: (0, r.cW)({
id: r.Yj
})
})
})
//r.z4对应函数为
le = function (e, t) {
return ae(t, {
unrecognizedKeyBehavior: "ignore",
name: e
})
}
//ae对应函数为,其返回为函数function (t, s, l)
ae = function (e) {
var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {},
n = t.unrecognizedKeyBehavior,
c = t.name;
return function (t, s, l) {
var u = null != n ? n : "warn";
if (t && "object" == typeof t && !Array.isArray(t)) {
var d = t,
p = (0, i.I6)(Object.keys(d), (function (t) {
return !e[t]
}));
if (p && "error" === u)
return h(new a.N2("Invalid ".concat(s.label, " parameter: ").concat([].concat((0, o.A)(l), [p]).join("."), " is not an accepted parameter.")));
var m = Object.keys(d),
_ = f("passthrough" === u ? (0, r.A)({}, t) : {});
return p && "warn" === u && !("__shared_params__" === p) && (_ = m.reduce((function (t, n) {
return e[n] ? t : f(t.value, [].concat((0, o.A)(t.warnings), ["Unrecognized ".concat(s.label, " parameter: ").concat([].concat((0, o.A)(l), [n]).join("."), " is not a recognized parameter. This may cause issues with your integration in the future.")]))
}), _)),
Object.keys(e).reduce((function (n, r) {
if ("error" === n.type)
return n;
var o = (0, e[r])(d[r], s, g(l, r));
return "valid" === o.type && void 0 !== o.value ? (n.value[r] = o.value, o.warnings.forEach((function (e) {
n.warnings.push(e)
})), n) : "valid" === o.type ? (o.warnings.forEach((function (e) {
n.warnings.push(e)
})), n) : c ? v(c, t, s, l) : o
}), _)
}
return v(null != c ? c : "an object", t, s, l)
}
}
即var o = (0, g.gJ)(n)中o对应function (t, s, l)调用后的返回值
token创建是通过e.action.tokenizeCvcUpdate,其中e为controller。action的初始化是通过
this.action = (n = {}, C_.forEach((function (e) {
n[e] = function (t) {
var n = a._requests.create(),
r = n.promise,
o = n.nonce;
return a._controllerFrame.send({
action: "stripe-controller-action-request",
payload: {
nonce: o,
actionName: e,
request: t
}
}),
r
}
})), n)
createSourcepaymentRequestopenLinkModal
injectStripe
是高阶组件,为组件添加属性
stripeelementsref
Elements
是上下方提供者,类型为
getRegisteredElements: () => ElementsList,
elements: ElementsShape | null,
addElementsLoadListener: (ElementsLoadListener) => void,
registerElement: (
element: ElementShape,
impliedTokenType: ?string,
impliedSourceType: ?string,
impliedPaymentMethodType: ?string
) => void,
unregisterElement: (element: ElementShape) => void
763



被折叠的 条评论
为什么被折叠?



