스트라이프를 사용하여 카드의 데이터를 보내면 다음 메시지가 표시됩니다.데이터를받지 않을 때 치명적인 오류를 해결하는 방법 및 페이지를 다시로드 할 때 데이터를 전송하는 줄무늬?
$ 50를 성공적으로 청구했습니다!
tok_1BKYfLDi3J7CIS2eVqZVeZqT
그러나 지불 데이터를 보낼 때 데이터를 수신하지 않을 때 표시됩니다 이러한 오류Notice: Undefined index: token in C:\xampp\htdocs\DesignFormStripe\charge.php on line 9 Fatal error: Uncaught Stripe\Error\Card: Cannot charge a customer that has no active card in C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php:128 from API request 'req_W6Qbd7iMVHDsGS' Stack trace: #0 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php(102): Stripe\ApiRequestor::_specificAPIError('{\n "error": {\n...', 402, Array, Array, Array) #1 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php(309): Stripe\ApiRequestor->handleErrorResponse('{\n "error": {\n...', 402, Array, Array) #2 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php(65): Stripe\ApiRequestor->_interpretResponse('{\n "error": {\n...', 402, Array) #3 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiResource.php(119): Stripe\ApiRequestor->request('post', '/v1/charges', Array, Array) #4 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiResource.php(158): Stripe\ApiResource::_staticRequest('post', '/v1/charges', Array, NULL) #5 C:\xampp\htdocs\DesignFormStripe\php\lib\str in C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php on line 128
어떻게 그 실행 오류를 해결할 수 있습니까?
업데이트 내 질문에
는 handling errors에, 스트라이프의 설명서와 함께 이전 오류를 수정합니다.
코드는 거의 다음과 같이 해결된다 : 이제
Status is:402 Type is:card_error Code is:missing Param is:card Message is:Cannot charge a customer that has no active card
: 수신 데이터 않고 페이지를 열면
<?php
require_once('./config.php');
$token = $_POST['token']; // retrieve token POST parameter to charge the card (stripeToken)
$customer = \Stripe\Customer::create(array(
'email' => '[email protected]',
//'email' => $_POST['stripeEmail'],
'card' => $token
));
try {
// Use Stripe's library to make requests...
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 500,
'description' => 'Event charge',
'currency' => 'usd'
));
echo '<h1>Successfully charged $50!</h1>';
echo "$token";
} catch(\Stripe\Error\Card $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 (\Stripe\Error\RateLimit $e) {
// Too many requests made to the API too quickly
} catch (\Stripe\Error\InvalidRequest $e) {
// Invalid parameters were supplied to Stripe's API
} catch (\Stripe\Error\Authentication $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
} catch (\Stripe\Error\ApiConnection $e) {
// Network communication with Stripe failed
} catch (\Stripe\Error\Base $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
}
?>
이제 다음 메시지를 도시 새로운 문제 :(
그러나 페이지를 다시로드하고 양식 재 제출을 확인하면 이전 오류와 동일한 메시지가 표시됩니다.
나는 스트라이프 만 토큰은 한 번 충전의 요청에 따라 생성 허용하기 때문에 오류가 표시되어 있는지 상상한다.
양식 재 제출을 확인할 때 이러한 오류를 표시하는 대신 사용자 정의 오류 메시지를 표시하십시오 (예 : ). 지불 요청이 이미 처리 중입니다.
친구 나는 당신이 말한 것과는 다른 방식으로 해결했지만 해결했지만 불구하고 페이지가 다시로드되고 양식을 다시 제출할 때 오류가 표시됩니다. – OneL
그건 완전히 다른 문제입니다. 페이지를 다시로드하면 동일한 토큰을 다시 제출하고 토큰은 한 번만 사용할 수 있습니다. 이것은 여전히 오류를 적절하게 포착하지 못한다는 것을 의미합니다. – koopajah
오류가 올바르게 잡히고 해결되었지만 문제는 이미 주석 처리 한 것입니다. 예를 들어 사례를 수행하고 있지만 클라이언트가 요청을 보내면 어떻게됩니까? – OneL