How to save response object from external script in database?

Using Razorpay, their handler function returns response object which I need to store in database. How do I access the response object sent from an external script? Here is the code from their documentation -

"handler": function (response) {

It is used in the HTML element which calls the razorpay script. I can send alerts and probably console log this but how do I store it in the database?