/**
 * Incentives shouldn't be used on non-wallet purchases!
 *
 * @since		1.0.0
 * @return		void
 */
function edd_wallet_maybe_remove_incentive()
{
    if (!function_exists('edd_is_checkout')) {
        return;
    }
    if (edd_get_chosen_gateway() !== 'wallet') {
        EDD()->session->set('wallet_has_incentives', null);
    }
}
/**
 * Renders the hidden Checkout fields
 *
 * @since 1.3.2
 * @return void
 */
function edd_checkout_hidden_fields()
{
    ?>
	<?php 
    if (is_user_logged_in()) {
        ?>
	<input type="hidden" name="edd-user-id" value="<?php 
        echo get_current_user_id();
        ?>
"/>
	<?php 
    }
    ?>
	<input type="hidden" name="edd_action" value="purchase"/>
	<input type="hidden" name="edd-gateway" value="<?php 
    echo edd_get_chosen_gateway();
    ?>
" />
<?php 
}
    /**
     * Display the log in button
     *
     * @access public
     * @since  2.4
     * @return void
     */
    public function login_form()
    {
        if (empty($this->reference_id) && 'amazon' == edd_get_chosen_gateway()) {
            remove_all_actions('edd_purchase_form_after_cc_form');
            remove_all_actions('edd_purchase_form_after_user_info');
            remove_all_actions('edd_purchase_form_register_fields');
            remove_all_actions('edd_purchase_form_login_fields');
            remove_all_actions('edd_register_fields_before');
            remove_all_actions('edd_cc_form');
            remove_all_actions('edd_checkout_form_top');
            ob_start();
            ?>
			<fieldset id="edd-amazon-login-fields" class="edd-amazon-fields">

				<div id="edd-amazon-pay-button"></div>
				<script type="text/javascript">
					var authRequest;
					OffAmazonPayments.Button('edd-amazon-pay-button', edd_amazon.sellerId, {
						type:  edd_amazon.buttonType,
						color: edd_amazon.buttonColor,
						size:  edd_amazon.buttonSize,

						authorization: function() {

							loginOptions = {
								scope: edd_amazon.scope,
								popup: edd_amazon.popup
							};

							authRequest = amazon.Login.authorize( loginOptions, edd_amazon.redirectUri );

						},
						onSignIn: function( orderReference ) {
							amazonOrderReferenceId = orderReference.getAmazonOrderReferenceId();
							window.location = edd_amazon.signinUri + '&amazon_reference_id=' + amazonOrderReferenceId;
						}, onError: function(error) {
							jQuery('#edd_purchase_submit').prepend( '<div class="edd_errors"><p class="edd_error" id="edd_error_"' + error.getErrorCode() + '>' + error.getErrorMessage() + '</p></div>' );
						}
					});
				</script>

			</fieldset>

		<?php 
            echo ob_get_clean();
        }
    }
 /**
  * Add validation in shmart payment gateway form.
  * @param array   $required_fields All Require fields
  * @return $required_fields
  */
 public function shmart_payment_form_fields_validation($required_fields)
 {
     if ('shmart' == edd_get_chosen_gateway()) {
         $required_fields['contact_number'] = array('error_id' => 'invalid_contact_number', 'error_message' => __('Please enter contact number', 'edd-shmart'));
         if (edd_get_cart_total()) {
             $required_fields['card_address'] = array('error_id' => 'invalid_address', 'error_message' => __('Please enter billing address', 'edd-shmart'));
         }
     }
     return $required_fields;
 }