• 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 
<?php

/**
 * @since 3.3.13
 */
class WC_Stripe_Utils {

    /**
     * @param WC_Order $data
     */
    public static function display_fee( $order ) {
        return self::display_amount( 'fee', $order );
    }

    /**
     * @param WC_Order $order
     *
     * @return string
     */
    public static function display_net( $order ) {
        return self::display_amount( 'net', $order );
    }

    /**
     * @param WC_Order $order
     *
     * @return string
     */
    private static function display_amount( $type, $order ) {
        $payment_balance = self::get_payment_balance( $order );
        if ( $payment_balance && isset( $payment_balance->{$type}, $payment_balance->currency ) && is_numeric( $payment_balance->{$type} ) ) {
            if ( $type === 'fee' ) {
                $amount = - 1 * $payment_balance->fee;
            } else {
                $amount = $payment_balance->net;
            }

            return wc_price( $amount, array( 'currency' => $payment_balance->currency ) );
        }

        return '';
    }

    /**
     * @param \Stripe\Charge $charge
     * @param \WC_Order      $order
     * @param bool           $save
     */
    public static function add_balance_transaction_to_order( $charge, $order, $save = false ) {
        if ( isset( $charge->balance_transaction ) && is_object( $charge->balance_transaction ) ) {
            $display_order_currency = stripe_wc()->advanced_settings->is_display_order_currency();
            $balance_transaction    = $charge->balance_transaction;
            $exchange_rate          = $balance_transaction->exchange_rate === null ? 1 : $balance_transaction->exchange_rate;
            $amount_refunded        = $display_order_currency ? $charge->amount_refunded : $charge->amount_refunded * $exchange_rate;
            // the balance_transaction_net already has the fee deducted from it.
            $net                       = $display_order_currency ? $balance_transaction->net / $exchange_rate : $balance_transaction->net;
            $net                       = wc_format_decimal( $net - $amount_refunded, 4 );
            $fee                       = $display_order_currency ? wc_format_decimal( $balance_transaction->fee / $exchange_rate, 4 ) : $balance_transaction->fee;
            $currency                  = $display_order_currency ? $order->get_currency() : strtoupper( $balance_transaction->currency );
            $payment_balance           = new WC_Stripe_Payment_Balance( $order );
            $payment_balance->currency = $currency;
            $payment_balance->fee      = wc_stripe_remove_number_precision( $fee, $currency, true, 4 );
            $payment_balance->net      = wc_stripe_remove_number_precision( $net, $currency, true, 4 );
            if ( $charge->refunds->count() > 0 ) {
                foreach ( $charge->refunds->data as $refund ) {
                    /**
                     * @var \Stripe\Refund $refund
                     */
                    if ( is_object( $refund->balance_transaction ) ) {
                        self::update_balance_transaction( $refund->balance_transaction, $order, false, $payment_balance );
                    }
                }
            }
            $payment_balance->update_meta_data( $save );
        }
    }

    /**
     * @param \Stripe\BalanceTransaction $balance_transaction
     * @param \WC_Order                  $order
     */
    public static function update_balance_transaction( $balance_transaction, $order, $save = false, $payment_balance = null ) {
        if ( $balance_transaction->reporting_category === 'partial_capture_reversal' ) {
            $payment_balance = $payment_balance ? $payment_balance : self::get_payment_balance( $order );
            if ( $payment_balance ) {
                $exchange_rate          = $balance_transaction->exchange_rate === null ? 1 : $balance_transaction->exchange_rate;
                $display_order_currency = stripe_wc()->advanced_settings->is_display_order_currency() && $payment_balance->currency !== strtoupper( $balance_transaction->currency );
                $currency               = $display_order_currency ? $order->get_currency() : strtoupper( $balance_transaction->currency );
                // fee is negative here since it's a reversal, that's why for net we subtract and for fee we add.
                $fee                  = $display_order_currency ? $balance_transaction->fee / $exchange_rate : $balance_transaction->fee;
                $fee                  = wc_stripe_remove_number_precision( $fee, $currency, true, 4 );
                $payment_balance->net = $payment_balance->net - $fee;
                $payment_balance->fee = $payment_balance->fee + $fee;
                $payment_balance->update_meta_data( $save );
            }
        }
    }

    /**
     * @param WC_Order $order
     *
     * @return \WC_Stripe_Payment_Balance|null
     */
    private static function get_payment_balance( $order ) {
        return new WC_Stripe_Payment_Balance( $order );
    }

    /**
     * @param $value
     *
     * @since 3.3.14
     * @return string
     */
    public static function sanitize_statement_descriptor( $value ) {
        return trim( str_replace( array( '<', '>', '\\', '\'', '"', '*' ), '', $value ) );
    }

}
Stripe API documentation generated by ApiGen