niranjan94 / payumoney-php

Simple library for accepting payments via PayUMoney.
https://niranjan94.github.io/payumoney-php
MIT License
0 stars 4 forks source link

[27-Jun-2018 08:40:18 UTC] PHP Fatal error: Undefined class constant 'STATUS_COMPLETED' in /home/jrsarath/public_html/alpha/return.php on line 14 #4

Closed jrsarath closed 6 years ago

jrsarath commented 6 years ago

im getting this error after getting redirected after a successful payment

niranjan94 commented 6 years ago

Hi @jrsarath

This seems to be something that is related to your code and not because of this library. Please check your code.

jrsarath commented 6 years ago

here is the the files.. index.php

<?php
use CodeZero\PayUMoney\PayUMoney;
require 'vendor/autoload.php';

$payumoney = new PayUMoney([
    'merchantId' => 'uz7qF2fx',
    'secretKey'  => 'TwRub9M3oR',
    'testMode'   => true
]);

$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$params = [
  'txnid'       => $txnid,
  'amount'      => 10.50,
  'productinfo' => 'A book',
  'firstname'   => 'Peter',
  'email'       => 'abc@example.com',
  'phone'       => '8697487237',
  'surl'        => 'http://jrsarath.cf/alpha/return.php',
  'furl'        => 'http://jrsarath.cf/alpha/return.php',
];
 // Redirects to PayUMoney
  $payumoney->initializePurchase($params)->send();

?>

return.php

<?php
use CodeZero\PayUMoney\PayUMoney;
require 'vendor/autoload.php';

$payumoney = new PayUMoney([
    'merchantId' => 'uz7qF2fx',
    'secretKey'  => 'TwRub9M3oR',
    'testMode'   => true
]);

$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$params = [
  'txnid'       => $txnid,
  'amount'      => 10.50,
  'productinfo' => 'A book',
  'firstname'   => 'Peter',
  'email'       => 'abc@example.com',
  'phone'       => '8697487237',
  'surl'        => 'http://jrsarath.cf/alpha/return.php',
  'furl'        => 'http://jrsarath.cf/alpha/return.php',
];
if(isset($_POST['submit'])){ //check if form was submitted
  // Redirects to PayUMoney
  $payumoney->initializePurchase($params)->send();
}

?>

what im doing wrong here ?

niranjan94 commented 6 years ago

You're index.php & return.php seems to be identical. I think you pasted the wrong content here.

jrsarath commented 6 years ago
<?php
// return.php
use CodeZero\PayUMoney\PayUMoney;
require 'vendor/autoload.php';

$payumoney = new PayUMoney([
    'merchantId' => 'uz7qF2fx',
    'secretKey'  => 'TwRub9M3oR',
    'testMode'   => true
]);
$result = $payumoney->completePurchase($_POST);

if ($result->checksumIsValid() && $result->getStatus() === PayUMoney::STATUS_COMPLETED) {
  print 'Payment was successful. Transaction ID :'.$result->getTransactionId();
} else {
  print 'Payment was not successful.Transaction ID :'.$result->getTransactionId();
}

here - return.php

jrsarath commented 6 years ago

@niranjan94 help please

niranjan94 commented 6 years ago

Use PurchaseResult::STATUS_COMPLETED. Looks like a documentation error. I'll update the readme/

jrsarath commented 6 years ago

Class 'PurchaseResult' not found in /home/jrsarath/public_html/alpha/return.php here is what i got after your update

jrsarath commented 6 years ago

im using if ($result->checksumIsValid() && $result->getStatus() === "Completed") instead