• 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  357  358  359  360  361  362  363  364  365  366  367  368  369  370  371  372  373  374  375  376  377  378  379  380  381  382  383  384  385  386  387  388  389  390  391  392  393  394  395  396  397  398  399  400  401  402  403  404  405  406  407  408  409  410  411  412  413  414  415  416  417  418  419  420  421  422  423  424  425  426  427  428  429  430  431  432  433  434  435  436  437  438  439  440  441  442  443  444  445  446  447  448  449  450  451  452  453  454  455  456  457  458  459  460  461  462  463  464  465  466  467  468  469  470  471  472  473  474  475  476  477  478  479  480  481  482  483  484  485  486  487  488  489  490  491  492  493  494  495  496  497  498  499  500  501  502  503  504  505  506  507  508  509  510  511  512  513  514  515  516  517  518  519  520  521  522  523  524  525  526  527  528  529  530  531  532  533  534  535  536  537  538  539  540  541  542  543  544  545  546  547  548  549  550  551  552  553  554  555  556  557  558  559  560  561  562  563  564  565  566  567  568  569  570  571  572  573  574  575  576  577  578  579  580  581  582  583  584  585  586  587  588  589  590  591  592  593  594  595  596  597  598  599  600  601  602  603  604  605  606  607  608  609  610  611  612  613  614  615  616  617  618  619  620  621  622  623  624  625  626  627  628  629  630  631  632  633  634  635  636  637  638  639  640  641  642  643  644  645  646  647  648  649  650  651  652  653  654  655  656  657  658  659  660  661  662  663  664  665  666  667  668  669  670  671  672  673  674  675  676  677  678  679  680  681  682  683  684  685  686  687  688  689  690  691  692  693  694  695  696  697  698  699  700  701  702  703  704  705  706  707  708  709  710  711  712  713  714  715  716  717  718  719  720  721  722  723  724  725  726  727  728  729  730  731  732  733  734  735  736  737  738  739  740  741  742  743  744  745  746  747  748  749  750  751  752  753  754  755  756  757  758  759  760  761  762  763  764  765  766  767  768  769  770  771  772  773  774  775  776  777  778  779  780  781  782  783  784  785  786  787  788  789  790  791  792  793  794  795  796  797  798  799  800  801  802  803  804  805  806  807  808  809  810  811  812  813  814  815  816  817  818  819  820  821  822  823  824  825  826  827  828  829  830  831  832  833  834  835  836  837  838  839  840  841  842  843  844  845  846  847  848  849  850  851  852  853  854  855  856  857  858  859  860  861  862  863  864  865  866  867  868  869  870  871  872  873  874  875  876  877  878  879  880  881  882  883  884  885  886  887  888  889  890  891  892  893  894  895  896  897  898  899  900  901  902  903  904  905  906  907  908  909  910  911  912  913  914  915  916  917  918  919  920  921  922  923  924  925  926  927  928  929  930  931  932  933  934  935  936  937  938  939  940  941  942  943  944  945  946  947  948  949  950  951  952  953  954  955  956  957  958  959  960  961  962  963  964  965  966  967  968  969  970  971  972  973  974  975  976  977  978  979  980  981  982  983  984  985  986  987  988  989  990  991  992  993  994  995  996  997  998  999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 
<?php

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

/**
 *
 * @param string $template_name
 * @param array  $args
 *
 * @since 3.0.0
 * @package Stripe/Functions
 *          Wrapper for wc_get_template that returns Stripe specfic templates.
 */
function wc_stripe_get_template( $template_name, $args = array() ) {
    wc_get_template( $template_name, $args, stripe_wc()->template_path(), stripe_wc()->default_template_path() );
}

/**
 *
 *
 * Wrapper for wc_get_template_html that returns Stripe specififc templates in an html string.
 *
 * @param string $template_name
 * @param array  $args
 *
 * @since 3.0.0
 * @return string
 * @package Stripe/Functions
 */
function wc_stripe_get_template_html( $template_name, $args = array() ) {
    return wc_get_template_html( $template_name, $args, stripe_wc()->template_path(), stripe_wc()->default_template_path() );
}

/**
 * Return true if WCS is active.
 *
 * @return boolean
 * @package Stripe/Functions
 */
function wcs_stripe_active() {
    return function_exists( 'wcs_is_subscription' );
}

/**
 *
 * @param WC_Payment_Gateway_Stripe $gateway
 *
 * @package Stripe/Functions
 */
function wc_stripe_token_field( $gateway ) {
    wc_stripe_hidden_field( $gateway->token_key, 'wc-stripe-token-field' );
}

/**
 *
 * @param WC_Payment_Gateway_Stripe $gateway
 *
 * @package Stripe/Functions
 */
function wc_stripe_payment_intent_field( $gateway ) {
    wc_stripe_hidden_field( $gateway->payment_intent_key, 'wc-stripe-payment-intent-field' );
}

/**
 *
 * @param string $id
 * @param string $class
 * @param string $value
 *
 * @package Stripe/Functions
 */
function wc_stripe_hidden_field( $id, $class = '', $value = '' ) {
    printf( '<input type="hidden" class="%1$s" id="%2$s" name="%2$s" value="%3$s"/>', $class, esc_attr( $id ), esc_attr( $value ) );
}

/**
 * Return the mode for the plugin.
 *
 * @return string
 * @package Stripe/Functions
 */
function wc_stripe_mode() {
    return apply_filters( 'wc_stripe_mode', stripe_wc()->api_settings->get_option( 'mode' ) );
}

/**
 * Return the secret key for the provided mode.
 * If no mode given, the key for the active mode is returned.
 *
 * @param string $mode
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_get_secret_key( $mode = '' ) {
    $mode = empty( $mode ) ? wc_stripe_mode() : $mode;

    return apply_filters( 'wc_stripe_get_secret_key', stripe_wc()->api_settings->get_option( "secret_key_{$mode}" ), $mode );
}

/**
 * Return the publishable key for the provided mode.
 * If no mode given, the key for the active mode is returned.
 *
 * @param string $mode
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_get_publishable_key( $mode = '' ) {
    $mode = empty( $mode ) ? wc_stripe_mode() : $mode;

    return apply_filters( 'wc_stripe_get_publishable_key', stripe_wc()->api_settings->get_option( "publishable_key_{$mode}" ), $mode );
}

/**
 * Return the merchant's Stripe account.
 *
 * @since 3.1.4
 * @return string
 * @package Stripe/Functions
 */
