Development

Step 1: Open project file

  1. Open the Android Studio.

  2. Click on the Open an existing Android Studio project option. If the mastercard-anyshop-android project is already open, jump to point 5.

  3. If some other project is already open, click File -> Open.

  4. Open the mastercard_anyshop_android project.

    • For Windows workstation: C:\{APP_DIRECTORY}\AnyShop\mastercard-anyshop-android

    • For Linux workstation: ./{APP_DIRECTORY}/AnyShop/mastercard-anyshop-android

  5. Wait a couple of minutes until the whole project is loaded.

Step 2: Code implementation

  1. Initiate requests for scopes when a user clicks Continue with ID button.

    • Analyze the application flow and find in source code the place to put the corresponding code fragment

    • Add a click listener to image with id=continue_iv in RestrictedItemFragment.onViewCreated() method

    • Use RPClaimRequestBuilder class to create a request with proper scopeType

    • Test if there is proper result redirecting to Samsung Pass application

RestrictedItemFragment.kt

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    continue_iv!!.setOnClickListener(View.OnClickListener {
        this.activity?.let { activity -> 
    RPClaimRequestBuilder().requestForScopes(activity, ScopeType.AgeOver18) }
    })
}

  1. Handle the response with requested scope from Samsung Pass application.

    • Implement proper application manifest to filter intents from Samsung Pass

AndroidManifest.xml

<activity android:name=".activities.MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    <intent-filter
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="rpdemo"
                android:host="callback" />
    </intent-filter>
</activity>

  • Implement code to read intent data and pass it to handlerScopeResponse in onCreate() method in MainActivity. For ScopeType.AgeOver18 expected result is true or false as a String. Parse this result to a boolean value and pass it out to PaymentActivity using intents. Then, forward the result to PaymentActivity class. Use intent.putExtra() with key "ReturnedScope".

MainActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initIds()

    if (intent.action == Intent.ACTION_VIEW) {
        (intent.data as? Uri)?.let {
            RPClaimResponseParser().handlerScopeResponse(this, it, { scopes ->
                val scopeDetails = scopes.map { scope -> scope.value }.joinToString { "\n" + it }

                var intent = Intent(this, PaymentActivity::class.java)
                intent.putExtra("ReturnedScope", scopeDetails.toBoolean())
                startActivity(intent)
            })
        }
    }

        defaultFragment()
}

  • In defaultFragment() method inside Payment Activity class implement code to get information from intent. Then, verify if the user is adult or not. If not, show a toast with proper information and redirect the user to MainActivity, otherwise show AgeVerifiedFragment.

PaymentActivity.kt

private fun defaultFragment() {
    val ifUserAdult = intent.getBooleanExtra(("ReturnedScope"), false)
    if (ifUserAdult){
        val fragment = AgeVerifiedFragment.newInstance(ifUserAdult.toString(), "")
        setDefaultFragment(fragment)
    }else{
        Toast.makeText(this,"User is too young", Toast.LENGTH_LONG).show()
        var intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
    }
}

Step 3: Deployment

  1. In the top menu bar click: Build -> Make project.

  2. Connect the Samsung Galaxy device to the workstation via USB. Click Allow if you see a popup on the Galaxy device.

  3. Run the project.

  4. Select the Galaxy device as a deployment target. Do not deploy the project on any emulator. Click the OK button.

  5. The project has been deployed on the Galaxy device.

  6. Close the mastercard_anyshop_android project: >File -> Close Project

You're done!

Congratulations! You have successfully achieved the goal of this Code Lab activity. Now, you can provide specific authorized user data from Digital ID by yourself! But, if you're having trouble, you may check out the link below.

Digital ID on Shopping Complete Code2.30 MB