Posted on • Updated on

How To Store Entire JSON response of Razorpay fetch/capture API



Step 1 - Fetch response

use Razorpay\Api\Api;
$api = new Api($key_id, $secret);
$response = $api->payment->fetch($paymentId);


$response = $api->payment->fetch($paymentId)->capture(array('amount'=>$amount,'currency' => 'INR'));

//sample response

"id": "pay_G8VQzjPLoAvm6D", 
"entity": "payment",  
"amount": 1000,  
"currency": "INR",  
"status": "captured",  
"order_id": "order_G8VPOayFxWEU28",  
"invoice_id": null,  
"international": false,  
"method": "upi",  
"amount_refunded": 0,  
"refund_status": null,  
"captured": true,  
"description": "Purchase Shoes",  
"card_id": null,  
"bank": null,  
"wallet": null,  
"vpa": "gaurav.kumar@exampleupi",  
"email": "",  
"contact": "+919999999999",  
"customer_id": "cust_DitrYCFtCIokBO",  
"notes": [],  
"fee": 24,  
"tax": 4,  
"error_code": null,  
"error_description": null,  
"error_source": null,  
"error_step": null,  
"error_reason": null,  
"acquirer_data": {    
	"rrn": "033814379298"  
"created_at": 1606985209

Step 2 - Save the response to the database.

	"details" => json_encode($response->toArray())

Step 3 - In RazorpayPayment Model

class RazorpayPayment extends Model
    public function getDetailsAttribute($value)
        return json_decode($value);


Razorpay payment fetch/capture returns a large block of JSON data. I'll show you how to save the entire JSON response at once.

end of article

Related Posts

Join Our Newsletter

Want the latest & greatest from our blog straight to your inbox with some exclusive offers from our partners and sponsors?

We won't spam. Promise.