0

very simple thing but i'm trying to include this:

<?php echo $_SESSION['totalprice']; ?>

Into the amount field of charge.php which is this:

<?php
  require_once('config.php');

  $token  = $_POST['stripeToken'];

  $customer = \Stripe\Customer::create(array(
      'email' => '[email protected]',
      'card'  => $token
  ));

  $charge = \Stripe\Charge::create(array(
      'customer' => $customer->id,
      'amount'   => "".$_SESSION['totalprice']."",
      'currency' => 'eur'
  ));

  echo '<h1>Successfully charged $50.00!</h1>';
?>

I think it's a problem of indentation but can't get a way around it. This is the error:

*Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'Invalid integer: ' in /home/barceloneta/public_html/stripe-php-3.2.0/lib/ApiRequestor.php:98 from API request 'req_6ycxcj8LmrLt9T' Stack trace: #0 /home/barceloneta/public_html/stripe-php-3.2.0/lib/ApiRequestor.php(210): Stripe\ApiRequestor->handleApiError('{\n "error": {\n...', 400, Array, Array) #1 /home/barceloneta/public_html/stripe-php-3.2.0/lib/ApiRequestor.php(60): Stripe\ApiRequestor->_interpretResponse('{\n "error": {\n...', 400, Array) #2 /home/barceloneta/public_html/stripe-php-3.2.0/lib/ApiResource.php(105): Stripe\ApiRequestor->request('post', '/v1/charges', Array, Array) #3 /home/barceloneta/public_html/stripe-php-3.2.0/lib/ApiResource.php(137): Stripe\ApiResource::_staticRequest('post', '/v1/charges', Array, NULL)

4 /home/barceloneta/public_html/stripe-php-3.2.0/lib/Charge.php(37): Stripe\ApiResource::_create(Array, NULL) #5

/home/barceloneta/public_html/charge.php(15): Stripe\Charge::create(Array) #6 /home/barceloneta/public_htm in /home/barceloneta/public_html/stripe-php-3.2.0/lib/ApiRequestor.php on line 98*

1 Answer 1

0

You are wrapping the amount in quotes, making it a string type. It seems that Stripe is pretty strict about that, so remove the quotes and make sure you are sending an integer.

$charge = \Stripe\Charge::create(array(
    'customer' => $customer->id,
    'amount'   => (int) $_SESSION['totalprice'],
    'currency' => 'eur'
));

Also, make sure the session key is set and has an integer value before sending it to stripe.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.