@alipay/ams-checkout 1.10.0 → 1.11.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.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/core/bus/ability/callback.d.ts +9 -0
- package/esm/core/bus/ability/callback.js +55 -0
- package/esm/core/bus/ability/security.d.ts +10 -0
- package/esm/core/bus/ability/security.js +104 -0
- package/esm/core/bus/ability/tracker.d.ts +9 -0
- package/esm/core/bus/ability/tracker.js +77 -0
- package/esm/core/bus/index.d.ts +125 -0
- package/esm/core/bus/index.js +366 -0
- package/esm/core/bus/interface.d.ts +32 -0
- package/esm/core/bus/interface.js +35 -0
- package/esm/core/component/index.d.ts +20 -1
- package/esm/core/component/index.js +270 -23
- package/esm/core/instance/index.d.ts +5 -1
- package/esm/core/instance/index.js +41 -4
- package/esm/index.d.ts +9 -4
- package/esm/index.js +56 -21
- package/esm/{core/applepay/index.d.ts → plugin/applepay/component.d.ts} +27 -8
- package/esm/{core/applepay/index.js → plugin/applepay/component.js} +150 -180
- package/esm/plugin/applepay/index.d.ts +17 -0
- package/esm/plugin/applepay/index.js +117 -0
- package/esm/{common → plugin}/applepay/interface.d.ts +62 -3
- package/esm/plugin/applepay/interface.js +69 -0
- package/esm/{common/applepay/index.d.ts → plugin/applepay/service.d.ts} +13 -7
- package/esm/{common/applepay/index.js → plugin/applepay/service.js} +159 -41
- package/esm/plugin/component/cashierApp.d.ts +3 -0
- package/esm/plugin/component/cashierApp.js +23 -2
- package/esm/plugin/component/index.d.ts +6 -2
- package/esm/plugin/component/index.js +126 -44
- package/esm/plugin/const.d.ts +2 -0
- package/esm/plugin/const.js +19 -0
- package/esm/plugin/type.d.ts +33 -0
- package/esm/request/index.d.ts +1 -1
- package/esm/service/index.d.ts +1 -1
- package/esm/types/index.d.ts +63 -6
- package/esm/types/index.js +8 -1
- package/esm/util/createIframeNode.d.ts +1 -0
- package/esm/util/createIframeNode.js +6 -0
- package/package.json +1 -1
- /package/esm/{common/applepay/interface.js → plugin/type.js} +0 -0
@@ -0,0 +1,117 @@
|
|
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
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
5
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
6
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
7
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
8
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
9
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
10
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
11
|
+
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); } }
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
13
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
14
|
+
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; }
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
16
|
+
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); }
|
17
|
+
import { BusManager, BusMessage, BusSubscriber } from "../../core/bus";
|
18
|
+
import { ApplePayActionEnum, PaymentActionEnum, SDKCallbackActionEnum } from "../../core/bus/interface";
|
19
|
+
import ApplePayComponent, { ApplePayComponentEvent } from "./component";
|
20
|
+
import ApplePayService from "./service";
|
21
|
+
export var ApplePayInitMessage = /*#__PURE__*/_createClass(function ApplePayInitMessage() {
|
22
|
+
_classCallCheck(this, ApplePayInitMessage);
|
23
|
+
_defineProperty(this, "environment", void 0);
|
24
|
+
_defineProperty(this, "locale", void 0);
|
25
|
+
});
|
26
|
+
export var ApplePayBusSubscriber = /*#__PURE__*/function (_BusSubscriber) {
|
27
|
+
_inherits(ApplePayBusSubscriber, _BusSubscriber);
|
28
|
+
var _super = _createSuper(ApplePayBusSubscriber);
|
29
|
+
function ApplePayBusSubscriber(logger) {
|
30
|
+
var _this;
|
31
|
+
_classCallCheck(this, ApplePayBusSubscriber);
|
32
|
+
_this = _super.call(this);
|
33
|
+
_defineProperty(_assertThisInitialized(_this), "applePay", void 0);
|
34
|
+
_defineProperty(_assertThisInitialized(_this), "logger", void 0);
|
35
|
+
_this.logger = logger;
|
36
|
+
return _this;
|
37
|
+
}
|
38
|
+
_createClass(ApplePayBusSubscriber, [{
|
39
|
+
key: "actionNames",
|
40
|
+
value: function actionNames() {
|
41
|
+
return Object.values(ApplePayActionEnum).concat(Object.values(PaymentActionEnum));
|
42
|
+
}
|
43
|
+
}, {
|
44
|
+
key: "onOptionalInit",
|
45
|
+
value: function onOptionalInit(context, message) {
|
46
|
+
console.log('onOptionalInit', message.getData());
|
47
|
+
}
|
48
|
+
}, {
|
49
|
+
key: "onCanMakePayments",
|
50
|
+
value: function onCanMakePayments(context, message) {
|
51
|
+
var _message$getJSONObjec;
|
52
|
+
console.log('onCanMakePayments', message.getData());
|
53
|
+
var subPaymentMethod = (_message$getJSONObjec = message.getJSONObject()) === null || _message$getJSONObjec === void 0 ? void 0 : _message$getJSONObjec.subPaymentMethod;
|
54
|
+
var canMakePayments = ApplePayService.canMakePayments(subPaymentMethod);
|
55
|
+
context === null || context === void 0 || context.onCallBack(message.result(canMakePayments));
|
56
|
+
this.logger.logInfo({
|
57
|
+
name: 'APPLE_PAY',
|
58
|
+
title: ApplePayComponentEvent.sdk_event_appleAvailable
|
59
|
+
}, {
|
60
|
+
biz: 'sdk',
|
61
|
+
type: 'funnel',
|
62
|
+
success: canMakePayments,
|
63
|
+
recurring: subPaymentMethod === 'ApplePayRecurringPayment'
|
64
|
+
}).send();
|
65
|
+
}
|
66
|
+
}, {
|
67
|
+
key: "onCreateComponent",
|
68
|
+
value: function onCreateComponent(context, message) {
|
69
|
+
var data = message.getJSONObject();
|
70
|
+
console.log('onCreateComponent', message);
|
71
|
+
this.applePay = new ApplePayComponent(_objectSpread(_objectSpread({}, data === null || data === void 0 ? void 0 : data.options), {}, {
|
72
|
+
onEventCallback: function onEventCallback(state) {
|
73
|
+
console.log('onCreateComponent#onEventCallback', state);
|
74
|
+
if (state) {
|
75
|
+
BusManager.publish(new BusMessage(SDKCallbackActionEnum.onEventCallback, JSON.stringify(state)));
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}), this.logger);
|
79
|
+
var appendParams = data === null || data === void 0 ? void 0 : data.appendParams;
|
80
|
+
this.applePay.submitPay(appendParams);
|
81
|
+
}
|
82
|
+
}, {
|
83
|
+
key: "onDestoryComponent",
|
84
|
+
value: function onDestoryComponent(context, message) {
|
85
|
+
this.applePay = null;
|
86
|
+
console.log('onDestoryComponent', context, message);
|
87
|
+
this.logger.logInfo({
|
88
|
+
name: 'APPLE_PAY',
|
89
|
+
title: ApplePayComponentEvent.sdk_event_appleDestoryComponent
|
90
|
+
}, {
|
91
|
+
biz: 'sdk',
|
92
|
+
type: 'funnel'
|
93
|
+
}).send();
|
94
|
+
}
|
95
|
+
}, {
|
96
|
+
key: "onMessage",
|
97
|
+
value: function onMessage(context, message) {
|
98
|
+
switch (message.getAction()) {
|
99
|
+
case PaymentActionEnum.optional_init:
|
100
|
+
this.onOptionalInit(context, message);
|
101
|
+
break;
|
102
|
+
case ApplePayActionEnum.canMakePayments:
|
103
|
+
this.onCanMakePayments(context, message);
|
104
|
+
break;
|
105
|
+
case ApplePayActionEnum.createComponent:
|
106
|
+
this.onCreateComponent(context, message);
|
107
|
+
break;
|
108
|
+
case ApplePayActionEnum.destoryComponent:
|
109
|
+
this.onDestoryComponent(context, message);
|
110
|
+
break;
|
111
|
+
default:
|
112
|
+
console.log("Unknown action: " + message.getAction());
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}]);
|
116
|
+
return ApplePayBusSubscriber;
|
117
|
+
}(BusSubscriber);
|
@@ -6,6 +6,8 @@
|
|
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
8
|
export type Version = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
9
|
+
export declare const APPLE_PAY_VERSION = 2;
|
10
|
+
export declare const APPLE_PAY_RECURRING_VERSION = 14;
|
9
11
|
export interface IApplePayValidateMerchantEvent {
|
10
12
|
validationURL: string;
|
11
13
|
}
|
@@ -35,10 +37,41 @@ export interface IApplePayPaymentContact {
|
|
35
37
|
countryCode: string;
|
36
38
|
}
|
37
39
|
export type IApplePayLineItemType = 'final' | 'pending';
|
40
|
+
export type ApplePayPaymentTiming = "immediate" | "recurring" | "deferred" | "automaticReload";
|
41
|
+
export type ApplePayRecurringPaymentDateUnit = "year" | "month" | "day" | "hour" | "minute";
|
42
|
+
/**
|
43
|
+
*
|
44
|
+
{
|
45
|
+
"label": "Subscription",
|
46
|
+
"amount": "20.00",
|
47
|
+
"type": "final",
|
48
|
+
"paymentTiming": "recurring",
|
49
|
+
"recurringPaymentStartDate": new Date("2022-01-01T00:00:00"),
|
50
|
+
"recurringPaymentIntervalUnit": "month",
|
51
|
+
"recurringPaymentIntervalCount": 6,
|
52
|
+
"recurringPaymentEndDate": new Date("2024-01-01T00:00:00"),
|
53
|
+
}
|
54
|
+
*/
|
38
55
|
export interface IApplePayLineItem {
|
56
|
+
/**
|
57
|
+
* A value that indicates whether the line item is final or pending.
|
58
|
+
*/
|
39
59
|
type: IApplePayLineItemType;
|
60
|
+
/**
|
61
|
+
* A required value that’s a short, localized description of the line item.
|
62
|
+
*/
|
40
63
|
label: string;
|
64
|
+
/**
|
65
|
+
* A required value that’s the monetary amount of the line item.
|
66
|
+
*/
|
41
67
|
amount: string;
|
68
|
+
paymentTiming?: ApplePayPaymentTiming;
|
69
|
+
recurringPaymentStartDate?: Date;
|
70
|
+
recurringPaymentEndDate?: Date;
|
71
|
+
recurringPaymentIntervalUnit?: ApplePayRecurringPaymentDateUnit;
|
72
|
+
recurringPaymentIntervalCount?: number;
|
73
|
+
deferredPaymentDate?: Date;
|
74
|
+
automaticReloadPaymentThresholdAmount?: string;
|
42
75
|
}
|
43
76
|
export type applePayShippingType = 'shipping' | 'delivery' | 'storePickup' | 'servicePickup';
|
44
77
|
export interface IApplePayShippingMethod {
|
@@ -75,6 +108,34 @@ export interface IApplePayPaymentRequest {
|
|
75
108
|
currencyCode: string;
|
76
109
|
shippingType?: applePayShippingType;
|
77
110
|
shippingMethods?: IApplePayShippingMethod[];
|
111
|
+
recurringPaymentRequest?: IApplePayRecurringPaymentRequest;
|
112
|
+
}
|
113
|
+
export interface IApplePayRecurringPaymentRequest {
|
114
|
+
/**
|
115
|
+
* A description of the recurring payment that Apple Pay displays to the user in the payment sheet.
|
116
|
+
*/
|
117
|
+
paymentDescription: string;
|
118
|
+
/**
|
119
|
+
* A localized billing agreement that the payment sheet displays to the user before the user authorizes the payment.
|
120
|
+
*/
|
121
|
+
billingAgreement?: string;
|
122
|
+
/**
|
123
|
+
* The regular billing cycle for the recurring payment, including start and end dates, an interval, and an interval count.
|
124
|
+
*/
|
125
|
+
regularBilling: IApplePayLineItem;
|
126
|
+
/**
|
127
|
+
* 订阅试用的周期控制,暂时不需要
|
128
|
+
* The trial billing cycle for the recurring payment.
|
129
|
+
*/
|
130
|
+
trialBilling?: IApplePayLineItem;
|
131
|
+
/**
|
132
|
+
* A URL to a web page where the user can update or delete the payment method for the recurring payment.
|
133
|
+
*/
|
134
|
+
managementURL: string;
|
135
|
+
/**
|
136
|
+
* A URL you provide for receiving life-cycle notifications from the Apple Pay servers about the Apple Pay merchant token for the recurring payment.
|
137
|
+
*/
|
138
|
+
tokenNotificationURL?: string;
|
78
139
|
}
|
79
140
|
export interface IApplePaySession {
|
80
141
|
supportsVersion?: (version: Version) => boolean;
|
@@ -97,6 +158,4 @@ export type ICompletePaymentAuthorized = (params: {
|
|
97
158
|
paymentToken?: string;
|
98
159
|
}) => Promise<any>;
|
99
160
|
export type ICompleteApplePay = (data: any) => void;
|
100
|
-
export type ILogError = (msg: string, error?: any) => void;
|
101
|
-
export type traceMsg = 'start' | 'sessionBegin' | 'onValidateMerchant' | 'completeMerchantValidation' | 'onpaymentauthorized' | 'completePaymentAuthorized' | 'completeApplePay';
|
102
|
-
export type IApplePayTrace = (msg: traceMsg) => void;
|
161
|
+
export type ILogError = (code: string, msg: string, error?: any) => void;
|
@@ -0,0 +1,69 @@
|
|
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
|
+
*/
|
8
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
9
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_on_the_web_version_history
|
10
|
+
|
11
|
+
export var APPLE_PAY_VERSION = 2;
|
12
|
+
export var APPLE_PAY_RECURRING_VERSION = 14;
|
13
|
+
|
14
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepayvalidatemerchantevent
|
15
|
+
|
16
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaymerchantcapability
|
17
|
+
|
18
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentrequest/1916122-supportednetworks
|
19
|
+
|
20
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaycontactfield
|
21
|
+
|
22
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentcontact
|
23
|
+
|
24
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaylineitemtype
|
25
|
+
|
26
|
+
//https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymenttiming
|
27
|
+
|
28
|
+
//https://developer.apple.com/documentation/apple_pay_on_the_web/applepayrecurringpaymentdateunit
|
29
|
+
|
30
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaylineitem
|
31
|
+
/**
|
32
|
+
*
|
33
|
+
{
|
34
|
+
"label": "Subscription",
|
35
|
+
"amount": "20.00",
|
36
|
+
"type": "final",
|
37
|
+
"paymentTiming": "recurring",
|
38
|
+
"recurringPaymentStartDate": new Date("2022-01-01T00:00:00"),
|
39
|
+
"recurringPaymentIntervalUnit": "month",
|
40
|
+
"recurringPaymentIntervalCount": 6,
|
41
|
+
"recurringPaymentEndDate": new Date("2024-01-01T00:00:00"),
|
42
|
+
}
|
43
|
+
*/
|
44
|
+
|
45
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepayshippingtype
|
46
|
+
|
47
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepayshippingmethod
|
48
|
+
|
49
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypayment
|
50
|
+
|
51
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentauthorizedevent
|
52
|
+
|
53
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/apple_pay_status_codes
|
54
|
+
|
55
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentauthorizationresult
|
56
|
+
|
57
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentrequest
|
58
|
+
|
59
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepayrecurringpaymentrequest
|
60
|
+
|
61
|
+
// https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession
|
62
|
+
|
63
|
+
// IGetMerchantSession spi type
|
64
|
+
|
65
|
+
// ICompletePaymentAuthorized spi type
|
66
|
+
|
67
|
+
// ICompleteApplePay spi type
|
68
|
+
|
69
|
+
// ILogError spi type
|
@@ -5,8 +5,9 @@
|
|
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 { IGetMerchantSession, ICompletePaymentAuthorized, ICompleteApplePay, ILogError
|
9
|
-
import { IpaymentSessionMetaData } from '../../types';
|
8
|
+
import { IGetMerchantSession, ICompletePaymentAuthorized, ICompleteApplePay, ILogError } from './interface';
|
9
|
+
import { ApplePaySubTypeEnum, IpaymentSessionMetaData } from '../../types';
|
10
|
+
import type { Logger } from '../../util/logger';
|
10
11
|
/**
|
11
12
|
* Apple Pay Service
|
12
13
|
*/
|
@@ -14,12 +15,14 @@ declare class ApplePayService {
|
|
14
15
|
private merchantIdentifier;
|
15
16
|
private merchantName;
|
16
17
|
private session;
|
18
|
+
private paymentState;
|
17
19
|
private getMerchantSession;
|
18
20
|
private completePaymentAuthorized;
|
19
21
|
private completeApplePay;
|
20
22
|
private logError;
|
21
|
-
private
|
22
|
-
|
23
|
+
private isRecurring;
|
24
|
+
private logger;
|
25
|
+
constructor(logger: Logger);
|
23
26
|
/**
|
24
27
|
* set Apple Pay Params
|
25
28
|
* @param getMerchantSession
|
@@ -28,17 +31,20 @@ declare class ApplePayService {
|
|
28
31
|
* @param logError
|
29
32
|
* @param applePayTrace
|
30
33
|
*/
|
31
|
-
setApplePayParams(getMerchantSession: IGetMerchantSession, completePaymentAuthorized: ICompletePaymentAuthorized, completeApplePay: ICompleteApplePay, logError: ILogError
|
34
|
+
setApplePayParams(getMerchantSession: IGetMerchantSession, completePaymentAuthorized: ICompletePaymentAuthorized, completeApplePay: ICompleteApplePay, logError: ILogError): void;
|
32
35
|
/**
|
33
|
-
* Apple Pay
|
36
|
+
* Is Apple Pay Enabled
|
37
|
+
* @param subTypeEnum
|
38
|
+
* @returns
|
34
39
|
*/
|
35
|
-
|
40
|
+
static canMakePayments(subTypeEnum?: ApplePaySubTypeEnum): any;
|
36
41
|
/**
|
37
42
|
* has Active Card in Apple Pay
|
38
43
|
* @param merchantIdentifier
|
39
44
|
*/
|
40
45
|
hasActiveCard(merchantIdentifier: string): Promise<boolean>;
|
41
46
|
private onvalidatemerchant;
|
47
|
+
private sessionAbort;
|
42
48
|
private onpaymentauthorized;
|
43
49
|
/**
|
44
50
|
* Start Pay
|
@@ -16,104 +16,197 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
16
16
|
* 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.
|
17
17
|
*/
|
18
18
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
19
|
+
import { APPLE_PAY_VERSION, APPLE_PAY_RECURRING_VERSION } from "./interface";
|
20
|
+
import { eventCodeEnum } from "../../types";
|
21
|
+
import { ApplePayComponentEvent } from "./component";
|
22
|
+
var PaymentState = /*#__PURE__*/function (PaymentState) {
|
23
|
+
PaymentState[PaymentState["notStarted"] = 0] = "notStarted";
|
24
|
+
PaymentState[PaymentState["pending"] = 1] = "pending";
|
25
|
+
PaymentState[PaymentState["fail"] = 2] = "fail";
|
26
|
+
PaymentState[PaymentState["success"] = 3] = "success";
|
27
|
+
return PaymentState;
|
28
|
+
}(PaymentState || {});
|
19
29
|
/**
|
20
30
|
* Apple Pay Service
|
21
31
|
*/
|
22
32
|
var ApplePayService = /*#__PURE__*/function () {
|
23
|
-
function ApplePayService() {
|
33
|
+
function ApplePayService(logger) {
|
24
34
|
var _this = this;
|
25
35
|
_classCallCheck(this, ApplePayService);
|
26
36
|
_defineProperty(this, "merchantIdentifier", void 0);
|
27
37
|
_defineProperty(this, "merchantName", void 0);
|
28
38
|
_defineProperty(this, "session", void 0);
|
39
|
+
_defineProperty(this, "paymentState", void 0);
|
29
40
|
_defineProperty(this, "getMerchantSession", void 0);
|
30
41
|
_defineProperty(this, "completePaymentAuthorized", void 0);
|
31
42
|
_defineProperty(this, "completeApplePay", void 0);
|
32
43
|
_defineProperty(this, "logError", void 0);
|
33
|
-
_defineProperty(this, "
|
34
|
-
|
35
|
-
* Apple Pay is enabled
|
36
|
-
*/
|
37
|
-
_defineProperty(this, "isEnabled", function () {
|
38
|
-
return window.ApplePaySession ? window.ApplePaySession.canMakePayments() : false;
|
39
|
-
});
|
44
|
+
_defineProperty(this, "isRecurring", false);
|
45
|
+
_defineProperty(this, "logger", void 0);
|
40
46
|
_defineProperty(this, "onvalidatemerchant", function (event) {
|
41
|
-
|
47
|
+
var success = false;
|
42
48
|
_this.getMerchantSession({
|
43
49
|
displayName: _this.merchantName,
|
44
50
|
merchantIdentifier: _this.merchantIdentifier,
|
45
51
|
validationUrl: event.validationURL
|
46
52
|
}).then(function (merchantSessionObjectString) {
|
53
|
+
console.log("onvalidatemerchant#merchantSessionObjectString", merchantSessionObjectString);
|
47
54
|
var merchantSessionObject = JSON.parse(merchantSessionObjectString);
|
48
55
|
_this.session.completeMerchantValidation(merchantSessionObject);
|
49
|
-
|
56
|
+
success = true;
|
50
57
|
}).catch(function (error) {
|
51
|
-
_this.logError('MerchantValidationError', error);
|
52
|
-
_this.
|
58
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'MerchantValidationError', error);
|
59
|
+
_this.sessionAbort();
|
53
60
|
});
|
61
|
+
_this.logger.logInfo({
|
62
|
+
name: 'APPLE_PAY',
|
63
|
+
title: ApplePayComponentEvent.sdk_event_appleCreateComponent
|
64
|
+
}, {
|
65
|
+
biz: 'sdk',
|
66
|
+
type: 'funnel',
|
67
|
+
success: success,
|
68
|
+
recurring: _this.isRecurring
|
69
|
+
}).send();
|
54
70
|
});
|
55
71
|
_defineProperty(this, "onpaymentauthorized", function (event) {
|
56
72
|
var _event$payment;
|
57
|
-
_this.applePayTrace('onpaymentauthorized');
|
58
73
|
var _window = window,
|
59
74
|
ApplePaySession = _window.ApplePaySession;
|
75
|
+
var success = false;
|
60
76
|
var exception = function exception(error) {
|
61
77
|
_this.session.completePayment(ApplePaySession.STATUS_FAILURE);
|
62
|
-
_this.logError('PaymentAuthorizedError', error);
|
63
|
-
_this.
|
78
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'PaymentAuthorizedError', error);
|
79
|
+
_this.sessionAbort();
|
64
80
|
};
|
65
81
|
if (event !== null && event !== void 0 && (_event$payment = event.payment) !== null && _event$payment !== void 0 && _event$payment.token) {
|
66
|
-
_this.
|
82
|
+
_this.paymentState = PaymentState.pending;
|
67
83
|
_this.completePaymentAuthorized({
|
68
84
|
paymentToken: JSON.stringify(event.payment.token)
|
69
85
|
}).then(function (data) {
|
70
|
-
_this.applePayTrace('completeApplePay');
|
71
86
|
_this.session.completePayment(ApplePaySession.STATUS_SUCCESS);
|
72
87
|
_this.completeApplePay(data);
|
88
|
+
_this.paymentState = PaymentState.success;
|
89
|
+
success = true;
|
73
90
|
}).catch(function (error) {
|
74
91
|
exception(error);
|
92
|
+
_this.paymentState = PaymentState.fail;
|
75
93
|
});
|
76
94
|
} else {
|
77
95
|
exception();
|
78
96
|
}
|
97
|
+
_this.logger.logInfo({
|
98
|
+
name: 'APPLE_PAY',
|
99
|
+
title: ApplePayComponentEvent.sdk_event_appleSubmitToken
|
100
|
+
}, {
|
101
|
+
biz: 'sdk',
|
102
|
+
type: 'funnel',
|
103
|
+
success: success,
|
104
|
+
recurring: _this.isRecurring
|
105
|
+
}).send();
|
79
106
|
});
|
80
107
|
/**
|
81
108
|
* Start Pay
|
82
109
|
*/
|
83
110
|
_defineProperty(this, "startPay", function (param) {
|
84
|
-
_this.applePayTrace('start');
|
85
|
-
var _window2 = window,
|
86
|
-
ApplePaySession = _window2.ApplePaySession;
|
87
|
-
if (!ApplePaySession) {
|
88
|
-
throw Error('ApplePaySession is null in window');
|
89
|
-
}
|
90
111
|
var paymentSessionFactor = param.paymentSessionFactor;
|
91
|
-
var
|
112
|
+
var extendInfo = paymentSessionFactor.extendInfo,
|
92
113
|
merchantInfo = paymentSessionFactor.merchantInfo,
|
93
114
|
paymentAmount = paymentSessionFactor.paymentAmount,
|
94
|
-
order = paymentSessionFactor.order
|
115
|
+
order = paymentSessionFactor.order,
|
116
|
+
recurringInfo = paymentSessionFactor.recurringInfo;
|
95
117
|
_this.merchantIdentifier = merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.partnerId;
|
96
|
-
var
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
118
|
+
var _window2 = window,
|
119
|
+
ApplePaySession = _window2.ApplePaySession;
|
120
|
+
_this.isRecurring = recurringInfo !== null;
|
121
|
+
_this.logger.logInfo({
|
122
|
+
name: 'APPLE_PAY',
|
123
|
+
title: ApplePayComponentEvent.sdk_event_appleCreateComponent
|
124
|
+
}, {
|
125
|
+
biz: 'sdk',
|
126
|
+
type: 'funnel',
|
127
|
+
success: ApplePaySession !== null,
|
128
|
+
recurring: _this.isRecurring
|
129
|
+
}).send();
|
130
|
+
if (!ApplePaySession) {
|
131
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "ApplePaySession is only support in Safari");
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
if (!(extendInfo !== null && extendInfo !== void 0 && extendInfo.merchantCapabilities) || !(extendInfo !== null && extendInfo !== void 0 && extendInfo.supportedNetworks) || !(merchantInfo !== null && merchantInfo !== void 0 && merchantInfo.registeredCountry) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.currency) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.value) || !(merchantInfo !== null && merchantInfo !== void 0 && merchantInfo.merchantName)) {
|
135
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal params paymentSessionFactor");
|
136
|
+
return;
|
137
|
+
}
|
138
|
+
if (recurringInfo) {
|
139
|
+
var _recurringInfo$interv;
|
140
|
+
if (!(order !== null && order !== void 0 && order.orderDescription) || !(recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.managementURL)) {
|
141
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal params recurringInfo");
|
142
|
+
return;
|
105
143
|
}
|
106
|
-
|
107
|
-
|
144
|
+
var lineItem = {
|
145
|
+
type: 'final',
|
146
|
+
label: recurringInfo.title,
|
147
|
+
amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value,
|
148
|
+
paymentTiming: "recurring",
|
149
|
+
recurringPaymentStartDate: recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.startDate ? new Date(Number(recurringInfo.startDate) * 1000) : null,
|
150
|
+
recurringPaymentEndDate: recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.endDate ? new Date(Number(recurringInfo.endDate) * 1000) : null,
|
151
|
+
recurringPaymentIntervalUnit: recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.intervalUnit ? recurringInfo.intervalUnit : "month",
|
152
|
+
recurringPaymentIntervalCount: (_recurringInfo$interv = recurringInfo === null || recurringInfo === void 0 ? void 0 : recurringInfo.intervalCount) !== null && _recurringInfo$interv !== void 0 ? _recurringInfo$interv : 1
|
153
|
+
};
|
154
|
+
var recurringRequest = {
|
155
|
+
// 不知道显示在哪里
|
156
|
+
paymentDescription: order === null || order === void 0 ? void 0 : order.orderDescription,
|
157
|
+
billingAgreement: recurringInfo.agreementDescription,
|
158
|
+
regularBilling: lineItem,
|
159
|
+
managementURL: recurringInfo === null || recurringInfo === void 0 ? void 0 : recurringInfo.managementURL,
|
160
|
+
tokenNotificationURL: recurringInfo === null || recurringInfo === void 0 ? void 0 : recurringInfo.tokenNotificationURL
|
161
|
+
};
|
162
|
+
var request = {
|
163
|
+
merchantCapabilities: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities,
|
164
|
+
supportedNetworks: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks,
|
165
|
+
countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
|
166
|
+
currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
|
167
|
+
total: lineItem,
|
168
|
+
recurringPaymentRequest: recurringRequest,
|
169
|
+
lineItems: [lineItem]
|
170
|
+
};
|
171
|
+
_this.session = new ApplePaySession(APPLE_PAY_RECURRING_VERSION, request);
|
172
|
+
} else {
|
173
|
+
var _request = {
|
174
|
+
merchantCapabilities: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities,
|
175
|
+
supportedNetworks: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks,
|
176
|
+
countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
|
177
|
+
currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
|
178
|
+
total: {
|
179
|
+
type: 'final',
|
180
|
+
label: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName,
|
181
|
+
amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value
|
182
|
+
}
|
183
|
+
};
|
184
|
+
_this.session = new ApplePaySession(APPLE_PAY_VERSION, _request);
|
185
|
+
}
|
186
|
+
// 核身前触发
|
108
187
|
_this.session.onvalidatemerchant = _this.onvalidatemerchant;
|
188
|
+
// 核身后触发
|
109
189
|
_this.session.onpaymentauthorized = _this.onpaymentauthorized;
|
110
190
|
_this.session.oncancel = function () {
|
111
|
-
_this.
|
112
|
-
|
191
|
+
if (_this.paymentState === PaymentState.pending) {
|
192
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_PROCESSING, 'Payment processing but user dismissed the sheet');
|
193
|
+
} else {
|
194
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_CANCEL, 'User dismissed the sheet');
|
195
|
+
}
|
196
|
+
_this.sessionAbort();
|
113
197
|
};
|
114
198
|
_this.session.begin();
|
115
|
-
_this.
|
199
|
+
_this.logger.logInfo({
|
200
|
+
name: 'APPLE_PAY',
|
201
|
+
title: ApplePayComponentEvent.sdk_event_appleShowPaymentSheet
|
202
|
+
}, {
|
203
|
+
biz: 'sdk',
|
204
|
+
type: 'funnel',
|
205
|
+
success: true,
|
206
|
+
recurring: recurringInfo !== null
|
207
|
+
}).send();
|
116
208
|
});
|
209
|
+
this.logger = logger;
|
117
210
|
}
|
118
211
|
|
119
212
|
/**
|
@@ -126,13 +219,19 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
126
219
|
*/
|
127
220
|
_createClass(ApplePayService, [{
|
128
221
|
key: "setApplePayParams",
|
129
|
-
value: function setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError
|
222
|
+
value: function setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError) {
|
130
223
|
this.getMerchantSession = getMerchantSession;
|
131
224
|
this.completePaymentAuthorized = completePaymentAuthorized;
|
132
225
|
this.completeApplePay = completeApplePay;
|
133
226
|
this.logError = logError;
|
134
|
-
this.
|
227
|
+
this.paymentState = PaymentState.notStarted;
|
135
228
|
}
|
229
|
+
|
230
|
+
/**
|
231
|
+
* Is Apple Pay Enabled
|
232
|
+
* @param subTypeEnum
|
233
|
+
* @returns
|
234
|
+
*/
|
136
235
|
}, {
|
137
236
|
key: "hasActiveCard",
|
138
237
|
value: (
|
@@ -165,6 +264,25 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
165
264
|
}
|
166
265
|
return hasActiveCard;
|
167
266
|
}())
|
267
|
+
}, {
|
268
|
+
key: "sessionAbort",
|
269
|
+
value: function sessionAbort() {
|
270
|
+
if (this.session) {
|
271
|
+
try {
|
272
|
+
this.session.abort();
|
273
|
+
} catch (error) {
|
274
|
+
console.log("session.abort() error");
|
275
|
+
}
|
276
|
+
}
|
277
|
+
}
|
278
|
+
}], [{
|
279
|
+
key: "canMakePayments",
|
280
|
+
value: function canMakePayments(subTypeEnum) {
|
281
|
+
if ('ApplePayRecurringPayment' === subTypeEnum) {
|
282
|
+
return window.ApplePaySession ? window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion(APPLE_PAY_RECURRING_VERSION) : false;
|
283
|
+
}
|
284
|
+
return window.ApplePaySession ? window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion(APPLE_PAY_VERSION) : false;
|
285
|
+
}
|
168
286
|
}]);
|
169
287
|
return ApplePayService;
|
170
288
|
}();
|
@@ -17,6 +17,8 @@ export declare const getIframeUrl: (iframeParams: {
|
|
17
17
|
locale: string;
|
18
18
|
instanceId: string;
|
19
19
|
renderDisplayType: renderDisplayTypeEnum;
|
20
|
+
isPreload?: string;
|
21
|
+
hostSign?: string;
|
20
22
|
}) => {
|
21
23
|
path: string;
|
22
24
|
locationSearch: string;
|
@@ -25,3 +27,4 @@ export declare const getIframeUrl: (iframeParams: {
|
|
25
27
|
* @description Create iframe
|
26
28
|
*/
|
27
29
|
export declare const createIframe: (mode: string, platform: 'mobile' | 'desktop') => HTMLIFrameElement;
|
30
|
+
export declare const createPreloadIframe: (channelType: any, version: any) => HTMLIFrameElement;
|