Android Reference App

Overview

This section guides you through the process of building and integrating the Android SDK into the application. The application demonstrates the use case of a merchant application where Mastercard Checkout Sound and Animation is played by default on a transaction approval using a Mastercard card. The application is a stand-alone project that does not require any backend to perform end-to-end testing and it also provides details on how the code can be changed to demonstrate all three features of Mastercard Sonic Branding.

Technologies used

Get the source code

Reference Application for Android SDK can be downloaded below:

What you will need

What you will build

  • A simple Android application that shows how Mastercard Checkout Sound and Animation is integrated into the merchant application.

  • A merchant application that shows how Mastercard Checkout Sound and Animation is played on a transaction approval.

What you will learn

  • When to integrate Mastercard Checkout Sound and Animation

    Integration of Android SDK can be done in a fragment where confirmation of checkout is handled. In reference application, refer code in ConfirmOrderFragment fragment which initializes the SonicController.

        private val sonicController = SonicController()
        
  • What changes are required to play different features of Mastercard Sonic Branding

After the integration of Android SDK is completed, prepare the SonicController with SonicType at the creation of the confirmation view. Your controller is now prepared with the assets which are required to play the Checkout Sound and/or Animation. In reference application, refer in prepareSonicAnimation method of ConfirmOrderFragment fragment where you can provide a value of SonicType and can check different behaviours of Mastercard Sonic Brand.

       private fun prepareSonicAnimation() {

        sonicMerchant = SonicMerchant.Builder()
            .merchantName("Uber")
            .city("New York")
            .merchantCategoryCodes(arrayOf("MCC 5122"))
            .countryCode("USA")
            .merchantId("UberId")
            .build()

        /*
         * SonicEnvironment.SANDBOX: Please pass SANDBOX in prepare() while the application is in developing or testing.
         * SonicEnvironment.PRODUCTION: Please pass PRODUCTION when the application getting release to live users.
         */

        sonicController.prepare(sonicType = SonicType.SOUND_AND_ANIMATION,
            sonicCue = "checkout",
            sonicEnvironment = SonicEnvironment.SANDBOX,
            merchant = sonicMerchant,
            isHapticsEnabled = true,
            context = requireContext(),
            onPrepareListener = object : OnPrepareListener {
                override fun onPrepared(statusCode: Int) {
                    btnConfirmOrder.isEnabled = true
                    Log.d(TAG, "onPrepared() statusCode = $statusCode")
                }
            })
    }
     
  • When to play Mastercard Checkout Sound and Animation

    After the integration of Android SDK is completed and resources are prepared, wait for the transaction approval event. As soon as the transaction is approved, validate the Payment Network of Card account holder. For Mastercard, the Checkout Sound and/or Animation is played. In reference application, refer code in paymentSuccess method of ConfirmOrderFragment fragment which plays the Checkout Sound and/or Animation.

        private fun paymentSuccess() {
            if (dialogShown) {
                dialogShown = false
                orderGroup.visibility = View.GONE
                sonicView.visibility = View.VISIBLE
    
                if (getSelectedPaymentCard().type() != CardType.MASTERCARD) {
                    findNavController().navigate(R.id.action_confirmOrderFragment_to_thankYouFragment)
                } else {
                    sonicController.play(sonicView, object : OnCompleteListener {
                        override fun onComplete(statusCode: Int) {
                            Log.d(TAG, "onComplete() statusCode = $statusCode")
                            isSonicAnimationCompleted = true
                            findNavController().navigate(R.id.action_confirmOrderFragment_to_than

Last updated