/**
  * Function that will actually charge the customers credit card
  *
  * @since 2.0.0
  */
 public static function charge_card()
 {
     if (self::$token && wp_verify_nonce($_POST['wp-simple-pay-pro-nonce'], 'charge_card')) {
         global $sc_options;
         // Set redirect
         $redirect = $_POST['sc-redirect'];
         $fail_redirect = $_POST['sc-redirect-fail'];
         $failed = null;
         // Get the credit card details submitted by the form
         $token = $_POST['stripeToken'];
         $payment_email = $_POST['stripeEmail'];
         $amount = $_POST['sc-amount'];
         $description = isset($_POST['sc-description']) ? $_POST['sc-description'] : '';
         $store_name = isset($_POST['sc-name']) ? $_POST['sc-name'] : '';
         $currency = isset($_POST['sc-currency']) ? $_POST['sc-currency'] : '';
         $test_mode = isset($_POST['sc_test_mode']) ? $_POST['sc_test_mode'] : 'false';
         $details_placement = isset($_POST['sc-details-placement']) ? $_POST['sc-details-placement'] : '';
         $customer = null;
         $charge = array();
         parent::set_key($test_mode);
         // We allow a spot to hook in, but the hook is responsible for all of the code.
         // If the action is non-existant, then we run a default for the button.
         // Used by subscriptions add-on (overrides base plugin charge process below).
         if (has_action('sc_do_charge')) {
             do_action('sc_do_charge');
         } else {
             try {
                 // Init metadata object with filter allowing it to be overridden/added to.
                 $meta = apply_filters('sc_meta_values', array());
                 // Init customer ID with filter allowing it to be overridden.
                 $customer_id = apply_filters('sc_customer_id', null);
                 // Create new customer unless there's an existing customer ID set through filters.
                 if (empty($customer_id)) {
                     $customer = \Stripe\Customer::create(array('email' => $payment_email, 'card' => $token));
                 } else {
                     $customer = \Stripe\Customer::retrieve($customer_id);
                 }
                 $charge_args = array('amount' => $amount, 'currency' => $currency, 'customer' => $customer->id, 'metadata' => $meta);
                 if (!empty($description)) {
                     $charge_args['description'] = $description;
                 }
                 $charge = \Stripe\Charge::create($charge_args);
                 // Add Stripe charge ID to querystring.
                 // From https://developer.wordpress.org/reference/functions/add_query_arg/:
                 // Values are expected to be encoded appropriately with urlencode() or rawurlencode().
                 $query_args = array('charge' => $charge->id, 'store_name' => rawurlencode($store_name));
                 $failed = false;
             } catch (\Stripe\Error\Card $e) {
                 // Something else happened, completely unrelated to Stripe
                 $redirect = $fail_redirect;
                 $failed = true;
                 $e = $e->getJsonBody();
                 $query_args = array('charge' => $e['error']['charge'], 'error_code' => $e['error']['type'], 'charge_failed' => true);
             }
             unset($_POST['stripeToken']);
             do_action('sc_redirect_before', $failed);
             if ($test_mode == 'true') {
                 $query_args['test_mode'] = 'true';
             }
             if ('below' == $details_placement) {
                 $query_args['details_placement'] = $details_placement;
             }
             self::$token = false;
             $redirect_url = esc_url_raw(add_query_arg(apply_filters('sc_redirect_args', $query_args, $charge), apply_filters('sc_redirect', $redirect, $failed)));
             wp_redirect($redirect_url);
             exit;
         }
     }
 }
 /**
  * Function that will actually charge the customers credit card
  * 
  * @since 2.0.0
  */
 public static function charge_card()
 {
     if (self::$token && wp_verify_nonce($_POST['wp-simple-pay-pro-nonce'], 'charge_card')) {
         global $sc_options;
         // Set redirect
         $redirect = $_POST['sc-redirect'];
         $fail_redirect = $_POST['sc-redirect-fail'];
         $failed = null;
         $message = '';
         // Get the credit card details submitted by the form
         $token = $_POST['stripeToken'];
         $amount = $_POST['sc-amount'];
         $description = $_POST['sc-description'];
         $store_name = $_POST['sc-name'];
         $currency = $_POST['sc-currency'];
         $test_mode = isset($_POST['sc_test_mode']) ? $_POST['sc_test_mode'] : 'false';
         $details_placement = $_POST['sc-details-placement'];
         parent::set_key($test_mode);
         $meta = array();
         $meta = apply_filters('sc_meta_values', $meta);
         // We allow a spot to hook in, but the hook in is responsible for all of the code.
         // If the action is non-existant, then we run a default for the button.
         if (has_action('sc_do_charge')) {
             do_action('sc_do_charge');
         } else {
             try {
                 // Create new customer
                 $new_customer = \Stripe\Customer::create(array('email' => $_POST['stripeEmail'], 'card' => $token));
                 $charge_args = array('amount' => $amount, 'currency' => $currency, 'customer' => $new_customer['id'], 'metadata' => $meta);
                 if (!empty($description)) {
                     $charge_args['description'] = $description;
                 }
                 $charge = \Stripe\Charge::create($charge_args);
                 $query_args = array('charge' => $charge->id, 'store_name' => urlencode($store_name));
                 $failed = false;
             } catch (\Stripe\Error\Card $e) {
                 // Something else happened, completely unrelated to Stripe
                 $redirect = $fail_redirect;
                 $failed = true;
                 $e = $e->getJsonBody();
                 $query_args = array('charge' => $e['error']['charge'], 'error_code' => $e['error']['type'], 'charge_failed' => true);
             }
             unset($_POST['stripeToken']);
             do_action('sc_redirect_before', $failed);
             if ($test_mode == 'true') {
                 $query_args['test_mode'] = 'true';
             }
             if ('below' == $details_placement) {
                 $query_args['details_placement'] = $details_placement;
             }
             self::$token = false;
             wp_redirect(esc_url_raw(add_query_arg(apply_filters('sc_redirect_args', $query_args, $charge), apply_filters('sc_redirect', $redirect, $failed))));
             exit;
         }
     }
 }