Contents
This sample app demonstrates integrating with Driivz APIs using Android compose components app and a ktor server that this Android app is communicating with. The app is communicating with the server written in ktor framework to perform driver login, list the payment methods that this driver has, add a payment method to the logged in driver (currently only Stripe is available in this demo), show sites on a map, fetch chargers that are associated to a particular site and initiate an OTP transaction with a selected charger.
Note about Stripe integration: The Stripe integration includes only a simple credit card component that can create a token for a SetupIntent only with card number, expiration & cvv inputs. 3DS or other Stripe integrations are not available in this example. In this example it is merely shown how to retrieve a token and save it as an authorized token within Driivz system.
This integration is powered by the following Driivz APIs
- Operator login API
- Find accounts API
- Operator login as customer API
- Get card payment method details API
- Add card payment method API
- Find site API
- Get charger’s profile details API
- Search sites API
- Find charger locations
- Send guest driver start transaction command
The Android app is comprised of six screens that are composable functions:
- MainScreen, which represents the main hub to let the user choose a particular flow, either add payment method to logged in driver or initiate an OTP charging session using his payment method details
-
LoginScreen, which represents the driver login credentials screen
-
PaymentListScreen, which represents all the payment methods that the logged in driver has
-
MapScreen, which represents a map with site pins or cluster of site pins on this map
-
ChargerListScreen, which represents a list of chargers in a particular site
-
PaymentScreen, which represents a payment component to either create a payment for a driver or one time payment for a charging session
- Clone the
driivz-api-example
repository. - Open the project in Android Studio.
- After configuring the apps, build and run the server app and the android app separately.
Edit the server configuration file application.conf
-
Set the
ktor.serviceAccount.baseURL
to the api-gateway server URL that you'd like to connect to.For example,
ktor { serviceAccount { baseURL = "https://example.driivz.com/api-gateway/" } }
-
Set the
ktor.serviceAccount.userName
&ktor.serviceAccount.password
to the operator user that is going to be used to authenticate all the operations with Driivz apis (the service account).For example,
ktor { serviceAccount { userName = "example@driivz.com" password = "Pass123" } }
-
Set the
ktor.stripe.privateKey
to the Stripe account private key that will be used to create the token and Stripe payment integration.For example,
ktor { stripe { privateKey = "sk_test_12345" } }
-
Set the
ktor.stripe.publicKey
to the Stripe account private key that will be used to create the token and Stripe payment integration.For example,
ktor { stripe { publicKey = "pk_test_12345" } }
Edit the run configuration of ApplicationKt
-
Set the VM option
config.file
to the application.conf file locationFor example,
-Dconfig.file=/local-machine-path/driivz-api-example/server/src/main/resources/application.conf
Edit the local properties file local.properties
-
Add a property
MAPS_API_KEY
with the key from your google maps API console. You need this key for the map to showFor example,
MAPS_API_KEY=key_from_google_apis_console
Edit the android app urls XML file urls.xml
-
Set the string resource
base_url
to the URL of the ktor server. by default it is set to http://10.0.2.2:8090 which is local host from the android emulator.For example,
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="base_url">http://192.168.2.1:8090</string> </resources>
The following is a demonstration of a Customer (driver) adding a payment
- Login with driver credentials
- Navigating to the driver's payment methods list
- Click on "Add payment" and navigating to the payment screen
- Fill test credit card details
- Click on "Pay now"
- App navigating back to the payment methods list
- Payment method is added successfully to payment methods list
The following is a demonstration of a Customer (driver) that is not authenticated paying with one time payment with a specific charger from a map of sites
- Navigate to the map of sites clicking on the "Sites map" button
- Clicking on the cluster of sites or on a particular site pin in the map
- Navigating to the site's chargers list
- Pick a charger from the list and navigating to the payment screen
- Fill test credit card details
- Click on "Pay now"
- App navigating back to the main screen
The following is a demonstration of a Customer (driver) that is not authenticated paying with one time payment with a specific charger from the charger ID input in main screen
- Fill some charger ID in the charger ID input in the main screen
- Clicking on the "Charger (OTP)" button
- Navigating to the payment screen
- Fill test credit card details
- Click on "Pay now"
- App navigating back to the main screen