Step 2: Open the Checkout URL in WebView
Once you have a checkout URL from your backend, use WePaySDK.openCheckoutUrl() to launch the checkout screen.
Usage​
import com.wepay.sdk.WePaySDK
// Inside an Activity or Fragment
private fun openWePayCheckout(checkoutUrl: String) {
WePaySDK.openCheckoutUrl(
context = this, // Activity
checkoutUrl = checkoutUrl,
)
}
What Happens Automatically​
Calling WePaySDK.openCheckoutUrl() will:
- Start
WebViewPaymentActivity - Load the checkout URL in a WebView
- Watch URL redirects for
/successor/error - Show a Toast message and close the screen automatically
Handling the Result​
The SDK closes the checkout screen automatically on success or error. To handle the outcome in your app, listen for the activity result:
// Register callback
private val checkoutLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
when (result.resultCode) {
RESULT_OK -> {
// Payment succeeded
}
RESULT_CANCELED -> {
// User cancelled or payment failed
}
}
}
// Launch using the callback
private fun openWePayCheckout(checkoutUrl: String) {
val intent = WebViewPaymentActivity.createIntent(
context = this,
checkoutUrl = checkoutUrl,
)
checkoutLauncher.launch(intent)
}
Next Step​
See Step 3 — Advanced Usage if you prefer to start WebViewPaymentActivity directly, or skip to Configuration to add the required Android permissions.