public function do_charge()
 {
     if (wp_verify_nonce($_POST['wp-simple-pay-pro-nonce'], 'charge_card')) {
         global $sc_options;
         $query_args = array();
         // 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'];
         $details_placement = $_POST['sc-details-placement'];
         $charge = null;
         $sub = isset($_POST['sc_sub_id']);
         $interval = isset($_POST['sc_sub_interval']) ? $_POST['sc_sub_interval'] : 'month';
         $interval_count = isset($_POST['sc_sub_interval_count']) ? $_POST['sc_sub_interval_count'] : 1;
         $statement_description = isset($_POST['sc_sub_statement_description']) ? $_POST['sc_sub_statement_description'] : '';
         $setup_fee = isset($_POST['sc_sub_setup_fee']) ? $_POST['sc_sub_setup_fee'] : 0;
         $coupon = isset($_POST['sc_coup_coupon_code']) ? $_POST['sc_coup_coupon_code'] : '';
         $test_mode = isset($_POST['sc_test_mode']) ? $_POST['sc_test_mode'] : 'false';
         if ($sub) {
             $sub = !empty($_POST['sc_sub_id']) ? $_POST['sc_sub_id'] : 'custom';
         }
         Stripe_Checkout_Functions::set_key($test_mode);
         $meta = array();
         if (!empty($setup_fee)) {
             $meta['Setup Fee'] = Stripe_Checkout_Misc::to_formatted_amount($setup_fee, $currency);
         }
         $meta = apply_filters('sc_meta_values', $meta);
         try {
             if ($sub == 'custom') {
                 $timestamp = time();
                 $plan_id = $_POST['stripeEmail'] . '_' . $amount . '_' . $timestamp;
                 $name = __('Subscription:', 'sc_sub') . ' ' . Stripe_Checkout_Misc::to_formatted_amount($amount, $currency) . ' ' . strtoupper($currency) . '/' . $interval;
                 // Create a plan
                 $plan_args = array('amount' => $amount, 'interval' => $interval, 'name' => $name, 'currency' => $currency, 'id' => $plan_id, 'interval_count' => $interval_count);
                 if (!empty($statement_description)) {
                     $plan_args['statement_descriptor'] = $statement_description;
                 }
                 $new_plan = \Stripe\Plan::create($plan_args);
                 // Create a customer and charge
                 $new_customer = \Stripe\Customer::create(array('email' => $_POST['stripeEmail'], 'card' => $token, 'plan' => $plan_id, 'metadata' => $meta, 'account_balance' => $setup_fee));
             } else {
                 // Create new customer
                 $cust_args = array('email' => $_POST['stripeEmail'], 'card' => $token, 'plan' => $sub, 'metadata' => $meta, 'account_balance' => $setup_fee);
                 if (!empty($coupon)) {
                     $cust_args['coupon'] = $coupon;
                 }
                 $new_customer = \Stripe\Customer::create($cust_args);
                 // Set currency based on sub
                 $plan = \Stripe\Plan::retrieve($sub);
                 //echo $subscription . '<Br>';
                 $currency = strtoupper($plan->currency);
             }
             // We want to add the meta data and description to the actual charge so that users can still view the meta sent with a subscription + custom fields
             // the same way that they would normally view it without subscriptions installed.
             // We need the steps below to do this
             // First we get the latest invoice based on the customer ID
             $invoice = \Stripe\Invoice::all(array('customer' => $new_customer->id, 'limit' => 1));
             // If this is a trial we need to skip this part since a charge is not made
             $trial = $invoice->data[0]->lines->data[0]->plan->trial_period_days;
             if (empty($trial) || !empty($setup_fee)) {
                 // Now that we have the invoice object we can get the charge ID
                 $inv_charge = $invoice->data[0]->charge;
                 // Finally, with the charge ID we can update the specific charge and inject our meta data sent from Stripe Custom Fields
                 $ch = \Stripe\Charge::retrieve($inv_charge);
                 $charge = $ch;
                 if (!empty($meta)) {
                     $ch->metadata = $meta;
                 }
                 if (!empty($description)) {
                     $ch->description = $description;
                 }
                 $ch->save();
                 $query_args = array('charge' => $ch->id, 'store_name' => urlencode($store_name));
                 $failed = false;
             } else {
                 $sub_id = $invoice->data[0]->subscription;
                 if (!empty($description)) {
                     $customer = \Stripe\Customer::retrieve($new_customer->id);
                     $subscription = $customer->subscriptions->retrieve($sub_id);
                     $subscription->metadata = array('product' => $description);
                     $subscription->save();
                 }
                 $query_args = array('cust_id' => $new_customer->id, 'sub_id' => $sub_id, 'store_name' => urlencode($store_name));
                 $failed = false;
             }
         } catch (Exception $e) {
             // Something else happened, completely unrelated to Stripe
             $redirect = $fail_redirect;
             $failed = true;
             $e = $e->getJsonBody();
             $query_args = array('sub' => true, 'error_code' => $e['error']['type'], 'charge_failed' => true);
         }
         unset($_POST['stripeToken']);
         do_action('sc_redirect_before');
         if ($test_mode == 'true') {
             $query_args['test_mode'] = 'true';
         }
         if ('below' == $details_placement) {
             $query_args['details_placement'] = $details_placement;
         }
         if (!empty($trial) && empty($setup_fee)) {
             $query_args['trial'] = 1;
         }
         wp_redirect(esc_url_raw(add_query_arg(apply_filters('sc_redirect_args', $query_args, $charge), apply_filters('sc_redirect', $redirect, $failed))));
         exit;
     }
 }
