• 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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 
<?php

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

/**
 *
 * @since 3.1.0
 * @author PaymentPlugins
 * @package Stripe/Abstract
 *
 */
abstract class WC_Stripe_Payment {

    /**
     *
     * @var WC_Payment_Gateway_Stripe
     */
    protected $payment_method;

    /**
     *
     * @var WC_Stripe_Gateway
     */
    protected $gateway;

    /**
     *
     * @param WC_Payment_Gateway_Stripe $payment_method
     * @param WC_Stripe_Gateway         $gateway
     */
    public function __construct( $payment_method, $gateway ) {
        $this->payment_method = $payment_method;
        $this->gateway        = $gateway;
    }

    public function get_gateway() {
        return $this->gateway;
    }

    /**
     * Process the payment for the order.
     *
     * @param WC_Order                  $order
     * @param WC_Payment_Gateway_Stripe $payment_method
     */
    public abstract function process_payment( $order );

    /**
     *
     * @param float    $amount
     * @param WC_Order $order
     *
     * @return \Stripe\Charge
     */
    public abstract function capture_charge( $amount, $order );

    /**
     *
     * @param WC_Order $order
     */
    public abstract function void_charge( $order );

    /**
     *
     * @param \Stripe\Charge $charge
     */
    public abstract function get_payment_method_from_charge( $charge );

    /**
     *
     * @param array    $args
     * @param WC_Order $order
     */
    public abstract function add_order_payment_method( &$args, $order );

    /**
     *
     * @param float    $amount
     * @param WC_Order $order
     */
    public abstract function scheduled_subscription_payment( $amount, $order );

    /**
     *
     * @param WC_Order $order
     */
    public abstract function process_pre_order_payment( $order );

    /**
     * Return true if the charge can be voided.
     *
     * @param WC_Order $order
     */
    public abstract function can_void_order( $order );

    /**
     * Perform post payment processes
     *
     * @param WC_Order       $order
     * @param \Stripe\Charge $charge
     *
     * @since 3.1.7
     */
    public function payment_complete( $order, $charge ) {
        WC_Stripe_Utils::add_balance_transaction_to_order( $charge, $order );
        $this->payment_method->save_order_meta( $order, $charge );
        if ( 'pending' === $charge->status ) {
            $order->update_status( apply_filters( 'wc_stripe_pending_charge_status', 'on-hold', $order, $this->payment_method ),
                sprintf( __( 'Charge %1$s is pending. Payment Method: %2$s. Payment will be completed once charge.succeeded webhook received from Stripe.', 'woo-stripe-payment' ),
                    $order->get_transaction_id(),
                    $order->get_payment_method_title() ) );
        } else {
            if ( $charge->captured ) {
                $order->payment_complete( $charge->id );
            } else {
                $order_status = $this->payment_method->get_option( 'order_status' );
                $order->update_status( apply_filters( 'wc_stripe_authorized_order_status', 'default' === $order_status ? 'on-hold' : $order_status, $order, $this->payment_method ) );
            }
            $order->add_order_note( sprintf( __( 'Order %1$s successful in Stripe. Charge: %2$s. Payment Method: %3$s', 'woo-stripe-payment' ),
                $charge->captured ? __( 'charge', 'woo-stripe-payment' ) : __( 'authorization', 'woo-stripe-payment' ),
                $order->get_transaction_id(),
                $order->get_payment_method_title() ) );
        }

        /**
         * @since 3.3.6
         */
        do_action( 'wc_stripe_order_payment_complete', $charge, $order );
    }

    /**
     *
     * @param WC_Order $order
     * @param float    $amount
     *
     * @throws Exception
     */
    public function process_refund( $order, $amount = null ) {
        $charge = $order->get_transaction_id();
        try {
            if ( empty( $charge ) ) {
                throw new Exception( __( 'Transaction Id cannot be empty.', 'woo-stripe-payment' ) );
            }

            /**
             * @param array
             * @param WC_Stripe_Payment
             * @param WC_Order $order
             * @param float    $amount
             *
             * @since 3.2.10
             */
            $args   = apply_filters( 'wc_stripe_refund_args', array(
                'charge'   => $charge,
                'amount'   => wc_stripe_add_number_precision( $amount, $order->get_currency() ),
                'metadata' => array(
                    'order_id'    => $order->get_id(),
                    'created_via' => 'woocommerce'
                ),
                'expand'   => stripe_wc()->advanced_settings->is_fee_enabled() ? array( 'charge.balance_transaction', 'charge.refunds.data.balance_transaction' ) : array()
            ), $this, $order, $amount );
            $result = $this->gateway->refunds->mode( wc_stripe_order_mode( $order ) )->create( $args );
            if ( ! is_wp_error( $result ) ) {
                WC_Stripe_Utils::add_balance_transaction_to_order( $result->charge, $order, true );

                return true;
            }

            return $result;
        }
        catch ( Exception $e ) {
            return new WP_Error( 'refund-error', $e->getMessage() );
        }
    }

