Wordpress-Stripe集成:致命错误:未捕获的错误:未找到类“ Stripe”

时间:2018-12-13 07:08:33

标签: php wordpress stripe-payments php-integration

尝试在我的条纹帐户上提交测试付款时出现以下错误:

  

致命错误:未捕获错误:在中找不到类“条带”       /home/dh_y3rvc7/vvnow.dreamhosters.com/wp-content/plugins/wp-stripe-       integration / includes / process-payment.php:25堆栈跟踪:#0       /home/dh_y3rvc7/vvnow.dreamhosters.com/wp-includes/class-wp-       hook.php(286):vvnow_stripe_process_payment('')#1       /home/dh_y3rvc7/vvnow.dreamhosters.com/wp-includes/class-wp-       hook.php(310):WP_Hook-> apply_filters(NULL,数组)#2       /home/dh_y3rvc7/vvnow.dreamhosters.com/wp-includes/plugin.php(453):       WP_Hook-> do_action(Array)#3       /home/dh_y3rvc7/vvnow.dreamhosters.com/wp-settings.php(450):       do_action('init')#4 /home/dh_y3rvc7/vvnow.dreamhosters.com/wp-       config.php(89):require_once('/ home / dh_y3rvc7 ...')#5       /home/dh_y3rvc7/vvnow.dreamhosters.com/wp-load.php(37):       require_once('/ home / dh_y3rvc7 ...')#6       /home/dh_y3rvc7/vvnow.dreamhosters.com/wp-blog-header.php(13):       require_once('/ home / dh_y3rvc7 ...')#7       /home/dh_y3rvc7/vvnow.dreamhosters.com/index.php(17):       require('/ home / dh_y3rvc7 ...')#8 {main}被抛出       /home/dh_y3rvc7/vvnow.dreamhosters.com/wp-content/plugins/wp-stripe-       第25行的integration / includes / process-payment.php

第25行被认为是Stripe::setApiKey($secret_key);内的process-payment.php

<?php

function vvnow_stripe_process_payment() {
    if(isset($_POST['action']) && $_POST['action'] == 'stripe' && wp_verify_nonce($_POST['stripe_nonce'], 'stripe-nonce')) {

        global $stripe_options;

        // load the stripe libraries
        require_once(STRIPE_BASE_DIR . '/lib/Stripe.php');
        // require_once('./init.php');
        // require_once(realpath(dirname(__FILE__) . '/../includes/init.php'));

        // retrieve the token generated by stripe.js
        $token = $_POST['stripeToken'];

        // check if we are using test mode
        if(isset($stripe_options['test_mode']) && $stripe_options['test_mode']) {
            $secret_key = $stripe_options['test_secret_key'];
        } else {
            $secret_key = $stripe_options['live_secret_key'];
        }

        // attempt to charge the customer's card
        try {
            Stripe::setApiKey($secret_key);
            $charge = Stripe_Charge::create(array(
                    'amount' => 1000, // $10
                    'currency' => 'usd',
                    'card' => $token
                )
            );


            // redirect on successful payment
            $redirect = add_query_arg('payment', 'paid', $_POST['redirect']);

        } catch (Exception $e) {
            // redirect on failed payment
            $redirect = add_query_arg('payment', 'failed', $_POST['redirect']);
        }

        //will redirect back to our previous page with the added query variable
        wp_redirect($redirect); exit;
    }
}
add_action('init', 'vvnow_stripe_process_payment');

自从遵循Stripe的API准则以来,就一直试图找出问题的根源,但并不幸运。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

这是因为它使用名称空间。尝试在Stripe之前添加user_id

SELECT
    t1.id,
    t1.user_id,
    t1.date
FROM yourTable t1
INNER JOIN
(
    SELECT user_id, MAX(date) AS max_date
    FROM yourTable
    WHERE user_id IN (10, 11, 12)
    GROUP BY user_id
) t2
    ON t1.user_id = t2.user_id AND t1.date = t2.max_date
WHERE
    t1.user_id IN (10, 11, 12);

如果仍然失败,则实际上您想包含\而不是\Stripe\Stripe::setApiKey($stripe['secret_key']); (或使用Composer安装Stripe并自动加载库)。

答案 1 :(得分:0)

您需要从一开始就从任何目录中都需要Stripe php库。

    require_once('stripe-php-6.28.0/init.php');

    function vvnow_stripe_process_payment() {
    if(isset($_POST['action']) && $_POST['action'] == 'stripe' && wp_verify_nonce($_POST['stripe_nonce'], 'stripe-nonce')) {

        global $stripe_options;

    //the rest of your code here....