function wc_stripe_get_account_id() {
    return apply_filters( 'wc_stripe_get_account_id', stripe_wc()->api_settings->get_option( 'account_id' ) );
}

/**
 * Return the stripe customer ID
 *
 * @param int    $user_id
 * @param string $mode
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_get_customer_id( $user_id = '', $mode = '' ) {
    $mode = empty( $mode ) ? wc_stripe_mode() : $mode;
    if ( $user_id === 0 ) {
        return '';
    }
    if ( empty( $user_id ) ) {
        $user_id = get_current_user_id();
    }

    /**
     * @param string
     * @param int    $user_id
     * @param string $mode
     *
     * @since 3.2.12
     */
    return apply_filters( 'wc_stripe_get_customer_id', get_user_option( "wc_stripe_customer_{$mode}", $user_id ), $user_id, $mode );
}

/**
 *
 * @param string $customer_id
 * @param int    $user_id
 * @param string $mode
 *
 * @package Stripe/Functions
 */
function wc_stripe_save_customer( $customer_id, $user_id, $mode = '' ) {
    $mode = empty( $mode ) ? wc_stripe_mode() : $mode;
    $key  = "wc_stripe_customer_{$mode}";
    update_user_option( $user_id, $key, apply_filters( 'wc_stripe_save_customer', $customer_id, $user_id, $mode ) );
}

/**
 * @param int    $user_id
 * @param string $mode
 * @param bool   $global
 *
 * @since 3.2.13
 */
function wc_stripe_delete_customer( $user_id, $mode = '', $global = false ) {
    $mode = empty( $mode ) ? wc_stripe_mode() : $mode;
    delete_user_option( $user_id, "wc_stripe_customer_{$mode}", $global );
}

/**
 *
 * @param int              $token_id
 * @param WC_Payment_Token $token
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_woocommerce_payment_token_deleted( $token_id, $token ) {
    if ( ! did_action( 'woocommerce_payment_gateways' ) ) {
        WC_Payment_Gateways::instance();
    }
    do_action( 'wc_stripe_payment_token_deleted_' . $token->get_gateway_id(), $token_id, $token );
}

/**
 * Log the provided message in the WC logs directory.
 *
 * @param int    $level
 * @param string $message
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_log( $level, $message ) {
    if ( stripe_wc()->api_settings->is_active( 'debug_log' ) ) {
        $log = wc_get_logger();
        $log->log( $level, $message, array( 'source' => 'wc-stripe' ) );
    }
}

/**
 *
 * @param string $message
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_log_error( $message ) {
    wc_stripe_log( WC_Log_Levels::ERROR, $message );
}

/**
 *
 * @param string $message
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_log_info( $message ) {
    wc_stripe_log( WC_Log_Levels::INFO, $message );
}

/**
 * Return the mode that the order was created in.
 * Values can be <strong>live</strong> or <strong>test</strong>
 *
 * @param WC_Order|int $order
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_order_mode( $order ) {
    if ( is_object( $order ) ) {
        return $order->get_meta( WC_Stripe_Constants::MODE, true );
    }

    return get_post_meta( $order, WC_Stripe_Constants::MODE, true );
}

/**
 *
 * @param array $gateways
 *
 * @since 3.0.0
 * @package Stripe\Functions
 */
function wc_stripe_payment_gateways( $gateways ) {
    return array_merge( $gateways, stripe_wc()->payment_gateways() );
}

/**
 * Cancel the Stripe charge
 *
 * @param int      $order_id
 * @param WC_Order $order
 *
 * @package Stripe/Functions
 */
function wc_stripe_order_cancelled( $order_id, $order ) {
    if ( stripe_wc()->advanced_settings->is_refund_cancel_enabled() ) {
        $gateways = WC()->payment_gateways()->payment_gateways();
        /**
         *
         * @var WC_Payment_Gateway_Stripe $gateway
         */
        $gateway = isset( $gateways[ $order->get_payment_method() ] ) ? $gateways[ $order->get_payment_method() ] : null;

        if ( $gateway && $gateway instanceof WC_Payment_Gateway_Stripe ) {
            $gateway->void_charge( $order );
        }
    }
}

/**
 *
 * @param int      $order_id
 * @param WC_Order $order
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_order_status_completed( $order_id, $order ) {
    $gateways = WC()->payment_gateways()->payment_gateways();
    /**
     *
     * @var WC_Payment_Gateway_Stripe $gateway
     */
    $gateway = isset( $gateways[ $order->get_payment_method() ] ) ? $gateways[ $order->get_payment_method() ] : null;
    // @since 3.0.3 check added to ensure this is a Stripe gateway.
    if ( $gateway && $gateway instanceof WC_Payment_Gateway_Stripe && ! $gateway->processing_payment ) {
        $gateway->capture_charge( $order->get_total(), $order );
    }
}

/**
 *
 * @param [] $address
 *
 * @since 3.0.0
 * @throws Exception
 * @package Stripe/Functions
 */
