• Namespace
  • Class
  • Tree
  • Deprecated
  • Hook Reference

Namespaces

  • None
  • PaymentPlugins

Classes

  • PaymentPlugins\WC_Stripe_Admin_Meta_Box_Product_Data
  • PaymentPlugins\WC_Stripe_Admin_Notices
  • WC_Payment_Gateway_Stripe
  • WC_Payment_Gateway_Stripe_ACH
  • WC_Payment_Gateway_Stripe_Afterpay
  • WC_Payment_Gateway_Stripe_Alipay
  • WC_Payment_Gateway_Stripe_ApplePay
  • WC_Payment_Gateway_Stripe_Bancontact
  • WC_Payment_Gateway_Stripe_BECS
  • WC_Payment_Gateway_Stripe_Boleto
  • WC_Payment_Gateway_Stripe_CC
  • WC_Payment_Gateway_Stripe_EPS
  • WC_Payment_Gateway_Stripe_FPX
  • WC_Payment_Gateway_Stripe_Giropay
  • WC_Payment_Gateway_Stripe_GooglePay
  • WC_Payment_Gateway_Stripe_GrabPay
  • WC_Payment_Gateway_Stripe_Ideal
  • WC_Payment_Gateway_Stripe_Klarna
  • WC_Payment_Gateway_Stripe_Local_Payment
  • WC_Payment_Gateway_Stripe_Multibanco
  • WC_Payment_Gateway_Stripe_OXXO
  • WC_Payment_Gateway_Stripe_P24
  • WC_Payment_Gateway_Stripe_Payment_Request
  • WC_Payment_Gateway_Stripe_Sepa
  • WC_Payment_Gateway_Stripe_Sofort
  • WC_Payment_Gateway_Stripe_WeChat
  • WC_Payment_Token_Stripe
  • WC_Payment_Token_Stripe_ACH
  • WC_Payment_Token_Stripe_ApplePay
  • WC_Payment_Token_Stripe_CC
  • WC_Payment_Token_Stripe_GooglePay
  • WC_Payment_Token_Stripe_Local
  • WC_Payment_Token_Stripe_Sepa
  • WC_Stripe_Account_Settings
  • WC_Stripe_Admin_Assets
  • WC_Stripe_Admin_Menus
  • WC_Stripe_Admin_Order_Metaboxes
  • WC_Stripe_Admin_Settings
  • WC_Stripe_Admin_User_Edit
  • WC_Stripe_Advanced_Settings
  • WC_Stripe_API_Operation
  • WC_Stripe_API_Request_Filter
  • WC_Stripe_API_Settings
  • WC_Stripe_Constants
  • WC_Stripe_Controller_Cart
  • WC_Stripe_Controller_Checkout
  • WC_Stripe_Controller_Gateway_Settings
  • WC_Stripe_Controller_GooglePay
  • WC_Stripe_Controller_Order_Actions
  • WC_Stripe_Controller_Payment_Intent
  • WC_Stripe_Controller_Payment_Method
  • WC_Stripe_Controller_Plaid
  • WC_Stripe_Controller_Product_Data
  • WC_Stripe_Controller_Source
  • WC_Stripe_Controller_Webhook
  • WC_Stripe_Customer_Manager
  • WC_Stripe_Field_Manager
  • WC_Stripe_Frontend_Scripts
  • WC_Stripe_Gateway
  • WC_Stripe_Gateway_Conversion
  • WC_Stripe_Install
  • WC_Stripe_Manager
  • WC_Stripe_Payment
  • WC_Stripe_Payment_Balance
  • WC_Stripe_Payment_Charge
  • WC_Stripe_Payment_Charge_Local
  • WC_Stripe_Payment_Factory
  • WC_Stripe_Payment_Intent
  • WC_Stripe_Product_Gateway_Option
  • WC_Stripe_Product_Option
  • WC_Stripe_Redirect_Handler
  • WC_Stripe_Rest_API
  • WC_Stripe_Rest_Controller
  • WC_Stripe_Settings_API
  • WC_Stripe_Shortcode_Payment_Buttons
  • WC_Stripe_Shortcodes
  • WC_Stripe_Update
  • WC_Stripe_Utils

