2016-12-21 2 views
0

Все работает отлично в Stripe - маркер генерируется, записывается в разделе «log» на моей панели инструментов и т. Д. Однако нет никакой платы. У меня не было ошибок от 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

Вы, вероятно, получить ошибку, и ваш код правильно обработки этой ошибки, но код обработки ошибок на самом деле не делать ничего для многих случаев.

Возможно, вы должны добавить что-нибудь (например, вызов print) в каждый блок catch, чтобы точно увидеть, какой тип вопроса возвращается.

В качестве альтернативы, ваша панель управления Stripe имеет возможность просматривать ваши журналы в режиме реального времени и в тестовом режиме на https://dashboard.stripe.com/logs, который будет содержать запись для каждого запроса (успешно или иначе), который попадает на серверы Stripe.

+0

Я нашел проблему !! –

+0

На самом деле мой API не был в курсе! По-видимому, Stripe не хотелось говорить мне, что это было важно :) –

+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."; 
    } 
} 
Смежные вопросы