Search code examples
androidpaymentcredit-cardrazorpay

How to get saved card details razorpay android


I am trying to retrieve saved card details in android I implemented Razorpay payment gateway my requirement is to show user saved card details to the user how do I implement this.

this is what i done so far

val options = JSONObject()
options.put("name","Razorpay Corp")
options.put("description","Demoing Charges")
//You can omit the image option to fetch the image from dashboard
options.put("image","https://s3.amazonaws.com/rzp-mobile/images/rzp.png")
options.put("theme.color", "#3399cc");
options.put("currency","INR");
options.put("amount","50000")//pass amount in currency subunits

val retryObj = JSONObject()
retryObj.put("enabled", true)
retryObj.put("max_count", 4)
options.put("retry", retryObj)

val preFill = JSONObject()

preFill.put("email", "[email protected]")

preFill.put("contact", "9011111111")

options.put("prefill",preFill)
co.open(activity,options)

I find this question but a solution is not available that's why I am asking again

I don't know is it possible or not

Please help me any help would be helpful.


Solution

  • i asked this question to the razorpay team and they provide me the solution

    you have to add customer id and save in your object so it will save your card detail

    options.put("customer_id", "cust_4lsdkfldlteskf");
    options.put("save", "1");
    

    you can create customer using razorpay add customer api

    below is the curl of add customer

    curl -u <YOUR_KEY_ID>:<YOUR_KEY_SECRET> \
    -X POST https://api.razorpay.com/v1/customers \
    -H "Content-Type: application/json" \
    -d '{
      "name":"Gaurav Kumar",
      "contact":"9123456780",
      "email":"[email protected]",
      "fail_existing":"0",
      "gstin":"29XAbbA4369J1PA",
      "notes":{
        "notes_key_1":"Tea, Earl Grey, Hot",
        "notes_key_2":"Tea, Earl Grey… decaf."
      }
    }'
    

    to retrieve card details you have to call fetch all tokens of customer api below is curl

    curl -u <YOUR_KEY_ID>:<YOUR_KEY_SECRET> \-X GET https://api.razorpay.com/v1/customers/:customer_id/tokens
    

    <YOUR_KEY_ID> is your key which start from rzp_***

    <YOUR_KEY_SECRET> you have to generate from razorpay from website Setting>api keys

    from website

    Hope this will solve your issue