(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/RetrievePaymentsHandler'), 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/RetrievePaymentsHandler
* @class
*/
var exports = function() {
};
exports.prototype.process = function (payments, callback) {
var secret = payments.invocation_context.secret;
var host = payments.api_end_point;
var api_key = payments.invocation_context.api_key;
var auth_scheme = payments.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 = payments.invocation_context['channel'];
var client_key = payments.invocation_context['client_key'];
var product = payments.invocation_context['product'];
var timestamp;
if (payments.invocation_context['timestamp'])
{
timestamp = payments.invocation_context['timestamp'];
}
else
{
timestamp = CommonUtil.getTimeStamp();
}
var idempotent_request_key = payments.invocation_context['idempotent_request_key'];
var requestor_type = payments.invocation_context['requestor_type'];
var opts = _this.getOptions(payments);
var result = api_instance.retrievePayments(channel, client_key, product, timestamp, idempotent_request_key, requestor_type, 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 (payments) {
return {
'requestor': payments['invocation_context']['requestor'],
'x_opay_headers': payments['invocation_context']['X-OPAY-Headers'],
'id_customer': payments['id_customer'],
'id_funding_account': payments['id_funding_account'],
'id_customer_account': payments['id_customer_account'],
'confirmation_number': payments['confirmation_number'],
'status': payments['status'],
'payment_schedule_type': payments['payment_schedule_type'],
'from_date': payments['from_date'],
'to_date': payments['to_date'],
'page_size': payments['page_size'],
'query_id': payments['query_id'],
'from_index': payments['from_index'],
'to_index': payments['to_index']
};
};
return exports;
}));