Skip to content

driivz/driivz-api-example

Repository files navigation

Driivz API integration example

Contents

  1. Overview
  2. Setup
  3. Demo

Overview

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.


APIs

This integration is powered by the following Driivz APIs

App components

The Android app is comprised of six screens that are composable functions:

  1. 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

  1. LoginScreen, which represents the driver login credentials screen

  2. PaymentListScreen, which represents all the payment methods that the logged in driver has

  3. MapScreen, which represents a map with site pins or cluster of site pins on this map

  4. ChargerListScreen, which represents a list of chargers in a particular site

  5. PaymentScreen, which represents a payment component to either create a payment for a driver or one time payment for a charging session

Setup

Install

  1. Clone the driivz-api-example repository.
  2. Open the project in Android Studio.
  3. After configuring the apps, build and run the server app and the android app separately.

Configure the apps

Required

Edit the server configuration file application.conf

  1. 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/"
        }
    }
    
  2. 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"
        }
    }
    
  3. 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"
        }
    }
    
  4. 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

  1. Set the VM option config.file to the application.conf file location

    For example,

    -Dconfig.file=/local-machine-path/driivz-api-example/server/src/main/resources/application.conf
    

Edit the local properties file local.properties

  1. Add a property MAPS_API_KEY with the key from your google maps API console. You need this key for the map to show

    For example,

    MAPS_API_KEY=key_from_google_apis_console
    

Optional

Edit the android app urls XML file urls.xml

  1. 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>
    

Demo

The following is a demonstration of a Customer (driver) adding a payment

  1. Login with driver credentials
  2. Navigating to the driver's payment methods list
  3. Click on "Add payment" and navigating to the payment screen
  4. Fill test credit card details
  5. Click on "Pay now"
  6. App navigating back to the payment methods list
  7. 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

  1. Navigate to the map of sites clicking on the "Sites map" button
  2. Clicking on the cluster of sites or on a particular site pin in the map
  3. Navigating to the site's chargers list
  4. Pick a charger from the list and navigating to the payment screen
  5. Fill test credit card details
  6. Click on "Pay now"
  7. 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

  1. Fill some charger ID in the charger ID input in the main screen
  2. Clicking on the "Charger (OTP)" button
  3. Navigating to the payment screen
  4. Fill test credit card details
  5. Click on "Pay now"
  6. App navigating back to the main screen

About

Example integration with Driivz API gateway

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages