Post Response Module
This module automates the handling of Post-Response Actions. The action
part of the server-side response should be extracted and converted into a Javascript object, and passed to the handleAction
function in this module, which will take care of everything else.
Add the Post Response Module to your App
After you have set up the Comcarde JavaScript Client, you can add the post-response-action
module to your website source.
<script src="https://sandbox-assets.comcarde.com/web/v2/js/post-response-action.min.js"></script>
<script src="https://assets.comcarde.com/web/v2/js/post-response-action.min.js"></script>
Finally, add the module to your Comcarde JavaScript Client:
comcarde.client.create(
{
authorization: client - api - key, // your client API Key
},
function (clientErr, clientInstance) {
// optionally configure other plugin modules...
/*
* Create a Post-Response Action Plugin Module Component.
*/
comcarde.postResponseAction.create(
{
client: clientInstance,
},
function (err, postResponseActionInstance) {
if (err) {
console.log(err)
return
}
// create an object representing the 'action' part of the JSON response received
// on your server
var action = JSON.parse(actionJsonFromServerResponse)
postResponseActionInstance
.handleAction(action)
.then(function (response) {
// optionally include your own code here to execute when everything's
//complete
})
.catch(function (err) {
console.log('handleAction failed. err: ' + JSON.stringify(err))
})
}
)
}
)
Optionally, you can also pass in callback functions that are invoked at certain points in the execution of the post-respose action. Please note that not all kinds of post-response action are guaranteed to allow execution of callback
functions during the execution, and the exact callback functions supported will depend on the type of post-response action.
Please get in contact with support for further details on which callback functions are supported for post-response actions configured for your account. However, an example of how these might be defined is given below:
comcarde.client.create(
{
authorization: clientApiKey, // your client API Key
},
function (clientErr, clientInstance) {
/*
* Create a Post-Response Action Plugin Module Component.
*/
comcarde.postResponseAction.create(
{
client: clientInstance,
},
function (err, postResponseActionInstance) {
if (err) {
console.log(err)
return
}
var action = // the 'action' part of the response received on your server
function myWindowClosedFunction() {
console.log('Window was closed')
}
function myActionCompletedFunction() {
console.log('Action was completed')
}
var callbacks = {
windowClosed: myWindowClosedFunction,
actionCompleted: myActionCompletedFunction,
}
postResponseActionInstance
.handleAction(action, callbacks)
.then(function (response) {
// optionally include your own code here to execute when everything's
// complete
})
.catch(function (err) {
console.log('handleAction failed. err: ' + JSON.stringify(err))
})
}
)
}
)
3-D Secure Payment Flows
The Post-Response Action module should be used to automate the handling of 3-D Secure additional actions, as part of the 3-D Secure Payment Flow.
comcarde.client.create(
{
authorization: clientApiKey, // your client API Key
},
function (clientErr, clientInstance) {
// optionally configure other plugin modules...
/*
* Create a Post-Response Action Plugin Module Component.
*/
comcarde.postResponseAction.create(
{
client: clientInstance,
},
function (err, postResponseActionInstance) {
if (err) {
console.log(err)
return
}
// create an object representing the 'action' part of the JSON response
// received on your server
var action = JSON.parse(actionJsonFromServerResponse)
postResponseActionInstance
.handleAction(action)
.then(function (response) {
var message = response.message // text explanation of the outcome
var paymentId = response.paymentId // unique id of the payment
if (response.code === '2002') {
// 3DS additional payment with nonce required.
// https://docs.br-dge.io/docs/response-codes#2002
// can be used to progress the payment via your server as
// part of the BR-DGE 3-D Secure Payment Flow
var nonce = response.nonce
// Optional additional information to help you make an informed decision
// whether to proceed with the payment
if (response.threeDSecureInfo) {
// status description returned by the PSP
var pspStatus = response.threeDSecureInfo.pspStatus
// e.g. "2"
var threeDSecureVersion =
response.threeDSecureInfo.threeDSecureVersion
if (response.threeDSecureInfo.liabilityShifted) {
/*
* 3-D Secure worked and authentication succeeded.
*
* This will also be true if the issuing bank does not support 3-D
* Secure, but the payment method does. In both cases, the liability
* for fraud has been shifted to the bank. You can now finalize the
* payment using response.nonce on your server.
*/
} else {
/*
* 3-D Secure authentication failed. It is still possible to finalize
* the payment using the payment.nonce via your server, but you will
* need to set 3-D secure required flag to false.
*/
if (response.threeDSecureInfo.liabilityShiftPossible) {
// the payment instrument was eligible for 3-D Secure
} else {
// the payment instrument was not eligible for 3-D secure.
}
}
}
} else if (response.code === '2004') {
/*
* an error occurred when attempting 3-D Secure authentication.
* https://docs.br-dge.io/docs/response-codes#2004
*/
}
})
.catch(function (err) {
/*
* err will usually contain 3-D Secure action error code to explain
* what went wrong If you need to raise a support request please
* include this information to help us assist you.
*/
console.log(
'Exception thrown while processing 3-D Secure Payment Flow Action: '
+ JSON.stringify(err)
)
})
}
)
}
)
3-D Secure action error codes
THREE_D_SECURE_ERROR
THREE_D_SECURE_ERROR
A problem occurred during the 3D Secure verification process.
THREE_D_SECURE_METHOD_FAILURE
THREE_D_SECURE_METHOD_FAILURE
Did not receive nonce during the 3D Secure verification process.
THREE_D_SECURE_ACTION_REQUIRED
THREE_D_SECURE_ACTION_REQUIRED
A problem occurred during the 3D Secure verification process.
THREE_D_SECURE_ACTION_INVALID
THREE_D_SECURE_ACTION_INVALID
A problem occurred during the 3D Secure verification process.
THREE_D_SECURE_UNSUPPORTED_PSP
THREE_D_SECURE_UNSUPPORTED_PSP
The 3D Secure Action PSP is not supported by this version of the SDK.
THREE_D_SECURE_ERROR_INVALID_ACTION_TYPE
THREE_D_SECURE_ERROR_INVALID_ACTION_TYPE
Invalid action type was provided.
THREE_D_SECURE_ERROR_MISSING_PROPERTY_ACS_URL
THREE_D_SECURE_ERROR_MISSING_PROPERTY_ACS_URL
Required acsUrl property is missing.
THREE_D_SECURE_ERROR_MISSING_PROPERTY_TOKEN
THREE_D_SECURE_ERROR_MISSING_PROPERTY_TOKEN
Required token property is missing.
THREE_D_SECURE_ERROR_MISSING_PROPERTY_JWT
THREE_D_SECURE_ERROR_MISSING_PROPERTY_JWT
Required jwt property is missing.
THREE_D_SECURE_ERROR_INVALID_ORIGIN
THREE_D_SECURE_ERROR_INVALID_ORIGIN
This origin is not allowed.
THREE_D_SECURE_ERROR_NO_RESPONSE
THREE_D_SECURE_ERROR_NO_RESPONSE
Server did not respond in time. It can also indicate BAD_REQUEST from ACS.
BARCLAYCARD_THREE_D_SECURE_HTML_ERROR
BARCLAYCARD_THREE_D_SECURE_HTML_ERROR
The Barclaycard htmlAnswer was invalid.
STRIPE_THREE_D_SECURE_ERROR_FAILED_TO_LOAD_SDK
STRIPE_THREE_D_SECURE_ERROR_FAILED_TO_LOAD_SDK
Failed to load Stripe SDK.
TRUST_THREE_D_SECURE_ERROR_FAILED_TO_LOAD_SDK
TRUST_THREE_D_SECURE_ERROR_FAILED_TO_LOAD_SDK
Failed to load Trust Payments SDK.
NUVEI_THREE_D_SECURE_METHOD_PAYLOAD
NUVEI_THREE_D_SECURE_METHOD_PAYLOAD
methodPayload
object missing from threeDSecureAction
.
NUVEI_THREE_D_SECURE_C_REQ
NUVEI_THREE_D_SECURE_C_REQ
cReq
object missing from threeDSecureAction
.
ADYEN_THREE_D_SECURE_MISSING_POST_URL
ADYEN_THREE_D_SECURE_MISSING_POST_URL
URL
missing from payment response.
ADYEN_THREE_D_SECURE_MISSING_PA_REQ
ADYEN_THREE_D_SECURE_MISSING_PA_REQ
PaReq
object missing from threeDSecureAction.
ADYEN_THREE_D_SECURE_MISSING_MD
ADYEN_THREE_D_SECURE_MISSING_MD
MD
object missing from threeDSecureAction.
Updated 4 days ago