【发布时间】:2018-08-23 15:14:04
【问题描述】:
我在让 Stripe 充电时遇到了一些问题。 Composer 不会安装,所以我手动加载了它。没有出现PHP 错误,并且我的令牌创建工作正常。我看不到任何明显的错误或语法错误,有人能指出正确的方向吗?
谢谢
index.html 代码:
<script src="https://checkout.stripe.com/checkout.js"></script>
<script>
var handler = StripeCheckout.configure({
key: 'xxxxxxxxxx',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
token: function(token) {
/* Use the token to create the charge with a server-side script.
You can access the token ID with `token.id`
Pass along various parameters you get from the token response
and your form.*/
var myData = {
token: token.id,
email: token.email,
amount: 500,
message: $("#message").val()
};
/* Make an AJAX post request using JQuery,
change the first parameter to your charge script*/
$.post("charge2.php", myData,function (data) {
// if you get some results back update results
$(".results").html("Your charge was successful");
}).fail(function () {
// if things fail, tell us
$(".results").html("I'm sorry something went wrong");
})
}
});
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'GUTIC',
description: 'Join today!',
amount: 500
});
e.preventDefault();
});
// Close Checkout on page navigation
$(window).on('popstate', function () {
handler.close();
});
</script>
charge2.php
<?php echo // 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
require_once('stripe-php/init.php');
\Stripe\Stripe::setApiKey("pk_test_DapJwVUCol6JDjJ4jsqEr6S7");
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['token'];
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
print_r($_POST)
]);; ?>
【问题讨论】:
-
您能稍微澄清一下确切的问题是什么吗?只是没有创建费用吗?如果您查看dashboard.stripe.com/test/logs,您是否看到任何错误或收费请求?
-
@karllekko 是的 - 尚未创建。那里没有错误。也没有收费要求。只有 v1 令牌
-
您是否在浏览器的开发人员工具中看到对charge2.php 的请求?如果您从脚本中
print_r($_POST),您会看到什么? -
当我放置并加载 PHP 文件时,我看到了“1Array ( )”。我在我的开发人员工具中看到正在请求 change2.php 并返回 500 错误。据我所知,没有语法错误......
-
哦,我刚刚注意到 - 您在 PHP 脚本中将您的公钥传递给
setApiKey。它应该是你的密钥(sk_test_xxx)。
标签: javascript php stripe-payments