(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/GetRecordPaymentHandler'), 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/GetRecordPaymentHandler
   * @class
   */

  var exports = function() {
  };

  exports.prototype.process = function (recordedPayment, callback) {
        
        var secret = recordedPayment.invocation_context.secret;
		var host = recordedPayment.api_end_point;
        var api_key = recordedPayment.invocation_context.api_key;
        var auth_scheme = recordedPayment.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 = recordedPayment.invocation_context['channel'];
			var client_key = recordedPayment.invocation_context['client_key'];
			var product = recordedPayment.invocation_context['product'];
			var timestamp;
			if (recordedPayment.invocation_context['timestamp'])
			{
				timestamp = recordedPayment.invocation_context['timestamp'];
			}		
			else
			{
				timestamp = CommonUtil.getTimeStamp();
			}
			var idempotent_request_key = recordedPayment.invocation_context['idempotent_request_key'];
			var requestor_type = recordedPayment.invocation_context['requestor_type'];
			var id_payment = recordedPayment['ID_PAYMENT'];
            var opts = _this.getOptions(recordedPayment);
			var result = api_instance.getRecordPayment(channel, client_key, product, timestamp, idempotent_request_key, requestor_type, id_payment,  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 (recordedPayment) {
        return {
		    'requestor': recordedPayment['invocation_context']['requestor'], 
		    'x_opay_headers': recordedPayment['invocation_context']['X-OPAY-Headers'], 
		    'trace_id': recordedPayment['invocation_context']['trace_id']
        };
    };  


  return exports;
}));