(function(root, factory) {

if (typeof module === 'object' && module.exports) {
    // CommonJS-like environments that support module.exports, like Node.
    module.exports = factory(require('../ApiClient'), require('./InvocationContext'), require('../CommonUtil'), require('../ResponseWrapper'), require('./Base')
, require('../handlers/CancelPaymentAuthorizationHandler')
, require('../handlers/CreatePaymentAuthorizationHandler'), require('../OrbipayApiError'));
  }
}(this, function(ApiClient, InvocationContext, CommonUtil, ResponseWrapper, Base, CancelPaymentAuthorizationHandler, CreatePaymentAuthorizationHandler, OrbipayApiError) {
  'use strict';

    /**
    * The PaymentAuthorization wrapper module.
    * @module wrappers/PaymentAuthorization
    */
  var exports = function(id_authorization) {
  	var _this = this;
        Base.call(_this);
  		_this['ID_AUTHORIZATION'] = id_authorization;
        _this.id = id_authorization;
  };

      /**
      * Constructs a <code>PaymentAuthorization</code> from a plain JavaScript object, optionally creating a new instance.
      * Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
      * @param {Object} data The plain JavaScript object bearing properties of interest.
      * @param {module:wrappers/PaymentAuthorization} obj Optional instance to populate.
      * @return {module:wrappers/PaymentAuthorization} The populated <code>PaymentAuthorization</code> instance.
      */
  exports.constructFromObject = function (data, obj) {
        if (data) {
            obj = obj || new exports();
            if (data.hasOwnProperty('payment_auth_reference')) {
                obj['payment_auth_reference'] = data['payment_auth_reference'];
            }
            if (data.hasOwnProperty('id')) {
                obj['id'] = data['id'];
            }
            if (data.hasOwnProperty('url')) {
                obj['url'] = data['url'];
            }
            if (data.hasOwnProperty('auth_amount')) {
                obj['auth_amount'] = data['auth_amount'];
            }
            if (data.hasOwnProperty('status')) {
                obj['status'] = data['status'];
            }
            if (data.hasOwnProperty('payment_method')) {
                obj['payment_method'] = data['payment_method'];
            }
            if (data.hasOwnProperty('currency_code3d')) {
                obj['currency_code3d'] = data['currency_code3d'];
            }
            if (data.hasOwnProperty('card_cvv_number')) {
                obj['card_cvv_number'] = data['card_cvv_number'];
            }
            if (data.hasOwnProperty('entry_time')) {
                obj['entry_time'] = data['entry_time'];
            }
            if (data.hasOwnProperty('captured_time')) {
                obj['captured_time'] = data['captured_time'];
            }
            if (data.hasOwnProperty('comments')) {
                obj['comments'] = data['comments'];
            }
            if (data.hasOwnProperty('custom_fields')) {
                obj['custom_fields'] = data['custom_fields'];
            }
            if (data.hasOwnProperty('customer')) {
                var Customer = require('./Customer');
                obj['customer'] = Customer.constructFromObject(data['customer']);
            }
            if (data.hasOwnProperty('funding_account')) {
                var FundingAccount = require('./FundingAccount');
                obj['funding_account'] = FundingAccount.constructFromObject(data['funding_account']);
            }
            if (data.hasOwnProperty('customer_account')) {
                var CustomerAccount = require('./CustomerAccount');
                obj['customer_account'] = CustomerAccount.constructFromObject(data['customer_account']);
            }
            if (data.hasOwnProperty('payment_network_response')) {
                var PaymentNetworkResponse = require('./PaymentNetworkResponse');
                obj['payment_network_response'] = PaymentNetworkResponse.constructFromObject(data['payment_network_response']);
            }
            if (data.hasOwnProperty('audit_info')) {
                var AuditInfo = require('./AuditInfo');
                obj['audit_info'] = AuditInfo.constructFromObject(data['audit_info']);
            }
            if (data.hasOwnProperty('ID_CUSTOMER')) {
                obj['ID_CUSTOMER'] = data['ID_CUSTOMER'];
            }
            if (data.hasOwnProperty('ID_AUTHORIZATION')) {
                obj['ID_AUTHORIZATION'] = data['ID_AUTHORIZATION'];
            }
        }
        return obj;
  };


  exports.prototype = Object.create(Base.prototype);
  exports.prototype.constructor = exports;

    /**
    * The unique identifier in the client system for the payment.
    * @member {String} payment_auth_reference
    */
  exports.prototype['payment_auth_reference'] = undefined;
    /**
    * The unique identifier assigned by EBPP to the payment authorization.
    * @member {String} id
    */
  exports.prototype['id'] = undefined;
    /**
    * This URL fetches the details of payment authorization.
    * @member {String} url
    */
  exports.prototype['url'] = undefined;
    /**
    * The amount being authorized.
    * @member {String} auth_amount
    */
  exports.prototype['auth_amount'] = undefined;
    /**
    * The status of the payment.
    * @member {String} status
    */
  exports.prototype['status'] = undefined;
    /**
    * The fulfillment method for the payment authorization.
    * @member {String} payment_method
    */
  exports.prototype['payment_method'] = undefined;
    /**
    * The three-letter currency code in the ISO4217 format, in uppercase, for the card account. It must be a currency supported by EBPP. This defaults to USD.
    * @member {String} currency_code3d
    */
  exports.prototype['currency_code3d'] = undefined;
    /**
    * This is never returned by EBPP. This needs to be passed to EBPP when making or editing a payment with a card funding account.
    * @member {String} card_cvv_number
    */
  exports.prototype['card_cvv_number'] = undefined;
    /**
    * The date on which the payment authorization created in UTC timestamp, with ISO8601 format. For e.g., 2019-08-13T09:21:34.359+0000.
    * @member {String} entry_time
    */
  exports.prototype['entry_time'] = undefined;
    /**
    * The date on which the payment authorization is captured in UTC timestamp, with ISO8601 format. For e.g., 2019-08-13T09:21:34.359+0000..
    * @member {String} captured_time
    */
  exports.prototype['captured_time'] = undefined;
    /**
    * Comments that can be used to recollect the operation performed on the resource object. API clients need to ensure that no sensitive information is passed in the memo. Alacriti (EBPP) is not responsible for the security of any sensitive information that may be passed as part of the memo.
    * @member {String} comments
    */
  exports.prototype['comments'] = undefined;
    /**
    * The additional information or meta-information that EBPP can accept, maintain and transmit back to the client. The custom fields need to be configured with EBPP before they can be accepted. EBPP would reject custom fields that are not pre-configured. Please contact <a href = \"mailto: support@billerpayments.com\">support@billerpayments.com</a> for more information on configuring and using custom fields. Only the custom fields enabled for the client, in EBPP, would be accepted in the requests.
    * @member {{String: String}} custom_fields
    */
  exports.prototype['custom_fields'] = undefined;
    /**
    * @member {Customer} customer
    */
  exports.prototype['customer'] = undefined;
    /**
    * @member {FundingAccount} funding_account
    */
  exports.prototype['funding_account'] = undefined;
    /**
    * @member {CustomerAccount} customer_account
    */
  exports.prototype['customer_account'] = undefined;
    /**
    * @member {PaymentNetworkResponse} payment_network_response
    */
  exports.prototype['payment_network_response'] = undefined;
    /**
    * @member {AuditInfo} audit_info
    */
  exports.prototype['audit_info'] = undefined;
    /**
    * The unique identifier assigned by EBPP to the customer.
    * @member {String} ID_CUSTOMER
    */
  exports.prototype['ID_CUSTOMER'] = undefined;
    /**
    * The unique identifier assigned by EBPP to the payment authorization.
    * @member {String} ID_AUTHORIZATION
    */
  exports.prototype['ID_AUTHORIZATION'] = undefined;

  /**
  * @param  {String} client_key - The client_key of PaymentAuthorization. 
  * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  */
  exports.prototype.forClient = function (client_key) {
        var _this = this;
	    Base.prototype.forClient.call(_this,client_key);
        return _this;
  };
  /**
  * @param  {String} channel - The channel of PaymentAuthorization. 
  * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  */
  exports.prototype.videChannel = function (channel) {
        var _this = this;
	    Base.prototype.videChannel.call(_this,channel);
        return _this;
  };
  /**
  * @param  {String} auth_amount - The auth_amount of PaymentAuthorization. 
  * @param  {String} card_cvv_number - The card_cvv_number of PaymentAuthorization. 
  * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  */
  exports.prototype.withDetails = function (auth_amount, card_cvv_number) {
        var _this = this;

        _this['auth_amount'] = auth_amount;

        _this['card_cvv_number'] = card_cvv_number;


        return _this;
  };
  /**
  * @param  {String} ID_CUSTOMER - The ID_CUSTOMER of PaymentAuthorization. 
  * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  */
  exports.prototype.forCustomer = function (id_customer) {
        var _this = this;

        _this['ID_CUSTOMER'] = id_customer;
        var Customer = require('./Customer');
        _this['customer'] = new Customer(id_customer);


        return _this;
  };
  /**
  * @param  {FundingAccount} funding_account - The funding_account of PaymentAuthorization. 
  * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  */
  exports.prototype.fromAccount = function (funding_account) {
        var _this = this;

        _this['funding_account'] = funding_account;


        return _this;
  };
  /**
  * @param  {CustomerAccount} customer_account - The customer_account of PaymentAuthorization. 
  * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  */
  exports.prototype.toAccount = function (customer_account) {
        var _this = this;

        _this['customer_account'] = customer_account;


        return _this;
  };
  /**
  * @param  {String} payment_auth_reference - The payment_auth_reference of PaymentAuthorization. 
  * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  */
  exports.prototype.withReference = function (payment_auth_reference) {
        var _this = this;

        _this['payment_auth_reference'] = payment_auth_reference;


        return _this;
  };
  /**
  * @param  {{String: String}} custom_fields - The custom_fields of PaymentAuthorization. 
  * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  */
  exports.prototype.withCustomFields = function (custom_fields) {
        var _this = this;

        _this['custom_fields'] = custom_fields;


        return _this;
  };
  /**
  * @param  {String} comments - The comments of PaymentAuthorization. 
  * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  */
  exports.prototype.withMemo = function (comments) {
        var _this = this;

        _this['comments'] = comments;


        return _this;
  };

  exports.prototype.cancelledBy = function (requestor, requestor_type) {
        var _this = this;
        _this.requestedBy(requestor, requestor_type);
        return _this;
  };
  exports.prototype.createdBy = function (requestor, requestor_type) {
        var _this = this;
        _this.requestedBy(requestor, requestor_type);
        return _this;
  };

  exports.prototype.cancel = function (invocation_context, callback, live_mode, api_end_point) {
        var _this = this;
        var internalCallback = function (errorMessage, parsedData, httpResponse, exception) {
            try {
                var response = ResponseWrapper.wrapResponse(exports, exception, errorMessage, parsedData, httpResponse);
                if (callback) {
                    callback(response['exception'], response['data'])
                }
            } catch (e) {
                exception = OrbipayApiError.getDefaultException(e);
                if (callback) {
                    callback(exception)
                }
            }
        };
        try {
			_this.withContext(invocation_context, live_mode, api_end_point);
			var handler = new CancelPaymentAuthorizationHandler();
			if (callback && CommonUtil.isFunction(callback)) {
			    return handler.process(_this, internalCallback);
			} else {
			    return handler.process(_this);
			}
		}
		catch (e){
		    var error = OrbipayApiError.getDefaultException(e);
		    if (callback) {
		        callback(error)
		    }
        }
  };
  exports.prototype.create = function (invocation_context, callback, live_mode, api_end_point) {
        var _this = this;
        var internalCallback = function (errorMessage, parsedData, httpResponse, exception) {
            try {
                var response = ResponseWrapper.wrapResponse(exports, exception, errorMessage, parsedData, httpResponse);
                if (callback) {
                    callback(response['exception'], response['data'])
                }
            } catch (e) {
                exception = OrbipayApiError.getDefaultException(e);
                if (callback) {
                    callback(exception)
                }
            }
        };
        try {
			_this.withContext(invocation_context, live_mode, api_end_point);
			var handler = new CreatePaymentAuthorizationHandler();
			if (callback && CommonUtil.isFunction(callback)) {
			    return handler.process(_this, internalCallback);
			} else {
			    return handler.process(_this);
			}
		}
		catch (e){
		    var error = OrbipayApiError.getDefaultException(e);
		    if (callback) {
		        callback(error)
		    }
        }
  };

  return exports;

}));