Search code examples
androidrazorpay

Razor pay payment will refunding amount continuously


I'm developing e-commerce application. I used razor pay for payment gateway. payment is successfully happening but amount will be refunding automatically. what is the issue? some people suggested use Auto capture API. how to do that?

This is my code..

final Activity activity = this;

        final Checkout co = new Checkout();

        try {
            JSONObject options = new JSONObject();
            options.put("name", "Fortune");
            options.put("description", "");
            options.put("currency", "INR");
            options.put("amount", amount);
            options.put("payment_capture", true);



            co.open(activity, options);
        } catch (Exception e) {
            Toast.makeText(activity, "Error in payment: " + e.getMessage(), Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }

Solution

  • You need to capture the amount from your backend.

    Step 1:- When your payment is successful you will receive one paymentId as a response from Razorpay

    Step 2:- That id along with amount you need to send it to razorpay then the amount is going to capture.

    Razorpay Doc Reference

                request({
                      method: 'POST',
                      url: 'https://<YOUR_KEY_ID<YOUR_KEY_SECRET>@api.razorpay.com/v1/payments/' + generatedRazorpayId +'/capture',
                      form: {
                        amount: amountPaid
                      }
                    }, function (error, response, body) {
                      console.log('Status:', response.statusCode);
                      console.log('Headers:', JSON.stringify(response.headers));
                      console.log('Response:', body);
                    });
    

    If you are using firebase you need to trigger the function.