【发布时间】:2015-07-11 16:39:13
【问题描述】:
我所做的很简单,使用条纹 JS 代码向客户收费,就像这样。
<form method="post" action="?p=charge">
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="pk_test_ngaGkIg8PowWzIh5GRS18tRO"
data-image="img/logo.png"
data-name="Wine Glass Transport"
data-description="Transport Case (65.00/each + Shipping)"
data-amount="<?php echo $FinalTotal * 100; ?>" >
</script>
<input type="hidden" name="final" value="<?php echo $FinalTotal * 100; ?>" />
</form>
从那里它被发送到收费脚本,就像这样。
<?php
require_once('inc/stripe/lib/Stripe.php');
try {
var_dump($_POST);
Stripe::setApiKey("sk_test_");
$charge = Stripe_Charge::create(array(
"amount" => $_POST['final'] / 100,
"currency" => "usd",
"card" => $_POST['stripeToken'],
"description" => "Wine Glass Transport Case"
));
echo '<h1>Your payment has been completed. Thank You,<br><br>Click <a href="https://www.wineglasstransport.com/index.php">Here</a></h1>';
//users email.
echo $_POST['stripeEmail'];
} catch (Stripe_CardError $e) {
echo 'There was an error with your card!<br><br>';
echo $e;
}
//catch the errors in any way you like
catch (Stripe_InvalidRequestError $e) {
echo 'We can not process your order there was something wrong with the information submitted, please go back and correct this error,if the error persists please contact the administrator<br><br>';
echo $e;
// Invalid parameters were supplied to stripe's API
} catch (Stripe_AuthenticationError $e) {
echo 'Sorry, we can not connect to stripe, please contact Administrator.';
// Authentication with stripe's API failed
// (maybe you changed API keys recently)
} catch (Stripe_ApiConnectionError $e) {
// Network communication with stripe failed
echo 'sorry we cant connect to stripe please contact website administrator.';
} catch (Stripe_Error $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
} catch (Exception $e) {
echo 'UH OH, something Really went wrong here, Contact the system administrator ASAP!';
// Something else happened, completely unrelated to stripe
}
在这一点上,我不知道发生了什么,我收到了这个错误
异常“Stripe_InvalidRequestError”,消息“无法识别” 请求 URL(POST:/v1/stripecharges)。请参见 https://stripe.com/docs 或者我们可以在 https://support.stripe.com/.'在 /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiRequestor.php:147 堆栈跟踪:#0 /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiRequestor.php(268): Stripe_ApiRequestor->handleApiError('{\n "error": {\n...', 404, Array)
1 /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiRequestor.php(109):
Stripe_ApiRequestor->_interpretResponse('{\n "error": {\n...', 404) #2 /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiResource.php(143): Stripe_ApiRequestor->request('post', '/v1/stripecharg...', 数组, 阵列)#3 /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/Charge.php(38): Stripe_ApiResource::_scopedCreate('Stripe_Charge', Array, NULL) #4 /home/arthmael/PhpstormProjects/Vino/pages/charge.php(21): Stripe_Charge::create(Array) #5 /home/arthmael/PhpstormProjects/Vino/inc/content.php(6): 包括('/home/arthmael/...')#6 /home/arthmael/PhpstormProjects/Vino/index.php(6): include('/home/arthmael/...') #7 {main}
提前致谢
编辑: 跳转到条纹 irc 后,我意识到我使用的是过时的 API,所以我更新了它,现在这是我的代码:
【问题讨论】:
-
请问可以打印_r($charge) 吗?
标签: php html stripe-payments