2016-12-21 102 views
0

在Stripe中一切工作正常 - 令牌生成,寫入儀表板中的「日誌」部分等。但沒有完成任何費用。即使我完成了條紋文檔給出的所有錯誤處理,我也沒有從Stripe或我的代碼中得到任何錯誤。我該如何解決這個問題?帶條紋充電卡

require_once ("vendor/autoload.php"); 

if ($_POST) { 
echo "catch if"; 

// Set your secret key: remember to change this to your live secret key in production 
// See your keys here: https://dashboard.stripe.com/account/apikeys 

StripeStripe::setApiKey("myApyKey"); 

// Get the credit card details submitted by the form 

$token = $_POST['stripeToken']; 

// Create a charge: this will charge the user's card 

try { 
    echo "charging"; 
    $charge = StripeCharge::create(array(
    "amount" => 1000, // Amount in cents 
    "currency" => "eur", 
    "source" => $token, 
    "description" => "Example charge" 
)); 
} 

catch(StripeErrorCard $e) { 

    // Since it's a decline, \Stripe\Error\Card will be caught 

    $body = $e->getJsonBody(); 
    $err = $body['error']; 
    print ('Status is:' . $e->getHttpStatus() . "\n"); 
    print ('Type is:' . $err['type'] . "\n"); 
    print ('Code is:' . $err['code'] . "\n"); 

    // param is '' in this case 

    print ('Param is:' . $err['param'] . "\n"); 
    print ('Message is:' . $err['message'] . "\n"); 
} 

catch(StripeErrorRateLimit $e) { 

    // Too many requests made to the API too quickly 

} 

catch(StripeErrorInvalidRequest $e) { 

    // Invalid parameters were supplied to Stripe's API 

} 

catch(StripeErrorAuthentication $e) { 

    // Authentication with Stripe's API failed 
    // (maybe you changed API keys recently) 

} 

catch(StripeErrorApiConnection $e) { 

    // Network communication with Stripe failed 

} 

catch(StripeErrorBase $e) { 

    // Display a very generic error to the user, and maybe send 
    // yourself an email 

} 

catch(Exception $e) { 

    // Something else happened, completely unrelated to Stripe 

} 
+0

你的漁獲大多默默地失敗。要麼刪除它們,要麼讓它們做一些明顯的事情,比如'print'OH SHIT Stripe InvalidRequest「;' – ceejayoz

+0

在這行之後嘗試$ err = $ body ['error'];的print_r($ ERR);並看到錯誤。 –

回答

2

你可能會得到一個錯誤,你的代碼是正確處理是錯誤的,但你的錯誤處理代碼實際上並不做很多的情況下什麼。

您應該在每個catch塊中添加一些內容(例如print調用)以確切地查看返回的問題類型。

或者,您的條帶儀表板可以查看您帳戶的實時模式和測試模式日誌https://dashboard.stripe.com/logs,其中包含每條打擊Stripe服務器的請求(成功或其他)的條目。

+0

我發現問題了! –

+0

其實我的API並不是最新的!顯然條紋並不想告訴我這是重要的:) –

+0

他們可能是在告訴你。你的無所作爲的捕獲陳述可能隱藏了你的想法。 – ceejayoz

0

嘗試使用下面的代碼中找到錯誤的問題

try { 
    echo "charging"; 
    $charge = StripeCharge::create(array(
    "amount" => 1000, // Amount in cents 
    "currency" => "eur", 
    "source" => $token, 
    "description" => "Example charge" 
)); 
} 

catch(StripeErrorCard $e) { 
    $error = $e->getJsonBody(); 
    <pre>print_r($error);</pre> 
    //then you can handle like that 
    if($error == "Your card was declined."){ 
     echo "Your credit card was declined. Please try again with an alternate card."; 
    } 
}