Skip to content

Razorpay plugin for Omnipay Payment Processing Library

License

Notifications You must be signed in to change notification settings

Epic/omnipay-razorpay

 
 

Repository files navigation

Omnipay: Razorpay

Travis branch License: MIT

Razorpay driver for the Omnipay PHP payment processing library

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP. This package implements Razorpay support for Omnipay.

To know more about Razorpay payment flow and steps involved, please read up here: https://docs.razorpay.com/docs

Requirements

PHP >= 5.6.0

Installation

Omnipay is installed via Composer. To install, simply add it to your composer.json file:

{
    "require": {
        "razorpay/omnipay-razorpay": "~3.0"
    }
}

And run composer to update your dependencies:

$ composer update

Basic Usage

The following gateways are provided by this package:

  • Razorpay

For general usage instructions, please see the main Omnipay repository.

   // Create a gateway for the Razorpay Gateway
   // (routes to GatewayFactory::create)
   $gateway = Omnipay::create('Razorpay');

   // Initialise the gateway
   $gateway->initialize(array(
       'key_id' => 'MyKeyId',
       'key_secret' => 'MyKeySecret',
       'automatic_capture' => true
   ));
   $order_id = null;

   // Create an order on the gateway
   $transaction = $gateway->purchase(array(
       'amount'                   => '1000.00',
       'currency'                 => 'INR'
   ));
   $response = $transaction->send();
   if ($response->isSuccessful()) {
       echo "Order creation was successful!\n";
       $order_id = $response->getTransactionId();
       echo "Order Id = " . $order_id . "\n";
       
       // Use this direct customer to complete check on Razorpay site
       $checkoutUrl = $response->getRedirectUrl();
       $checkoutMethod = $response->getRedirectMethod();
       $checkoutData = $response->getRedirectData();
   }
 
   // Complete the purchase for the order on the gateway
   $transaction = $gateway->completePurchase(array(
       'amount' => '1000.00',
       'currency' => 'INR',
       'token' => 'verification_signature',
       'transactionReference' => 'payment_id_from_razorpay',
       'transactionId' => $order_id
   ));
   $response = $transaction->sent();
   if ($response->isSuccessful()) {
       echo "Payment complete!\n";
   } else {
       echo "Payment incomplete!\n";
   }

If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.

If you want to keep up to date with release announcements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.