function wc_stripe_update_customer_location( $address ) {
    // address validation for countries other than US is problematic when using responses from payment sources like
    // Apple Pay.
    if ( $address['postcode'] && $address['country'] === 'US' && ! WC_Validation::is_postcode( $address['postcode'], $address['country'] ) ) {
        throw new Exception( __( 'Please enter a valid postcode / ZIP.', 'woocommerce' ) );
    } elseif ( $address['postcode'] ) {
        $address['postcode'] = wc_format_postcode( $address['postcode'], $address['country'] );
    }

    if ( $address['country'] ) {
        WC()->customer->set_billing_location( $address['country'], $address['state'], $address['postcode'], $address['city'] );
        WC()->customer->set_shipping_location( $address['country'], $address['state'], $address['postcode'], $address['city'] );
        // set the customer's address if it's in the $address array
        if ( ! empty( $address['address_1'] ) ) {
            WC()->customer->set_shipping_address_1( wc_clean( $address['address_1'] ) );
        }
        if ( ! empty( $address['address_2'] ) ) {
            WC()->customer->set_shipping_address_2( wc_clean( $address['address_2'] ) );
        }
        if ( ! empty( $address['first_name'] ) ) {
            WC()->customer->set_shipping_first_name( $address['first_name'] );
        }
        if ( ! empty( $address['last_name'] ) ) {
            WC()->customer->set_shipping_last_name( $address['last_name'] );
        }
    } else {
        WC()->customer->set_billing_address_to_base();
        WC()->customer->set_shipping_address_to_base();
    }

    WC()->customer->set_calculated_shipping( true );
    WC()->customer->save();

    do_action( 'woocommerce_calculated_shipping' );
}

/**
 *
 * @param [] $methods
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_update_shipping_methods( $methods ) {
    $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', array() );

    foreach ( $methods as $i => $method ) {
        $chosen_shipping_methods[ $i ] = $method;
    }

    WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
}

/**
 * Return true if there are shipping packages that contain rates.
 *
 * @param array $packages
 *
 * @since 3.0.0
 * @return boolean
 * @package Stripe/Functions
 */
function wc_stripe_shipping_address_serviceable( $packages = array() ) {
    if ( $packages ) {
        foreach ( $packages as $package ) {
            if ( count( $package['rates'] ) > 0 ) {
                return true;
            }
        }
    }

    return false;
}

/**
 *
 * @param string   $page
 * @param WC_Order $order
 *
 * @since 3.0.0
 * @deprecated
 * @package Stripe/Functions
 */
function wc_stripe_get_display_items( $page = 'cart', $order = null ) {
    wc_deprecated_function( 'wc_stripe_get_display_items', '3.1.0', 'WC_Payment_Gateway_Stripe::get_display_items()' );

    return array();
}

/**
 *
 * @param WC_Order $order
 * @param array    $packages
 *
 * @since 3.0.0
 * @return mixed
 * @deprecated
 * @package Stripe/Functions
 */
function wc_stripe_get_shipping_options( $order = null, $packages = array() ) {
    $methods                 = array();
    $incl_tax                = wc_stripe_display_prices_including_tax();
    $ids                     = array();
    $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', array() );
    $packages                = empty( $packages ) ? WC()->shipping()->get_packages() : $packages;
    foreach ( $packages as $i => $package ) {
        foreach ( $package['rates'] as $rate ) {
            /**
             *
             * @var WC_Shipping_Rate $rate
             */
            $method = array(
                'id'     => sprintf( '%s:%s', $i, $rate->id ),
                'label'  => sprintf( '%s', esc_attr( $rate->get_label() ) ),
                'detail' => '',
                'amount' => wc_stripe_add_number_precision( $incl_tax ? $rate->cost + $rate->get_shipping_tax() : $rate->cost ),
            );
            if ( $incl_tax ) {
                if ( $rate->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {
                    $method['detail'] = WC()->countries->inc_tax_or_vat();
                }
            } else {
                if ( $rate->get_shipping_tax() > 0 && wc_prices_include_tax() ) {
                    $method['detail'] = WC()->countries->ex_tax_or_vat();
                }
            }
            $methods[] = $method;
            if ( isset( $chosen_shipping_methods[ $i ] ) && $chosen_shipping_methods[ $i ] === $rate->id ) {
                $ids[] = $method['id'];
            }
        }
        /**
         * Sort the shipping methods so that the selected method is always first
         * in the array.
         */
        usort( $methods, function ( $a, $b ) use ( $ids ) {
            return in_array( $a['id'], $ids ) ? - 1 : 1;
        } );
    }

    /**
     *
     * @param array    $methods
     * @param WC_Order $orer
     */
    return apply_filters( 'wc_stripe_get_shipping_options', $methods, $order );
}

/**
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_set_checkout_error() {
    add_action( 'woocommerce_after_template_part', 'wc_stripe_output_checkout_error' );
}

/**
 *
 * @param string $template_name
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_output_checkout_error( $template_name ) {
    if ( $template_name === 'notices/error.php' && is_ajax() ) {
        echo '<input type="hidden" id="wc_stripe_checkout_error" value="true"/>';
        remove_action( 'woocommerce_after_template_part', 'wc_stripe_output_checkout_error' );
        add_filter( 'wp_kses_allowed_html', 'wc_stripe_add_allowed_html', 10, 2 );
    }
}

/**
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_add_allowed_html( $tags, $context ) {
    if ( $context === 'post' ) {
        $tags['input'] = array(
            'id'    => true,
            'type'  => true,
            'value' => true,
        );
    }

    return $tags;
}

/**
 * Save WCS meta data when it's changed in the admin section.
 * By default WCS saves the
 * payment method title as the gateway title. This method saves the payment method title in
 * a human readable format suitable for the frontend.
 *
 * @param int     $post_id
 * @param WP_Post $post
 *
 * @package Stripe/Functions
 */
function wc_stripe_process_shop_subscription_meta( $post_id, $post ) {
    $subscription = wcs_get_subscription( $post_id );
    $gateway_id   = $subscription->get_payment_method();
    $gateways     = WC()->payment_gateways()->payment_gateways();
    if ( isset( $gateways[ $gateway_id ] ) ) {
        $gateway = $gateways[ $gateway_id ];
        if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
            $token = $gateway->get_token( $subscription->get_meta( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN ), $subscription->get_customer_id() );
            if ( $token ) {
                $subscription->set_payment_method_title( $token->get_payment_method_title() );
                $subscription->save();
            }
        }
    }
}

/**
 * Filter the WC payment gateways based on criteria specific to Stripe functionality.
 *
 * <strong>Example:</strong> on add payment method page, only show the CC gateway for Stripe.
 *
 * @param WC_Payment_Gateway[] $gateways
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_available_payment_gateways( $gateways ) {
    global $wp;
    if ( is_add_payment_method_page() && ! isset( $wp->query_vars['payment-methods'] ) ) {
        foreach ( $gateways as $gateway ) {
            if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
                if ( 'stripe_cc' !== $gateway->id ) {
                    unset( $gateways[ $gateway->id ] );
                }
            }
        }
    }

    return $gateways;
}

/**
 *
 * @since 3.0.0
 * @return array
 * @package Stripe/Functions
 */
