(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/CreatePaymentHandler')
, require('../handlers/DeletePaymentHandler')
, require('../handlers/GetPaymentHandler')
, require('../handlers/UpdatePaymentHandler'), require('../OrbipayApiError'));
  }
}(this, function(ApiClient, InvocationContext, CommonUtil, ResponseWrapper, Base, CreatePaymentHandler, DeletePaymentHandler, GetPaymentHandler, UpdatePaymentHandler, OrbipayApiError) {
  'use strict';

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

      /**
      * Constructs a <code>Payment</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/Payment} obj Optional instance to populate.
      * @return {module:wrappers/Payment} The populated <code>Payment</code> instance.
      */
  exports.constructFromObject = function (data, obj) {
        if (data) {
            obj = obj || new exports();
            if (data.hasOwnProperty('id')) {
                obj['id'] = data['id'];
            }
            if (data.hasOwnProperty('url')) {
                obj['url'] = data['url'];
            }
            if (data.hasOwnProperty('fee')) {
                var Fee = require('./Fee');
                obj['fee'] = Fee.constructFromObject(data['fee']);
            }
            if (data.hasOwnProperty('status')) {
                obj['status'] = data['status'];
            }
            if (data.hasOwnProperty('payment_method')) {
                obj['payment_method'] = data['payment_method'];
            }
            if (data.hasOwnProperty('confirmation_number')) {
                obj['confirmation_number'] = data['confirmation_number'];
            }
            if (data.hasOwnProperty('custom_fields')) {
                obj['custom_fields'] = data['custom_fields'];
            }
            if (data.hasOwnProperty('currency_code3d')) {
                obj['currency_code3d'] = data['currency_code3d'];
            }
            if (data.hasOwnProperty('amount')) {
                obj['amount'] = data['amount'];
            }
            if (data.hasOwnProperty('card_cvv_number')) {
                obj['card_cvv_number'] = data['card_cvv_number'];
            }
            if (data.hasOwnProperty('payment_date')) {
                obj['payment_date'] = data['payment_date'];
            }
            if (data.hasOwnProperty('payment_schedule_type')) {
                obj['payment_schedule_type'] = data['payment_schedule_type'];
            }
            if (data.hasOwnProperty('payment_request_date')) {
                obj['payment_request_date'] = data['payment_request_date'];
            }
            if (data.hasOwnProperty('payment_amount_type')) {
                obj['payment_amount_type'] = data['payment_amount_type'];
            }
            if (data.hasOwnProperty('payment_reference')) {
                obj['payment_reference'] = data['payment_reference'];
            }
            if (data.hasOwnProperty('expected_payment_settlement_date')) {
                obj['expected_payment_settlement_date'] = data['expected_payment_settlement_date'];
            }
            if (data.hasOwnProperty('payment_entry_date')) {
                obj['payment_entry_date'] = data['payment_entry_date'];
            }
            if (data.hasOwnProperty('payment_return_date')) {
                obj['payment_return_date'] = data['payment_return_date'];
            }
            if (data.hasOwnProperty('return_code')) {
                obj['return_code'] = data['return_code'];
            }
            if (data.hasOwnProperty('payment_notification_email')) {
                obj['payment_notification_email'] = data['payment_notification_email'];
            }
            if (data.hasOwnProperty('comments')) {
                obj['comments'] = data['comments'];
            }
            if (data.hasOwnProperty('deleted')) {
                obj['deleted'] = data['deleted'];
            }
            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_PAYMENT')) {
                obj['ID_PAYMENT'] = data['ID_PAYMENT'];
            }
        }
        return obj;
  };


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

    /**
    * The unique identifier assigned by Orbipay to the payment.
    * @member {String} id
    */
  exports.prototype['id'] = undefined;
    /**
    * This URL fetches the details of payment.
    * @member {String} url
    */
  exports.prototype['url'] = undefined;
    /**
    * @member {Fee} fee
    */
  exports.prototype['fee'] = undefined;
    /**
    * The status of the payment.
    * @member {String} status
    */
  exports.prototype['status'] = undefined;
    /**
    * The fulfillment method for the payment.
    * @member {String} payment_method
    */
  exports.prototype['payment_method'] = undefined;
    /**
    * The confirmation number or reference provided to the customer for the payment.
    * @member {String} confirmation_number
    */
  exports.prototype['confirmation_number'] = undefined;
    /**
    * The additional information or meta-information that Orbipay can accept, maintain and transmit back to the client. The custom fields need to be configured with Orbipay before they can be accepted. Orbipay 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 Orbipay, would be accepted in the requests.
    * @member {{String: String}} custom_fields
    */
  exports.prototype['custom_fields'] = undefined;
    /**
    * The three-letter currency code in the ISO4217 format, in uppercase, for the card account. It must be a currency supported by Orbipay. This defaults to USD.
    * @member {String} currency_code3d
    */
  exports.prototype['currency_code3d'] = undefined;
    /**
    * The amount being paid. In case the payment_amount_type is 'discounted_amount', 'penalty_amount' or 'other', the amount needs to be specified. In other cases, this is derived from the payment_amount_type.
    * @member {String} amount
    */
  exports.prototype['amount'] = undefined;
    /**
    * This is never returned by Orbipay. This needs to be passed to Orbipay 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 is scheduled to be made. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
    * @member {String} payment_date
    */
  exports.prototype['payment_date'] = undefined;
    /**
    * The schedule type for the payment. This defaults to one_time_payment.
    * @member {String} payment_schedule_type
    */
  exports.prototype['payment_schedule_type'] = undefined;
    /**
    * The date on which the biller wants the payment to be settled. It must be in ISO8601 full-date format, namely, YYYY-MM-DD. This is applicable only if the client has opted for it.
    * @member {String} payment_request_date
    */
  exports.prototype['payment_request_date'] = undefined;
    /**
    * The type of amount, as per the bill/statement, that is being paid. The payment amount is derived from the amount type selected for the payment. This defaults to other.
    * @member {String} payment_amount_type
    */
  exports.prototype['payment_amount_type'] = undefined;
    /**
    * The unique identifier in the client system for the payment.
    * @member {String} payment_reference
    */
  exports.prototype['payment_reference'] = undefined;
    /**
    * The date on which the payment is expected to be settled with the biller. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
    * @member {String} expected_payment_settlement_date
    */
  exports.prototype['expected_payment_settlement_date'] = undefined;
    /**
    * The date on which the payment is captured in Orbipay. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
    * @member {String} payment_entry_date
    */
  exports.prototype['payment_entry_date'] = undefined;
    /**
    * The date on which the ACH returns is received by Orbipay.
    * @member {String} payment_return_date
    */
  exports.prototype['payment_return_date'] = undefined;
    /**
    * The ACH return code or the chargeback code received from Visa/Mastercard, in the event of returned payments.
    * @member {String} return_code
    */
  exports.prototype['return_code'] = undefined;
    /**
    * The email address of the customer to which payment notifications from EBPP will be sent. The notifications will be sent to customer email in case if this field is not present.
    * @member {String} payment_notification_email
    */
  exports.prototype['payment_notification_email'] = 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 (Orbipay) 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 status of payment which says whether the payment is deleted or not
    * @member {String} deleted
    */
  exports.prototype['deleted'] = 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.
    * @member {String} ID_PAYMENT
    */
  exports.prototype['ID_PAYMENT'] = undefined;

  /**
  * @param  {String} client_key - The client_key of Payment. 
  * @return {module:wrappers/Payment} The instance of <code>Payment</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 Payment. 
  * @return {module:wrappers/Payment} The instance of <code>Payment</code>.
  */
  exports.prototype.videChannel = function (channel) {
        var _this = this;
	    Base.prototype.videChannel.call(_this,channel);
        return _this;
  };
  /**
  * @param  {String} payment_amount_type - The payment_amount_type of Payment. 
  * @param  {String} amount - The amount of Payment. 
  * @param  {String} payment_date - The payment_date of Payment. 
  * @param  {String} payment_request_date - The payment_request_date of Payment. 
  * @param  {String} card_cvv_number - The card_cvv_number of Payment. 
  * @return {module:wrappers/Payment} The instance of <code>Payment</code>.
  */
  exports.prototype.withDetails = function (payment_amount_type, amount, payment_date, payment_request_date, card_cvv_number) {
        var _this = this;

        _this['payment_amount_type'] = payment_amount_type;

        _this['amount'] = amount;

        _this['payment_date'] = payment_date;

        _this['payment_request_date'] = payment_request_date;

        _this['card_cvv_number'] = card_cvv_number;


        return _this;
  };
  /**
  * @param  {FundingAccount} funding_account - The funding_account of Payment. 
  * @return {module:wrappers/Payment} The instance of <code>Payment</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 Payment. 
  * @return {module:wrappers/Payment} The instance of <code>Payment</code>.
  */
  exports.prototype.toAccount = function (customer_account) {
        var _this = this;

        _this['customer_account'] = customer_account;


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

        _this['payment_reference'] = payment_reference;


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

        _this['payment_notification_email'] = payment_notification_email;


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

        _this['status'] = status;


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

        _this['custom_fields'] = custom_fields;


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

        _this['comments'] = comments;


        return _this;
  };
  /**
  * @param  {Fee} fee - The fee of Payment. 
  * @return {module:wrappers/Payment} The instance of <code>Payment</code>.
  */
  exports.prototype.withFee = function (fee) {
        var _this = this;

        _this['fee'] = fee;


        return _this;
  };
  /**
  * @param  {String} ID_CUSTOMER - The ID_CUSTOMER of Payment. 
  * @return {module:wrappers/Payment} The instance of <code>Payment</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;
  };

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

  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 CreatePaymentHandler();
			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.delete = 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 DeletePaymentHandler();
			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.get = 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 GetPaymentHandler();
			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.update = 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 UpdatePaymentHandler();
			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;

}));