简体   繁体   English

Stripe Checkout PHP API收到500个内部服务器错误

[英]Stripe Checkout PHP API getting 500 Internal Server Error

Here is my situation, i'm implementing Custom Stripe Checkout with Stripe PHP Api. 这是我的情况,我正在使用Stripe PHP Api实现Custom Stripe Checkout。

I have requested a post Method using jquery like this one > 我已经要求使用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(); }); 

And the PHP side is just like this one > 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;
}

I have also enabled the curl,json,mbstring in php. 我还启用了php中的curl,json,mbstring。 But the function that accepts after requesting a post method to the charge.php, prints POST http://example.com/charge.php 500 (Internal Server Error) in the console log. 但是在对charge.php请求post方法后接受的功能将在控制台日志中显示POST http://example.com/charge.php 500 (Internal Server Error)

So is there any way i can fix this? 所以有什么办法可以解决这个问题?

500 (Internal Server Error) is something wrong in your code which means their is a fatal error. 500(内部服务器错误)在您的代码中出了点问题,这意味着它们是致命错误。

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. 注意:请勿在生产环境中使用它进行本地开发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM