Documentation
HOMEAPI ReferencePayment Demo
English
English
  • 📖Home
  • API Reference
  • Wallet
    • Activate Account
    • Multi-currency Balance
    • Global Collection Account
    • Payout
    • Account settings
  • Payment
    • Get started
    • Accept a payment
      • Hosted payment page
      • In-page checkout
      • iOS
      • Android
      • API-Direct
    • Save a card during payment
      • iOS
      • Android
    • Pre-authorize a payment
    • 3D secure authentication
      • iOS
      • Android
    • Subscriptions
      • Recurring
    • Add payment methods
      • Supported APM codes and attributes list
      • APM Integration Guide
    • After the payment
      • Webhook
      • Refunds
      • Response handling
    • About the APIs
      • Currencies
      • Payments
        • How payments work
  • Business Operation
    • MoneyCollect dashboard
      • Home
      • Mobile apps
    • Account
      • Your account
      • Multiple Accounts
      • Account security
    • Alternative payment methods
      • Apply for APMs from your dashboard
        • Google pay
    • Customers
      • Customer portal
    • Products & Prices
      • Pricing table
    • Invoicing
      • How invoicing works
      • Use the dashboard
        • Customers
        • Products and prices
        • Invoice page
      • Hosted Invoice Page
      • No-code quickstart guide
    • Subscriptions
      • Subscription status
      • Subscription settings
      • Create a subscription
    • Pricing
      • Reserves
      • Fees for APMs
    • Payouts
    • Financial reports
      • Select preferred report
      • Balance summary
      • Payout reconciliation
    • Partners
      • Partner pricing
    • Risk management
      • Disputes
        • How disputes work
        • Respond to disputes
          • Dispute reasons
        • Measuring disputes
      • Fraud
        • Monitoring programs
        • High risk merchant lists
        • Tools
        • Fraud prevention
    • Start a team
      • Teams
      • User roles
    • Startup incorporation
  • Developer tools
    • API-Keys
    • Libraries
    • Plugins
      • WooCommerce
      • Magento
        • Using Magento 2 Admin Panel
      • Shopify
        • MoneyCollect Payments App
        • Legacy Version
          • Credit Card Direct Payments App
          • Credit Card Redirected Payments App
          • Alternative Payment Methods App
      • Wix
      • SHOPLINE
      • SHOPLAZZA
      • Xshoppy
      • ShopBase
      • PrestaShop
      • OpenCart
      • AllValue
        • Using Allvalue Panel
Powered by GitBook
On this page
  • 1.After the payment is completed, redirect to the webpage for 3D Secure authentication
  • 2.3D Secure authentication on web
  • 3.Get the payment result
  1. Payment
  2. 3D secure authentication

Android

1.After the payment is completed, redirect to the webpage for 3D Secure authentication

After confirming the returned data after the payment contains the nextAction object and the web redirection addressredirectToUrl is not empty, the web page will be redirected to 3D Secure authentication.

moneyCollect.confirmPayment(requestConfirmPayment, payment.clientSecret,
                object : ApiResultCallback<Payment> {
                    override fun onSuccess(payment: Payment) {
                        //if nextAction object is not null and redirectToUrl address is not null, further 3d verification
                        if (payment.nextAction != null) {
                            if (!TextUtils.isEmpty(payment.nextAction?.redirectToUrl)) {
                                val intent = Intent(activity, ValidationWebActivity::class.java)
                                //pass redirectToUrl
                                intent.putExtra(Constant.VALIDATION_PARAM_URL,payment.nextAction?.redirectToUrl)
                                //pass payment id
                                intent.putExtra(Constant.VALIDATION_PAYMENT_ID, payment.id)
                                //pass payment clientSecret
                                intent.putExtra(Constant.VALIDATION_PAYMENT_CLIENTSECRET,payment.clientSecret)
                                startActivityLauncher.launch(intent)
                            } else {
                                moneyCollectResultBackInterface?.paymentConfirmResultBack(false,
                                    Constant.PAYMENT_PENDING_MESSAGE)
                            }
                        } else {
                            //Need to deal with the state has succeeded, uncaptured, pending, failed, canceled
                            when (payment.status) {
                                Constant.PAYMENT_SUCCEEDED -> {
                                    var intent =  Intent()
                                    intent.putExtra(Constant.PAYMENT_RESULT_PAYMENT, payment)
                                    activity?.setResult(Constant.PAYMENT_RESULT_CODE,intent)
                                    moneyCollectResultBackInterface?.paymentConfirmResultBack(true,"")
                                }
                                Constant.PAYMENT_FAILED -> {
                                    moneyCollectResultBackInterface?.paymentConfirmResultBack(false,payment.errorMessage)
                                }
                                Constant.PAYMENT_UN_CAPTURED -> {
                                    moneyCollectResultBackInterface?.paymentConfirmResultBack(false,
                                        Constant.PAYMENT_UN_CAPTURED_MESSAGE)
                                }
                                Constant.PAYMENT_PENDING -> {
                                    moneyCollectResultBackInterface?.paymentConfirmResultBack(false,
                                        Constant.PAYMENT_PENDING_MESSAGE)
                                }
                                Constant.PAYMENT_CANCELED -> {
                                    moneyCollectResultBackInterface?.paymentConfirmResultBack(false,
                                        Constant.PAYMENT_CANCELED_MESSAGE)
                                }
                                else -> {
                                    moneyCollectResultBackInterface?.paymentConfirmResultBack(false,
                                        Constant.PAYMENT_PENDING_MESSAGE)
                                }
                            }
                        }
                    }

                    override fun onError(e: Exception) {
                        moneyCollectResultBackInterface?.failExceptionBack(e.message)
                    }
                })

