Development
Step 1: Open project file
-
Open the Android Studio.
-
Click on the Open an existing Android Studio project option. If the
mastercard-anyshop-android
project is already open, jump to point 5. -
If some other project is already open, click File -> Open.
-
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
-
-
Wait a couple of minutes until the whole project is loaded.
Step 2: Code implementation
-
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
inRestrictedItemFragment.onViewCreated()
method -
Use
RPClaimRequestBuilder
class to create a request with properscopeType
-
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) }
})
}
Learn more by watching the video
-
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>
Learn more by watching the video
- Implement code to read intent data and pass it to
handlerScopeResponse
inonCreate()
method inMainActivity
. ForScopeType.AgeOver18
expected result is true or false as a String. Parse this result to a boolean value and pass it out toPaymentActivity
using intents. Then, forward the result toPaymentActivity
class. Useintent.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()
}
Learn more by watching the video
- 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 toMainActivity
, otherwise showAgeVerifiedFragment
.
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)
}
}
Learn more by watching the video
Step 3: Deployment
-
In the top menu bar click: Build -> Make project.
Warning :The project may not build unless you write the proper code described in the Development section of this document.
-
Connect the Samsung Galaxy device to the workstation via USB. Click Allow if you see a popup on the Galaxy device.
-
Run the project.
-
Select the Galaxy device as a deployment target. Do not deploy the project on any emulator. Click the OK button.
-
The project has been deployed on the Galaxy device.
-
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.