Stripe Checkout PHP API获得500内部服务器错误

时间:2018-05-24 09:13:50

标签: php stripe-payments

以下是我的情况,我正在使用Stripe PHP Api实现自定义条带检查。

我已经请求使用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)

那么有什么方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

500(内部服务器错误)在您的代码中出错,这意味着它们是致命错误。

要查找错误,请在页面顶部的代码下方使用。

ini_set('display_errors',1);
error_reporting(E_ALL);

它将返回确切的错误,因此可以修复它。

注意:请勿在生产环境中将其用于本地开发。