-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapple-pay-js-stubs.js
128 lines (99 loc) · 3.24 KB
/
apple-pay-js-stubs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Based on solution by naomik here http://stackoverflow.com/a/24216547
class Emitter {
constructor() {
var delegate = document.createDocumentFragment();
[
'addEventListener',
'dispatchEvent',
'removeEventListener'
].forEach(f =>
this[f] = (...xs) => delegate[f](...xs)
)
}
}
class ApplePaySessionStub extends Emitter {
constructor(version, paymentRequest) {
super();
this.version = version;
this._request = paymentRequest;
}
// Static Stub configuration
static get stubCanMakePayments() {
return this._stubCanMakePayments;
}
static set stubCanMakePayments(value) {
this._stubCanMakePayments = value;
}
static get stubCanMakePaymentsWithActiveCard() {
return this._stubCanMakePaymentsWithActiveCard;
}
static set stubCanMakePaymentsWithActiveCard(value) {
this._stubCanMakePaymentsWithActiveCard = value;
}
static set stubExecuteAfterMerchantValidation(callback) {
this._stubExecuteAfterMerchantValidation = callback;
}
static get stubExecuteAfterMerchantValidation() {
return this._stubExecuteAfterMerchantValidation;
}
// Static Apple Pay JS interface
static canMakePayments() {
return this._stubCanMakePayments;
}
static canMakePaymentsWithActiveCard(merchantIdentifier) {
return Promise.resolve(this.stubCanMakePaymentsWithActiveCard);
}
static supportsVersion(version) {
return true;
}
// Instance Apple Pay JS interface
abort() {}
begin() {
let url = 'https://apple-pay-gateway-cert.apple.com/paymentservices/startSession';
if (this._onvalidatemerchant) {
this._onvalidatemerchant(
{validationURL: url}
);
}
var event = new ApplePayValidateMerchantEvent(url);
this.dispatchEvent(event);
}
completeMerchantValidation(merchantSession) {
if (!ApplePaySession.stubExecuteAfterMerchantValidation) {
throw "Error: No stubExecuteAfterMerchantValidation() callback set";
}
ApplePaySession.stubExecuteAfterMerchantValidation(this);
}
completePayment(status) { }
completePaymentMethodSelection(newTotal, newLineItems) { }
completeShippingContactSelection(status, newShippingMethods, newTotal, newLineItems) { }
completeShippingMethodSelection(status, newTotal, newLineItems) { }
set onvalidatemerchant(value) {
this._onvalidatemerchant = value;
}
// Stub helper methods
get request() {
return this._request;
}
}
window.ApplePaySession = ApplePaySessionStub;
class ApplePayPaymentAuthorizedEvent extends Event {
constructor(payment) {
super("paymentauthorized");
this._payment = payment;
}
get payment() {
return this._payment;
}
}
window.ApplePayPaymentAuthorizedEvent = ApplePayPaymentAuthorizedEvent;
class ApplePayValidateMerchantEvent extends Event {
constructor(validationURL) {
super("validatemerchant");
this._validationURL = validationURL;
}
get validationURL() {
return this._validationURL;
}
}
window.ApplePayValidateMerchantEvent = ApplePayValidateMerchantEvent;