[英]Stripe Checkout PHP API getting 500 Internal Server Error
這是我的情況,我正在使用Stripe PHP Api實現Custom Stripe Checkout。
我已經要求使用jquery這樣的發布方法>
var handler = StripeCheckout.configure({ key: 'pk_test_yGQM97VuEUdttuOOFQcyaPHW', image: 'https://stripe.com/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方面就是這樣的>
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 http://example.com/charge.php 500 (Internal Server Error)
。
所以有什么辦法可以解決這個問題?
500(內部服務器錯誤)在您的代碼中出了點問題,這意味着它們是致命錯誤。
要查找錯誤,您應該在頁面頂部使用以下代碼。
ini_set('display_errors',1);
error_reporting(E_ALL);
它將返回確切的錯誤,因此可以修復它。
注意:請勿在生產環境中使用它進行本地開發。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.