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

    /**
    * The SimplePayment wrapper module.
    * @module wrappers/SimplePayment
    */
  var exports = function() {

  };
  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('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('save_funding_account')) {
                obj['save_funding_account'] = data['save_funding_account'];
            }
        }
        return obj;
  };


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

    /**
    * The unique identifier assigned by EBPP 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 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.
    * @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 EBPP. 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 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 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 EBPP. 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 EBPP.
    * @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 to which notifications for the payment will be sent. The notifications will be sent to the customer's email in case this is not provided.
    * @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 (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;
    /**
    * @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;
    /**
    * query param
    * @member {String} save_funding_account
    */
  exports.prototype['save_funding_account'] = undefined;

  /**
  * @param  {String} client_key - The client_key of SimplePayment. 
  * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</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 SimplePayment. 
  * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</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 SimplePayment. 
  * @param  {String} amount - The amount of SimplePayment. 
  * @param  {String} payment_date - The payment_date of SimplePayment. 
  * @param  {String} payment_request_date - The payment_request_date of SimplePayment. 
  * @param  {String} card_cvv_number - The card_cvv_number of SimplePayment. 
  * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</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 SimplePayment. 
  * @param  {String} save_funding_account - The save_funding_account of SimplePayment. 
  * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  */
  exports.prototype.fromAccount = function (funding_account, save_funding_account) {
        var _this = this;

        _this['funding_account'] = funding_account;

        _this['save_funding_account'] = save_funding_account;


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

        _this['payment_notification_email'] = payment_notification_email;


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

        _this['custom_fields'] = custom_fields;


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

        _this['comments'] = comments;


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

        _this['fee'] = fee;


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

        _this['customer'] = customer;


        return _this;
  };

  exports.prototype.createdBy = 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 SimplePaymentHandler();
			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;

}));