コード例 #2
0
 /**
  * Enqueue Front-end Scripts
  *
  * @since 1.0.0
  */
 public function enqueue_frontend_scripts()
 {
     global $base_class;
     $js_dir = SC_DIR_URL . 'assets/js/';
     // Localized PHP to JS global vars for front-end
     $localized_frontend_globals = apply_filters('simple_pay_global_script_vars', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('simple_pay_checkout_nonce'), 'paymentSubmittingButtonLabel' => __('Please wait...', 'stripe'), 'couponAmountOffText' => __('off', 'stripe'), 'zeroAmountCheckoutButtonLabel' => __('Start Now', 'stripe'), 'zeroDecimalCurrencies' => Stripe_Checkout_Misc::zero_decimal_currencies(), 'scriptDebug' => defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? 'true' : 'false'));
     wp_enqueue_script('jquery');
     wp_enqueue_script('stripe-checkout', 'https://checkout.stripe.com/checkout.js', array(), null, true);
     // Prefix local 3rd party libraries to prevent clashing.
     // Enqueued individually so we can dequeue if already enqueued by another plugin.
     wp_enqueue_script($base_class->plugin_slug . '-accounting', $js_dir . 'vendor/accounting' . $this->min . '.js', array(), $base_class->version, true);
     wp_enqueue_script($base_class->plugin_slug . '-parsley', $js_dir . 'vendor/parsley' . $this->min . '.js', array(), $base_class->version, true);
     wp_enqueue_script($base_class->plugin_slug . '-moment', $js_dir . 'vendor/moment' . $this->min . '.js', array(), $base_class->version, true);
     wp_enqueue_script($base_class->plugin_slug . '-pikaday', $js_dir . 'vendor/pikaday' . $this->min . '.js', array(), $base_class->version, true);
     wp_enqueue_script($base_class->plugin_slug . '-pikaday-jquery', $js_dir . 'vendor/pikaday.jquery.js', array(), $base_class->version, true);
     /** Plugin compatibility fixes */
     // Dequeue moment.js if detected from Simple Calendar.
     // TODO Eventually remove reference to moment.js from FullCalendar add-on (removed in 1.0.2).
     if (wp_script_is('simcal-moment', 'enqueued') || wp_script_is('simcal-fullcal-moment', 'enqueued')) {
         wp_dequeue_script($base_class->plugin_slug . '-moment');
     }
     // Finally enqueue our main public JS file.
     wp_enqueue_script($base_class->plugin_slug . '-public', $js_dir . 'pro-public' . $this->min . '.js', array('jquery', 'stripe-checkout'), $base_class->version, true);
     // Localize front-end global vars.
     wp_localize_script($base_class->plugin_slug . '-public', 'simplePayFrontendGlobals', $localized_frontend_globals);
 }