function wc_stripe_get_local_payment_params() {
    global $wp;
    $data     = array();
    $gateways = WC()->payment_gateways()->payment_gateways();
    foreach ( $gateways as $gateway ) {
        if ( $gateway instanceof WC_Payment_Gateway_Stripe_Local_Payment && $gateway->is_available() ) {
            $data['gateways'][ $gateway->id ] = $gateway->get_localized_params();
            if ( isset( $wp->query_vars['order-pay'] ) ) {
                $data['gateways'][ $gateway->id ]['order_id'] = $wp->query_vars['order-pay'];
            }
        }
    }
    $data['api_key'] = wc_stripe_get_publishable_key();

    return $data;
}

/**
 *
 * @param array $gateways
 *
 * @since 3.0.0
 * @return WC_Payment_Gateway[]
 * @package Stripe/Functions
 */
function wc_stripe_get_available_local_gateways( $gateways ) {
    foreach ( $gateways as $gateway ) {
        if ( $gateway instanceof WC_Payment_Gateway_Stripe_Local_Payment ) {
            if ( ! $gateway->is_local_payment_available() ) {
                unset( $gateways[ $gateway->id ] );
            }
        }
    }

    return $gateways;
}

/**
 *
 * @param string|int $key
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_set_idempotency_key( $key ) {
    global $wc_stripe_idempotency_key;
    $wc_stripe_idempotency_key = $key;
}

/**
 *
 * @since 3.0.0
 * @return mixed
 * @package Stripe/Functions
 */
function wc_stripe_get_idempotency_key() {
    global $wc_stripe_idempotency_key;

    return $wc_stripe_idempotency_key;
}

/**
 *
 * @param array $options
 *
 * @since 3.0.0
 * @return array
 * @package Stripe/Functions
 */
function wc_stripe_api_options( $options ) {
    $key = wc_stripe_get_idempotency_key();
    if ( $key ) {
        $options['idempotency_key'] = $key;
    }

    return $options;
}

/**
 *
 * @param string   $order_status
 * @param int      $order_id
 * @param WC_Order $order
 *
 * @since 3.0.0
 * <br/><strong>3.1.7</strong> - default $order argument of null added to prevent errors when 3rd party plugins trigger
 * action woocommerce_payment_complete_order_status and don't pass three arguments.
 * @package Stripe/Functions
 */
function wc_stripe_payment_complete_order_status( $order_status, $order_id, $order = null ) {
    if ( is_checkout() && $order && $order->get_payment_method() ) {
        $gateway = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
        if ( $gateway instanceof WC_Payment_Gateway_Stripe && 'default' !== $gateway->get_option( 'order_status', 'default' ) ) {
            $order_status = $gateway->get_option( 'order_status' );
        }
    }

    return $order_status;
}

/**
 * Converts the amount to cents.
 * Stripe processes all requests in cents.
 *
 * @param float  $value
 * @param string $currency
 * @param string $round
 *
 * @since 3.0.0
 * @return number
 * @package Stripe/Functions
 */
function wc_stripe_add_number_precision( $value, $currency = '', $round = true ) {
    if ( ! is_numeric( $value ) ) {
        $value = 0;
    }
    /**
     * @since 3.3.6 - Get the number of decimals that the amount should be rounded to.
     * round before performing precision calculation
     */
    $decimals       = wc_get_price_decimals();
    $value          = round( $value, $decimals );
    $currency       = empty( $currency ) ? get_woocommerce_currency() : $currency;
    $currencies     = wc_stripe_get_currencies();
    $exp            = isset( $currencies[ $currency ] ) ? $currencies[ $currency ] : 2;
    $cent_precision = pow( 10, $exp );
    $value          = $value * $cent_precision;
    $value          = $round ? round( $value, wc_get_rounding_precision() - $decimals ) : $value;

    if ( is_numeric( $value ) && floor( $value ) != $value ) {
        // there are some decimal points that need to be removed.
        $value = round( $value );
    }

    return $value;
}

/**
 * Remove precision from a number.
 *
 * @param        $value
 * @param string $currency
 * @param bool   $round
 *
 * @since 3.2.10
 */
function wc_stripe_remove_number_precision( $value, $currency = '', $round = true, $dp = null ) {
    $currency   = empty( $currency ) ? get_woocommerce_currency() : $currency;
    $currencies = wc_stripe_get_currencies();
    $exp        = isset( $currencies[ $currency ] ) ? $currencies[ $currency ] : 2;
    $number     = $value / pow( 10, $exp );

    return $round ? round( $number, $dp === null ? wc_get_price_decimals() : $dp ) : $number;
}

/**
 * Return an array of credit card forms.
 *
 * @since 3.0.0
 * @return mixed
 * @package Stripe/Functions
 */