2.3D Secure authentication on web

Check the current url address firstly after directing to the webpage. If the authenticated rules are met, retrievePayment interface will be called and the payment result will be returned to the customer.

If you click Returnbutton during the verification process, an Exit prompt box will be displayed. Clicking to exit will call the retrievePayment interface, and then return the payment result to the customer. For details, please refer to the ValidationWebActivity class under the MoneyCollectSDK demo.

//WebViewClient
   webView?.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
                val hitTestResult = view?.hitTestResult
                if (!TextUtils.isEmpty(url) && hitTestResult == null) {
                    url?.let { view?.loadUrl(it) }
                    return true
                } else {
                    url?.let {
                        //Check the web address
                        if (url.contains("payment_id")
                              && url.contains("payment_client_secret")
                              && url.contains("source_redirect_slug")) {
                            retrievePayment()
                            return true
                        }
                    }
                }
                return super.shouldOverrideUrlLoading(view, url)
            }
   }

   //retrieve Payment
   private fun retrievePayment() {
        showLoadingDialog()
        paymentId?.let {
            moneyCollect.retrievePayment(it, clientSecret,
                object : ApiResultCallback<Payment> {
                    override fun onSuccess(result: Payment) {
                        //Status: succeeded,uncaptured,pending,failed,canceled
                        dismissLoadingDialog()
                        val resultStr: String? = when (result.status) {
                            Constant.PAYMENT_SUCCEEDED -> {
                                ""
                            }
                            Constant.PAYMENT_FAILED -> {
                                result.errorMessage
                            }
                            Constant.PAYMENT_UN_CAPTURED -> {
                                Constant.PAYMENT_UN_CAPTURED_MESSAGE
                            }
                            Constant.PAYMENT_PENDING -> {
                                Constant.PAYMENT_PENDING_MESSAGE
                            }
                            Constant.PAYMENT_CANCELED -> {
                                Constant.PAYMENT_CANCELED_MESSAGE
                            }
                            else -> {
                                Constant.PAYMENT_PENDING_MESSAGE
                            }
                        }
                        completeThreeDCheckout(resultStr,result)
                    }

                    override fun onError(e: Exception) {
                        dismissLoadingDialog()
                        completeThreeDCheckout(e.message,null)
                    }
                })
        }

    //pass payment result
    private fun completeThreeDCheckout(result: String?, resultPayment: Payment?) {
        val intent = Intent()
        intent.putExtra(Constant.WEB_RESULT_TAG, result)
        intent.putExtra(Constant.PAYMENT_RESULT_PAYMENT, resultPayment)
        setResult(Constant.WEB_RESULT_CODE,intent)
        finish()
    }

3.Get the payment result

 private val startActivityLauncher: ActivityResultLauncher<Intent> =
        registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
            //selected paymentmethods's list
            if (it.resultCode == Constant.PAYMENT_RESULT_CODE) {
                var payment =
                    it.data?.getParcelableExtra<Payment>(Constant.PAYMENT_RESULT_PAYMENT)
                if (payment != null) {
                    when (payment.status) {
                        Constant.PAYMENT_SUCCEEDED -> {
                            Log.e(TAG, Constant.PAYMENT_SUCCEEDED)
                        }
                        Constant.PAYMENT_FAILED -> {
                            payment?.errorMessage?.let { it1 ->
                                Log.e(TAG, it1)
                            }
                        }
                        Constant.PAYMENT_UN_CAPTURED -> {
                            Log.e(TAG, Constant.PAYMENT_UN_CAPTURED_MESSAGE)
                        }
                        Constant.PAYMENT_PENDING -> {
                            Log.e(TAG, Constant.PAYMENT_PENDING_MESSAGE)
                        }
                        Constant.PAYMENT_CANCELED -> {
                            Log.e(TAG, Constant.PAYMENT_CANCELED_MESSAGE)
                        }
                        else -> {
                            Log.e(TAG, Constant.PAYMENT_PENDING_MESSAGE)
                        }
                    }
                }
            }

        }

Constant is data constant class. For details, please refer to the Constant class under the MoneyCollectSDK demo.

PreviousiOSNextSubscriptions

Last updated 3 years ago