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') {
// can be used to progress the payment via your server
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.
// See response.message
}
})
.catch(function (err) {
console.log(
'threeDSecureChallenge failed. err: ' + JSON.stringify(err)
)
})
}
)
}
)
Updated 3 months ago