Constructor
new ApplePay(options)
You cannot use this constructor directly. Use braintree.applePay.create instead.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | Options |
- Source:
Methods
createPaymentRequest(paymentRequest) → {external:ApplePayPaymentRequest}
Merges a payment request with Braintree defaults to return an {external:ApplePayPaymentRequest}.
The following properties are assigned to paymentRequest
if not already defined. Their default values come from the Braintree gateway.
countryCode
currencyCode
merchantCapabilities
supportedNetworks
Parameters:
Name | Type | Description |
---|---|---|
paymentRequest |
external:ApplePayPaymentRequest | The payment request details to apply on top of those from Braintree. |
- Source:
Example
var applePay = require('braintree-web/apple-pay');
applePay.create({client: clientInstance}, function (applePayErr, applePayInstance) {
if (applePayErr) {
// Handle error here
return;
}
var paymentRequest = applePayInstance.createPaymentRequest({
total: {
label: 'My Company',
amount: '19.99'
}
});
var session = new ApplePaySession(1, paymentRequest);
// ...
performValidation(options, callback) → {void}
Validates your merchant website, as required by ApplePaySession
before payment can be authorized.
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | Options Properties
|
|||||||||
callback |
callback | The second argument, |
- Source:
Example
var applePay = require('braintree-web/apple-pay');
applePay.create({client: clientInstance}, function (applePayErr, applePayInstance) {
if (applePayErr) {
// Handle error here
return;
}
var paymentRequest = applePayInstance.createPaymentRequest({
total: {
label: 'My Company',
amount: '19.99'
}
});
var session = new ApplePaySession(1, paymentRequest);
session.onvalidatemerchant = function (event) {
applePayInstance.performValidation({
validationURL: event.validationURL,
displayName: 'My Great Store'
}, function (validationErr, validationData) {
if (validationErr) {
console.error(validationErr);
session.abort();
return;
}
session.completeMerchantValidation(validationData);
});
};
});
tokenize(options, callback) → {void}
Tokenizes an Apple Pay payment. This will likely be called in your ApplePaySession
's onpaymentauthorized
callback.
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
options |
object | Options Properties
|
||||||
callback |
callback | The second argument, |
- Source:
Example
var applePay = require('braintree-web/apple-pay');
applePay.create({client: clientInstance}, function (applePayErr, applePayInstance) {
if (applePayErr) {
// Handle error here
return;
}
var paymentRequest = applePayInstance.createPaymentRequest({
total: {
label: 'My Company',
amount: '19.99'
}
});
var session = new ApplePaySession(1, paymentRequest);
session.onpaymentauthorized = function (event) {
applePayInstance.tokenize({
token: event.payment.token
}, function (tokenizeErr, tokenizedPayload) {
if (tokenizeErr) {
session.completePayment(ApplePaySession.STATUS_FAILURE);
return;
}
session.completePayment(ApplePaySession.STATUS_SUCCESS);
// Send the tokenizedPayload to your server here!
});
};
// ...
});