Here, createRefundTransaction() creates a POST request to /transactions/type/adjustment
Provided with a valid object representation, this endpoint allows for a new transaction to be created for a given transaction type 'adjustment' passed via the URL.
/**
* Set up your function to be invoked
*/
const createRefundTransaction = async (mandateReference, callback = false, debug = false) => {
try {
/**
* Construct a request object and set desired parameters
*/
const request = new mmapi.recurringPayment.createRefundTransaction();
/**
* Set the request body parameters individually or by request.body(body);
*/
request.creditParty([{ "key": "mandateReference", "value": `${mandateReference}` }]);
request.debitParty([{ "key": "msisdn", "value": "+44012345678" }]);
request.amount("200.00");
request.currency("USD");
/**
* Chose the callback method. Default is the polling method. You can also chose it by request.polling();
*/
if (callback) {
request.callback(callbackUrl);
}
if (debug) {
console.log("Request: ", JSON.stringify(request, null, 4));
}
/**
* Call API with your client and get a response for your call
*/
const response = await client.execute(request);
if (debug) {
console.log("Response Status: ", response.status);
console.log("Response Data: ", JSON.stringify(response.data, null, 4));
}
/**
* Return a successful response
*/
return response;
} catch (err) {
/**
* Handle any errors from the call
*/
if (debug) {
console.log(err);
}
/**
* Return an error response
*/
return err;
}
};
/**
* Invoke the function
*/
createRefundTransaction('<<REPLACE-WITH-MANDATE-REFERENCE>>', false, true);202
{
"serverCorrelationId": "233b226e-a2da-48f7-8510-9c79a352906b",
"status": "pending",
"notificationMethod": "callback",
"objectReference": "8182",
"pollLimit": 100
}202
{
"serverCorrelationId": "a0913b62-a7e1-4641-98fa-f93750413600",
"status": "pending",
"notificationMethod": "polling",
"objectReference": "14208",
"pollLimit": 100
}NOTE
In asynchronous flows, a callback mechanism or polling mechanism is utilised to allow the client to determine the request's final state. Use the viewRequestState() function for the polling mechanism to receive the status of a request, and the viewTransaction() function to acquire the final representation of the Transaction object.