razorpay / razorpay-android-sample-app

Sample app demonstrating integration of Razorpay checkout
MIT License
88 stars 90 forks source link

How do you programmatically disable selected payment options for android application #301

Open KrishanMac opened 2 years ago

KrishanMac commented 2 years ago

This is the code I wrote to disable some of the payment options , but it seems to be not working . Is there an easier way to disable those given payment options programmatically for android app . Thanks in advanced.

        Checkout.preload(requireContext());
        Checkout checkout = new Checkout();
        checkout.setKeyID(key);
        checkout.setImage(R.drawable.isthmus_logo);

        JSONObject orderRequest = new JSONObject();
        JSONObject options = new JSONObject();
        JSONObject checkoutObj = new JSONObject();
        JSONObject method = new JSONObject();
        try {
            orderRequest.put("name", "Isthmus");
            orderRequest.put("amount", 50000); // amount in the smallest currency unit
            orderRequest.put("currency", "INR");
            method.put("netbanking","1");
            method.put("card","1");
            method.put("upi","1");
            method.put("wallet","0");
            method.put("emi","0");
            method.put("pay_later","0");
            checkoutObj.put("method",method);
            options.put("checkout",checkoutObj);
            orderRequest.put("options",options);
            Log.i(TAG,orderRequest.toString());
            checkout.open(getParentFragment().getActivity(), orderRequest);
        } catch (Exception e) {
            Log.w(TAG,e.getMessage());
        }
vivekshindhe commented 2 years ago

@KrishanMac You can use config options to set those things. Attaching the doc here, link

KrishanMac commented 2 years ago

@KrishanMac You can use config options to set those things. Attaching the doc here, link

isn't that for web- integration , I need to it android-integration . I have read it and try some JSON format it doesn't seems to be working .

vivekshindhe commented 2 years ago

It also works for android. You have to position the objects correctly. You can look at the js example in the doc.

KrishanMac commented 2 years ago

I have read of doc. available and its still confusing . Why do we need JS is there JSON way do doing it like I wrote in the above code. Its my first time implementing Razor so im still loss .

vivekshindhe commented 2 years ago

@KrishanMac you can convert the json object in the js example to jsonobject for java.

KrishanMac commented 2 years ago
        Checkout checkout = new Checkout();
        checkout.setKeyID(keyId);
        checkout.setImage(R.drawable.isthmus_logo);
        try {
            JSONObject orderRequest = new JSONObject();
            JSONObject configObj = new JSONObject();
            JSONObject displayObj = new JSONObject();
            JSONArray hideObj = new JSONArray();
            JSONObject methodObj = new JSONObject();
            JSONObject methodObj2 = new JSONObject();
            JSONObject methodObj3 = new JSONObject();
            JSONObject preferencesObj = new JSONObject();

            preferencesObj.put("show_default_blocks", "true");
            methodObj.put("method","wallet");
            methodObj2.put("method","paylater");
            methodObj3.put("method","emi");
            hideObj.put(methodObj);
            hideObj.put(methodObj2);
            hideObj.put(methodObj3);
            displayObj.put("hide",hideObj);
            displayObj.put("preferences",preferencesObj);
            configObj.put("display",displayObj);

            orderRequest.put("name", "Isthmus Business");
            orderRequest.put("amount", subOrderAmount); // amount in the smallest currency unit
            orderRequest.put("currency", "INR");
            if (razorOrderId != null) {
                orderRequest.put("order_id", razorOrderId);
            }
            orderRequest.put("config", configObj);
            Log.i(TAG, orderRequest.toString());
            checkout.open(getParentFragment().getActivity(), orderRequest);

And this is the output JSON String structure :

{"name":"Isthmus Business", "amount":94900, "currency":"INR", "config":{ "display":{ "hide":[ {"method":"wallet"}, {"method":"paylater"}, {"method":"emi"} ], "preferences":{ "show_default_blocks":"true" } } } }

The wallet and paylater are gone from the payment options but still the emi option there . Is this a bug or did i do anything wrong . Thanks in advanced.

srbbans commented 1 year ago

resolved the emi option or not ?

KrishanMac commented 1 year ago

resolved the emi option or not ?

Not much have change