这是我的情况,我正在使用 Stripe PHP Api 实现自定义 Stripe Checkout.
Here is my situation, i'm implementing Custom Stripe Checkout with Stripe PHP Api.
我已经请求了一个像这样使用 jquery 的 post 方法 >
I have requested a post Method using jquery like this one >
var handler = StripeCheckout.configure({ key: 'pk_test_yGQM97VuEUdttuOOFQcyaPHW', image: 'stripe/img/documentation/checkout/marketplace.png', locale: 'auto', token: function (token) { // You can access the token ID with `token.id`. // Get the token ID to your server-side code for use. $.post( 'charge.php', { sT: token.id, sE: token.email }, function (data) { console.log(data); } ); } }); var thePayment = document.getElementById('pay-amount'); if (thePayment) { thePayment.addEventListener('click', function (e) { var desc = $('#pay-amount').attr('data-desc'); var amount = Number($('#pay-amount').attr('data-amount')); var email = $('#pay-amount').attr('data-email'); // Open Checkout with further options: handler.open({ name: 'Test', description: desc, amount: amount, email: email, allowRememberMe: false }); e.preventDefault(); }); } // Close Checkout on page navigation: window.addEventListener('popstate', function () { handler.close(); });PHP 方面就是这样的 >
And the PHP side is just like this one >
require_once('html/includes/vendor/autoload.php'); $stripe = array( "secret_key" => "sk_test_nJxSc9Yw716tLBWTa9HHMxhj", "publishable_key" => "pk_test_yGQM97VuEUdttuOOFQcyaPHW" ); $charge_reply = array(); \Stripe\Stripe::setApiKey($stripe['secret_key']); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $token = $_POST['sT']; $email = $_POST['sE']; $customer = \Stripe\Customer::create(array( 'email' => $email, 'source' => $token )); $charge = \Stripe\Charge::create(array( "amount" => 1000, "currency" => "usd", "source" => $customer->id, "email" => $email, "description" => "Example charge" )); $charge_reply[] = [ 'token' => $token, 'email' => $email ]; sendJson($charge_reply); return; }我还启用了 php 中的 curl、json、mbstring.但是在向charge.php请求post方法后接受的函数,在控制台日志中打印POST example/charge.php 500 (Internal Server Error).
I have also enabled the curl,json,mbstring in php. But the function that accepts after requesting a post method to the charge.php, prints POST example/charge.php 500 (Internal Server Error) in the console log.
有什么办法可以解决这个问题吗?
So is there any way i can fix this?
推荐答案500(内部服务器错误)是您的代码中的错误,这意味着它们是一个致命错误.
500 (Internal Server Error) is something wrong in your code which means their is a fatal error.
要查找错误,您应该在页面顶部使用以下代码.
To find the error you should use below code in your top of the page.
ini_set('display_errors',1); error_reporting(E_ALL);它将返回确切的错误以便修复它.
It will return the exact error so can fix it.
注意:请勿在本地开发的生产环境中使用它.
Note: Do not use it in production environment this for your local development.
更多推荐
Stripe Checkout PHP API 获取 500 内部服务器错误
发布评论