条纹此客户没有附加付款来源

时间:2018-07-05 12:42:36

标签: php wordpress stripe-payments

我的wordpress出现问题,我使用条纹,并显示以下错误消息:“此客户没有附加的付款来源”,但我不明白为什么。在开发环境中,我没有问题,现在在生产中,我有这个问题。有关信息,我使用卡号4242 4242 4242 4242进行测试。

非常感谢您的帮助

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

    global $stripe_options, $post;


    // load the stripe libraries
    require_once(STRIPE_BASE_DIR . '/init.php');

    // retrieve the token generated by stripe.js
    $token = $_POST['stripeToken'];
    $amount = base64_decode($_POST['amount'])*100;
    $email = $_POST['email'];
    $plan_nickname = $_POST['plan_nickname'];
    $plan_id = $_POST['plan_id'];
    $nom = $_POST['name'];
    $prenom = $_POST['prenom'];
    $adresse = $_POST['address-line1'];
    $ville = $_POST['address-city'];
    $zip = $_POST['address-zip'];



    // 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\Stripe::setApiKey($secret_key);

        $product = \Stripe\Product::create([
            'name' => $stripe_options['product_name'],
            'type' => 'service',
        ]);

        $plan = \Stripe\Plan::create([
            'product' => $stripe_options['product_key'],
            'nickname' => $plan_nickname,
            'interval' => 'month',
            'currency' => 'eur',
            'amount' => $amount,
          ]);

        $customer = \Stripe\Customer::create([
            'email' => $email,
            'source' => $token,
            'description' => $plan_nickname,
        ]);

        $subscription = \Stripe\Subscription::create([
            'customer' => $customer->id,
            'items' => [['plan' => $plan_id]],
        ]);

        // 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_failed']);
        var_dump($e);

    }

    // redirect back to our previous page with the added query variable
    wp_redirect($redirect); exit;
}

}

1 个答案:

答案 0 :(得分:0)

在Stripe上检查计划。如果计划有试用期,则需要使用试用期创建订阅。我正在使用laravel收银员和react-stripe-checkout,这对我有用:

$user->newSubscription('main', 'basic')
            ->trialDays(30)
            ->create($request->token);