    /**
     * @param WC_Order                  $order
     * @param WC_Payment_Gateway_Stripe $payment_method
     *
     * @since 3.3.8
     */
    public function process_zero_total_order( $order, $payment_method ) {
        $payment_method->save_zero_total_meta( $order );
        if ( 'capture' === $payment_method->get_option( 'charge_type' ) ) {
            $order->payment_complete();
        } else {
            $order_status = $payment_method->get_option( 'order_status' );
            $order->update_status( apply_filters( 'wc_stripe_authorized_order_status', 'default' === $order_status ? 'on-hold' : $order_status, $order, $payment_method ) );
        }
        WC()->cart->empty_cart();

        return array(
            'result'   => 'success',
            'redirect' => $payment_method->get_return_url( $order ),
        );
    }

    /**
     * Return a failed order response.
     *
     * @return array
     */
    public function order_error() {
        wc_stripe_set_checkout_error();

        return array( 'result' => 'failure' );
    }

    /**
     *
     * @param array    $args
     * @param WC_Order $order
     */
    public function add_general_order_args( &$args, $order ) {
        $this->add_order_amount( $args, $order );
        $this->add_order_currency( $args, $order );
        $this->add_order_description( $args, $order );
        $this->add_order_shipping_address( $args, $order );
        $this->add_order_metadata( $args, $order );
        $this->add_order_payment_method( $args, $order );
    }

    /**
     *
     * @param array    $args
     * @param WC_Order $order
     */
    public function add_order_metadata( &$args, $order ) {
        $meta_data = array(
            'gateway_id' => $order->get_payment_method(),
            'order_id'   => $order->get_id(),
            'user_id'    => $order->get_user_id(),
            'ip_address' => $order->get_customer_ip_address(),
            'user_agent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'unavailable',
            'partner'    => 'PaymentPlugins',
            'created'    => time()
        );
        if ( has_action( 'woocommerce_order_number' ) ) {
            $meta_data['order_number'] = $order->get_order_number();
        }
        $length = count( $meta_data );

        foreach ( $order->get_items( 'line_item' ) as $item ) {
            // Stripe limits metadata keys to 50 entries.
            if ( $length < 50 ) {
                /**
                 *
                 * @var WC_Order_Item_Product $item
                 */
                $key   = 'product_' . $item->get_product_id();
                $value = sprintf( '%s x %s', $item->get_name(), $item->get_quantity() );
                // Stripe limits key names to 40 chars and values to 500 chars
                if ( strlen( $key ) <= 40 && strlen( $value ) <= 500 ) {
                    $meta_data[ $key ] = $value;
                    $length ++;
                }
            }
        }
        $args['metadata'] = apply_filters( 'wc_stripe_order_meta_data', $meta_data, $order );
    }

    /**
     *
     * @param array    $args
     * @param WC_Order $order
     */
    public function add_order_description( &$args, $order ) {
        $args['description'] = sprintf( __( 'Order %1$s from %2$s', 'woo-stripe-payment' ), $order->get_order_number(), get_bloginfo( 'name' ) );
    }

    /**
     *
     * @param array    $args
     * @param WC_Order $order
     * @param float    $amount
     */
    public function add_order_amount( &$args, $order, $amount = null ) {
        $args['amount'] = wc_stripe_add_number_precision( $amount ? $amount : $order->get_total(), $order->get_currency() );
    }

    /**
     *
     * @param array    $args
     * @param WC_Order $order
     */
    public function add_order_currency( &$args, $order ) {
        $args['currency'] = $order->get_currency();
    }

    /**
     *
     * @param array    $args
     * @param WC_Order $order
     */
    public function add_order_shipping_address( &$args, $order ) {
        if ( wc_stripe_order_has_shipping_address( $order ) ) {
            $args['shipping'] = array(
                'address' => array(
                    'city'        => $order->get_shipping_city(),
                    'country'     => $order->get_shipping_country(),
                    'line1'       => $order->get_shipping_address_1(),
                    'line2'       => $order->get_shipping_address_2(),
                    'postal_code' => $order->get_shipping_postcode(),
                    'state'       => $order->get_shipping_state(),
                ),
                'name'    => $this->get_name_from_order( $order, 'shipping' ),
            );
        } else {
            $args['shipping'] = array();
        }
    }

    /**
     *
     * @param WC_Order $order
     * @param string   $type
     *
     * @return string
     */
    public function get_name_from_order( $order, $type ) {
        if ( $type === 'billing' ) {
            return sprintf( '%s %s', $order->get_billing_first_name(), $order->get_billing_last_name() );
        } else {
            return sprintf( '%s %s', $order->get_shipping_first_name(), $order->get_shipping_last_name() );
        }
    }

    /**
     * @param WC_Order $order
     * @param WP_Error $error
     *
     * @since 3.1.7
     */
    public function add_payment_failed_note( $order, $error ) {
        $note = sprintf( __( 'Error processing payment. Reason: %s', 'woo-stripe-payment' ), $error->get_error_message() );

        /**
         * @param string   $note
         * @param WP_Error $error
         *
         */
        $note = apply_filters( 'wc_stripe_order_failed_note', $note, $error, $this->payment_method );
        $order->update_status( 'failed', $note );
    }

    /**
     * @param $payment_method
     *
     * @since 3.3.3
     */
    public function set_payment_method( $payment_method ) {
        $this->payment_method = $payment_method;
    }

}
Stripe API documentation generated by ApiGen