条纹付款问题 - 网络错误,您尚未充电

时间:2014-11-21 10:19:17

标签: javascript php jquery stripe-payments

使用Stripe Connect处理付款时遇到了一些问题。出于某种原因,一旦我提交表单,我就会收到此错误:

发生网络错误,您尚未收费。请再试一次

我设置系统的方式是用户可以使用Stripe登录,这会从Stripe发回以下详细信息,并将其与用户ID一起保存到数据库中。

  • 的access_token
  • refresh_token
  • publishable key

在我的付款页面上,我有这个脚本:

Stripe.setPublishableKey('<?= $publishable_key; ?>');
                var stripeResponseHandler = function(status, response) { 
                    var $form = $('#payment-form'); 
                    $form.find('.form-error').text("") 
                    $form.find('.error').removeClass("error") 
                    validate = validateFields(); 

                    if (response.error) { 
                        error = 0; 
                        // Show the errors on the form  
                        if (response.error.message == "This card number looks invalid"){ 
                            error = error + 1; 
                            $form.find('.card_num').text(response.error.message); 
                            $('#dcard_num').addClass("error"); 
                        } 

                        if (response.error.message == "Your card number is incorrect."){ 
                            error = error + 1; 
                            $form.find('.card_num').text(response.error.message); 
                            $('#dcard_num').addClass("error"); 
                        } 

                        if (response.error.message == "Your card's expiration year is invalid."){ 
                            error = error + 1; 
                            $form.find('.exp').text(response.error.message); 
                            $('#dexp').addClass("error"); 
                        } 

                        if (response.error.message == "Your card's expiration month is invalid."){ 
                            error = error + 1; 
                            $form.find('.exp').text(response.error.message); 
                            $('#dexp').addClass("error"); 
                        } 

                        if (response.error.message == "Your card's security code is invalid."){ 
                            error = error + 1; 
                            $form.find('.cvc').text(response.error.message); 
                            $('#dcvc').addClass("error"); 
                        } 

                        if (error == 0){ 
                            $form.find('.payment-errors').text(response.error.message); 

                        } 
                        $form.find('button').prop('disabled', false); 
                    } else { 
                        if (validate == 1){ 
                            // token contains id, last4, and card type 
                            var token = response.id; 
                            // Insert the token into the form so it gets submitted to the server 
                            $form.append($('<input type="hidden" name="stripeToken" />').val(token)); 
                            // and re-submit 
                            $form.get(0).submit(); 
                        } 
                    } 
                }; 

出于某种原因,验证永远不会发生,我也没有得到卡详细信息的令牌。因此,我实际向用户收费的代码的下一部分无法运行:

global $wpdb;
        $author_id = get_the_author_meta('id');
        $stripe_connect_account = $wpdb->get_row("SELECT * FROM wp_stripe_connect WHERE wp_user_id = $author_id", ARRAY_A); 
        if($stripe_connect_account != null){
            $publishable_key = $stripe_connect_account['stripe_publishable_key'];
            $secret_key = $stripe_connect_account['stripe_access_token'];
        }
                    $charging = chargeWithCustomer($secret_key, $amountToDonate, $currency_stripe, $stripe_usr_id);

这是chargeWithCustomer函数:

function chargeWithCustomer($secret_key, $amountToDonate, $currency, $customer) {
    require_once('plugin/Stripe.php');
    Stripe::setApiKey($secret_key);
    $charging = Stripe_Charge::create(array("amount" => $amountToDonate,
                "currency" => $currency,
                "customer" => $customer,
                "description" => ""));

    return $charging;
}

如果有人能在这个问题上帮助我,我会很感激。我对我出错的地方感到困惑,我在条纹文档中找不到答案。

1 个答案:

答案 0 :(得分:4)

如果您还没有阅读整个系列,或者不知道秘密酱,Stripe.js会将付款信息直接发送给Stripe并获得相关的唯一令牌作为回报。然后该令牌将提交给您的服务器,并用于实际向客户收费。

如果你想知道充电尝试是如何仍然失败的话,那么说实话,你应该知道Stripe.js过程实际上只做了两件事:

1)以安全的方式获取Stripe的付款信息(限制您的责任) 2)验证付款信息是否可用

**处理被拒绝的卡片有点复杂,因为您需要找出卡被拒绝的原因并将该信息提供给客户,以便他或她能够纠正问题。目标是从异常中获得减少的具体原因。这是一个多步骤过程:

1)以异常

获取JSON格式的总响应

2)从响应中获取错误正文

3)从错误正文中获取特定消息**

    require_once('path/to/lib/Stripe.php');
try {
    Stripe::setApiKey(STRIPE_PRIVATE_KEY);
    $charge = Stripe_Charge::create(array(
        'amount' => $amount, // Amount in cents!
        'currency' => 'usd',
        'card' => $token,
        'description' => $email
    ));
} catch (Stripe_CardError $e) {
}
Knowing what kinds of exceptions might occur, you can expand this to watch for the various types, from the most common (Stripe_CardError) to a catch-all (Stripe_Error):

require_once('path/to/lib/Stripe.php');
try {
    Stripe::setApiKey(STRIPE_PRIVATE_KEY);
    $charge = Stripe_Charge::create(array(
        'amount' => $amount, // Amount in cents!
        'currency' => 'usd',
        'card' => $token,
        'description' => $email
    ));
} catch (Stripe_ApiConnectionError $e) {
    // Network problem, perhaps try again.
} catch (Stripe_InvalidRequestError $e) {
    // You screwed up in your programming. Shouldn't happen!
} catch (Stripe_ApiError $e) {
    // Stripe's servers are down!
} catch (Stripe_CardError $e) {
    // Card was declined.
}

希望这有助于......!