Constructor
new Transpayrent(url, config)
Creates a new instance of the Transpayrent SDK, which simplifies the strong consumer authentication (SCA) and payment authorization through the consumer's browser.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
String | The URL pointing to the Payment Gateway's OpenAPI service definitions. |
config |
BaseConfig | The base configuration for the API requests. |
- Version:
- 1.0.0
- Copyright:
- Transpayrent ApS 2021
- License:
- Common Transpayrent API license
- Source:
- See:
-
[SwaggerClient] https://github.com/swagger-api/swagger-js#swagger-client-
Example
Instantiate the Transpayrent SDK
<script src="https://storage.googleapis.com/static.[ENVIRONMENT].transpayrent.cloud/v1/swagger-client.js"></script>
<script src="https://storage.googleapis.com/static.[ENVIRONMENT].transpayrent.cloud/v1/transpayrent.js"></script>
<script>
var transpayrentConfig = {
merchantId: [UNIQUE MERCHANT ID ASSIGNED BY TRANSPAYRENT],
sessionId: [ID IN THE RESPONSE FROM "Create Payment Session"],
accessToken: '[x-transpayrent-access-token HTTP HEADER IN THE RESPONSE FROM "Create Payment Session"]'
};
var url = 'https://generator.[ENVIRONMENT].transpayrent.cloud/v1/'+ transpayrentConfig.merchantId +'/system/PAYMENT_GATEWAY/sdk/CLIENT';
var sdk = new Transpayrent(url, transpayrentConfig);
</script>
Methods
authenticate(transactionId, body, config) → {AuthenticationSuccessResult|AuthenticationFailureResult|Status}
Convenience method for authenticating the consumer of the specified payment transaction through the Transpayrent Payment Gateway using 3D secure or equivalent.
The method orchestrates each part (initialization, authentication and verification) of the strong consumer authentication process
by calling several methods internally in the SDK and automatically performs the following actions if required:
- Fingerprint the consumer's brower in an invisible iframe
- Display an authentication challenge to the consumer in an iframe
The look'n'feel of the authentication challenge may be fully customized using CSS simply by passing the appropriate iframe configuration as the 3rd argument to this method.
This is the 2nd method that should be called by the payment page.
Please note that:
- Calling createTransaction should be done prior to calling this method to create a new payment transaction and obtain a transaction id
- Calling this method is the recommended way to complete the strong consumer authentication (SCA) flow
- The method will register event listeners and listen for the following events:
- 3DS-authentication-complete
- 3DS-fingerprint-complete
- API calls made using this method falls under PCI DSS.
Parameters:
| Name | Type | Description |
|---|---|---|
transactionId |
Long | The unique id of the payment transaction for which strong consumer authentication using 3D secure or equivalent is required |
body |
AuthenticateConsumerRequest | A representation of the entered payment details required for strong authentication of a payment transaction using 3D Secure or equivalent.
Please note that the |
config |
IFrameConfig | The configuration for the iframe which will be constructed in case the consumer needs to be presented with an authentication challenge |
- Source:
- See:
Listens to Events:
- message:'3DS-fingerprint-complete'
- message:'3DS-authentication-complete'
Returns:
Example
Authenticate consumer with 3D Secure or equivalent using the Transpayrent SDK
var card = { payment_method_id: 108, // VISA
card_number: 4111111111111111, // Successful Authorization: Manual Challenge with browser fingerprint
expiry_month: 9,
expiry_year: 22,
cvv: 987,
card_holder_name: "John Doe",
save: true };
var address = { street : 'Arne Jacobsens Allé 7',
appartment : '5. sal',
city : 'Copenhagen S',
postal_code : '2300',
state : 'CO',
country: 208 }; // Denmark
var phone = { international_dialing_code: 45, // Denmark
phone_number: 12345678 };
var email = 'hello@transpayrent.dk';
var body = { card : card,
billing_address : address,
shipping_address : address,
contact : { mobile : phone,
work : phone,
home : phone,
email : email } };
var iframeConfig = { container : document.body,
css: 'challenge',
callback : function (event, iframe) {
switch (event) {
case 'authentication-challenge-initiated':
// DO SOMETHING BEFORE THE AUTHENTICATION CHALLENGE IS DISPLAYED
break;
case 'authentication-challenge-completed':
// DO SOMETHING AFTER THE AUTHENTICATION CHALLENGE IS COMPLETE
break;
}
} };
sdk.authenticate(transaction.id, body, iframeConfig);
.then(
authentication => {
// Consumer Authentication failed
if (authentication.status) {
// Consumer Authentication failure
if (authentication.status == 511) {
// HANDLE AUTHENTICATION FAILURE
return Promise.reject(null);
}
// API request failed - Display status message
else {
// HANDLE COMMUNICATION ERROR
return Promise.reject(null);
}
}
// Consumer Authentication succesfully completed
else {
// AUTHORIZE PAYMENT BY INVOKING METHOD: authorize
}
})
.catch(reason => {
// Low level error - Display error message
if (reason) {
console.error('Internal error: '+ reason);
}
});
authenticateConsumer(transactionId, body) → {AuthenticationSuccessResult|AuthenticationChallengeResult|AuthenticationFailureResult|Status}
Authenticates the consumer of the specified payment transaction through the Transpayrent Payment Gateway using 3D secure or equivalent
by invoking the Authenticate Consumer API.
Calling this method directly is not recommended, instead call method: Transpayrent#authenticate to orchestrate the complete flow for strong consumer authentication (SCA).
Please note that API calls made using this method falls under PCI DSS.
Parameters:
| Name | Type | Description |
|---|---|---|
transactionId |
Long | The unique id of the payment transaction for which strong consumer authentication using 3D secure or equivalent is required |
body |
AuthenticateConsumerRequest | A representation of the entered payment details and details of the consumer's browser attributes required for strong authentication of a payment transaction using 3D Secure or equivalent. |
- Source:
- See:
Returns:
- Type
- AuthenticationSuccessResult | AuthenticationChallengeResult | AuthenticationFailureResult | Status
authorize(transactionId, card) → {AuthorizePaymentResponse|Status}
Authorizes the payment for the specified payment transaction through the Transpayrent Payment Gateway using the provided payment details by
invoking the Authorize Payment For Transaction API.
This is the 3rd method that should be called by the payment page when authorizing a payment without storing the consumer's payment card.
Please note that:
- Calling authenticate should be done prior to calling this method to authenticate the consumer and obtain a cryptogram
- Call save prior to calling this method to securely store the consumer's payment card in Transpayren's Secure Vault and add the stored payment card to the consumer's wallet
- API calls made using this method falls under PCI DSS.
Parameters:
| Name | Type | Description |
|---|---|---|
transactionId |
Long | The unique id of the payment transaction for which the payment should be authorized |
card |
PaymentCard | A representation of a payment made using a payment card such as a MasterCard credit card or a VISA debit card |
- Source:
- See:
Returns:
- Type
- AuthorizePaymentResponse | Status
Examples
Authorize payment with payment card details using the Transpayrent SDK
var card = { payment_method_id: 108, // VISA
card_number: 4111111111111111, // Successful Authorization: Manual Challenge with browser fingerprint
expiry_month: 9,
expiry_year: 22,
cvv: 987,
card_holder_name: "John Doe",
save: true,
cryptogram : [CRYPTOGRAM RETURNED BY STRONG CONSUMER AUTHENTICATION] };
sdk.authorize(authentication.transaction_id, card)
.then(
authorization => {
// Payment Authorization failed - Display status message
if (authorization.status) {
// HANDLE AUTHORIZATION FAILURE
}
// Payment Authorization completed - Display success message
else {
// HANDLE AUTHORIZATION SUCCESS
}
})
.catch(reason => {
// Low level error - Display error message
if (reason) {
console.error('Internal error: '+ reason);
}
});
Authorize payment with stored payment card using the Transpayrent SDK
var request = { payment_method_id: 201, // Consumer Wallet
valuable_id: [VALUABLE ID RETURNED BY SDK METHOD: save] };
sdk.authorize(save.transaction_id, request)
.then(
authorization => {
// Payment Authorization failed - Display status message
if (authorization.status) {
// HANDLE AUTHORIZATION FAILURE
}
// Payment Authorization completed - Display success message
else {
// HANDLE AUTHORIZATION SUCCESS
}
})
.catch(reason => {
// Low level error - Display error message
if (reason) {
console.error('Internal error: '+ reason);
}
});
createTransaction(paymentMethodId, body) → {CreatePaymentTransactionResponse|Status}
Creates a new payment transaction through the Transpayrent Payment Gateway
by invoking the Create Payment Transaction API.
This is the 1st method that should be called by the payment page.
Parameters:
| Name | Type | Description |
|---|---|---|
paymentMethodId |
PAYMENT_METHOD_ID | The unique id of the payment method which will be used to authorize the payment for the payment transaction. |
body |
CreatePaymentTransactionRequest | A representation of the consumer's payment transaction. |
- Source:
Returns:
Example
Create a new payment transaction using the Transpayrent SDK
var paymentMethodId = 108; // VISA
var body = { correlation_id : 'TP-103645',
amount: { currency : 208, // DKK
value : 100 } };
sdk.createTransaction(paymentMethodId, body)
.then(
transaction => {
// Creation of Payment Transaction failed - Display status message
if (transaction.status) {
// HANDLE FAILURE
return Promise.reject(null);
}
else {
// AUTHENTICATE CONSUMER BY INVOKING METHOD: authenticate
}
})
.catch(reason => {
// Low level error - Display error message
if (reason) {
console.error('Internal error: '+ reason);
}
});
displayChallenge(url, data, config) → {HTMLIFrameElement}
Constructs the iframe element for displaying the authentication challenges and attaches it inside the provided container element.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
String | The URL to the Access Control Server (ACS) will use for the challenge during the strong consumer authentication (SCA) process. |
data |
String | The base64 encoded request data that must be sent to the Access Control Server (ACS).
The data will be sent to the ACS in the |
config |
IFrameConfig | The configuration for the constructed iframe element |
- Source:
Returns:
The constructed iframe element
- Type
- HTMLIFrameElement
fingerprint(url, data) → {HTMLIFrameElement}
Constructs an iframe which sends an HTTP POST request to enable the Access Control Server (ACS) to fingerprint the consumer's browser.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
String | The URL to the Access Control Server (ACS), which will create a fingerprint of the consumer's browser as part of the 3D Secure process for strong consumer authentication. |
data |
String | The base64 encoded request data that must be sent to the Access Control Server (ACS).
The data will be sent to the ACS in the |
- Source:
Returns:
The constructed iframe element
- Type
- HTMLIFrameElement
getAuthenticationResult(transactionId) → {AuthenticationSuccessResult|AuthenticationFailureResult|Status}
Retrieves the strong consumer authentication (SCA) result for the specified payment transaction through the Transpayrent Payment Gateway using 3D secure or equivalent.
The method will invoke the Get Authentication Result For Transaction API.
Please note that calling this method directly is not recommended, instead call method: Transpayrent#authenticate to orchestrate the complete flow for strong consumer authentication (SCA).
Parameters:
| Name | Type | Description |
|---|---|---|
transactionId |
Long | The unique id of the payment transaction for which the strong consumer authentication using 3D secure or equivalent is required should be verified |
- Source:
- See:
Returns:
initializeAuthentication(transactionId, body) → {InitializeAuthenticationResponse|Status}
Initializes strong consumer authentication for the specified payment transaction through the Transpayrent Payment Gateway using 3D secure or equivalent
by invoking the Initialize Authentication For Transaction API.
Calling this method directly is not recommended, instead call method: Transpayrent#authenticate to orchestrate the complete flow for strong consumer authentication (SCA).
Please note that API calls made using this method falls under PCI DSS.
Parameters:
| Name | Type | Description |
|---|---|---|
transactionId |
Long | The unique id of the payment transaction for which strong consumer authentication using 3D secure or equivalent is required |
body |
InitializeAuthenticationRequest | A representation of the payment details provided by the consumer for strong authentication of a payment transaction using 3D Secure or equivalent. |
- Source:
- See:
Returns:
save(transactionId, body) → {SaveConsumerValuableResponse|Status}
Securely stores the provided payment instrument for the specified payment transaction into Transpayrent's Secure Vault
by invoking the Save Consumer Valuable For Transaction API.
The saved payment instrument is automatically added to the consumer's wallet if a consumerId is provided in the request or was specified for the Payment Session.
This is the 3rd method that should be called by the payment page when storing the consumer's payment card.
Please note that:
- Calling authenticate should be done prior to calling this method to authenticate the consumer and obtain a cryptogram
- Merchants can only save a payment instrument for a payment transaction that is part of a payment session owned by the merchant
- API calls made using this method falls under PCI DSS.
Parameters:
| Name | Type | Description |
|---|---|---|
transactionId |
Long | The unique id of the payment transaction for which the payment card was authenicated |
body |
SaveConsumerValuableRequest | The payment details for the payment card which will be securely stored in Transpayrent's Secure Valut and added to the consumer's wallet |
- Source:
- See:
Returns:
Example
Save payment instrument using the Transpayrent SDK
var card = { payment_method_id: 108, // VISA
card_number: 4111111111111111, // Successful Authorization: Manual Challenge with browser fingerprint
expiry_month: 9,
expiry_year: 22,
cvv: 987,
card_holder_name: "John Doe",
cryptogram : [CRYPTOGRAM RETURNED BY STRONG CONSUMER AUTHENTICATION] };
var body = { card : card,
consumer_id : "CID-12345", // Defaults to the Consumer ID from the Payment Session if omitted
name : "My VISA Card" }
sdk.save(authentication.transaction_id, body)
.then(
save => {
// Saving payment instrument failed - Display status message
if (save.status) {
// HANDLE SAVE FAILURE
}
// Payment instrument successfully saved
else {
// AUTHORIZE PAYMENT BY INVOKING METHOD: authorize
}
})
.catch(reason => {
// Low level error - Display error message
if (reason) {
console.error('Internal error: '+ reason);
}
});