PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 11, 2022

[FIXED] How to fetch payment details using Razorpay PHP API?

 November 11, 2022     payment-gateway, php, razorpay     No comments   

Issue

I am trying to integrate the code for fetching payment details.

billno: This value will be taken from the URL.

My current code:

include 'razorpay/Razorpay.php';
use Razorpay\Api\Api;

$api = new Api('Secret ID', 'Secret Key');

$payment = $api->payment->fetch($_REQUEST['billno']);
$text =  json_encode($payment->toArray());
$obj = json_decode($text);
$shopping_id = $obj->{'notes'}->{'shopping_id'};

$rzp_amount = $obj->{'amount'};//xheck
$real_amount = $rzp_amount/100;
$rzp_key = $obj->{'id'};
$rzp_status = $obj->{'status'}; //Authorised cgecj
$rzp_descp = $obj->{'description'};
$rzp_mail = $obj->{'email'};
$rzp_phone = $obj->{'contact'};
$rzp_address = $obj->{'notes'}->{'address'};
$rzp_timestamp = $obj->{'created_at'};
$rzp_method = $obj->{'method'};

Extracting the billno using the code would give us the above mentioned $rzp variables.


Solution

The payment->fetch call returns a Payment Entity, and has all the data members available for direct access. You don't have to decode JSON yourselves, that is taken care of by the SDK:

include 'razorpay/Razorpay.php';
use Razorpay\Api\Api;

$api = new Api('Secret ID', 'Secret Key');

$payment = $api->payment->fetch($_REQUEST['billno']);

echo $payment->amount;
print_r($payment->notes);

Disclaimer: I work for Razorpay



Answered By - Nemo
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing