Skip to content

LalitChaudhary1/payumoney-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StyleCI

PayUMoney API for PHP

Simple library for accepting payments via PayUMoney.

Installation

To add this library to your project, simply add a dependency on niranjan94/payumoney to your project's composer.json file. Here is a minimal example of a composer.json file:

{
    "require": {
        "niranjan94/payumoney": "1.*"
    }
}

Usage

You'll find a minimal usage example below.

Initialize purchase

<?php
// purchase.php

use CodeZero\PayUMoney\PayUMoney;

require 'vendor/autoload.php';

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

// All of these parameters are required!
$params = [
    'txnid'       => 'A_UNIQUE_TRANSACTION_ID',
    'amount'      => 10.50,
    'productinfo' => 'A book',
    'firstname'   => 'Peter',
    'email'       => '[email protected]',
    'phone'       => '1234567890',
    'surl'        => 'http://localhost/payumoney-php/return.php',
    'furl'        => 'http://localhost/payumoney-php/return.php',
];

// Redirects to PayUMoney
$payumoney->initializePurchase($params)->send();

Finalize purchase

<?php
// return.php

use CodeZero\PayUMoney\PayUMoney;
use CodeZero\PayUMoney\PurchaseResult;

require 'vendor/autoload.php';

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

$result = $payumoney->completePurchase($_POST);

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

The PurchaseResult has a few more methods that might be useful:

$result = $payumoney->completePurchase($_POST);

// Returns Complete, Pending, Failed or Tampered
$result->getStatus(); 

// Returns an array of all the parameters of the transaction
$result->getParams();

// Returns the ID of the transaction
$result->getTransactionId();

// Returns true if the checksum is correct
$result->checksumIsValid();

About

Simple library for accepting payments via PayUMoney.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%