Search code examples
androidpayment-gatewayrazorpay

class file for com.razorpay.PaymentResultListener not found


I am implementing Razorpay payment integration in my Android project. I'm getting some error while implementing onPaymentError and onPaymentSuccess callback.

This is how I've integrated it,

build.gradle

implementation 'com.razorpay:checkout:1.5.12'

Activity

class BuyNowActivity : AppCompatActivity, PaymentResultListener {

lateinit var dataBinding : ViewDataBinding

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_buynow)
    preloadCheckoutEssentials()
    dataBinding.loginButton.setOnClickListener {
        startPayment()
    }
}

private fun preloadCheckoutEssentials() {
    Checkout.preload(applicationContext);
}

fun startPayment() {

    val checkout = Checkout()

    //checkout.setImage(R.drawable.logo)

    val activity: Activity = this

    val options = JSONObject()

    options.put("name", "Merchant Name")

    options.put("description", "Reference No. #123456")
    options.put("order_id", "order_9A33XWu170gUtm")
    options.put("currency", "INR")

    options.put("amount", "500")

    try {
        checkout.open(activity, options)
    } catch (e: Exception) {
        Timber.e(TAG, "Error in starting Razorpay Checkout")
    }
}

override fun onPaymentError(code: Int, response: String?) {
    Toast.makeText(this, "$code, AND $response", Toast.LENGTH_LONG).show()
}

override fun onPaymentSuccess(razorpayPaymentID: String?) {
    Toast.makeText(this, razorpayPaymentID, Toast.LENGTH_LONG).show()
}

/*override fun onPaymentError(code: Int, response: String?, p2: PaymentData?) {
    Toast.makeText(this, "$code, AND $response", Toast.LENGTH_LONG).show()
}

override fun onPaymentSuccess(razorpayPaymentID: String?, p1: PaymentData?) {
    Toast.makeText(this, razorpayPaymentID, Toast.LENGTH_LONG).show()
}*/

}

AndroidManifest

<meta-data
        android:name="com.razorpay.ApiKey"
        android:value="APIKeyHere" />

Now after writing all this code, whenever I try to build the project, build fails with following exception,

class file for com.razorpay.PaymentResultListener not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for 
com.razorpay.PaymentResultListener not found

Is there anyone who could help me with this? Thanks is advance.


Solution

  • If you've made a multi-modular project, and your paymentgateway module is separate then,

    replace

    implementation 'com.razorpay:checkout:1.5.12'
    

    with

    api 'com.razorpay:checkout:1.5.12'