条纹支付的条纹收费问题
Stripe charge issue with stripe payment
我做的很简单,使用stripes 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
}
在这一点上,我不知道发生了什么,我收到了这个错误
exception 'Stripe_InvalidRequestError' with message 'Unrecognized
request URL (POST: /v1/stripecharges). Please see
https://stripe.com/docs or we can help at
https://support.stripe.com/.' in
/home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiRequestor.php:147
Stack trace: #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...', Array,
Array) #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):
include('/home/arthmael/...') #6
/home/arthmael/PhpstormProjects/Vino/index.php(6):
include('/home/arthmael/...') #7 {main}
提前致谢
编辑:
我跳上 stripe irc 后意识到我使用的是过时的 API,所以我更新了它,现在这是我的代码:
删除数组。
试试这个:
$charge = Stripe_Charge::create(
"amount" => $_POST['final']/100,
"currency" => "usd",
"card" => $_POST['stripeToken'],
"description" => "Wine Glass Transport Case"
);
在这里我发现我的代码有 3 个问题。
我使用的是过时的 API :P
我隐藏的金额输入没有发布,因为它是在嵌入脚本之后。像这样...
<form action="?p=charge" method="post">
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="pk_test_ngaGkIg8PowWzIh5GRS18tRO"
data-amount="<?php echo $FinalTotal * 100; ?>"
data-name="Wine Glass Transport"
data-description="Transport Case (65.00/each + Shipping)"
data-image="img/logo.png">
</script>
<input type="hidden" name="amount" value="<?php echo $FinalTotal; ?>">
</form>
所以我把它调高了
<form action="?p=charge" method="post">
<input type="hidden" name="amount" value="<?php echo $FinalTotal; ?>">
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="pk_test_ngaGkIg8PowWzIh5GRS18tRO"
data-amount="<?php echo $FinalTotal * 100; ?>"
data-name="Wine Glass Transport"
data-description="Transport Case (65.00/each + Shipping)"
data-image="img/logo.png">
</script>
</form>
- 我的 charge.php 页面上也没有
$_POST['stripeToken']
变量。
感谢大家的帮助!
我做的很简单,使用stripes 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
}
在这一点上,我不知道发生了什么,我收到了这个错误
exception 'Stripe_InvalidRequestError' with message 'Unrecognized request URL (POST: /v1/stripecharges). Please see https://stripe.com/docs or we can help at https://support.stripe.com/.' in /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiRequestor.php:147 Stack trace: #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...', Array, Array) #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): include('/home/arthmael/...') #6 /home/arthmael/PhpstormProjects/Vino/index.php(6): include('/home/arthmael/...') #7 {main}
提前致谢
编辑: 我跳上 stripe irc 后意识到我使用的是过时的 API,所以我更新了它,现在这是我的代码:
删除数组。
试试这个:
$charge = Stripe_Charge::create(
"amount" => $_POST['final']/100,
"currency" => "usd",
"card" => $_POST['stripeToken'],
"description" => "Wine Glass Transport Case"
);
在这里我发现我的代码有 3 个问题。
我使用的是过时的 API :P
我隐藏的金额输入没有发布,因为它是在嵌入脚本之后。像这样...
<form action="?p=charge" method="post">
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="pk_test_ngaGkIg8PowWzIh5GRS18tRO"
data-amount="<?php echo $FinalTotal * 100; ?>"
data-name="Wine Glass Transport"
data-description="Transport Case (65.00/each + Shipping)"
data-image="img/logo.png">
</script>
<input type="hidden" name="amount" value="<?php echo $FinalTotal; ?>">
</form>
所以我把它调高了
<form action="?p=charge" method="post">
<input type="hidden" name="amount" value="<?php echo $FinalTotal; ?>">
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="pk_test_ngaGkIg8PowWzIh5GRS18tRO"
data-amount="<?php echo $FinalTotal * 100; ?>"
data-name="Wine Glass Transport"
data-description="Transport Case (65.00/each + Shipping)"
data-image="img/logo.png">
</script>
</form>
- 我的 charge.php 页面上也没有
$_POST['stripeToken']
变量。
感谢大家的帮助!