Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
919 views
in Technique[技术] by (71.8m points)

kotlin - Razorpay callbacks in android fragment is not working

Razorpay callbacks is not working in fragment instead of activity using fragment please give a solution If anyone aware thanks in advance.

private fun startPayment() {

    val activity: Activity = requireActivity()
    val co = Checkout()
    try {
        val options = JSONObject()
        options.put("name", "Vendor")
        options.put("description", " for Order")
        //You can omit the image option to fetch the image from dashboard
        options.put("image", "https://rzp-mobile.s3.amazonaws.com/images/rzp.png")
        options.put("currency", "INR")
        val payment: String = "1"//getcart?.CartTotal.toString()
        // amount is in paise so please multiple it by 100
        //Payment failed Invalid amount (should be passed in integer paise. Minimum value is 100 paise, i.e. ? 1)
        var total = payment.toDouble()
        total = total * 100
        options.put("amount", total)
        val preFill = JSONObject()
        preFill.put("email", "[email protected]")
        preFill.put("contact", "9898989898")
        options.put("prefill", preFill)
        co.open(requireActivity(), options)
    } catch (e: Exception) {
        Toast.makeText(activity, "Error in payment: " + e.message, Toast.LENGTH_SHORT).show()
        e.printStackTrace()
    }
}

override fun onPaymentSuccess(s: String?) {
    toast("onPaymentSuccess")
    Log.i(TAG, "onPaymentSuccess: $s")
}

override fun onPaymentError(i: Int, s: String?) {
    Log.e(TAG,  "error code "+i.toString()+" -- Payment failed "+s.toString())
    try {
        toast("Payment error please try again")
    } catch (e : Exception) {
        Log.e("OnPaymentError", "Exception in onPaymentError", e);
    }
}
question from:https://stackoverflow.com/questions/65713987/razorpay-callbacks-in-android-fragment-is-not-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...