0

hi i am using stripe api for payment using this tutorial http://code.tutsplus.com/tutorials/so-you-want-to-accept-credit-cards-online--net-25457 But i am getting this error

pay.php 500 (Internal Server Error)

here it is pay.php code

<?php
// Helper Function: used to post an error message back to our caller
function returnErrorWithMessage($message) 
{
    $a = array('result' => 1, 'errorMessage' => $message);
    echo json_encode($a);
}

// Credit Card Billing 
require_once('Stripe.php');  // change this path to wherever you put the Stripe PHP library!

$trialAPIKey = "";  // These are the SECRET keys!
$liveAPIKey = "";

Stripe::setApiKey($trialAPIKey);  // Switch to change between live and test environments

// Get all the values from the form
$token = $_POST['stripeToken'];
$email = $_POST['email'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$price = $_POST['price'];

$priceInCents = $price * 100;   // Stripe requires the amount to be expressed in cents

try
{
    // We must have all of this information to proceed. If it's missing, balk.
    if (!isset($token)) throw new Exception("Website Error: The Stripe token was not generated correctly or passed to the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");
    if (!isset($email)) throw new Exception("Website Error: The email address was NULL in the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");
    if (!isset($firstName)) throw new Exception("Website Error: FirstName was NULL in the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");
    if (!isset($lastName)) throw new Exception("Website Error: LastName was NULL in the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");
    if (!isset($priceInCents)) throw new Exception("Website Error: Price was NULL in the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");

    try
    {
        // create the charge on Stripe's servers. THIS WILL CHARGE THE CARD!
        $charge = Stripe_Charge::create(array(
            "amount" => $priceInCents,
            "currency" => "usd",
            "card" => $token,
            "description" => $email)
        );

        // If no exception was thrown, the charge was successful! 
        // Here, you might record the user's info in a database, email a receipt, etc.

        // Return a result code of '0' and whatever other information you'd like.
        // This is accessible to the jQuery Ajax call return-handler in "buy-controller.js"
        $array = array('result' => 0, 'email' => $email, 'price' => $price, 'message' => 'Thank you; your transaction was successful!');
        echo json_encode($array);
    }
    catch (Stripe_Error $e)
    {
        // The charge failed for some reason. Stripe's message will explain why.
        $message = $e->getMessage();
        returnErrorWithMessage($message);
    }
}
catch (Exception $e) 
{
    // One or more variables was NULL
    $message = $e->getMessage();
    returnErrorWithMessage($message);
}
?>

even i can't access strip's php files.

Please any idea?

Thanks

Farrukh Zaman
  • 49
  • 1
  • 9
  • Check your error logs. – Jonnix Aug 30 '16 at 14:41
  • nothing in error log. here is link when you fill up form you can see error in consol http://dev.jbtglobal.com/payments/ – Farrukh Zaman Aug 30 '16 at 14:44
  • No idea? or can't understand my issue anybody? – Farrukh Zaman Aug 30 '16 at 14:50
  • We can't really test your stuff as we don't have e.g. test cards. If you're getting a white screen and 500 error, then something has gone wrong. Check http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php to see how to display errors. – Jonnix Aug 30 '16 at 15:43

0 Answers0