条纹付款问题 - 网络错误,您尚未被扣款

Stripe Payment issue - Network Error, you have not been Charged

本文关键字:错误 付款 问题 网络      更新时间:2023-09-26

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

发生网络错误,并且尚未向您收费。请重试

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

  • access_token
  • refresh_token
  • 可发布密钥

在我的付款页面上,我有以下脚本:

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;
}

如果有人能在这个问题上帮助我,我将不胜感激。我对哪里出错感到困惑,在 Stripes 文档中找不到答案。

如果您还没有阅读整个系列,或者不知道秘诀,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.
}

希望这有帮助...!