コード例 #3
0
 /**
  * Function to show the payment details after the purchase
  *
  * @since 2.0.0
  */
 public static function show_payment_details($content)
 {
     $details_placement = isset($_GET['details_placement']) ? $_GET['details_placement'] : 'above';
     // Since this is a GET query arg I reset it here in case someone tries to submit it again with their own string written in the URL.
     // This helps ensure it can only be set to below or above.
     $details_placement = $details_placement == 'below' ? 'below' : 'above';
     $is_above = $details_placement == 'below' ? 0 : 1;
     $charge_response = null;
     if (in_the_loop() && is_main_query()) {
         global $sc_options;
         $html = '';
         $test_mode = isset($_GET['test_mode']) ? 'true' : 'false';
         parent::set_key($test_mode);
         // PRO ONLY: Check for error code.
         if (isset($_GET['error_code'])) {
             if (isset($_GET['charge'])) {
                 $charge = esc_html($_GET['charge']);
             } else {
                 $charge = '';
             }
             if ($is_above) {
                 $content = apply_filters('sc_payment_details_error', $html, $charge) . $content;
             } else {
                 $content = $content . apply_filters('sc_payment_details_error', $html, $charge);
             }
         }
         // Successful charge output.
         if (isset($_GET['charge']) && !isset($_GET['charge_failed'])) {
             $charge_id = esc_html($_GET['charge']);
             // https://stripe.com/docs/api/php#charges
             $charge_response = \Stripe\Charge::retrieve($charge_id);
             if (null === $sc_options->get_setting_value('disable_success_message')) {
                 $html = '<div class="sc-payment-details-wrap">' . "\n";
                 $html .= '<p>' . __('Congratulations. Your payment went through!', 'stripe') . '</p>' . "\n";
                 $html .= '<p>' . "\n";
                 if (!empty($charge_response->description)) {
                     $html .= __("Here's what you purchased:", 'stripe') . '<br/>' . "\n";
                     $html .= esc_html($charge_response->description) . '<br/>' . "\n";
                 }
                 if (isset($_GET['store_name']) && !empty($_GET['store_name'])) {
                     $html .= __('From: ', 'stripe') . esc_html($_GET['store_name']) . '<br/>' . "\n";
                 }
                 $html .= '<br/>' . "\n";
                 $html .= '<strong>' . __('Total Paid: ', 'stripe') . Stripe_Checkout_Misc::to_formatted_amount($charge_response->amount, $charge_response->currency) . ' ' . strtoupper($charge_response->currency) . '</strong>' . "\n";
                 $html .= '</p>' . "\n";
                 $html .= '<p>' . sprintf(__('Your transaction ID is: %s', 'stripe'), $charge_response->id) . '</p>' . "\n";
                 $html .= '</div>' . "\n";
                 if ($is_above) {
                     $content = apply_filters('sc_payment_details', $html, $charge_response) . $content;
                 } else {
                     $content = $content . apply_filters('sc_payment_details', $html, $charge_response);
                 }
             }
             do_action('sc_after_charge', $charge_response);
         }
     }
     return $content;
 }
コード例 #4
0
        /**
         * Function to process the [stripe] shortcode
         * 
         * @since 1.0.0
         */
        function stripe_shortcode($attr, $content = null)
        {
            global $sc_options;
            static $sc_id = 0;
            $sc_id++;
            $attr = shortcode_atts(array('name' => null !== $sc_options->get_setting_value('name') ? $sc_options->get_setting_value('name') : get_bloginfo('title'), 'description' => '', 'amount' => '', 'image_url' => null !== $sc_options->get_setting_value('image_url') ? $sc_options->get_setting_value('image_url') : '', 'currency' => null !== $sc_options->get_setting_value('currency') ? $sc_options->get_setting_value('currency') : 'USD', 'checkout_button_label' => null !== $sc_options->get_setting_value('checkout_button_label') ? $sc_options->get_setting_value('checkout_button_label') : '', 'billing' => null !== $sc_options->get_setting_value('billing') ? 'true' : 'false', 'payment_button_label' => null !== $sc_options->get_setting_value('payment_button_label') ? $sc_options->get_setting_value('payment_button_label') : __('Pay with Card', 'sc'), 'enable_remember' => null !== $sc_options->get_setting_value('enable_remember') ? 'true' : 'false', 'bitcoin' => null !== $sc_options->get_setting_value('use_bitcoin') ? 'true' : 'false', 'alipay' => null !== $sc_options->get_setting_value('alipay') ? $sc_options->get_setting_value('alipay') : 'false', 'alipay_reusable' => null !== $sc_options->get_setting_value('alipay_reusable') ? 'true' : 'false', 'locale' => null !== $sc_options->get_setting_value('locale') ? $sc_options->get_setting_value('locale') : 'auto', 'success_redirect_url' => null !== $sc_options->get_setting_value('success_redirect_url') ? $sc_options->get_setting_value('success_redirect_url') : get_permalink(), 'failure_redirect_url' => null !== $sc_options->get_setting_value('failure_redirect_url') ? $sc_options->get_setting_value('failure_redirect_url') : get_permalink(), 'prefill_email' => 'false', 'verify_zip' => null !== $sc_options->get_setting_value('verify_zip') ? 'true' : 'false', 'test_mode' => 'false', 'id' => null, 'payment_details_placement' => 'above', 'test_secret_key' => '', 'test_publishable_key' => '', 'live_secret_key' => '', 'live_publishable_key' => ''), $attr, 'stripe');
            // Assign variables since we are not using extract
            $name = $attr['name'];
            $description = $attr['description'];
            $amount = $attr['amount'];
            $image_url = $attr['image_url'];
            $currency = $attr['currency'];
            $checkout_button_label = $attr['checkout_button_label'];
            $billing = $attr['billing'];
            $payment_button_label = $attr['payment_button_label'];
            $enable_remember = $attr['enable_remember'];
            $bitcoin = $attr['bitcoin'];
            $alipay = $attr['alipay'];
            $alipay_reusable = $attr['alipay_reusable'];
            $locale = $attr['locale'];
            $success_redirect_url = $attr['success_redirect_url'];
            $failure_redirect_url = $attr['failure_redirect_url'];
            $prefill_email = $attr['prefill_email'];
            $verify_zip = $attr['verify_zip'];
            $test_mode = $attr['test_mode'];
            $id = $attr['id'];
            $payment_details_placement = $attr['payment_details_placement'];
            $test_secret_key = $attr['test_secret_key'];
            $test_publishable_key = $attr['test_publishable_key'];
            $live_secret_key = $attr['live_secret_key'];
            $live_publishable_key = $attr['live_publishable_key'];
            $sc_options->delete_setting('live_secret_key_temp');
            $sc_options->delete_setting('test_secret_key_temp');
            if (!empty($test_secret_key)) {
                $sc_options->add_setting('test_secret_key_temp', $test_secret_key);
            }
            if (!empty($test_publishable_key)) {
                $sc_options->add_setting('test_publishable_key_temp', $test_publishable_key);
            }
            if (!empty($live_secret_key)) {
                $sc_options->add_setting('live_secret_key_temp', $live_secret_key);
            }
            if (!empty($live_publishable_key)) {
                $sc_options->add_setting('live_publishable_key_temp', $live_publishable_key);
            }
            // Generate custom form id attribute if one not specified.
            // Rename var for clarity.
            $form_id = $id;
            if ($form_id === null || empty($form_id)) {
                $form_id = 'sc_checkout_form_' . $sc_id;
            }
            $test_mode = isset($_GET['test_mode']) ? 'true' : $test_mode;
            // Check if in test mode or live mode
            if (0 == $sc_options->get_setting_value('enable_live_key') || 'true' == $test_mode) {
                // Test mode
                if (!(null === $sc_options->get_setting_value('test_publishable_key_temp'))) {
                    $data_key = $sc_options->get_setting_value('test_publishable_key_temp');
                    $sc_options->delete_setting('test_publishable_key_temp');
                } else {
                    $data_key = null !== $sc_options->get_setting_value('test_publish_key') ? $sc_options->get_setting_value('test_publish_key') : '';
                }
                if (null === $sc_options->get_setting_value('test_secret_key') && null === $sc_options->get_setting_value('test_publishable_key_temp')) {
                    $data_key = '';
                }
            } else {
                // Live mode
                if (!(null === $sc_options->get_setting_value('live_publishable_key_temp'))) {
                    $data_key = $sc_options->get_setting_value('live_publishable_key_temp');
                    $sc_options->delete_setting('live_publishable_key_temp');
                } else {
                    $data_key = null !== $sc_options->get_setting_value('live_publish_key') ? $sc_options->get_setting_value('live_publish_key') : '';
                }
                if (null === $sc_options->get_setting_value('live_secret_key') && null === $sc_options->get_setting_value('live_publishable_key_temp')) {
                    $data_key = '';
                }
            }
            if (empty($data_key)) {
                if (current_user_can('manage_options')) {
                    return '<h6>' . __('You must enter your API keys before the Stripe button will show up here.', 'sc') . '</h6>';
                }
                return '';
            }
            if (!empty($prefill_email) && $prefill_email !== 'false') {
                // Get current logged in user email
                if (is_user_logged_in()) {
                    $prefill_email = get_userdata(get_current_user_id())->user_email;
                } else {
                    $prefill_email = 'false';
                }
            }
            $html = '<form id="' . esc_attr($form_id) . '" method="POST" action="" data-sc-id="' . $sc_id . '" class="sc-checkout-form">';
            $html .= '<script
					   src="https://checkout.stripe.com/checkout.js" class="stripe-button"
					   data-key="' . esc_attr($data_key) . '" ' . (!empty($image_url) ? 'data-image="' . esc_attr($image_url) . '" ' : '') . (!empty($name) ? 'data-name="' . esc_attr($name) . '" ' : '') . (!empty($description) ? 'data-description="' . esc_attr($description) . '" ' : '') . (!empty($amount) ? 'data-amount="' . esc_attr($amount) . '" ' : '') . (!empty($currency) ? 'data-currency="' . esc_attr($currency) . '" ' : '') . (!empty($checkout_button_label) ? 'data-panel-label="' . esc_attr($checkout_button_label) . '" ' : '') . (!empty($verify_zip) ? 'data-zip-code="' . esc_attr($verify_zip) . '" ' : '') . (!empty($prefill_email) && 'false' != $prefill_email ? 'data-email="' . esc_attr($prefill_email) . '" ' : '') . (!empty($payment_button_label) ? 'data-label="' . esc_attr($payment_button_label) . '" ' : '') . (!empty($enable_remember) ? 'data-allow-remember-me="' . esc_attr($enable_remember) . '" ' : 'data-allow-remember-me="true" ') . (!empty($bitcoin) ? 'data-bitcoin="' . $bitcoin . '" ' : '') . (!empty($billing) ? 'data-billing-address="' . esc_attr($billing) . '" ' : 'data-billing-address="false" ') . (!empty($alipay) ? 'data-alipay="' . $alipay . '" ' : '') . (!empty($alipay_reusable) ? 'data-alipay-reusable="' . $alipay_reusable . '" ' : '') . (!empty($locale) ? 'data-locale="' . $locale . '" ' : '') . '></script>';
            $html .= '<input type="hidden" name="sc-name" value="' . esc_attr($name) . '" />';
            $html .= '<input type="hidden" name="sc-description" value="' . esc_attr($description) . '" />';
            $html .= '<input type="hidden" name="sc-amount" class="sc_amount" value="' . esc_attr($amount) . '" />';
            $html .= '<input type="hidden" name="sc-redirect" value="' . esc_attr(!empty($success_redirect_url) ? $success_redirect_url : get_permalink()) . '" />';
            $html .= '<input type="hidden" name="sc-redirect-fail" value="' . esc_attr(!empty($failure_redirect_url) ? $failure_redirect_url : get_permalink()) . '" />';
            $html .= '<input type="hidden" name="sc-currency" value="' . esc_attr($currency) . '" />';
            $html .= '<input type="hidden" name="sc-details-placement" value="' . ($payment_details_placement == 'below' ? 'below' : 'above') . '" />';
            $html .= '<input type="hidden" name="wp-simple-pay" value="1" />';
            $html .= wp_nonce_field('charge_card', 'wp-simple-pay-nonce', '', false);
            if ('true' == $test_mode) {
                $html .= '<input type="hidden" name="sc_test_mode" value="true" />';
            }
            // Add a filter here to allow developers to hook into the form
            $filter_html = '';
            $html .= apply_filters('sc_before_payment_button', $filter_html);
            $html .= '</form>';
            //Stripe minimum amount allowed.
            $stripe_minimum_amount = 50;
            if (empty($amount) || $amount < $stripe_minimum_amount || !isset($amount)) {
                if (current_user_can('manage_options')) {
                    $html = '<h6>';
                    $html .= sprintf(__('WP Simple Pay for Stripe requires an amount of %1$s (%2$s %3$s) or larger.', 'sc'), $stripe_minimum_amount, Stripe_Checkout_Misc::to_formatted_amount($stripe_minimum_amount, $currency), $currency);
                    $html .= '</h6>';
                    return $html;
                }
                return '';
            } elseif (!isset($_GET['charge'])) {
                return $html;
            }
            return '';
        }