function wc_stripe_get_custom_forms() {
    return apply_filters(
        'wc_stripe_get_custom_forms',
        array(
            'bootstrap'  => array(
                'template'       => 'cc-forms/bootstrap.php',
                'label'          => __( 'Bootstrap form', 'woo-stripe-payment' ),
                'cardBrand'      => stripe_wc()->assets_url( 'img/card_brand2.svg' ),
                'elementStyles'  => array(
                    'base'    => array(
                        'color'             => '#495057',
                        'fontWeight'        => 300,
                        'fontFamily'        => 'Roboto, sans-serif, Source Code Pro, Consolas, Menlo, monospace',
                        'fontSize'          => '16px',
                        'fontSmoothing'     => 'antialiased',
                        '::placeholder'     => array(
                            'color'    => '#fff',
                            'fontSize' => '0px',
                        ),
                        ':-webkit-autofill' => array( 'color' => '#495057' ),
                    ),
                    'invalid' => array(
                        'color'         => '#E25950',
                        '::placeholder' => array( 'color' => '#757575' ),
                    ),
                ),
                'elementOptions' => array(
                    'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Source+Code+Pro' ) ),
                ),
            ),
            'simple'     => array(
                'template'       => 'cc-forms/simple.php',
                'label'          => __( 'Simple form', 'woo-stripe-payment' ),
                'cardBrand'      => stripe_wc()->assets_url( 'img/card_brand2.svg' ),
                'elementStyles'  => array(
                    'base'    => array(
                        'color'             => '#32325D',
                        'fontWeight'        => 500,
                        'fontFamily'        => 'Source Code Pro, Consolas, Menlo, monospace',
                        'fontSize'          => '16px',
                        'fontSmoothing'     => 'antialiased',
                        '::placeholder'     => array( 'color' => '#CFD7DF' ),
                        ':-webkit-autofill' => array( 'color' => '#32325D' ),
                    ),
                    'invalid' => array(
                        'color'         => '#E25950',
                        '::placeholder' => array( 'color' => '#FFCCA5' ),
                    ),
                ),
                'elementOptions' => array(
                    'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Source+Code+Pro' ) ),
                ),
            ),
            'minimalist' => array(
                'template'       => 'cc-forms/minimalist.php',
                'label'          => __( 'Minimalist form', 'woo-stripe-payment' ),
                'cardBrand'      => stripe_wc()->assets_url( 'img/card_brand2.svg' ),
                'elementStyles'  => array(
                    'base'    => array(
                        'color'             => '#495057',
                        'fontWeight'        => 300,
                        'fontFamily'        => 'Roboto, sans-serif, Source Code Pro, Consolas, Menlo, monospace',
                        'fontSize'          => '30px',
                        'fontSmoothing'     => 'antialiased',
                        '::placeholder'     => array(
                            'color'    => '#fff',
                            'fontSize' => '0px',
                        ),
                        ':-webkit-autofill' => array( 'color' => '#495057' ),
                    ),
                    'invalid' => array(
                        'color'         => '#495057',
                        '::placeholder' => array( 'color' => '#495057' ),
                    ),
                ),
                'elementOptions' => array(
                    'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Source+Code+Pro' ) ),
                ),
            ),
            'inline'     => array(
                'template'       => 'cc-forms/inline.php',
                'label'          => __( 'Inline Form', 'woo-stripe-payment' ),
                'cardBrand'      => stripe_wc()->assets_url( 'img/card_brand.svg' ),
                'elementStyles'  => array(
                    'base'    => array(
                        'color'               => '#819efc',
                        'fontWeight'          => 600,
                        'fontFamily'          => 'Roboto, Open Sans, Segoe UI, sans-serif',
                        'fontSize'            => '16px',
                        'fontSmoothing'       => 'antialiased',
                        ':focus'              => array( 'color' => '#819efc' ),
                        '::placeholder'       => array( 'color' => '#87BBFD' ),
                        ':focus::placeholder' => array( 'color' => '#CFD7DF' ),
                        ':-webkit-autofill'   => array( 'color' => '#819efc' ),
                    ),
                    'invalid' => array( 'color' => '#f99393' ),
                ),
                'elementOptions' => array(
                    'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Roboto' ) ),
                ),
            ),
            'rounded'    => array(
                'template'       => 'cc-forms/round.php',
                'label'          => __( 'Rounded Form', 'woo-stripe-payment' ),
                'cardBrand'      => stripe_wc()->assets_url( 'img/card_brand.svg' ),
                'elementStyles'  => array(
                    'base'    => array(
                        'color'               => '#fff',
                        'fontWeight'          => 600,
                        'fontFamily'          => 'Quicksand, Open Sans, Segoe UI, sans-serif',
                        'fontSize'            => '16px',
                        'fontSmoothing'       => 'antialiased',
                        ':focus'              => array( 'color' => '#424770' ),
                        '::placeholder'       => array( 'color' => '#9BACC8' ),
                        ':focus::placeholder' => array( 'color' => '#CFD7DF' ),
                        ':-webkit-autofill'   => array( 'color' => '#fff' ),
                    ),
                    'invalid' => array(
                        'color'         => '#fff',
                        ':focus'        => array( 'color' => '#FA755A' ),
                        '::placeholder' => array( 'color' => '#FFCCA5' ),
                    ),
                ),
                'elementOptions' => array(
                    'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Quicksand' ) ),
                ),
            ),
        )
    );
}

/**
 *
 * @param WC_Order $order
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_order_has_shipping_address( $order ) {
    if ( method_exists( $order, 'has_shipping_address' ) ) {
        return $order->has_shipping_address();
    } else {
        return $order->get_shipping_address_1() || $order->get_shipping_address_2();
    }
}

/**
 *
 * @since 3.0.0
 * @package Stripe/Functions
 */
function wc_stripe_display_prices_including_tax() {
    $cart = WC()->cart;
    if ( method_exists( $cart, 'display_prices_including_tax' ) ) {
        return $cart->display_prices_including_tax();
    }
    if ( is_callable( array( $cart, 'get_tax_price_display_mode' ) ) ) {
        return 'incl' == $cart->get_tax_price_display_mode() && ( WC()->customer && ! WC()->customer->is_vat_exempt() );
    }

    return 'incl' == $cart->tax_display_cart && ( WC()->customer && ! WC()->customer->is_vat_exempt() );
}

/**
 * Return true if the WC pre-orders plugin is active
 *
 * @since 3.0.1
 * @package Stripe/Functions
 */
function wc_stripe_pre_orders_active() {
    return class_exists( 'WC_Pre_Orders' );
}

/**
 *
 * @param string $source_id
 *
 * @since 3.0.5
 * @package Stripe/Functions
 */
function wc_stripe_get_order_from_source_id( $source_id ) {
    global $wpdb;
    $order_id
        = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id WHERE meta.meta_key = %s AND meta.meta_value = %s LIMIT 1",
        WC_Stripe_Constants::SOURCE_ID,
        $source_id ) );

    return wc_get_order( $order_id );
}

/**
 *
 * @param string $transaction_id
 *
 * @since 3.0.5
 * @return WC_Order|WC_Refund|boolean|WC_Order_Refund
 * @package Stripe/Functions
 */
