-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbraintree.ios.js
215 lines (215 loc) · 11.9 KB
/
braintree.ios.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import { Observable } from "@nativescript/core";
const setupAppDeligate = require('./getappdelegate').setupAppDeligate;
export function setupBraintreeAppDeligate(urlScheme) {
setupAppDeligate(urlScheme);
}
export class Braintree extends Observable {
constructor() {
super();
this.output = {
'status': 'fail',
'msg': 'unknown',
'nonce': '',
'paymentMethodType': '',
'deviceInfo': ''
};
}
startPayment(token, options) {
let request = BTDropInRequest.alloc().init();
if (options.vaultManager) {
request.vaultManager = options.vaultManager;
}
if (options.amount) {
request.amount = options.amount;
}
if (options.collectDeviceData) {
request.collectDeviceData = true;
}
if (options.requestThreeDSecureVerification && options.amount) {
let threeDSecureRequest = BTThreeDSecureRequest.alloc().init();
threeDSecureRequest.amount = NSDecimalNumber.decimalNumberWithString(options.amount);
threeDSecureRequest.versionRequested = BTThreeDSecureVersion.Version2;
request.threeDSecureVerification = true;
request.threeDSecureRequest = threeDSecureRequest;
}
let dropIn = BTDropInController.alloc().initWithAuthorizationRequestHandler(token, request, (controller, result, error) => {
if (error !== null) {
setTimeout(() => {
this.notify({
eventName: 'error',
object: this
});
});
}
else if (result.cancelled) {
this.output.status = 'cancelled';
this.output.msg = 'User has cancelled payment';
setTimeout(() => {
this.notify({
eventName: 'cancel',
object: this
});
});
}
else {
if (typeof result.paymentMethod == null) {
this.output.status = 'error';
this.output.msg = 'Nonce Value empty';
setTimeout(() => {
this.notify({
eventName: 'error',
object: this
});
});
return;
}
if (result.paymentDescription === "Apple Pay") {
let request = PKPaymentRequest.alloc().init();
request.paymentSummaryItems = options.applePayPaymentRequest.paymentSummaryItems;
request.countryCode = options.applePayPaymentRequest.countryCode;
request.currencyCode = options.applePayPaymentRequest.currencyCode;
request.merchantIdentifier = options.applePayPaymentRequest.merchantIdentifier;
request.merchantCapabilities = options.applePayPaymentRequest.merchantCapabilities;
request.supportedNetworks = options.applePayPaymentRequest.supportedNetworks;
console.log(`canMakePayments(): ${PKPaymentAuthorizationViewController.canMakePayments()}`);
console.log(`canMakePaymentsUsingNetworks(): ${PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(request.supportedNetworks)}`);
console.log(`canMakePaymentsUsingNetworksCapabilities(): ${PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworksCapabilities(request.supportedNetworks, request.merchantCapabilities)}`);
let applePayController = PKPaymentAuthorizationViewController.alloc().initWithPaymentRequest(request);
let pkPaymentDelegateImpl = new PKPaymentAuthorizationViewControllerDelegateImpl();
let applePayClient = new BTApplePayClient(dropIn.apiClient);
pkPaymentDelegateImpl.applePayClient = applePayClient;
pkPaymentDelegateImpl.braintree = this;
try {
applePayController.delegate = pkPaymentDelegateImpl;
}
catch (error) {
console.log(`Initialization of PKPaymentAuthorizationViewController failed`);
let alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle("Error", "An error has occurred, please try again or use a different payment method.", 1);
alertController.addAction(UIAlertAction.actionWithTitleStyleHandler("Ok", 0, null));
controller.presentViewControllerAnimatedCompletion(alertController, true, null);
return;
}
console.log(`applePayController: ${applePayController}`);
console.log(`delegateImpl: ${pkPaymentDelegateImpl}`);
this.dropInController = controller;
controller.presentViewControllerAnimatedCompletion(applePayController, true, () => {
});
return;
}
else {
this.output.nonce = result.paymentMethod.nonce;
this.output.paymentMethodType = result.paymentMethod.type;
this.output.status = 'success';
this.output.msg = 'Got Payment Nonce Value';
this.output.deviceInfo = PPDataCollector.collectPayPalDeviceData();
setTimeout(() => {
this.notify({
eventName: 'success',
object: this
});
});
}
}
controller.dismissViewControllerAnimatedCompletion(true, null);
});
let app = UIApplication.sharedApplication;
app.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(dropIn, true, null);
}
submitApplePayment(applePayNonce) {
this.output.nonce = applePayNonce;
this.output.paymentMethodType = "18";
this.output.status = 'success';
this.output.msg = 'Got Payment Nonce Value';
this.output.deviceInfo = PPDataCollector.collectPayPalDeviceData();
this.dropInController.dismissViewControllerAnimatedCompletion(true, null);
setTimeout(() => {
this.notify({
eventName: 'success',
object: this
});
});
}
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PKPaymentAuthorizationViewControllerDelegateImpl = void 0;
var PKPaymentAuthorizationViewControllerDelegateImpl = /** @class */ (function (_super) {
__extends(PKPaymentAuthorizationViewControllerDelegateImpl, _super);
function PKPaymentAuthorizationViewControllerDelegateImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidAuthorizePaymentCompletion = function (controller, payment, completion) {
var _this = this;
console.log("PaymentAuthorizationViewController Did Authorize Payment Completion executing");
this.applePayClient.tokenizeApplePayPaymentCompletion(payment, function (nonce, error) {
if (nonce) {
_this.nonce = nonce;
completion(PKPaymentAuthorizationStatus.Success);
}
else {
completion(PKPaymentAuthorizationStatus.Failure);
console.dir("#####################");
console.log("error: " + error);
console.dir("#####################");
}
});
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidAuthorizePaymentHandler = function (controller, payment, completion) {
var _this = this;
console.log("PaymentAuthorizationViewController Did Authorize Payment Handler executing");
var result = PKPaymentAuthorizationResult.alloc().init();
this.applePayClient.tokenizeApplePayPaymentCompletion(payment, function (nonce, error) {
if (nonce) {
_this.nonce = nonce;
result.status = PKPaymentAuthorizationStatus.Success;
completion(result);
}
else {
result.status = PKPaymentAuthorizationStatus.Failure;
completion(result);
console.dir("#####################");
console.log("error: " + error);
console.dir("#####################");
}
});
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidFinish = function (controller) {
console.log("paymentAuthorizationViewControllerDidFinish(" + controller + ")");
if (!this.nonce) {
controller.dismissViewControllerAnimatedCompletion(true, null);
}
else {
this.braintree.submitApplePayment(this.nonce.nonce);
this.braintree.dropInController.dismissViewControllerAnimatedCompletion(true, null);
}
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidSelectPaymentMethodCompletion = function (controller, paymentMethod, completion) {
console.log("paymentAuthorizationViewControllerDidSelectPaymentMethodCompletion Method not implemented 4.");
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidSelectPaymentMethodHandler = function (controller, paymentMethod, completion) {
var paymentMethodUpdate = PKPaymentRequestPaymentMethodUpdate.alloc().init();
completion(paymentMethodUpdate);
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidSelectShippingAddressCompletion = function (controller, address, completion) {
console.log("paymentAuthorizationViewControllerDidSelectShippingAddressCompletion Method not implemented 6.");
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidSelectShippingContactCompletion = function (controller, contact, completion) {
console.log("paymentAuthorizationViewControllerDidSelectShippingAddressCompletion Method not implemented 7.");
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidSelectShippingContactHandler = function (controller, contact, completion) {
console.log("paymentAuthorizationViewControllerDidSelectShippingContactHandler Method not implemented 8.");
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidSelectShippingMethodCompletion = function (controller, shippingMethod, completion) {
console.log("paymentAuthorizationViewControllerDidSelectShippingMethodCompletion Method not implemented 9.");
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerDidSelectShippingMethodHandler = function (controller, shippingMethod, completion) {
console.log("paymentAuthorizationViewControllerDidSelectShippingMethodHandler Method not implemented 10.");
};
PKPaymentAuthorizationViewControllerDelegateImpl.prototype.paymentAuthorizationViewControllerWillAuthorizePayment = function (controller) {
console.log("paymentAuthorizationViewControllerWillAuthorizePayment Method not implemented 11.");
};
PKPaymentAuthorizationViewControllerDelegateImpl.ObjCProtocols = [PKPaymentAuthorizationViewControllerDelegate];
return PKPaymentAuthorizationViewControllerDelegateImpl;
}(NSObject));
exports.PKPaymentAuthorizationViewControllerDelegateImpl = PKPaymentAuthorizationViewControllerDelegateImpl;
//# sourceMappingURL=braintree.ios.js.map