(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/CreatePaymentAuthorizationHandler'), require('../ApiClient'), require('../api/PaymentAuthorizationApi'), require('../OrbipayApiError'), require('../CommonUtil'));
}
}(this, function(logger, ApiClient, PaymentAuthorizationApi, 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/CreatePaymentAuthorizationHandler
* @class
*/
var exports = function() {
};
exports.prototype.process = function (paymentAuthorization, callback) {
var secret = paymentAuthorization.invocation_context.secret;
var host = paymentAuthorization.api_end_point;
var api_key = paymentAuthorization.invocation_context.api_key;
var auth_scheme = paymentAuthorization.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 PaymentAuthorizationApi(api_client);
var channel = paymentAuthorization.invocation_context['channel'];
var client_key = paymentAuthorization.invocation_context['client_key'];
var product = paymentAuthorization.invocation_context['product'];
var timestamp;
if (paymentAuthorization.invocation_context['timestamp'])
{
timestamp = paymentAuthorization.invocation_context['timestamp'];
}
else
{
timestamp = CommonUtil.getTimeStamp();
}
var idempotent_request_key = paymentAuthorization.invocation_context['idempotent_request_key'];
var requestor_type = paymentAuthorization.invocation_context['requestor_type'];
var create_payment_authorization_request = _this.populate_body(paymentAuthorization);
var opts = _this.getOptions(paymentAuthorization);
var result = api_instance.createPaymentAuthorization(channel, client_key, product, timestamp, idempotent_request_key, requestor_type, create_payment_authorization_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 (paymentAuthorization) {
return {
'requestor': paymentAuthorization['invocation_context']['requestor'],
'x_opay_headers': paymentAuthorization['invocation_context']['X-OPAY-Headers'],
'trace_id': paymentAuthorization['invocation_context']['trace_id']
};
};
exports.prototype.populate_body = function(paymentAuthorization){
var CreatePaymentAuthorizationRequest = require('../models/CreatePaymentAuthorizationRequest');
return CreatePaymentAuthorizationRequest.constructFromObject(paymentAuthorization);
};
return exports;
}));