コード例 #5
0
 /**
  * Return instance of this class.
  */
 public static function get_instance()
 {
     // If the single instance hasn't been set, set it now.
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 /**
  * Shortcode to output a number box - [stripe_radio]
  * 
  * @since 2.0.0
  */
 function stripe_radio($attr)
 {
     static $counter = 1;
     global $sc_script_options;
     $attr = shortcode_atts(array('id' => '', 'label' => '', 'default' => '', 'options' => '', 'is_quantity' => 'false', 'amounts' => '', 'is_amount' => 'false'), $attr, 'stripe_radio');
     $id = $attr['id'];
     $label = $attr['label'];
     $default = $attr['default'];
     $options = $attr['options'];
     $is_quantity = $attr['is_quantity'];
     $amounts = $attr['amounts'];
     $is_amount = $attr['is_amount'];
     Shortcode_Tracker::add_new_shortcode('stripe_radio_' . $counter, 'stripe_radio', $attr, false);
     // Check for ID and if it doesn't exist then we will make our own
     if ($id == '') {
         $id = 'sc_cf_radio_' . $counter;
     }
     $options = explode(',', $options);
     if (!empty($amounts)) {
         $amounts = explode(',', str_replace(' ', '', $amounts));
         if (count($options) != count($amounts)) {
             Shortcode_Tracker::update_error_count();
             if (current_user_can('manage_options')) {
                 Shortcode_Tracker::add_error_message('<h6>' . __('Admin note: Your number of options and amounts are not equal.', 'stripe') . '</h6>');
             } else {
                 return '';
             }
         }
     }
     if ($is_amount == 'true') {
         if (current_user_can('manage_options')) {
             echo '<h6>' . sprintf(__('Admin note: The "is_amount" attribute is deprecated and will be removed in an upcoming release. Please use the new "amounts" attribute instead. %s', 'stripe'), '<a href="' . SC_WEBSITE_BASE_URL . 'docs/shortcodes/stripe-custom-fields/" target="_blank">' . __('See Documentation', 'stripe') . '</a>') . '</h6>';
         }
     }
     $quantity_html = 'true' == $is_quantity ? 'data-sc-quantity="true" ' : '';
     $quantity_class = 'true' == $is_quantity ? ' sc-cf-quantity' : '';
     $amount_class = !empty($amounts) || $is_amount == 'true' ? ' sc-cf-amount' : '';
     $html = !empty($label) ? '<label>' . $label . '</label>' : '';
     $html .= '<div class="sc-radio-group">';
     $i = 1;
     foreach ($options as $option) {
         $option = trim($option);
         $value = $option;
         if (empty($default)) {
             $default = $option;
         }
         if ($is_amount == 'true') {
             $currency = strtoupper($sc_script_options['script']['currency']);
             $amount = Stripe_Checkout_Misc::to_formatted_amount($option, $currency);
             if ($currency == 'USD') {
                 $option_name = '$' . $amount;
             } else {
                 $option_name = $amount . ' ' . $currency;
             }
         } else {
             if (!empty($amounts)) {
                 $value = $amounts[$i - 1];
             }
         }
         if ($default == $option && $is_quantity != 'true' && !empty($amounts)) {
             $sc_script_options['script']['amount'] = $value;
         }
         // Don't use built-in checked() function here for now since we need "checked" in double quotes.
         $html .= '<label title="' . esc_attr($option) . '">';
         $html .= '<input type="radio" name="sc_form_field[' . esc_attr($id) . ']" value="' . (isset($option_name) ? $option_name : $option) . '" ' . 'data-sc-price="' . esc_attr($value) . '" ' . ($default == $option ? 'checked="checked"' : '') . ' class="' . esc_attr($id) . '_' . $i . $quantity_class . $amount_class . '" data-parsley-errors-container=".' . apply_filters('sc_form_group_class', 'sc-form-group') . '" ' . $quantity_html . '>';
         $html .= '<span>' . (isset($option_name) ? $option_name : $option) . '</span>';
         $html .= '</label>';
         $i++;
     }
     $html .= '</div>';
     //sc-radio-group
     $attr['currency'] = strtoupper($sc_script_options['script']['currency']);
     $args = $this->get_args($id, $attr, $counter);
     // Incrememnt static counter
     $counter++;
     $this->total_fields();
     return '<div class="' . apply_filters('sc_form_group_class', 'sc-form-group') . '">' . apply_filters('sc_stripe_radio', $html, $args) . '</div>';
 }
コード例 #7
0
 /**
  * Get the instance for all the included classes
  */
 public function init()
 {
     Stripe_Checkout_Scripts::get_instance();
     Stripe_Checkout_Shortcodes::get_instance();
     if (is_admin()) {
         Stripe_Checkout_Admin::get_instance();
         Stripe_Checkout_Upgrade_Link::get_instance();
         Stripe_Checkout_Notices::get_instance();
         Stripe_Checkout_System_Status::get_instance();
     } else {
         Stripe_Checkout_Misc::get_instance();
         Stripe_Checkout_Functions::get_instance();
     }
 }
コード例 #8
0
/**
 * Old SC functions to redirect
 */
function sc_stripe_to_formatted_amount($amount, $currency)
{
    Stripe_Checkout_Misc::to_formatted_amount($amount, $currency);
}
コード例 #9
0
 /**
  * Function to add the custom user amount textbox via shortcode - [stripe_amount]
  * 
  * @since 2.0.0
  */
 function stripe_amount($attr)
 {
     global $sc_script_options, $sc_options;
     static $counter = 1;
     $attr = shortcode_atts(array('label' => !null === $sc_options->get_setting_value('sc_uea_label') ? $sc_options->get_setting_value('sc_uea_label') : '', 'placeholder' => '', 'default' => ''), $attr, 'stripe_amount');
     $label = $attr['label'];
     $placeholder = $attr['placeholder'];
     $default = $attr['default'];
     Shortcode_Tracker::add_new_shortcode('stripe_amount_' . $counter, 'stripe_amount', $attr, false);
     $currency = strtoupper($sc_script_options['script']['currency']);
     $attr['currency'] = $currency;
     if (!empty($default)) {
         $default = Stripe_Checkout_Misc::to_formatted_amount($default, $currency);
     }
     $html = '';
     $html .= !empty($label) ? '<label for="sc_uea_custom_amount_' . $counter . '">' . $label . '</label>' : '';
     $html .= '<div class="sc-uea-container">';
     $currency_args['before'] = $currency === 'USD' ? '$' : '';
     $currency_args['after'] = $currency === 'USD' ? '' : $currency;
     $currency_args = apply_filters('sc_uea_currency', $currency_args);
     $currency_before = $currency_args['before'];
     $currency_after = $currency_args['after'];
     if (!empty($currency_before)) {
         $html .= '<span class="' . apply_filters('sc_uea_currency_class', 'sc-uea-currency') . ' ' . apply_filters('sc_uea_currency_before_class', 'sc-uea-currency-before') . '">' . $currency_before . '</span> ';
     }
     //Stripe minimum amount allowed.
     $stripe_minimum_amount = 50;
     //Get amount to validate based on currency.
     $converted_minimum_amount = Stripe_Checkout_Misc::to_decimal_amount($stripe_minimum_amount, $currency);
     // USD only: Show "50 cents" instead of "50" + currency code.
     // Non-USD: Format and show currency code on right.
     if ($currency === 'USD') {
         $minimum_amount_validation_msg = sprintf(__('Please enter an amount equal to or more than %s cents.', 'sc'), $stripe_minimum_amount);
     } else {
         // Format number with decimals depending on zero-decimal status.
         $minimum_amount_validation_msg = sprintf(__('Please enter an amount equal to or more than %s %s.', 'sc'), $converted_minimum_amount, $currency);
     }
     $minimum_amount_validation_msg = apply_filters('sc_stripe_amount_validation_msg', $minimum_amount_validation_msg, $stripe_minimum_amount, $currency);
     $attr['min_validation_msg'] = $minimum_amount_validation_msg;
     // Include inline Parsley JS validation data attributes.
     // http://parsleyjs.org/doc/index.html#psly-validators-list
     $html .= '<input type="text" class="' . apply_filters('sc_form_control_class', 'sc-form-control') . ' ' . apply_filters('sc_uea_custom_amount_class', 'sc-uea-custom-amount') . '" name="sc_uea_custom_amount" ';
     $html .= 'id="sc_uea_custom_amount_' . $counter . '" value="' . esc_attr($default) . '" placeholder="' . esc_attr($placeholder) . '" ';
     $html .= 'required data-parsley-required-message="Please enter an amount." ';
     $html .= 'data-parsley-type="number" data-parsley-type-message="Please enter a valid amount. Do not include a currency symbol." ';
     $html .= 'data-parsley-min="' . $converted_minimum_amount . '" data-parsley-min-message="' . $minimum_amount_validation_msg . '" ';
     // Point to custom container for errors so we can place the non-USD currencies on the right of the input box.
     $html .= 'data-parsley-errors-container="#sc_uea_custom_amount_errors_' . $counter . '">';
     if (!empty($currency_after)) {
         $html .= ' <span class="' . apply_filters('sc_uea_currency_class', 'sc-uea-currency') . ' ' . apply_filters('sc_uea_currency_after_class', 'sc-uea-currency-after') . '">' . $currency_after . '</span>';
     }
     // Custom validation errors container for UEA.
     // Needs counter ID specificity to match input above.
     $html .= '<div id="sc_uea_custom_amount_errors_' . $counter . '"></div>';
     $html .= '</div>';
     //sc-uea-container
     $args = $this->get_args('', $attr, $counter);
     $counter++;
     if (!isset($_GET['charge'])) {
         return '<div class="' . apply_filters('sc_form_group_class', 'sc-form-group') . '">' . apply_filters('sc_stripe_amount', $html, $args) . '</div>';
     }
     return '';
 }
コード例 #10
0
 /**
  * Get the instance for all the included classes.
  * Overrides SP Lite init().
  */
 public function init()
 {
     Stripe_Checkout_Scripts::get_instance();
     Stripe_Checkout_Shortcodes::get_instance();
     if (is_admin()) {
         Stripe_Checkout_Admin::get_instance();
         Stripe_Checkout_Pro_Admin::get_instance();
         Stripe_Checkout_Pro_Licenses::get_instance();
         Stripe_Checkout_Notices::get_instance();
         Stripe_Checkout_System_Status::get_instance();
     } else {
         Stripe_Checkout_Misc::get_instance();
     }
     // Need to leave outside of is_admin check or the AJAX will not work properly
     Stripe_Checkout_Pro_Functions::get_instance();
 }
 /**
  * [stripe_recurring_total] shortcode.
  */
 public function recurring_total($attr)
 {
     global $sc_script_options;
     static $counter = 1;
     $attr = shortcode_atts(array('label' => __('Recurring payment:', 'sc_sub') . ' '), $attr, 'stripe_recurring_total');
     $label = $attr['label'];
     $currency = strtoupper($sc_script_options['script']['currency']);
     $amount = $sc_script_options['script']['amount'];
     $setup_fee = isset($sc_script_options['script']['setupFee']) ? $sc_script_options['script']['setupFee'] : 0;
     Shortcode_Tracker::add_new_shortcode('stripe_recurring_total_' . $counter, 'stripe_total', $attr, false);
     $html = $label . ' ';
     $html .= '<span class="' . apply_filters('sc_recurring_total_amount_class', 'sc-recurring-total-amount') . '">';
     // USD only: Show dollar sign on left of amount.
     if ($currency === 'USD') {
         $html .= '$';
     }
     $html .= Stripe_Checkout_Misc::to_formatted_amount($amount + $setup_fee, $currency);
     // Non-USD: Show currency on right of amount.
     if ($currency !== 'USD') {
         $html .= ' ' . $currency;
     }
     $html .= '</span>';
     //sc-recurring-total-amount
     $counter++;
     // Set args to send with filter
     $args = array();
     $args['label'] = $label;
     $args['currency'] = $currency;
     $args['amount'] = $amount;
     $args['setup_fee'] = $setup_fee;
     return '<div class="' . apply_filters('sc_form_group_class', 'sc-form-group') . '">' . apply_filters('sc_stripe_recurring_total', $html, $args) . '</div>';
 }