AP2 Sample: User Authorization using Digital Payment Credentials
AP2 Sample: User Authorization using Digital Payment Credentials
Section titled “AP2 Sample: User Authorization using Digital Payment Credentials”This sample demonstrates user authentication of a purchase using digital payment credentials (DPC).
Scenario
Section titled “Scenario”This repository demonstrates a conversational Android shopping assistant. It features a full user experience, from natural language product discovery (powered by Gemini) to secure payment using Digital Payment Credentials (DPC). All backend communication is handled via the A2A protocol.
Key Actors
Section titled “Key Actors”This sample consists of:
- Shopping Agent: An Android app that handles user’s requests to shop.
- Merchant Agent: An agent that handles product queries from the shopping agent and verifies the DPC signature.
Key Features
Section titled “Key Features”- Purchase with a Digital Payment Credential (DPC): A modern, secure payment flow using the Android Credential Manager that allows signing over the user’s intent displayed on a trusted surface.
Executing the Example
Section titled “Executing the Example”-
Install Android Studio
Download Android Studio from the official website and install it. This will install the Android SDK, JDK, and all other necessary tools needed to build and run the Android app.
-
Obtain a Google API key from Google AI Studio
Configure this key in the following locations:
-
Declare it as an environment variable. This is needed to start the merchant agent server.
export GOOGLE_API_KEY=your_key -
Add it to the local.properties file.
echo "GOOGLE_API_KEY=your_key" >> samples/android/shopping_assistant/local.properties
-
-
Add the Android SDK path to the local.properties file.
You can find this path in Android Studio under
Settings > Languages & Frameworks > Android SDKecho "sdk.dir=your_path" >> samples/android/shopping_assistant/local.properties -
Set JAVA_HOME environment variable
The Java Development Kit (JDK) is typically installed with Android Studio, but does not set the JAVA_HOME environment variable. Be sure it is set.
You can find this path in Android Studio under
Settings > Build, Execution, Deployment > Build Tools > Gradleexport JAVA_HOME=your_path -
Ensure your environment meets the Python sample prerequisites.
-
Enable the Enhanced Payment Confirmation UI
To experience the most modern and secure payment flow, you must enable a required feature flag:
Enroll in the Google Play Services Beta Program: Ensure the Google Account on your test device is enrolled.
-
Install the Digital Wallet App (sideloaded)
This demo requires a separate digital wallet app (‘CM Wallet’) to be installed on the same device that holds the Digital Payment Credentials.
-
Download the latest CM Wallet APK.
-
Install the APK and start the app:
adb install app-debug.apkadb shell am start -n "com.credman.cmwallet/.MainActivity"
-
Execution
Section titled “Execution”A convenience script is included to automatically build, install, and launch the Android app, and start the local merchant server.
bash samples/android/scenarios/digital-payment-credentials/run.shHow to Use the App
Section titled “How to Use the App”-
Ensure the local Merchant Agent server is running:
curl http://localhost:8001/a2a/merchant_agent/.well-known/agent-card.json -
Launch the Shopping Assistant app on your device.
-
In the app’s settings screen, enter the URL for your local merchant server. The default URL will be
http://10.0.2.2:8001. -
Click the Connect button. The app will fetch the A2A Agent Card from the server and initialize the chat session.
-
You can now start a conversation with the shopping assistant. For example, try saying: “I’m looking for a new car.”
Next Steps
Section titled “Next Steps”- Understand the Life of a Transaction.
- Explore the Python Card Scenario for a comparison.
- Read about Privacy and Security in agent payments.