Skip to content

Instantly share code, notes, and snippets.

@deepak140596
Last active October 30, 2019 15:29
Show Gist options
  • Save deepak140596/abc5a4bcc08f3fe9c715d20d9fd06de4 to your computer and use it in GitHub Desktop.
Save deepak140596/abc5a4bcc08f3fe9c715d20d9fd06de4 to your computer and use it in GitHub Desktop.
class PaymentActivity : AppCompatActivity() {
private val builder = PayUmoneySdkInitializer.PaymentParam.Builder()
var paymentParam: PayUmoneySdkInitializer.PaymentParam? = null
val merchantID = "6392590"
private fun startPay(
amount: String, txnid: String, phoneNumber: String,
productinfo: String, name: String, email: String, udf1: String, udf2: String,
udf3: String, udf4: String, udf5: String
) {
builder.setAmount(amount)
.setTxnId(txnid)
.setPhone(phoneNumber)
.setProductName(productinfo)
.setFirstName(name)
.setEmail(email)
.setsUrl("https://www.payumoney.com/mobileapp/payumoney/success.php")
.setfUrl("https://www.payumoney.com/mobileapp/payumoney/failure.php")
.setUdf1(udf1)
.setUdf2(udf2)
.setUdf3(udf3)
.setUdf4(udf4)
.setUdf5(udf5)
.setUdf6("")
.setUdf7("")
.setUdf8("")
.setUdf9("")
.setUdf10("")
.setIsDebug(BuildConfig.DEBUG)
.setKey(key)
.setMerchantId(merchantID)
paymentParam = builder.build()
val call = getService().getHash(
txnid, productinfo, amount, name, email,
udf1, udf2, udf3, udf4, udf5
)
call.enqueue(object : Callback<JsonObject> {
override fun onFailure(call: Call<JsonObject>, t: Throwable) {
log(E, "Failed getting hash from server ${t.message}")
}
override fun onResponse(
call: Call<JsonObject>,
response: Response<JsonObject>
) {
val responseBody = response.body().toString()
try {
val jsonObject = JSONObject(responseBody)
val hash: String = jsonObject.get("hash").toString()
paymentParam?.setMerchantHash(hash)
PayUmoneyFlowManager.startPayUMoneyFlow(
paymentParam,
this@PaymentActivity, R.style.PaymentAppTheme, false
)
} catch (e: JSONException) {
log(E, "error parsing json: ${e.message}")
}
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment