Giter Club home page Giter Club logo

razorpay-php's Introduction

razorpay-php

Build Status Stable License

Official PHP library for Razorpay API.

Read up here for getting started and understanding the payment flow with Razorpay: https://docs.razorpay.com/docs/getting-started

Prerequisites

  • A minimum of PHP 7.3 upto 8.1

Installation

  • If your project using composer, run the below command
composer require razorpay/razorpay:2.*
  • If you are not using composer, download the latest release from the releases section. You should download the razorpay-php.zip file. After that, include Razorpay.php in your application and you can use the API as usual.

##Note: This PHP library follows the following practices:

  • Namespaced under Razorpay\Api
  • API throws exceptions instead of returning errors
  • Options are passed as an array instead of multiple arguments wherever possible
  • All requests and responses are communicated over JSON

Documentation

Documentation of Razorpay's API and their usage is available at https://docs.razorpay.com

Basic Usage

Instantiate the razorpay php instance with key_id & key_secret. You can obtain the keys from the dashboard app (https://dashboard.razorpay.com/#/app/keys)

use Razorpay\Api\Api;

$api = new Api($api_key, $api_secret);

The resources can be accessed via the $api object. All the methods invocations follows the following pattern

    // $api->class->function() to access the API
    //Example
    $api->payment->fetch($paymentId);

Supported Resources

Development

See the doc.md file for getting started with development.

Release

Steps to follow for a release:

  1. Merge the branch with the new code to master.
  2. Bump the Version in src/Api.php.
  3. Rename Unreleased to the new tag in CHANGELOG.md
  4. Add a new empty "Unreleased" section at the top of CHANGELOG.md
  5. Fix links at bottom in CHANGELOG.md
  6. Commit
  7. Tag the release and push to GitHub
  8. A release should automatically be created once the travis build passes. Edit the release to add some description.

License

The Razorpay PHP SDK is released under the MIT License. See LICENSE file for more details.

razorpay-php's People

Contributors

73sl4 avatar albingeorge avatar amitmahbubani avatar amitmerchant1990 avatar ankitdas13 avatar captn3m0 avatar ccrims0n avatar chetangn avatar deadmantfa avatar dependabot-preview[bot] avatar harman28 avatar harshilmathur avatar jitendra-1217 avatar kajolnigam avatar mayur-wadpalliwar avatar msonowal avatar naveen-s-rzp avatar neera11 avatar phpindia avatar prem-razorpay avatar ramth05 avatar rkamath3 avatar rpshah avatar saurav1991 avatar shashankkumar avatar shashankmehta avatar smarchint avatar sonyy-m avatar sunnyagg avatar swati31196 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

razorpay-php's Issues

Allow capture without fetching

As it stands, php and other SDKs need to fetch a payment before capturing. Since Razorpay recommends merchants to capture before responding success/failure to user, this places an extra fetch call within merchant-to-customer request. So it should be removed.

Make the returned Object Public, $customer = $api->customer->create

Why this class is returning a protected array, which obviously will not be accessible outside of the class.
$customer = $api->customer->create


class Entity extends Resource implements ArrayableInterface {

    protected $attributes = array();


can't it be like protected $attributes = array();`` ?

The requested URL was not found on the server.

When I try to create a new transfer request it says "The requested URL was not found on the server"

my request was

$transfer = $api->transfer->create(array('account' => 'Customer Id', 'amount' => 10, 'currency' => 'INR'));

Please help me to fix this.

Customer Creation Issue

Our customers are getting error if the try to pay using razor pay for the 2nd time using their same email address

download_20180921_170624

Unable to fetch transfers

My transfer is successful, but when I am fetching it, I am getting an empty result,

$apiKey = env('RAZORPAY_API_KEY');
        $apiSecret = env('RAZORPAY_SECRET_KEY');
        $api = new Api($apiKey, $apiSecret);
        $paymentId = 'pay_CdJPa3B6n1o8ag';

        $transferDetails = [
             [
                'account' => 'acc_####',
                'amount' => 100, 
                'currency' => 'INR',
                'notes' => [
                    'name' => 'PQR pvt Ltd'
                ]
            ],
            [
                'account' => 'acc_####',
                'amount' => 100, 
                'currency' => 'INR',
                'notes' => [
                    'name' => 'Abc Pvt ltd'
                ]
            ]
        ];
    
        $transfers  = $api->payment->fetch($paymentId)->transfer(['transfers' => $transferDetails]); // Create transfer

    //    $transfers = $api->transfer->all();  even if I will try to fetch all the transfer, I am getting empty.

        return response()->json(
           [ 'transfers' => $transfers]
        );

Note: In report, I can see transactions are successful.

Any suggestion?

order data returning null data

use Razorpay\Api\Api; $api = new Api($this->key, $this->secret); $order_data = [<data>] $api->order->create($order_data);

On creating new order returning null data.
if i change the api keys getting invalid api key as exception from razor pay. but order is not creating.

Exception - Class 'Requests_Hooks' not found

I am getting the php error,
Exception - Class 'Requests_Hooks' not found
on line 44 of entity.php, here is the code snippet below and the stack trace below it.
(I am using your php library, and had to comment out lines 4-21 of Razorpay.php since it was calling Requests.php from a non-existant /libs directory in your library. )

require_once(DIR . '/razorpay-php-master/Razorpay.php');
// use Razorpay\Api\Api;

$api_key    = "my key here";
$api_secret = "my secret here";

$api = new Razorpay\Api\Api($api_key, $api_secret);

    $va_constructor = array(
						'receivers' => array('types' => array('bank_account')), 
						'description' 	 => 'Virtual Account for Sritoni1 Moodle1', 
						'notes' 		 => array(
													'sritoni_id' => '00_00-01'
												 )
						);
    $virtualAccount  = $api->virtualAccount->create($va_constructor);

---------------------------stack trace below-------------------------------------------------

  • line 44 of /blocks/configurable_reports/export/wpsync/razorpay-php-master/src/Request.php: Error thrown
  • line 79 of /blocks/configurable_reports/export/wpsync/razorpay-php-master/src/Entity.php: call to Razorpay\Api\Request->request()
  • line 15 of /blocks/configurable_reports/export/wpsync/razorpay-php-master/src/Entity.php: call to Razorpay\Api\Entity->request()
  • line 9 of /blocks/configurable_reports/export/wpsync/razorpay-php-master/src/VirtualAccount.php: call to Razorpay\Api\Entity->create()
  • line 46 of /blocks/configurable_reports/export/wpsync/export.php: call to Razorpay\Api\VirtualAccount->create()
  • line 117 of /blocks/configurable_reports/viewreport.php: call to export_report()

Does not return payment details in test account

I am trying to fetch payment details in my test account but can't get payment details
$api = new Api($this->razorpay_api_key, $this->razorpay_secret_key);
$payment = $api->payment->fetch($request->payment_id);

this is returning empty {} object.

Fetch all customers

I'm trying to fetch all customers ,
but it returns only 10 instead of all
How to get all without out any limit

        $api = new Api($keyId, $secret);
        $relativeUrl = 'customers';
        $customers = $api->request->request('GET', $relativeUrl, []);

Environment:

PHP 5.6
composer 1.5.2
Laravel 5.4

Any suggestions or help ?

Webhook validation error : invalid signature passed

Hi,
In My test enviroment, I have used the following code to validate the Webhook:

try{
        	 if(!$oApi->utility->verifyWebhookSignature($requestBody, $razorPaySignature, $this->RAZOR_PAY_SECRET_KEY)) {
	            Log::info('Hash validation failed. so terminating the process');
	            die;
        	}
        }
        catch(Exception $e) {
        	Log::info('RazorPay Webhook validation Error: '.$e->getMessage());
        	die;
        }

Where $requestBody is the json encoded request data, $razorPaySignature is the value received form header X-Razorpay-Signature.
But always I'm getting this error : Invalid signature passed.
I'm sure the $this->RAZOR_PAY_SECRET_KEY contains right value.

This is the request JSON:

{
"entity": "event",
"event": "payment.authorized",
"contains": [
"payment"
],
"payload": {
"payment": {
"entity": {
"id": "pay_8Tikb77Pvn10yb",
"entity": "payment",
"amount": 1000,
"currency": "INR",
"status": "authorized",
"order_id": null,
"invoice_id": null,
"international": false,
"method": "netbanking",
"amount_refunded": 0,
"refund_status": null,
"captured": false,
"description": "Purchase Description",
"card_id": null,
"bank": "HDFC",
"wallet": null,
"vpa": null,
"email": "[email protected]",
"contact": "123123456789",
"notes": {
"booking_id": "15666A",
"service": "hotel"
},
"fee": null,
"service_tax": null,
"error_code": null,
"error_description": null,
"created_at": 1503320553,
"tax": null
}
}
},
"created_at": 1503320554
}

Load Requests class conditionally

Currently, I am working on WordPress project and it has this class in core, so conflict will occur.

For Ref:
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-requests.php
https://github.com/razorpay/razorpay-php/blob/master/Razorpay.php#L4

// Custom Fix: WordPress also has Requests class.
if( ! class_exists( 'Requests' ) ) {
	// Include Requests
	require_once __DIR__.'/libs/Requests-1.6.1/library/Requests.php';
}

Note: Can we also update Requests lib version
For ref:
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-requests.php#L91
https://github.com/razorpay/razorpay-php/blob/master/composer.json#L32

Golang SDK for Razorpay?

Hi,

Since there is no option to create an issue in razorpay for new SDK, I am requesting here. Please provide me correct place to post this?

Does razorpay have official Golang SDK?

Resource class and PHP 7

In PHP 7 Resource is reserved keyword
And in razorpay-PHP there is Resource class and guess it needs update

Documentation ?

I see zero documentation on how to get started on the Api (What is $options, or $id) or atleast a working code sample for taking a payment. Any help would be appreciated.

API Documentation Issues

Today i tested both Repositories

  1. https://github.com/Razorpay/razorpay-php-testapp
  2. https://github.com/Razorpay/razorpay-php

I hope this is some sort of documentation issue

Here - https://github.com/Razorpay/razorpay-php-testapp/blob/master/charge.php
I found out this code to initiate Razorpay API

use Razorpay\Api\Api;
//Use your key_id and key secret
$api = new Api('rzp_test_1DP5mmOlF5G5ag', 'thisissupersecret');

and this code works fine for me

But here - https://github.com/Razorpay/razorpay-php

use Razorpay\Api\Api
$api = new Razorpay($api_key, $api_secret);

This method gives me following error
Fatal error: Class 'Razorpay' not found in /opt/lampp/htdocs/razorpay/index.php on line 38

payment transfer error

Getting this error "The server encountered an error. The incident has been reported to admins."

Webhook not being fired for Route transfer

When a transfer made to a linked account is settled the settlement.processed webhook is not fired.
Also, the scheduled transfer is not updating as settled even if the settlement date has crossed.

Webhooks PHP code

Hi,

I'm new to Payment integration and webhooks integration. Can anyone help with the Webhooks code in PHP. Below is a sample code i found...is this right?

use Razorpay\Api\Api;
$api = new Api("API_key", "API_secret");

$json=file_get_contents('php://input');
$webhookBody = json_decode($json);

$webhookSecret='Webhook_secret';
$webhookSignature = $api->header('X-Razorpay-Signature');
$api->utility->verifyWebhookSignature($webhookBody, $webhookSignature, $webhookSecret);

Composer Vendor Directory

Currently, Vendor directory is excluded from .gitignore. Vendor directories should not be included in the source code commits.

Move to guzzle

We want to move our HTTP backend to guzzle down the line. Things we need to take care of:

  • Don't break the existing SDK
  • How to handle the httplug requirement [https://packagist.org/packages/php-http/httplug]
  • Should this be a major version upgrade?
  • Decide between guzzle 5 and 6 (I'd prefer 6, but not everyone has upgraded there yet)
  • If we go with 6, do we keep supporting the older requests releases?
  • How to handle the razorpay-php.zip bundle we give out in our releases? This is important because we currently don't include the composer autoloader, but just the custom Requests autoloader, which only autoloads requests library. This helps us avoiding the entire composer dependency. However, guzzle probably will resolve to 10-15 dependencies which we need to autoload cleanly, even if the end-user is using the Razorpay.php file without using composer.

Assigning to @StSarc to look into this.

USE without Namespace for frameworks like Codeigniter,Cakephp

Frameworks like Codeigniter, CakePHP do not support NAMESPACES in class files how can this be used in such environment ??

Currently i am trying Razorpay Integration in CakePHP 2.3.0 but this class is not working since CakePhp do not support namespaces in classes..

I hope this gets ready for such Frameworks since CakePhp and Codeigniter are highly used for developing web applications

While reloading verify page it will giving "true" condition always

After getting success on the payment page, it will go to the verify.php page. When we are reloading this page it will give "true" condition always but As per the correct manner, it will be killed automatically once after reloading the verify.php page.

Please help me out in this. We are waiting for this by so long.

Ticket no. 555062

Currency is not supported error

As per this doc, when creating an order, we can simply pass the currency parameter in Order as USD or EUR.

However, in practice, I am not able to make it to work.

It only works when currency parameter is 'INR'.

My code:

<?php
require 'vendor/autoload.php';
use Razorpay\Api\Api;
$api = new Api('rzp_test_xxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxx');
$order  = $api->order->create(array('receipt' => '123', 'amount' => 100, 'currency' => 'USD'));
?>

On running this code, I am getting this error:

Fatal error: Uncaught Razorpay\Api\Errors\BadRequestError: Currency is not supported in D:\Freelancer\skipqlah\vendor\razorpay\razorpay\src\Request.php:120 Stack trace: #0 D:\Freelancer\skipqlah\vendor\razorpay\razorpay\src\Request.php(90): Razorpay\Api\Request->processError(Array, 400, Object(Requests_Response)) #1 D:\Freelancer\skipqlah\vendor\razorpay\razorpay\src\Request.php(44): Razorpay\Api\Request->checkErrors(Object(Requests_Response)) #2 D:\Freelancer\skipqlah\vendor\razorpay\razorpay\src\Entity.php(79): Razorpay\Api\Request->request('POST', 'https://api.raz...', Array) #3 D:\Freelancer\skipqlah\vendor\razorpay\razorpay\src\Entity.php(15): Razorpay\Api\Entity->request('POST', 'orders/', Array) #4 D:\Freelancer\skipqlah\vendor\razorpay\razorpay\src\Order.php(12): Razorpay\Api\Entity->create(Array) #5 D:\Freelancer\skipqlah\rzp_order.php(15): Razorpay\Api\Order->create(Array) #6 {main} thrown in D:\Freelancer\skipqlah\vendor\razorpay\razorpay\src\Request.php on line 120

Fatal error: account, amount is/are not required and should not be sent

I tried to transfer a captured payment to linked account by calling the API:

$trasnfer = $api->payment->fetch(<razorpay_payment_id>)->transfer(array('account'=><razorpay_linked_account_number>,'amount'=><amount_to_transfer>));

I am getting below error:

PHP Fatal error: Uncaught exception 'Razorpay\Api\Errors\BadRequestError' with message 'account, amount is/are not required and should not be sent' in /vendor/razorpay/razorpay/src/Request.php:123
Stack trace:
#0 /vendor/razorpay/razorpay/src/Request.php(90): Razorpay\Api\Request->processError(Array, 400, Object(Requests_Response))
#1 /vendor/razorpay/razorpay/src/Request.php(44): Razorpay\Api\Request->checkErrors(Object(Requests_Response))
#2 /vendor/razorpay/razorpay/src/Entity.php(79): Razorpay\Api\Request->request('POST', 'payments/pay_Cg...', Array)
#3 /vendor/razorpay/razorpay/src/Payment.php(46): Razorpay\Api\Entity->request('POST', 'payments/pay_Cg...', Array)
#4 /ajax_controller.php(848): Razorpay\Api\Payment->transfer(Array)
#5 {main}
thrown in /vendor/razorpay/razorpay/src/Request.php on line 123

Can you please let me know what wrong I am doing here.

Add a changelog

Add a changelog and keep updating it with every version released.

Razorpay ajax issue

I'm loading the razorpay form by ajax. In ajax call it is directly calling '/pay/index' page instead of showing the razorpay gateway.

I'm Loading this by ajax call.

` <form action="/pay/index" method="POST" id="payForm">
      <script
        src="https://checkout.razorpay.com/v1/checkout.js"
        data-key="rzp_test_lQNUlfCzqCnq4h"
        data-amount="1111" 
        data-name="company-name"
        data-description="Enjoy savings and benefits of Premium Service"
        data-image="image-url"
        data-prefill.email="<?php echo $userEmail; ?>"
        data-prefill.contact="<?php echo $userMobile; ?>"
        data-theme.color="#00bbff"
      ></script>
        <input type="hidden" value="<?php echo $currentUrl; ?>"  name="redirectURL">
        <input type="hidden" value="3"  name="subscriptionId">
    </form>`
  <a class= js-make-payment-btn">Make Payment <i class="icon-arrow-right pay-right-arrow"></i> </a> 

jquery to call razorpay:

$('body').on('click', '.js-make-payment-btn', function (e) { e.preventDefault(); e.stopPropagation(); $('#payForm').submit(); });

QR Code Auto Redirect Handler method in razorpay

When i use razorpay and choose QR Scanner to payment then without taking any payment in comes in handler method with payment id and signature.

Please check this.
Reply as soon as possible

Regards,
Vivek

Razorpay php server side integration without composer

The documentation says i should download the razorpay-php.zip file. After that include Razorpay.php in your application.
My project does not use composer.
I have all my php class files under sys->class folder. Example : sys->class->class.account.inc.php

Now i have extracted razorpay-php under sys folder. So folder structure looks like sys->razorpay-php

How do i use or include Razorpay.php in my class files? I am new to PHP and need help in setting up. Thank You.

Customer already exists on edit call

Here's my code:

$api = new \Razorpay\Api\Api(env('RAZORPAY_API_KEY'), env('RAZORPAY_API_SECRET'));
$response = $api->customer->fetch('CUSTOMER_ID')->edit([
    'name'  => 'Rohit Khatri updated'
]);
print_r($response);

It throws error:

BadRequestErrorCustomer already exists for the merchant - 400

Not able to get the order information after creation

Please give me a solution asap.

if ((isset($response['entity'])) and
            ($response['entity'] == $this->getEntity()))   <- this condition is failing because `Entity from response is 'order' entity in code is '//order'`
        {
            $this->fill($response);     
            return $this;
        }
        else
        {
             return static::buildEntity($response);      <- not returning anything from $response
        }

Class 'Razorpay\\Api' not found

I'm trying to use Razorpay razorpay-php library with composer in my package for laravel .
But I'm unable to include it in my project.

Error I'm getting is Class 'Razorpay\\Api' not found

My sample code:

use Razorpay\Api;
$api = new Api($key, $secret);

Environment :

  • PHP 7.1
  • composer 1.5.2
  • Laravel 5.5

Any suggestions or help ?

$api->payment->fetch() is not accepting a variable

I have created an order, fetched the order id and tried to fetch payment details.
$order = $api->order->create(array('receipt' => '123', 'amount' => 100, 'currency' => 'INR')); $OrderId = $order->id; $payment = $api->payment->fetch($OrderId);
But echo $payment->amount didn't work.

Here $OrderId is of type string. If I insert a order id string manually
instead of inserting variable $OrderId it works fine.
Note that I was able to echo $OrderId. Where exactly am I wrong ?
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.