如何验证 Stripe 中的交易是否真实?
How to verify if a transaction is genuine in Stripe?
我正在研究 Cake PHP Ftramework。我的任务是验证 交易是否真实 。我正在尝试使用交易 ID(付款成功时收到)进行以下操作。
try {
$stripe = new \Stripe\StripeClient(STRIPE_SECRET_KEY);
$stripe->transfers->retrieve('pi_xxxxxxxxxxxxxxxxxxxxxx', []);
echo "<pre>"; print_r( $stripe ); die;
} catch(\Stripe\Error\Card $e) {
echo "<pre>in catch<br>"; print_r($e->getMessage());
die;
}
这是我在错误日志中得到的内容。
Error: [Stripe\Exception\InvalidRequestException] No such transfer: 'pi_xxxxxxxxxxxxxxxxxxxxxxxxxxxx' (E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php:38)
#0 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Exception\InvalidRequestException.php(35): Stripe\Exception\ApiErrorException::factory('No such transfe...', 404, '{\n "error": {\n...', Array, Object(Stripe\Util\CaseInsensitiveArray), 'resource_missin...')
#1 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(189): Stripe\Exception\InvalidRequestException::factory('No such transfe...', 404, '{\n "error": {\n...', Array, Object(Stripe\Util\CaseInsensitiveArray), 'resource_missin...', 'transfer')
#2 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(151): Stripe\ApiRequestor::_specificAPIError('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array, Array)
#3 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(478): Stripe\ApiRequestor->handleErrorResponse('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array)
#4 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(120): Stripe\ApiRequestor->_interpretResponse('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray))
#5 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\BaseStripeClient.php(134): Stripe\ApiRequestor->request('get', '/v1/transfers/p...', Array, Array)
#6 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Service\AbstractService.php(59): Stripe\BaseStripeClient->request('get', '/v1/transfers/p...', Array, Object(Stripe\Util\RequestOptions))
#7 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Service\TransferService.php(115): Stripe\Service\AbstractService->request('get', '/v1/transfers/p...', Array, NULL)
#8 E:\Wamp64\www\TrainerSlate\src\Controller\ApisController.php(4516): Stripe\Service\TransferService->retrieve('pi_1ILNxXKDtVMA...', Array)
#9 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Controller\Controller.php(609): App\Controller\ApisController->verifyTransaction()
#10 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\ActionDispatcher.php(120): Cake\Controller\Controller->invokeAction()
#11 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\ActionDispatcher.php(94): Cake\Http\ActionDispatcher->_invoke(Object(App\Controller\ApisController))
#12 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\BaseApplication.php(234): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#13 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#14 E:\Wamp64\www\TrainerSlate\vendor\admad\cakephp-social-auth\src\Middleware\SocialAuthMiddleware.php(161): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#15 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): ADmad\SocialAuth\Middleware\SocialAuthMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#16 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Routing\Middleware\RoutingMiddleware.php(162): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#17 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#18 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Routing\Middleware\AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#19 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#20 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Error\Middleware\ErrorHandlerMiddleware.php(96): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#21 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#22 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#23 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Server.php(97): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#24 E:\Wamp64\www\TrainerSlate\webroot\index.php(40): Cake\Http\Server->run()
#25 {main}
Request URL: /Apis/verifyTransaction/
在这种情况下,要使用 pi_xxx PaymentIntent ID 从 API 检索 PaymentIntent,那么执行此操作的 PHP 代码是 [1]:
$pi = $stripe->paymentIntents->retrieve(
'pi_xxx',
[]
);
[1] https://stripe.com/docs/api/payment_intents/retrieve?lang=php
我正在研究 Cake PHP Ftramework。我的任务是验证 交易是否真实 。我正在尝试使用交易 ID(付款成功时收到)进行以下操作。
try {
$stripe = new \Stripe\StripeClient(STRIPE_SECRET_KEY);
$stripe->transfers->retrieve('pi_xxxxxxxxxxxxxxxxxxxxxx', []);
echo "<pre>"; print_r( $stripe ); die;
} catch(\Stripe\Error\Card $e) {
echo "<pre>in catch<br>"; print_r($e->getMessage());
die;
}
这是我在错误日志中得到的内容。
Error: [Stripe\Exception\InvalidRequestException] No such transfer: 'pi_xxxxxxxxxxxxxxxxxxxxxxxxxxxx' (E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php:38)
#0 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Exception\InvalidRequestException.php(35): Stripe\Exception\ApiErrorException::factory('No such transfe...', 404, '{\n "error": {\n...', Array, Object(Stripe\Util\CaseInsensitiveArray), 'resource_missin...')
#1 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(189): Stripe\Exception\InvalidRequestException::factory('No such transfe...', 404, '{\n "error": {\n...', Array, Object(Stripe\Util\CaseInsensitiveArray), 'resource_missin...', 'transfer')
#2 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(151): Stripe\ApiRequestor::_specificAPIError('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array, Array)
#3 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(478): Stripe\ApiRequestor->handleErrorResponse('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array)
#4 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(120): Stripe\ApiRequestor->_interpretResponse('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray))
#5 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\BaseStripeClient.php(134): Stripe\ApiRequestor->request('get', '/v1/transfers/p...', Array, Array)
#6 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Service\AbstractService.php(59): Stripe\BaseStripeClient->request('get', '/v1/transfers/p...', Array, Object(Stripe\Util\RequestOptions))
#7 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Service\TransferService.php(115): Stripe\Service\AbstractService->request('get', '/v1/transfers/p...', Array, NULL)
#8 E:\Wamp64\www\TrainerSlate\src\Controller\ApisController.php(4516): Stripe\Service\TransferService->retrieve('pi_1ILNxXKDtVMA...', Array)
#9 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Controller\Controller.php(609): App\Controller\ApisController->verifyTransaction()
#10 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\ActionDispatcher.php(120): Cake\Controller\Controller->invokeAction()
#11 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\ActionDispatcher.php(94): Cake\Http\ActionDispatcher->_invoke(Object(App\Controller\ApisController))
#12 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\BaseApplication.php(234): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#13 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#14 E:\Wamp64\www\TrainerSlate\vendor\admad\cakephp-social-auth\src\Middleware\SocialAuthMiddleware.php(161): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#15 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): ADmad\SocialAuth\Middleware\SocialAuthMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#16 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Routing\Middleware\RoutingMiddleware.php(162): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#17 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#18 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Routing\Middleware\AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#19 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#20 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Error\Middleware\ErrorHandlerMiddleware.php(96): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#21 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#22 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#23 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Server.php(97): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#24 E:\Wamp64\www\TrainerSlate\webroot\index.php(40): Cake\Http\Server->run()
#25 {main}
Request URL: /Apis/verifyTransaction/
在这种情况下,要使用 pi_xxx PaymentIntent ID 从 API 检索 PaymentIntent,那么执行此操作的 PHP 代码是 [1]:
$pi = $stripe->paymentIntents->retrieve(
'pi_xxx',
[]
);
[1] https://stripe.com/docs/api/payment_intents/retrieve?lang=php