Traits

  • WC_Payment_Token_Payment_Method_Trait
  • WC_Payment_Token_Source_Trait
  • WC_Stripe_Controller_Cart_Trait
  • WC_Stripe_Controller_Frontend_Trait
  • WC_Stripe_Local_Payment_Charge_Trait
  • WC_Stripe_Local_Payment_Intent_Trait
  • WC_Stripe_Payment_Charge_Trait
  • WC_Stripe_Payment_Intent_Trait
  • WC_Stripe_Settings_Trait

Functions

  • stripe_wc
  • wc_stripe_add_allowed_html
  • wc_stripe_add_number_precision
  • wc_stripe_api_options
  • wc_stripe_available_payment_gateways
  • wc_stripe_charge_dispute_closed
  • wc_stripe_charge_dispute_created
  • wc_stripe_credit_card_labels
  • wc_stripe_delete_customer
  • wc_stripe_display_prices_including_tax
  • wc_stripe_filter_address_state
  • wc_stripe_filter_order_id
  • wc_stripe_get_account_id
  • wc_stripe_get_available_local_gateways
  • wc_stripe_get_checkout_fields
  • wc_stripe_get_currencies
  • wc_stripe_get_current_page
  • wc_stripe_get_custom_forms
  • wc_stripe_get_customer_id
  • wc_stripe_get_customer_payment_tokens
  • wc_stripe_get_display_items
  • wc_stripe_get_error_messages
  • wc_stripe_get_idempotency_key
  • wc_stripe_get_local_payment_params
  • wc_stripe_get_order_from_source_id
  • wc_stripe_get_order_from_transaction
  • wc_stripe_get_publishable_key
  • wc_stripe_get_secret_key
  • wc_stripe_get_shipping_options
  • wc_stripe_get_site_locale
  • wc_stripe_get_template
  • wc_stripe_get_template_html
  • wc_stripe_hidden_field
  • wc_stripe_log
  • wc_stripe_log_error
  • wc_stripe_log_info
  • wc_stripe_mode
  • wc_stripe_order_cancelled
  • wc_stripe_order_has_shipping_address
  • wc_stripe_order_mode
  • wc_stripe_order_status_completed
  • wc_stripe_output_checkout_error
  • wc_stripe_payment_complete_order_status
  • wc_stripe_payment_gateways
  • wc_stripe_payment_intent_field
  • wc_stripe_pre_orders_active
  • wc_stripe_process_charge_failed
  • wc_stripe_process_charge_succeeded
  • wc_stripe_process_create_refund
  • wc_stripe_process_payment_intent_succeeded
  • wc_stripe_process_shop_subscription_meta
  • wc_stripe_process_source_chargeable
  • wc_stripe_remove_number_precision
  • wc_stripe_remove_order_locks
  • wc_stripe_restore_cart
  • wc_stripe_restore_cart_after_product_checkout
  • wc_stripe_retry_source_chargeable
  • wc_stripe_review_closed
  • wc_stripe_review_opened
  • wc_stripe_save_customer
  • wc_stripe_set_checkout_error
  • wc_stripe_set_idempotency_key
  • wc_stripe_shipping_address_serviceable
  • wc_stripe_stash_cart
  • wc_stripe_stash_product_cart
  • wc_stripe_token_field
  • wc_stripe_update_customer_location
  • wc_stripe_update_option_3_3_13
  • wc_stripe_update_shipping_methods
  • wc_stripe_woocommerce_payment_token_deleted
  • wcs_stripe_active
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 
<?php

defined( 'ABSPATH' ) || exit();

/**
 *
 * @author  PaymentPlugins
 * @package Stripe/Classes
 *
 */
class WC_Stripe_Redirect_Handler {

    public static function init() {
        add_action( 'wp', array( __CLASS__, 'local_payment_redirect' ) );
        add_action( 'get_header', array( __CLASS__, 'maybe_restore_cart' ), 100 );
    }

    /**
     * Check if this request is for a local payment redirect.
     */
    public static function local_payment_redirect() {
        if ( isset( $_GET['_stripe_local_payment'] ) ) {
            self::process_redirect();
        } elseif ( isset( $_GET['_stripe_voucher_payment'], $_GET['order-id'] ) ) {
            self::process_voucher_redirect();
        }
    }

