@alipay/ams-checkout 1.10.1 → 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 +15 -1
- package/esm/core/component/index.js +185 -28
- package/esm/core/instance/index.d.ts +5 -1
- package/esm/core/instance/index.js +41 -4
- package/esm/index.d.ts +0 -3
- package/esm/index.js +8 -18
- 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/index.d.ts +2 -2
- package/esm/plugin/component/index.js +10 -10
- 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 +60 -6
- package/esm/types/index.js +8 -1
- package/package.json +1 -1
- /package/esm/{common/applepay/interface.js → plugin/type.js} +0 -0
@@ -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
|
}();
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type AMSCheckout from '../../core/instance';
|
2
2
|
import type { eventPayload, eventPayloadContext, IappendIframeNodesParams, IMerchantAppointParam, Iselector } from '../../types';
|
3
|
-
import { componentSignEnum, platformEnum, renderDisplayTypeEnum } from '../../types';
|
3
|
+
import { componentSignEnum, DeviceIdParameter, platformEnum, renderDisplayTypeEnum } from '../../types';
|
4
4
|
type IrenderFuncParams = (context: ComponentApp, selector: Iselector, renderDisplayType: renderDisplayTypeEnum) => Promise<void>;
|
5
5
|
export default class ComponentApp {
|
6
6
|
app: null | HTMLIFrameElement;
|
@@ -44,7 +44,7 @@ export default class ComponentApp {
|
|
44
44
|
setPreloadRender(renderFunc: any): void;
|
45
45
|
private initSecurity;
|
46
46
|
private logDeviceId;
|
47
|
-
|
47
|
+
getDeviceIdAndLog(deviceIdParameter?: DeviceIdParameter, isPolling?: boolean): Promise<string>;
|
48
48
|
/**
|
49
49
|
* @description render iframe content
|
50
50
|
*/
|
@@ -54,7 +54,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
54
54
|
_defineProperty(this, "_merchantAppointParam", void 0);
|
55
55
|
_defineProperty(this, "_webAppHeartBeatTimeoutId", void 0);
|
56
56
|
_defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
|
57
|
-
this._appVersion = '1.
|
57
|
+
this._appVersion = '1.11.0';
|
58
58
|
this._isInitComponent = false;
|
59
59
|
this._selector = "#".concat(COMPONENT_SECTION_ID);
|
60
60
|
this.createIframeNode = function () {
|
@@ -364,7 +364,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
364
364
|
this._actionQueryPromise = new Promise( /*#__PURE__*/function () {
|
365
365
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve, reject) {
|
366
366
|
var _this5$_renderParams, _this5$_renderParams2, _this5$_renderParams3, _this5$_renderParams4, _this5$_renderParams5;
|
367
|
-
var envInfo, params,
|
367
|
+
var envInfo, params, _ref3, extendInfo, enableVaultingApiOptimize, enableEasypayApiOptimize, extendInfoData, _this5$_renderParams6, _this5$_renderParams7, _ref4, _ref4$productSceneVer, productSceneVersion, _ref4$productScene, productScene, _ref5, _ref5$action, _ref5$action2, _ref5$action2$autoDeb, autoDebitWithToken, _this5$_renderParams8, _action$web, _action$wap, action, signType;
|
368
368
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
369
369
|
while (1) switch (_context2.prev = _context2.next) {
|
370
370
|
case 0:
|
@@ -380,7 +380,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
380
380
|
/**
|
381
381
|
* @description Simulated or unnecessary scenarios
|
382
382
|
*/
|
383
|
-
|
383
|
+
_ref3 = ((_this5$_renderParams4 = _this5._renderParams) === null || _this5$_renderParams4 === void 0 ? void 0 : _this5$_renderParams4.paymentSessionMetaData) || {}, extendInfo = _ref3.extendInfo;
|
384
384
|
enableVaultingApiOptimize = false;
|
385
385
|
enableEasypayApiOptimize = false;
|
386
386
|
try {
|
@@ -427,8 +427,8 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
427
427
|
_context2.next = 26;
|
428
428
|
break;
|
429
429
|
}
|
430
|
-
|
431
|
-
|
430
|
+
_ref4 = params.paymentSessionConfig || {}, _ref4$productSceneVer = _ref4.productSceneVersion, productSceneVersion = _ref4$productSceneVer === void 0 ? '' : _ref4$productSceneVer, _ref4$productScene = _ref4.productScene, productScene = _ref4$productScene === void 0 ? '' : _ref4$productScene;
|
431
|
+
_ref5 = ((_this5$_renderParams6 = _this5._renderParams) === null || _this5$_renderParams6 === void 0 ? void 0 : _this5$_renderParams6.paymentSessionMetaData) || {}, _ref5$action = _ref5.action, _ref5$action2 = _ref5$action === void 0 ? {} : _ref5$action, _ref5$action2$autoDeb = _ref5$action2.autoDebitWithToken, autoDebitWithToken = _ref5$action2$autoDeb === void 0 ? false : _ref5$action2$autoDeb;
|
432
432
|
if (!((_this5$_renderParams7 = _this5._renderParams) !== null && _this5$_renderParams7 !== void 0 && (_this5$_renderParams7 = _this5$_renderParams7.paymentSessionMetaData) !== null && _this5$_renderParams7 !== void 0 && (_this5$_renderParams7 = _this5$_renderParams7.action) !== null && _this5$_renderParams7 !== void 0 && _this5$_renderParams7.skipSdkQuery && enableEasypayApiOptimize)) {
|
433
433
|
_context2.next = 21;
|
434
434
|
break;
|
@@ -542,7 +542,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
542
542
|
|
543
543
|
// eslint-disable-next-line no-async-promise-executor
|
544
544
|
this._actionSubmitPromise = new Promise( /*#__PURE__*/function () {
|
545
|
-
var
|
545
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
546
546
|
var _this6$_renderParams;
|
547
547
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
548
548
|
while (1) switch (_context3.prev = _context3.next) {
|
@@ -605,7 +605,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
605
605
|
}, _callee3);
|
606
606
|
}));
|
607
607
|
return function (_x3) {
|
608
|
-
return
|
608
|
+
return _ref6.apply(this, arguments);
|
609
609
|
};
|
610
610
|
}());
|
611
611
|
}
|
@@ -1196,9 +1196,9 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
1196
1196
|
}
|
1197
1197
|
}, {
|
1198
1198
|
key: "handleDeclareInfo",
|
1199
|
-
value: function handleDeclareInfo(
|
1200
|
-
var
|
1201
|
-
closeDialogData =
|
1199
|
+
value: function handleDeclareInfo(_ref7) {
|
1200
|
+
var _ref7$closeDialogData = _ref7.closeDialogData,
|
1201
|
+
closeDialogData = _ref7$closeDialogData === void 0 ? {} : _ref7$closeDialogData;
|
1202
1202
|
_handleDeclareInfo({
|
1203
1203
|
closeDialogData: closeDialogData
|
1204
1204
|
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { ApplePayActionEnum, PaymentActionEnum } from "../core/bus/interface";
|
2
|
+
import { paymentMethodCategoryTypeEnum, productSceneEnum, ProductSceneVersion } from "../types/index";
|
3
|
+
export var ExtendPlugin = [{
|
4
|
+
sessionMatcher: {
|
5
|
+
productScene: productSceneEnum.CASHIER_PAYMENT,
|
6
|
+
productSceneVersion: ProductSceneVersion.V1,
|
7
|
+
paymentMethodCategoryType: paymentMethodCategoryTypeEnum.CARD,
|
8
|
+
paymentMethodTypes: ["CARD_APPLE_PAY"]
|
9
|
+
},
|
10
|
+
paymentChannelMatcher: {
|
11
|
+
paymentMethod: 'ApplePay'
|
12
|
+
},
|
13
|
+
busActionNames: {
|
14
|
+
canMakePayments: ApplePayActionEnum.canMakePayments,
|
15
|
+
optional_init: PaymentActionEnum.optional_init,
|
16
|
+
createComponent: ApplePayActionEnum.createComponent,
|
17
|
+
destoryComponent: ApplePayActionEnum.destoryComponent
|
18
|
+
}
|
19
|
+
}];
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { BusSubscriber } from '../core/bus';
|
2
|
+
import { paymentMethodCategoryTypeEnum, productSceneEnum, ProductSceneVersion } from '../types';
|
3
|
+
export type IExtendPlugin = IExtendPluginItem[];
|
4
|
+
export interface ComponentActionNamesType {
|
5
|
+
canMakePayments?: string;
|
6
|
+
optional_init?: string;
|
7
|
+
createComponent?: string;
|
8
|
+
mountComponent?: string;
|
9
|
+
submit?: string;
|
10
|
+
destoryComponent?: string;
|
11
|
+
}
|
12
|
+
export type IExtendPluginItem = {
|
13
|
+
/**
|
14
|
+
* 以下为sessionData匹配的场景
|
15
|
+
*/
|
16
|
+
sessionMatcher?: {
|
17
|
+
productScene: productSceneEnum;
|
18
|
+
productSceneVersion: ProductSceneVersion;
|
19
|
+
paymentMethodCategoryType: paymentMethodCategoryTypeEnum;
|
20
|
+
paymentMethodTypes: string[];
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* 用于无sessionData场景,比如:canMakePayments
|
24
|
+
*/
|
25
|
+
paymentChannelMatcher?: {
|
26
|
+
paymentMethod: string;
|
27
|
+
};
|
28
|
+
/**
|
29
|
+
* 以下plugin 实现的定义
|
30
|
+
*/
|
31
|
+
busActionNames: ComponentActionNamesType;
|
32
|
+
busSubscriber?: BusSubscriber;
|
33
|
+
};
|
package/esm/request/index.d.ts
CHANGED