Constructor
new UnionPay(options)
You cannot use this constructor directly. Use braintree-web.unionpay.create instead.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | See unionpay.create. |
- Source:
Methods
enroll(options, callbackopt) → {void}
Enrolls a UnionPay card. Use fetchCapabilities to determine if the SMS enrollment process is required.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | UnionPay enrollment options: Properties
|
||||||||||||||||||||||||||||||||||||||||||||||
callback |
callback |
<optional> |
The second argument, |
- Source:
Examples
unionpayInstance.enroll({
card: {
number: '4111111111111111',
expirationMonth: '12',
expirationYear: '2038'
},
mobile: {
countryCode: '62',
number: '111111111111'
}
}, function (enrollErr, response) {
if (enrollErr) {
console.error(enrollErr);
return;
}
if (response.smsCodeRequired) {
// If smsCodeRequired, wait for SMS auth code from customer
// Then use response.enrollmentId during UnionPay#tokenize
} else {
// SMS code is not required from the user.
// UnionPay#tokenize can be called immediately
});
unionpayInstance.enroll({
hostedFields: hostedFields,
mobile: {
countryCode: '62',
number: '111111111111'
}
}, function (enrollErr, response) {
if (enrollErr) {
console.error(enrollErr);
return;
}
if (response.smsCodeRequired) {
// If smsCodeRequired, wait for SMS auth code from customer
// Then use response.enrollmentId during UnionPay#tokenize
} else {
// SMS code is not required from the user.
// UnionPay#tokenize can be called immediately
}
});
fetchCapabilities(options, callbackopt) → {Promise|void}
Fetches the capabilities of a card, including whether or not the SMS enrollment process is required.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | UnionPay fetchCapabilities options Properties
|
|||||||||||||||||||
callback |
callback |
<optional> |
The second argument, |
- Source:
Examples
unionpayInstance.fetchCapabilities({
card: {
number: '4111111111111111'
}
}, function (fetchErr, cardCapabilities) {
if (fetchErr) {
console.error(fetchErr);
return;
}
if (cardCapabilities.isUnionPay) {
if (cardCapabilities.unionPay && !cardCapabilities.unionPay.isSupported) {
// Braintree cannot process this UnionPay card.
// Ask the user for a different card.
return;
}
if (cardCapabilities.isDebit) {
// CVV and expiration date are not required
} else {
// CVV and expiration date are required
}
// Show mobile phone number field for enrollment
}
});
// Fetch capabilities on `validityChange` inside of the Hosted Fields `create` callback
hostedFieldsInstance.on('validityChange', function (event) {
// Only attempt to fetch capabilities when a valid card number has been entered
if (event.emittedBy === 'number' && event.fields.number.isValid) {
unionpayInstance.fetchCapabilities({
hostedFields: hostedFieldsInstance
}, function (fetchErr, cardCapabilities) {
if (fetchErr) {
console.error(fetchErr);
return;
}
if (cardCapabilities.isUnionPay) {
if (cardCapabilities.unionPay && !cardCapabilities.unionPay.isSupported) {
// Braintree cannot process this UnionPay card.
// Ask the user for a different card.
return;
}
if (cardCapabilities.isDebit) {
// CVV and expiration date are not required
// Hide the containers with your `cvv` and `expirationDate` fields
} else {
// CVV and expiration date are required
}
} else {
// Not a UnionPay card
// When form is complete, tokenize using your Hosted Fields instance
}
// Show your own mobile country code and phone number inputs for enrollment
});
});
});
teardown(callbackopt) → {Promise|void}
Cleanly remove anything set up by create. This only needs to be called when using UnionPay with Hosted Fields.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
callback |
<optional> |
Called on completion. If no callback is provided, returns a promise. |
- Source:
Example
unionpayInstance.teardown();
tokenize(options, callbackopt) → {Promise|void}
Tokenizes a UnionPay card and returns a nonce payload.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | UnionPay tokenization options: Properties
|
|||||||||||||||||||||||||||||||||||||||||||||
callback |
callback |
<optional> |
The second argument, |
- Source:
Examples
unionpayInstance.tokenize({
card: {
number: '4111111111111111',
expirationMonth: '12',
expirationYear: '2038',
cvv: '123'
},
enrollmentId: enrollResponse.enrollmentId, // Returned from enroll
smsCode: '11111' // Received by customer's phone, if SMS enrollment was required. Otherwise it should be omitted
}, function (tokenizeErr, response) {
if (tokenizeErr) {
console.error(tokenizeErr);
return;
}
// Send response.nonce to your server
});
unionpayInstance.tokenize({
hostedFields: hostedFieldsInstance,
enrollmentId: enrollResponse.enrollmentId, // Returned from enroll
smsCode: '11111' // Received by customer's phone, if SMS enrollment was required. Otherwise it should be omitted
}, function (tokenizeErr, response) {
if (tokenizeErr) {
console.error(tokenizeErr);
return;
}
// Send response.nonce to your server
});
Type Definitions
enrollPayload :object
Properties:
Name | Type | Description |
---|---|---|
enrollmentId |
string | UnionPay enrollment ID. This value should be passed to |
smsCodeRequired |
boolean | UnionPay |
- Source:
fetchCapabilitiesPayload :object
Properties:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
isUnionPay |
boolean | Determines if this card is a UnionPay card. |
|||||||||
isDebit |
boolean | Determines if this card is a debit card. This property is only present if |
|||||||||
unionPay |
object | UnionPay specific properties. This property is only present if Properties
|
- Source:
tokenizePayload :object
Properties:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
nonce |
string | The payment method nonce. |
|||||||||
type |
string | Always |
|||||||||
details |
object | Additional account details: Properties
|
|||||||||
description |
string | A human-readable description. |
- Source: