【问题标题】:Stripe Payment issue - Network Error, you have not been Charged条纹支付问题 - 网络错误,您没有被收费
【发布时间】:2015-01-19 11:01:33
【问题描述】:

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

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

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

  • access_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 文档中找不到答案。

【问题讨论】:

    标签: javascript php jquery stripe-payments


    【解决方案1】:

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

    希望这会有所帮助...!

    【讨论】:

    • 感谢您的帮助,我会调查您所说的内容,希望我能对其进行排序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 2020-06-01
    • 1970-01-01
    • 2014-12-06
    • 2021-01-13
    • 1970-01-01
    • 2018-06-12
    相关资源
    最近更新 更多