1

I have successfully integrated stripe payment. However, when I pass hardcoded amount and currency it works fine, but as I use variable in the charge array it gives me HTTP ERROR 500

My code:

 <?php
require_once "config.php";
session_start();
$depoamount=$_SESSION['stripeamount'];
$curr=$_SESSION['curr'];
$token  = $_POST['stripeToken'];
$email  = $_POST['stripeEmail'];
$custid=$_SESSION['reg_no'];
//$custid='123';
$id=$_POST['ID'];
/* $depoamount=1200;
$curr='inr';*/
$customer = \Stripe\Customer::create([
  'email' => $email,
  'source'  => $token,
  'customer'=> $custid,

]);

$charge = \Stripe\Charge::create([
  'customer' => $customer->id,
  'amount'   => $depoamount,// If I use '5000' it works
  'currency' => $curr,// same if I put 'usd' it works
 ]);

  echo '<h1>Successfully charged</h1>';
  echo $charge->email;
  echo $charge->id;
  echo $custid;
 ?>

I think syntax is ok , however its not working.

mark
  • 561
  • 3
  • 18
  • 45
  • What are the values of `$depoamount` and `$curr`? – showdev Apr 16 '19 at 22:25
  • these are coming from previous page, its user input value – mark Apr 16 '19 at 22:26
  • What are their values when you get the error? Try `var_dump($demoamount);var_dump($curr);`. – showdev Apr 16 '19 at 22:26
  • in charge array I put `'amount' => $depoamount,` it gives error and if I put `'amount' => '5000',` works fine – mark Apr 16 '19 at 22:28
  • 2
    page is not loading `kaem.in is currently unable to handle this request. HTTP ERROR 500` – mark Apr 16 '19 at 22:28
  • 2
    that what my concern is, I thought may be SESSION might not be working hence i hard coded it to test `$depoamount=5000` but still it shows error – mark Apr 16 '19 at 22:30
  • I tried `$depoamount='5000'` still the sam e – mark Apr 16 '19 at 22:32
  • You may want to check server error logs and try [outputting PHP errors](https://stackoverflow.com/a/21429652/924299). – showdev Apr 16 '19 at 22:44
  • I am on shared hosting, so `display_errors = on` would be difficult – mark Apr 16 '19 at 22:48
  • Try `error_reporting(E_ALL); ini_set('display_errors', 1);`. Is the `$_SESSION` populated? You might get an error like "Undefined index: stripeamount". – showdev Apr 16 '19 at 22:54
  • If you're getting an error from the API server, there's probably not much we can do for you. Have you asked the API maintainers why your requests are failing? – miken32 Apr 16 '19 at 23:03
  • @miken32 "kaem.in" doesn't sound like a Stripe server. I think it's the OP's server, but I could be wrong. – showdev Apr 16 '19 at 23:04
  • 1
    So, using `'amount' => 5000` works, and `'amount' => '5000'` works, but setting `$depoamount = 5000;` and then `'amount' => $depoamount` doesn't work? – Greg Schmidt Apr 16 '19 at 23:15
  • `'amount' => '5000'` this works but `$depoamount = 5000;` and then `'amount' => $depoamount` this doesnt – mark Apr 17 '19 at 06:14
  • @GregSchmidt guided me to think on line of string , so I converted `$depoamount=(string)$depoamount;` now its working – mark Apr 17 '19 at 07:07

0 Answers0