• 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 
<?php

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

/**
 *
 * @author PaymentPlugins
 * @package Stripe/Classes
 * @property WC_Stripe_Rest_Controller $order_actions
 * @property WC_Stripe_Rest_Controller $cart
 * @property WC_Stripe_Rest_Controller $checkout
 * @property WC_Stripe_Rest_Controller $payment_intent
 * @property WC_Stripe_Rest_Controller $googlepay
 * @property WC_Stripe_Rest_Controller $settings
 * @property WC_Stripe_Rest_Controller $webhook
 * @property WC_Stripe_Rest_Controller $product_data
 * @property WC_Stripe_Rest_Controller $plaid
 * @property WC_Stripe_Rest_Controller $source
 */
class WC_Stripe_Rest_API {

    /**
     *
     * @var array
     */
    private $controllers = array();

    public function __construct() {
        $this->include_classes();
        add_action( 'wc_ajax_wc_stripe_frontend_request', array( $this, 'process_frontend_request' ) );
        add_action( 'rest_api_init', array( $this, 'register_routes' ) );
        add_action( 'wp_ajax_wc_stripe_admin_request', array( $this, 'process_frontend_request' ) );
    }

    /**
     *
     * @param string $key
     *
     * @return WC_Stripe_Rest_Controller
     */
    public function __get( $key ) {
        $controller = isset( $this->controllers[ $key ] ) ? $this->controllers[ $key ] : '';
        if ( empty( $controller ) ) {
            wc_doing_it_wrong( __FUNCTION__,
                sprintf( __( '%1$s is an invalid controller name.', 'woo-stripe-payment' ), $key ),
                stripe_wc()->version );
        }

        return $controller;
    }

    public function __set( $key, $value ) {
        $this->controllers[ $key ] = $value;
    }

    private function include_classes() {
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-stripe-rest-controller.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-order-actions.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-payment-intent.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-cart.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-checkout.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-googlepay.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-payment-method.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-gateway-settings.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-webhook.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-product-data.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-plaid.php';
        include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-source.php';

        foreach ( $this->get_controllers() as $key => $class_name ) {
            if ( class_exists( $class_name ) ) {
                $this->{$key} = new $class_name();
            }
        }
    }

    public function register_routes() {
        if ( self::is_rest_api_request() ) {
            foreach ( $this->controllers as $key => $controller ) {
                if ( is_callable( array( $controller, 'register_routes' ) ) ) {
                    $controller->register_routes();
                }
            }
        }
    }

    public function get_controllers() {
        $controllers = array(
            'order_actions'  => 'WC_Stripe_Controller_Order_Actions',
            'checkout'       => 'WC_Stripe_Controller_Checkout',
            'cart'           => 'WC_Stripe_Controller_Cart',
            'payment_intent' => 'WC_Stripe_Controller_Payment_Intent',
            'googlepay'      => 'WC_Stripe_Controller_GooglePay',
            'payment_method' => 'WC_Stripe_Controller_Payment_Method',
            'settings'       => 'WC_Stripe_Controller_Gateway_Settings',
            'webhook'        => 'WC_Stripe_Controller_Webhook',
            'product_data'   => 'WC_Stripe_Controller_Product_Data',
            'plaid'          => 'WC_Stripe_Controller_Plaid',
            'source'         => 'WC_Stripe_Controller_Source'
        );

        /**
         * @param string[] $controllers
         */
        return apply_filters( 'wc_stripe_api_controllers', $controllers );
    }

    /**
     * @return string
     */
    public function rest_url() {
        return stripe_wc()->rest_url();
    }

    /**
     * @return string
     */
    public function rest_uri() {
        return stripe_wc()->rest_uri();
    }

    /**
     * @return bool
     */
    public static function is_rest_api_request() {
        global $wp;
        if ( ! empty( $wp->query_vars['rest_route'] ) && strpos( $wp->query_vars['rest_route'], stripe_wc()->rest_uri() ) !== false ) {
            return true;
        }
        if ( ! empty( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], stripe_wc()->rest_uri() ) !== false ) {
            return true;
        }

        return false;
    }

    /**
     * Return true if this is a WP rest request. This function is a wrapper for WC()->is_rest_api_request()
     * if it exists.
     *
     * @since 3.2.7
     * @return bool
     */
    public static function is_wp_rest_request() {
        if ( function_exists( 'WC' ) && property_exists( WC(), 'is_rest_api_request' ) ) {
            return WC()->is_rest_api_request();
        }

        return ! empty( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], trailingslashit( rest_get_url_prefix() ) ) !== false;
    }

    /**
     * @since 3.2.7
     */
    public function process_frontend_request() {
        if ( isset( $_GET['path'] ) ) {
            global $wp;
            $wp->set_query_var( 'rest_route', sanitize_text_field( $_GET['path'] ) );
            rest_api_loaded();
        }
    }

    /**
     * Return an endpoint for ajax requests that integrate with the WP Rest API.
     *
     * @param string $path
     *
     * @since 3.2.7
     * @return string
     */
    public static function get_endpoint( $path ) {
        if ( version_compare( WC()->version, '3.2.0', '<' ) ) {
            $endpoint = esc_url_raw( apply_filters( 'woocommerce_ajax_get_endpoint',
                add_query_arg( 'wc-ajax',
                    'wc_stripe_frontend_request',
                    remove_query_arg( array(
                        'remove_item',
                        'add-to-cart',
                        'added-to-cart',
                        'order_again',
                        '_wpnonce'
                    ), home_url( '/', 'relative' ) ) ),
                'wc_stripe_frontend_request' ) );
        } else {
            $endpoint = WC_AJAX::get_endpoint( 'wc_stripe_frontend_request' );
        }

        return add_query_arg( 'path', '/' . trim( $path, '/' ), $endpoint );
    }

    public static function get_admin_endpoint( $path ) {
        $url = admin_url( 'admin-ajax.php' );

        return add_query_arg( array( 'action' => 'wc_stripe_admin_request', 'path' => '/' . trim( $path, '/' ) ), $url );
    }

}
Stripe API documentation generated by ApiGen