function wc_stripe_get_order_from_transaction( $transaction_id ) {
    global $wpdb;
    $order_id
        = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id WHERE meta.meta_key = %s AND meta.meta_value = %s LIMIT 1",
        '_transaction_id',
        $transaction_id ) );

    return wc_get_order( $order_id );
}

/**
 * Stash the WC cart contents in the session and empty it's contents.
 * If $product_cart is true, add the stashed product(s)
 * to the cart.
 *
 * @param WC_Cart $cart
 * @param bool    $product_cart
 *
 * @since 3.0.6
 * @todo Maybe empty cart silently so actions are not triggered that cause session data to be removed
 *       from 3rd party plugins.
 *
 * @package Stripe/Functions
 */
function wc_stripe_stash_cart( $cart, $product_cart = true ) {
    $data         = WC()->session->get( 'wc_stripe_cart', array() );
    $data['cart'] = $cart->get_cart_for_session();
    WC()->session->set( 'wc_stripe_cart', $data );
    $cart->empty_cart( false );
    if ( $product_cart && isset( $data['product_cart'] ) ) {
        // if there are args, map them to the request
        if ( isset( $data['request_params'] ) ) {
            foreach ( $data['request_params'] as $key => $value ) {
                $_REQUEST[ $key ] = $value;
            }
        }
        foreach ( $data['product_cart'] as $cart_item ) {
            $cart->add_to_cart( $cart_item['product_id'], $cart_item['quantity'], $cart_item['variation_id'], $cart_item['variation'] );
        }
    }
}

/**
 *
 * @param WC_Cart $cart
 * @param array   $params
 *
 * @since 3.0.6
 * @package Stripe/Functions
 */
function wc_stripe_stash_product_cart( $cart, $params = array() ) {
    $data                   = WC()->session->get( 'wc_stripe_cart', array() );
    $data['product_cart']   = $cart->get_cart_for_session();
    $data['request_params'] = $params;
    WC()->session->set( 'wc_stripe_cart', $data );
    WC()->cart->set_session();
}

/**
 *
 * @param WC_Cart $cart
 *
 * @since 3.0.6
 * @package Stripe/Functions
 */
function wc_stripe_restore_cart( $cart ) {
    $data                = WC()->session->get( 'wc_stripe_cart', array( 'cart' => array() ) );
    $cart->cart_contents = $data['cart'];
    $cart->set_session();
}

/**
 *
 * @since 3.0.6
 * @package Stripe/Functions
 */
function wc_stripe_restore_cart_after_product_checkout() {
    wc_stripe_restore_cart( WC()->cart );
    $cart_contents = array();
    foreach ( WC()->cart->get_cart() as $key => $cart_item ) {
        $cart_item['data']     = wc_get_product( $cart_item['variation_id'] ? $cart_item['variation_id'] : $cart_item['product_id'] );
        $cart_contents[ $key ] = $cart_item;
    }
    WC()->cart->cart_contents = $cart_contents;
    WC()->cart->calculate_totals();
}

/**
 *
 * @param WC_Payment_Token[] $tokens
 * @param int                $user_id
 * @param string             $gateway_id
 *
 * @since 3.1.0
 * @return WC_Payment_Token[]
 * @package Stripe/Functions
 */
function wc_stripe_get_customer_payment_tokens( $tokens, $user_id, $gateway_id ) {
    foreach ( $tokens as $idx => $token ) {
        if ( $token instanceof WC_Payment_Token_Stripe ) {
            $mode = wc_stripe_mode();
            if ( $token->get_environment() != $mode ) {
                unset( $tokens[ $idx ] );
            }
        }
    }

    return $tokens;
}

/**
 *
 * @param array $labels
 *
 * @since 3.1.0
 * @return string
 * @package Stripe/Functions
 */
function wc_stripe_credit_card_labels( $labels ) {
    if ( ! isset( $labels['amex'] ) ) {
        $labels['amex'] = __( 'Amex', 'woocommerce' );
    }

    return $labels;
}

/**
 * Return an array of Stripe error messages.
 *
 * @since 3.1.1
 * @package Stripe/Functions
 */