    /**
     */
    public static function process_redirect() {
        if ( isset( $_GET['source'] ) ) {
            $result        = WC_Stripe_Gateway::load()->sources->retrieve( wc_clean( $_GET['source'] ) );
            $client_secret = isset( $_GET['client_secret'] ) ? $_GET['client_secret'] : '';
        } else {
            $result        = WC_Stripe_Gateway::load()->paymentIntents->retrieve( wc_clean( $_GET['payment_intent'] ) );
            $client_secret = isset( $_GET['payment_intent_client_secret'] ) ? $_GET['payment_intent_client_secret'] : '';
        }
        if ( is_wp_error( $result ) ) {
            wc_add_notice( sprintf( __( 'Error retrieving payment source. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ), 'error' );
        } elseif ( ! hash_equals( $client_secret, $result->client_secret ) ) {
            wc_add_notice( __( 'This request is invalid. Please try again.', 'woo-stripe-payment' ), 'error' );
        } else {
            define( WC_Stripe_Constants::REDIRECT_HANDLER, true );
            $order_id = $result->metadata['order_id'];
            $order    = wc_get_order( wc_stripe_filter_order_id( $order_id, $result ) );

            /**
             *
             * @var WC_Payment_Gateway_Stripe_Local_Payment $payment_method
             */
            $payment_method = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
            $redirect       = $payment_method->get_return_url( $order );

            if ( in_array( $result->status, array( 'requires_action', 'pending' ) ) ) {
                if ( $result->status === 'pending' ) {
                    $order->update_status( 'on-hold' );
                } else {
                    return;
                }
            } elseif ( in_array( $result->status, array( 'requires_payment_method', 'failed' ) ) ) {
                wc_add_notice( __( 'Payment authorization failed. Please select another payment method.', 'woo-stripe-payment' ), 'error' );
                if ( $result instanceof \Stripe\PaymentIntent ) {
                    $order->update_meta_data( WC_Stripe_Constants::PAYMENT_INTENT, $result->jsonSerialize() );
                } else {
                    $order->delete_meta_data( WC_Stripe_Constants::SOURCE_ID );
                }
                $order->update_status( 'failed', __( 'Payment authorization failed.', 'woo-stripe-payment' ) );

                return;
            } elseif ( 'chargeable' === $result->status ) {
                if ( ! $payment_method->has_order_lock( $order ) && ! $order->get_transaction_id() ) {
                    $payment_method->set_order_lock( $order );
                    $payment_method->set_new_source_token( $result->id );
                    $result = $payment_method->process_payment( $order_id );
                    // we don't release the order lock so there aren't conflicts with the source.chargeable webhook
                    if ( $result['result'] === 'success' ) {
                        $redirect = $result['redirect'];
                    }
                }
            } elseif ( in_array( $result->status, array( 'succeeded', 'requires_capture' ) ) ) {
                if ( ! $payment_method->has_order_lock( $order ) ) {
                    $payment_method->set_order_lock( $order );
                    $result = $payment_method->process_payment( $order_id );
                    if ( $result['result'] === 'success' ) {
                        $redirect = $result['redirect'];
                    }
                }
            }
            wp_safe_redirect( $redirect );
            exit();
        }
    }

    public static function maybe_restore_cart() {
        global $wp;
        if ( isset( $wp->query_vars['order-received'] ) && isset( $_GET['wc_stripe_product_checkout'] ) ) {
            add_action( 'woocommerce_cart_emptied', 'wc_stripe_restore_cart_after_product_checkout' );
        }
    }

    private static function process_voucher_redirect() {
        $payment_method = wc_clean( $_GET['_stripe_voucher_payment'] );
        /**
         * @var \WC_Payment_Gateway_Stripe $payment_method
         */
        $payment_method = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
        $order          = wc_get_order( absint( wc_clean( $_GET['order-id'] ) ) );
        $order_key      = isset( $_GET['order-key'] ) ? wc_clean( wp_unslash( $_GET['order-key'] ) ) : '';
        if ( $order && hash_equals( $order->get_order_key(), $order_key ) ) {
            if ( method_exists( $payment_method, 'process_voucher_order_status' ) ) {
                $payment_method->process_voucher_order_status( $order );
                wp_safe_redirect( $payment_method->get_return_url( $order ) );
                exit();
            }
        }
    }

}

WC_Stripe_Redirect_Handler::init();
Stripe API documentation generated by ApiGen