Detection of the end of the payment

In order to detect the end of payment, it is necessary to analyze the different URLs that go through the webview.

Depending on the URL, the mobile application can:

  • accept the propagation of the URL and display the page in the webview
    (for example, during a payment request, allow the buyer to make his or her payment)
  • refuse the propagation of the URL and regain control.
    (for example, in case of success and at the end of payment, allow the buyer to return to the native application)

Thanks to the listening mechanism of URLs, you can control the payment progress and decide when to switch to your native application.

Exerpt of code sample for Android (Kotlin)

private fun checkUrl(view: WebView, url: String): Boolean {
	val isCallBack = isCallbackUrl(url)

	when {
		// payment is finish
		isCallBack -> {
		else -> view.loadUrl(url)
	return (!isCallBack)

Exerpt of code sample for iOS (Swift) :

func notifyPaymentFinish(navigationAction: WKNavigationAction){
	let webViewUrlResponse = self.buildWebviewUrlResponse(navigationAction: navigationAction)
	var error: NSError?
	switch webViewUrlResponse.paymentStatus {
		case "success":
			error = nil
		case "cancel":
			error = NSError.init(domain: PaymentProvider.ERROR_DOMAIN, code: PaymentProvider.ERROR_PAYMENT_CANCELATION.errorCode, userInfo: [NSLocalizedFailureReasonErrorKey: PaymentProvider.ERROR_PAYMENT_CANCELATION.errorMsg])
		case "refused":
			error = NSError.init(domain:PaymentProvider.ERROR_DOMAIN, code: PaymentProvider.ERROR_PAYMENT_REFUSED.errorCode, userInfo: [NSLocalizedFailureReasonErrorKey: PaymentProvider.ERROR_PAYMENT_REFUSED.errorMsg])
			error = NSError.init(domain:PaymentProvider.ERROR_DOMAIN, code: PaymentProvider.ERROR_UNKNOW.errorCode, userInfo: [NSLocalizedFailureReasonErrorKey: PaymentProvider.ERROR_UNKNOW.errorMsg])

	self.dismiss(animated: true) {
		self.paymentDelegate?.didPaymentProcessFinish(error: error)