2014-11-21 77 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