function wc_stripe_get_error_messages() {
    return apply_filters(
        'wc_stripe_get_error_messages',
        array(
            'stripe_cc_generic'                => __( 'There was an error processing your credit card.', 'woo-stripe-payment' ),
            'incomplete_number'                => __( 'Your card number is incomplete.', 'woo-stripe-payment' ),
            'incomplete_expiry'                => __( 'Your card\'s expiration date is incomplete.', 'woo-stripe-payment' ),
            'incomplete_cvc'                   => __( 'Your card\'s security code is incomplete.', 'woo-stripe-payment' ),
            'incomplete_zip'                   => __( 'Your card\'s zip code is incomplete.', 'woo-stripe-payment' ),
            'incorrect_number'                 => __( 'The card number is incorrect. Check the card\'s number or use a different card.', 'woo-stripe-payment' ),
            'incorrect_cvc'                    => __( 'The card\'s security code is incorrect. Check the card\'s security code or use a different card.', 'woo-stripe-payment' ),
            'incorrect_zip'                    => __( 'The card\'s ZIP code is incorrect. Check the card\'s ZIP code or use a different card.', 'woo-stripe-payment' ),
            'invalid_number'                   => __( 'The card number is invalid. Check the card details or use a different card.', 'woo-stripe-payment' ),
            'invalid_characters'               => __( 'This value provided to the field contains characters that are unsupported by the field.', 'woo-stripe-payment' ),
            'invalid_cvc'                      => __( 'The card\'s security code is invalid. Check the card\'s security code or use a different card.', 'woo-stripe-payment' ),
            'invalid_expiry_month'             => __( 'The card\'s expiration month is incorrect. Check the expiration date or use a different card.', 'woo-stripe-payment' ),
            'invalid_expiry_year'              => __( 'The card\'s expiration year is incorrect. Check the expiration date or use a different card.', 'woo-stripe-payment' ),
            'invalid_number'                   => __( 'The card number is invalid. Check the card details or use a different card.', 'woo-stripe-payment' ),
            'incorrect_address'                => __( 'The card\'s address is incorrect. Check the card\'s address or use a different card.', 'woo-stripe-payment' ),
            'expired_card'                     => __( 'The card has expired. Check the expiration date or use a different card.', 'woo-stripe-payment' ),
            'card_declined'                    => __( 'The card has been declined.', 'woo-stripe-payment' ),
            'invalid_expiry_year_past'         => __( 'Your card\'s expiration year is in the past.', 'woo-stripe-payment' ),
            'account_number_invalid'           => __( 'The bank account number provided is invalid (e.g., missing digits). Bank account information varies from country to country. We recommend creating validations in your entry forms based on the bank account formats we provide.',
                'woo-stripe-payment' ),
            'amount_too_large'                 => __( 'The specified amount is greater than the maximum amount allowed. Use a lower amount and try again.', 'woo-stripe-payment' ),
            'amount_too_small'                 => __( 'The specified amount is less than the minimum amount allowed. Use a higher amount and try again.', 'woo-stripe-payment' ),
            'authentication_required'          => __( 'The payment requires authentication to proceed. If your customer is off session, notify your customer to return to your application and complete the payment. If you provided the error_on_requires_action parameter, then your customer should try another card that does not require authentication.',
                'woo-stripe-payment' ),
            'balance_insufficient'             => __( 'The transfer or payout could not be completed because the associated account does not have a sufficient balance available. Create a new transfer or payout using an amount less than or equal to the account\'s available balance.',
                'woo-stripe-payment' ),
            'bank_account_declined'            => __( 'The bank account provided can not be used to charge, either because it is not verified yet or it is not supported.', 'woo-stripe-payment' ),
            'bank_account_exists'              => __( 'The bank account provided already exists on the specified Customer object. If the bank account should also be attached to a different customer, include the correct customer ID when making the request again.',
                'woo-stripe-payment' ),
            'bank_account_unusable'            => __( 'The bank account provided cannot be used for payouts. A different bank account must be used.', 'woo-stripe-payment' ),
            'bank_account_unverified'          => __( 'Your Connect platform is attempting to share an unverified bank account with a connected account.', 'woo-stripe-payment' ),
            'bank_account_verification_failed' => __( 'The bank account cannot be verified, either because the microdeposit amounts provided do not match the actual amounts, or because verification has failed too many times.',
                'woo-stripe-payment' ),
            'card_decline_rate_limit_exceeded' => __( 'This card has been declined too many times. You can try to charge this card again after 24 hours. We suggest reaching out to your customer to make sure they have entered all of their information correctly and that there are no issues with their card.',
                'woo-stripe-payment' ),
            'charge_already_captured'          => __( 'The charge you\'re attempting to capture has already been captured. Update the request with an uncaptured charge ID.', 'woo-stripe-payment' ),
            'charge_already_refunded'          => __( 'The charge you\'re attempting to refund has already been refunded. Update the request to use the ID of a charge that has not been refunded.',
                'woo-stripe-payment' ),
            'charge_disputed'                  => __( 'The charge you\'re attempting to refund has been charged back. Check the disputes documentation to learn how to respond to the dispute.',
                'woo-stripe-payment' ),
            'charge_exceeds_source_limit'      => __( 'This charge would cause you to exceed your rolling-window processing limit for this source type. Please retry the charge later, or contact us to request a higher processing limit.',
                'woo-stripe-payment' ),
            'charge_expired_for_capture'       => __( 'The charge cannot be captured as the authorization has expired. Auth and capture charges must be captured within seven days.',
                'woo-stripe-payment' ),
            'charge_invalid_parameter'         => __( 'One or more provided parameters was not allowed for the given operation on the Charge. Check our API reference or the returned error message to see which values were not correct for that Charge.',
                'woo-stripe-payment' ),
            'email_invalid'                    => __( 'The email address is invalid (e.g., not properly formatted). Check that the email address is properly formatted and only includes allowed characters.',
                'woo-stripe-payment' ),
            'idempotency_key_in_use'           => __( 'The idempotency key provided is currently being used in another request. This occurs if your integration is making duplicate requests simultaneously.',
                'woo-stripe-payment' ),
            'invalid_charge_amount'            => __( 'The specified amount is invalid. The charge amount must be a positive integer in the smallest currency unit, and not exceed the minimum or maximum amount.',
                'woo-stripe-payment' ),
            'invalid_source_usage'             => __( 'The source cannot be used because it is not in the correct state (e.g., a charge request is trying to use a source with a pending, failed, or consumed source). Check the status of the source you are attempting to use.',
                'woo-stripe-payment' ),
            'missing'                          => __( 'Both a customer and source ID have been provided, but the source has not been saved to the customer. To create a charge for a customer with a specified source, you must first save the card details.',
                'woo-stripe-payment' ),
            'postal_code_invalid'              => __( 'The ZIP code provided was incorrect.', 'woo-stripe-payment' ),
            'processing_error'                 => __( 'An error occurred while processing the card. Try again later or with a different payment method.', 'woo-stripe-payment' ),
            'card_not_supported'               => __( 'The card does not support this type of purchase.', 'woo-stripe-payment' ),
            'call_issuer'                      => __( 'The card has been declined for an unknown reason.', 'woo-stripe-payment' ),
            'card_velocity_exceeded'           => __( 'The customer has exceeded the balance or credit limit available on their card.', 'woo-stripe-payment' ),
            'currency_not_supported'           => __( 'The card does not support the specified currency.', 'woo-stripe-payment' ),
            'do_not_honor'                     => __( 'The card has been declined for an unknown reason.', 'woo-stripe-payment' ),
            'fraudulent'                       => __( 'The payment has been declined as Stripe suspects it is fraudulent.', 'woo-stripe-payment' ),
            'generic_decline'                  => __( 'The card has been declined for an unknown reason.', 'woo-stripe-payment' ),
            'incorrect_pin'                    => __( 'The PIN entered is incorrect. ', 'woo-stripe-payment' ),
            'insufficient_funds'               => __( 'The card has insufficient funds to complete the purchase.', 'woo-stripe-payment' ),
            'empty_element'                    => __( 'Please select a payment method before proceeding.', 'woo-stripe-payment' ),
            'empty_element_sepa_debit'         => __( 'Please enter your IBAN before proceeding.', 'woo-stripe-payment' ),
            'empty_element_ideal'              => __( 'Please select a bank before proceeding', 'woo-stripe-payment' ),
            'incomplete_iban'                  => __( 'The IBAN you entered is incomplete.', 'woo-stripe-payment' ),
            'incomplete_boleto_tax_id'         => __( 'Please enter a valid CPF / CNPJ', 'woo-stripe-payment' ),
            'test_mode_live_card'              => __( 'Your card was declined. Your request was in test mode, but you used a real credit card. Only test cards can be used in test mode.',
                'woo-stripe-payment' )
        )
    );
}

