Skip to content

Instantly share code, notes, and snippets.

@shaon2016
Created July 1, 2021 06:32
Show Gist options
  • Save shaon2016/8414d11f0bb5f7b11d9d4ebc7b0e9dcc to your computer and use it in GitHub Desktop.
Save shaon2016/8414d11f0bb5f7b11d9d4ebc7b0e9dcc to your computer and use it in GitHub Desktop.
import android.content.Context
import com.sslwireless.alil.view.activity.payment.SSLCommerzCredentialResponseData
import com.sslwireless.sslcommerzlibrary.model.initializer.SSLCommerzInitialization
import com.sslwireless.sslcommerzlibrary.model.util.SSLCCurrencyType
import com.sslwireless.sslcommerzlibrary.model.util.SSLCSdkType
import com.sslwireless.sslcommerzlibrary.view.singleton.IntegrateSSLCommerz
import com.sslwireless.sslcommerzlibrary.viewmodel.listener.SSLCTransactionResponseListener
object MySSLCommerz {
fun initPayment(
context: Context,
data: SSLCommerzCredentialResponseData,
listener: SSLCTransactionResponseListener
) {
val init = SSLCommerzInitialization(
data.store_id,
data.store_password,
data.amount.toDouble(),
SSLCCurrencyType.BDT,
data.transaction_id,
"insurance",
if (data.environment == "TESTBOX") SSLCSdkType.TESTBOX else SSLCSdkType.LIVE
).addIpnUrl(data.ipn_url)
init.success_url = data.success_url
init.cancel_url = data.cancel_url
init.fail_url = data.fail_url
IntegrateSSLCommerz.getInstance(context)
.addSSLCommerzInitialization(init)
.buildApiCall(listener)
}
}
// Call this to initialize
MySSLCommerz.initPayment(this, it, object : SSLCTransactionResponseListener {
override fun transactionSuccess(model: SSLCTransactionInfoModel?) {
model?.let {
finish()
}
}
override fun transactionFail(msg: String?) {
msg?.let {
showToast(this, msg)
}
}
override fun merchantValidationError(p0: String?) {
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment