A standalone kit for handling Google Pay™
demo.mov
To use the SDK the following requirements must be met:
- Android Studio 4.2.1 or newer
- Android SDK Tools 33 or newer
- Android Platform Version: API 33: Android 11 revision 7 or later
- **Android targetSdkVersion: 33
- Clone checkoutSDK library from Tap repository
https://github.com/Tap-Payments/TapGooglePayKit
- Add goSellSDK library to your project settings.gradle file as following
include ':library', ':YourAppName'
- Setup your project to include checkout as a dependency Module.
- File -> Project Structure -> Modules -> << your project name >>
- Dependencies -> click on + icon in the screen bottom -> add Module Dependency
- select checkout library
JitPack is a novel package repository for JVM and Android projects. It builds Git projects on demand and provides you with ready-to-use artifacts (jar, aar).
To integrate tapGooglePay™SDK into your project add it in your root build.gradle
at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.Tap-Payments:TapGooglePayKit:0.0.35'
}
First of all, tapGooglePay™SDK
should be set up. In this section secret key and application ID are required.
First of all, tapGooglePay™SDK
should be set up. To set it up, add the following lines of code somewhere in your project and make sure they will be called before any usage of tapGoooglePaySDK
.
Below is the list of properties in tapGooglePaySDK class you can manipulate. Make sure you do the setup before any usage of the SDK.
To set it up, add the following line of code somewhere in your project and make sure it will be called before any usage of checkOutSDK
, otherwise an exception will be thrown. Required.
Java:
dataConfig.initSDK(this@MainActivity as Context,"sk_test_kXXXXXXXXXXXXXXXXXXXXXXXX","app_id");
Kotlin: Here we need to make a Top level declaration
var dataConfig: DataConfiguration = DataConfiguration
dataConfig.initSDK(this@MainActivity as Context,"sk_test_kXXXXXXXXXXXXXXXXXXXXXXXX","app_id")
authToken
- to authorize your requests.// Secret key (format: "sk_XXXXXXXXXXXXXXXXXXXXXXXX")app_id
- replace it using your application ID "Application main package".
Include the Google Pay™ button view inside the xml file as below
Kotlin
<company.tap.google.pay.open.GooglePayButton
android:id="@+id/googlePayView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:enabled="true"
android:focusable="true"
/>
Then declare it in the class as follows:
- In Top level add
Kotlin
lateinit var googlePayView: GooglePayButton
- Set the Button Type you prefer from the list of enums we have
Kotlin
googlePayView = findViewById(R.id.googlePayView)
googlePayView.setGooglePayButtonType(GooglePayButtonType.CHECKOUT_WITH_GOOGLE_PAY)
- Set The click event for the Google Pay™ view as below:
Kotlin
googlePayView.buttonView.setOnClickListener {
Here you choose what you prefer to call getGooglePayToken or getTapToken
if(defaultPref.toString() == "GET GOOGLEPAY TOKEN"){
dataConfig.getGooglePayToken(this, googlePayView)
}else if(defaultPref.toString() == "GET TAP TOKEN"){
dataConfig.getTapToken(this, googlePayView)
}
}
SDK mode defines which mode SDK is operating in, either sandbox or production.
SDK Mode is automatically identified in the backend based on the secrete key you defined earlier in setup process.
tapGooglePay™SDK
should be set up. To set it up, add the following lines of code somewhere in your project and make sure they will be called before any usage of tapGoooglePaySDK
.
Kotlin:
/**
* Required step.
* Configure SDK with your choice from the given list.
*/
initializeSDK()
/**
* Required step.
* Configure SDK Session with all required data.
*/
configureSDKData()
To set it up, add the following line of code somewhere in your project and make sure it will be called before any usage of tapGoooglePaySDK
, otherwise an exception will be thrown. Required.
Kotlin:
/**
* Required step.
* Configure SDK with your Secret API key and App Bundle name registered with tap company.
*/
private fun initializeSDK(){
dataConfig.initSDK(this@MainActivity as Context,"sk_test_kXXXXXXXXXXXXXXXXXXXXXXXX","app_id")
}
authToken
- to authorize your requests.// Secret key (format: "sk_XXXXXXXXXXXXXXXXXXXXXXXX")app_id
- replace it using your application ID "Application main package".
DATACONFIGURATION is the main interface for library from you application
Property | Type | Description |
---|---|---|
sdkDelegate | Activity | Activity. it is used to notify Merchant application with all SDK Events |
Property | Type |
---|---|
addSDKDelegate | pass your activity that implements SdkDelegate interface . you have to override all methods available through this interface |
setTransactionCurrency | Set the transaction currency associated to your account. Transaction currency must be of type TapCurrency("currency_iso_code"). i.e new TapCurrency("KWD") |
setEnvironmentMode | SDK offers different environment modes such as [ TEST - PRODUCTION] |
setAmount | Set Total Amount. Amount value must be of type BigDecimal i.e new BigDecimal(40) |
setGatewayId | Gateway id required to use TAP as PSP . Here it is tappayments |
setGatewayMerchantID | MerchantID available with TAP |
setAllowedCardAuthMethods | ALLOWED CARD auth methods here it is PAN_ONLY, CRYPTOGRAM_3DS , ALL |
setCountryCode | Set country code. |
setAllowedCardNetworks | CARD networks like VISA, AMEX, JCB ,MADA. |
Configure SDK DATA Example
Kotlin:
private fun configureSDKData() {
// pass your activity as a session delegate to listen to SDK internal payment process follow
dataConfig.addSDKDelegate(this) //** Required **
dataConfig.setEnvironmentMode(SDKMode.ENVIRONMENT_TEST) //**Required SDK MODE**/
dataConfig.setGatewayId("tappayments") //**Required GATEWAY ID**/
dataConfig.setGatewayMerchantID("1124340") //**Required GATEWAY Merchant ID**/
dataConfig.setAmount(BigDecimal.valueOf(23)) //**Required Amount**/
settingsManager?.getAllowedMethods("allowed_card_auth_key")
?.let { dataConfig.setAllowedCardAuthMethods(it) } //**Required type of auth PAN_ONLY, CRYPTOGRAM , ALL**/
settingsManager?.getString("key_currency_code","USD")
?.let { dataConfig.setTransactionCurrency(it) } //**Required Currency **/
settingsManager?.getString("country_code_key","US")?.let { dataConfig.setCountryCode(it) } //**Required Country **/
dataConfig.setAllowedCardNetworks(settingsManager?.getSet("key_payment_networks")?.toMutableList()) //**Required Payment Networks you want google to display for you **/
}
SDK open Interfaces available for implementation through Merchant Project:
- SessionDelegate
fun onGooglePayToken(token:String)
fun onTapToken(token: Token)
fun onFailed(error:String)
SDK open Enums available for implementation through Merchant Project:
- AllowedMethods
Choose your allowed methods like PAN,CRYPTO etc
enum class AllowedMethods {
PAN_ONLY,
CRYPTOGRAM_3DS,ALL
}
2.SdkMode
Setup the mode you want to test in
enum class SDKMode {
/**
* Sandbox is for testing purposes
*/
ENVIRONMENT_TEST,
/**
* Production is for live
*/
ENVIRONMENT_PRODUCTION
}
3.GooglePayButtonType
Choose the type of button you wish to use in your app
enum class GooglePayButtonType {
BUY_WITH_GOOGLE_PAY,
DONATE_WITH_GOOGLE_PAY,
NORMAL_GOOGLE_PAY,
PAY_WITH_GOOGLE_PAY,
SUBSCRIBE_WITH_GOOGLE_PAY,
CHECKOUT_WITH_GOOGLE_PAY,
ORDER_WITH_GOOGLE_PAY,
BOOK_WITH_GOOGLE_PAY
}
SDK Delegate is an interface which you may want to implement to receive payment/authorization/card saving status updates and update your user interface accordingly when payment window closes. Below are listed down all available callbacks:
Notifies the receiver that googlepay token has succeed.
Kotlin:
- fun onGooglePayToken(token:String)
token: Successful Token object.
Notifies the receiver that token generated for TAP .
Kotlin:
- fun onTapToken(token: Token)
token: Token object from TAP.
<a name=failed_callback">
Notifies the receiver that failed.
Kotlin:
- fun onFailed(error:String)
error: Failure object.
To use GooglePay in your app , you will be required to do additional configuration as follows:
- In build.gradle file add
implementation "com.google.android.gms:play-services-wallet:18.1.3"
- Ensure your min sdk is 21
minSdk 21
targetSdk 32
- In Manifest file , Inside the <application tag do the below:
<meta-data
android:name="com.google.android.gsm.wallet.api.enabled"
android:value="true"
/>
You might encounter the following errors at some point in your integration. This list provides some helpful troubleshooting advice should these errors arise.
-
This merchant is not enabled for Google Pay The Google Pay API requires a Google merchantId for sites that configure PaymentsClient for a PRODUCTION environment. A Google merchantId is associated with one or more fully qualified domains through the Google Pay and Wallet Console. Check the returned error details for more information.
-
This merchant has not completed registration to use Google Pay API. Please go to console (https://pay.google.com/business/console) to verify. You haven't completed the process to register your apps for the Google Pay API. Review Request production access to register using the Google Pay and Wallet Console and request a review of your app's use of the Google Pay API.
-
This merchant profile does not have access to this feature Google hasn't configured your app to use the Google Pay API. Review Request production access to request a review of your app's use of the Google Pay API via the Google Pay and Wallet Console. This Google Pay API integration is disabled. Please contact us for more information (https://developers.google.com/pay/api/faq#how-to-get-support). Contact us to learn more about the required steps to re-enable the Google Pay API for your Google Account.
Documentation is available at [github-pages][2].
Also documented sources are attached to the library.
[1]:https://www.tap.company/developers/