/**
 * Return an array of Stripe currencies where the value of each
 * currency is the curency multiplier.
 *
 * @since 3.1.2
 * @return mixed
 * @package Stripe/Functions
 */
function wc_stripe_get_currencies() {
    return apply_filters(
        'wc_stripe_get_currencies',
        array(
            'BHD' => 3,
            'BIF' => 0,
            'CLP' => 0,
            'DJF' => 0,
            'GNF' => 0,
            'IQD' => 3,
            'JOD' => 3,
            'JPY' => 0,
            'KMF' => 0,
            'KRW' => 0,
            'KWD' => 3,
            'LYD' => 3,
            'MGA' => 0,
            'OMR' => 3,
            'PYG' => 0,
            'RWF' => 0,
            'TND' => 3,
            'UGX' => 0,
            'VND' => 0,
            'VUV' => 0,
            'XAF' => 0,
            'XOF' => 0,
            'XPF' => 0,
        )
    );
}

/**
 * Function that triggers a filter on the order id.
 * Allows 3rd parties to
 * convert the order_id from the metadata of the Stripe object.
 *
 * @param int                 $order_id
 * @param \Stripe\ApiResource $object
 *
 * @since 3.1.3
 * @package Stripe/Functions
 */
function wc_stripe_filter_order_id( $order_id, $object ) {
    return apply_filters( 'wc_stripe_filter_order_id', $order_id, $object );
}

/**
 * Removes order locks that have expired so the options table does not get cluttered with transients.
 *
 * @since 3.1.6
 * @package  Stripe/Functions
 */
function wc_stripe_remove_order_locks() {
    global $wpdb;

    // this operation could take some time, ensure it completes.
    wc_set_time_limit();

    $results = $wpdb->get_results( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s AND option_value < %d", '_transient_timeout_stripe_lock_order_%', time() ) );
    if ( $results ) {
        foreach ( $results as $result ) {
            // call delete_transient so Wordpress can fire all it's transient actions.
            delete_transient( substr( $result->option_name, strlen( '_transient_timeout_' ) ) );
        }
    }
}

/**
 * Returns an array of checkout fields needed to complete an order.
 *
 * @since 3.1.8
 * @return array
 */
function wc_stripe_get_checkout_fields() {
    global $wp;
    $fields = array();
    $order  = false;
    if ( ! empty( $wp->query_vars['order-pay'] ) ) {
        $order = wc_get_order( absint( ( $wp->query_vars['order-pay'] ) ) );
    }
    foreach ( array( 'billing', 'shipping' ) as $key ) {
        if ( ( $field_set = WC()->checkout()->get_checkout_fields( $key ) ) ) {
            $fields = array_merge( $fields, $field_set );
        }
    }
    // loop through fields and assign their value to the field.
    array_walk( $fields, function ( &$field, $key ) use ( $order ) {
        if ( $order ) {
            if ( is_callable( array( $order, "get_{$key}" ) ) ) {
                $field['value'] = $order->{"get_{$key}"}();
            } else {
                $field['value'] = WC()->checkout()->get_value( $key );
            }
        } else {
            $field['value'] = WC()->checkout()->get_value( $key );
        }
        /**
         * Some 3rd party plugins hook in to WC filters and alter the expected
         * type for required. This ensures it's converted back to a boolean.
         */
        if ( isset( $field['required'] ) && ! is_bool( $field['required'] ) ) {
            $field['required'] = (bool) $field['required'];
        }
    } );

    return $fields;
}

/**
 * Filters a state value, making sure the abbreviated state value recognized by WC is returned.
 * Example: Texas = TX
 *
 * @param string $state
 * @param string $country
 *
 * @since 3.2.1
 * @return string
 *
 */
function wc_stripe_filter_address_state( $state, $country ) {
    $states = WC()->countries ? WC()->countries->get_states( $country ) : array();
    if ( ! empty( $states ) && is_array( $states ) && ! isset( $states[ $state ] ) ) {
        $state_keys = array_flip( array_map( 'strtoupper', $states ) );
        if ( isset( $state_keys[ strtoupper( $state ) ] ) ) {
            $state = $state_keys[ strtoupper( $state ) ];
        }
    }

    return $state;
}

/**
 * @since 3.2.3
 * @retun string
 */
function wc_stripe_get_current_page() {
    global $wp;
    if ( is_product() ) {
        return 'product';
    }
    if ( is_cart() ) {
        return 'cart';
    }
    if ( is_checkout() ) {
        if ( ! empty( $wp->query_vars['order-pay'] ) ) {
            if ( wcs_stripe_active() && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) {
                return 'change_payment_method';
            }

            return 'order_pay';
        }

        return 'checkout';
    }
    if ( is_add_payment_method_page() ) {
        return 'add_payment_method';
    }

    return '';
}

/**
 * @since 3.3.14
 * @return mixed|void
 */
function wc_stripe_get_site_locale() {
    if ( stripe_wc()->advanced_settings && stripe_wc()->advanced_settings->get_option( 'locale', 'auto' ) !== 'auto' ) {
        if ( ( $locale = get_locale() ) ) {
            $locale = str_replace( '_', '-', substr( $locale, 0, 5 ) );
        } else {
            $locale = 'auto';
        }
    } else {
        $locale = 'auto';
    }

    return apply_filters( 'wc_stripe_get_site_locale', $locale );
}
Stripe API documentation generated by ApiGen