Paytm All in One付款网关在Android中的集成

时间:2020-08-19 13:37:04

标签: android kotlin

这就是我试图将Paytm全部集成到android的sdk中的方式。我在onActivityResult中遇到networkError。在paytm支付网关中,不清楚生成txnToken所需的所有参数是什么。我已经使用订单ID和Mid来生成txnToken,但无法正常工作。请给我建议一个可行的解决方案。

class MainActivity : AppCompatActivity() {
private val TAG = "MainActivity"
private val orderId = "ORDER1597825492814021"
private val mId = "your mid here "
private val txnToken =
    "Mw9iBKebVdJmnAMspiiPGQ5CdQkkEstZTudWmTmUwv91BXQi0F5iwmw6b0DXaW+FiTBakTdWTHjBYYAQAjI8Xor+HpIgxr1Fg1LRfDWqWKo="
private val amount = "99.00"

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val startPayment: Button = findViewById(R.id.btn_start_payment)

    startPayment.setOnClickListener {
        startPayment()
    }
}

private fun startPayment() {
    // String host = "https://securegw-stage.paytm.in/";
    val host = "https://securegw.paytm.in/"
    val callbackUrl = host + "theia/paytmCallback?ORDER_ID=" + orderId;

    val paytmOrder = PaytmOrder(orderId, mId, txnToken, amount, callbackUrl)
    val transactionManager = TransactionManager(
        paytmOrder,
        object : PaytmPaymentTransactionCallback {
            override fun onTransactionResponse(p0: Bundle?) {

            }

            override fun networkNotAvailable() {

            }

            override fun onErrorProceed(p0: String?) {

            }

            override fun clientAuthenticationFailed(p0: String?) {

            }

            override fun someUIErrorOccurred(p0: String?) {

            }

            override fun onErrorLoadingWebPage(p0: Int, p1: String?, p2: String?) {

            }

            override fun onBackPressedCancelTransaction() {

            }

            override fun onTransactionCancel(p0: String?, p1: Bundle?) {

            }
        })

    transactionManager.startTransaction(this, 1000)

}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == 1000 && data != null) {
        val bundle = data.extras
        if (bundle != null) {
            for (key in bundle.keySet()) {
                Log.e(TAG, key + " : " + if (bundle[key] != null) bundle[key] else "NULL")
            }
        }
        Log.e(TAG, " data " + data.getStringExtra("nativeSdkForMerchantMessage"))
        Log.e(TAG, " data response - " + data.getStringExtra("response"))
        Toast.makeText(
            this, data.getStringExtra("nativeSdkForMerchantMessage")
                    + data.getStringExtra("response"), Toast.LENGTH_SHORT
        ).show()
    } else {
        Log.e(TAG, " payment failed")
    }
}

}

0 个答案:

没有答案