2014-11-21 60 views
4

我在使用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文档中找到答案。

回答

4

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

,如果你想知道如何收费的尝试也不能正常工作,那么说实话,你应该知道,Stripe.js过程中确实只有两件事:

1)获取支付信息的条锈(限制您的责任) 2)验证付款信息是否可用

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

1)获取的总响应,JSON格式,从异常

2)从响应

三送错误体)获得从错误的特定消息身体**

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

希望这有助于...!

+0

感谢您的有益回应,我会研究你所说的话,希望我能对其进行分类。 – Javacadabra 2014-11-21 10:34:40

+1

是的...和你的欢迎.. :) – CODeeerrrrrrrr 2014-11-21 10:36:47