(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/SimplePaymentHandler'), 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/SimplePaymentHandler
* @class
*/
var exports = function() {
};
exports.prototype.process = function (simplePayment, callback) {
var secret = simplePayment.invocation_context.secret;
var host = simplePayment.api_end_point;
var api_key = simplePayment.invocation_context.api_key;
var auth_scheme = simplePayment.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 = simplePayment.invocation_context['channel'];
var client_key = simplePayment.invocation_context['client_key'];
var product = simplePayment.invocation_context['product'];
var timestamp;
if (simplePayment.invocation_context['timestamp'])
{
timestamp = simplePayment.invocation_context['timestamp'];
}
else
{
timestamp = CommonUtil.getTimeStamp();
}
var idempotent_request_key = simplePayment.invocation_context['idempotent_request_key'];
var requestor_type = simplePayment.invocation_context['requestor_type'];
var simple_payment_request = _this.populate_body(simplePayment);
var opts = _this.getOptions(simplePayment);
var result = api_instance.simplePayment(channel, client_key, product, timestamp, idempotent_request_key, requestor_type, simple_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 (simplePayment) {
return {
'requestor': simplePayment['invocation_context']['requestor'],
'x_opay_headers': simplePayment['invocation_context']['X-OPAY-Headers'],
'save_funding_account': simplePayment['save_funding_account']
};
};
exports.prototype.populate_body = function(simplePayment){
var SimplePaymentRequest = require('../models/SimplePaymentRequest');
return SimplePaymentRequest.constructFromObject(simplePayment);
};
return exports;
}));