(function(root, factory) {
if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('logtown').getLogger('/src/handlers/DeletePaymentHandler'), require('../ApiClient'), require('../api/PaymentApi'), require('../OrbipayApiError'), require('../CommonUtil'));
}
}(this, function(logger, ApiClient, PaymentApi, OrbipayApiError, CommonUtil) {
'use strict';
/**
* @module ApiClient
*/
/**
* <h3 style="color:red"> This class subject to change without prior notice, Please dont use this class directly. </h3>
* @module handlers/DeletePaymentHandler
* @class
*/
var exports = function() {
};
exports.prototype.process = function (payment, callback) {
var secret = payment.invocation_context.secret;
var host = payment.api_end_point;
var api_key = payment.invocation_context.api_key;
var auth_scheme = payment.invocation_context.auth_scheme;
var _this=this;
var response = {};
var exception;
try {
var api_client = new ApiClient(secret, host,api_key,auth_scheme);
var api_instance = new PaymentApi(api_client);
var channel = payment.invocation_context['channel'];
var client_key = payment.invocation_context['client_key'];
var product = payment.invocation_context['product'];
var timestamp;
if (payment.invocation_context['timestamp'])
{
timestamp = payment.invocation_context['timestamp'];
}
else
{
timestamp = CommonUtil.getTimeStamp();
}
var idempotent_request_key = payment.invocation_context['idempotent_request_key'];
var requestor_type = payment.invocation_context['requestor_type'];
var id_payment = payment['ID_PAYMENT'];
var id_customer = payment['ID_CUSTOMER'];
var delete_payment_request = _this.populate_body(payment);
var opts = _this.getOptions(payment);
var result = api_instance.deletePayment(channel, client_key, product, timestamp, idempotent_request_key, requestor_type, id_payment, id_customer, delete_payment_request, opts, callback);
response['request'] = result;
return response;
} catch (e) {
exception = OrbipayApiError.getDefaultException(e);
if (callback) {
callback(null, null, null, exception);
}
response['exception'] = exception;
return response;
}
};
exports.prototype.getOptions = function (payment) {
return {
'requestor': payment['invocation_context']['requestor'],
'x_opay_headers': payment['invocation_context']['X-OPAY-Headers']
};
};
exports.prototype.populate_body = function(payment){
var DeletePaymentRequest = require('../models/DeletePaymentRequest');
return DeletePaymentRequest.constructFromObject(payment);
};
return exports;
}));