Integrar el SDK D1 usando Apache Cordova
Overview
Apache Cordova is an open-source mobile development framework. It allows you to use standard web technologies such as HTML5, CSS3, and JavaScript for cross-platform development. To access each device's capabilities such as sensors, data, network status, the applications are executed within their platform-specific wrappers using standards-compliant API bindings.
To integrate D1 SDK using Apache Cordova, refer to the following sections:
Cordova plugin
Creating Cordova plugin for D1 SDK
Basic plugin structure
JavaScript interface
Android platform
Java source code
Adding D1 SDK binaries to the plugin module
Updating the plugin manifest file for Android platform
iOS platform
Swift source code
Updating the plugin manifest file for iOS platform
D1 SDK Pod wrapper
Integrating plugin module to Cordova project
Android application signing
Minimum Android SDK version supported for Android apps
Firebase Cloud Messaging
Calling the D1 plugin API from the Cordova project
Integrating plugin module to Ionic Cordova project
References
Cordova plugin
When D1 SDK is integrated using Apache Cordova to your project, the Android and iOS native platforms are automatically generated. To integrate third party SDKs and native components, they have to be placed in to the respective modules called Plugins, which are then added to the Cordova project.
Creating Cordova plugin for D1 SDK
This guide was tested with:
D1 SDK
4.0.0 Android
4.0.0 iOS
Cordova
CLI 11.1.0
Android 10.1.2
iOS 6.3.0
Xcode 14.3.1
Basic plugin structure
The structure of the Plugins module is as follows:
Where:
package.json: Project meta data.
plugin.xml: Top level Plugin manifest file.
D1Plugin.java: Android native code entry point.
gemcbp.properties, mobilegateway.properties, rages.properties: NFC payment configuration files.
d1-debug.aar, d1-release.aar: Android binaries in debug and release mode.
d1-build.gradle: Android native platform Gradle file which will be added to the generated Android platform.
apduservice.xml: Host APDU service resource file
D1Plugin.swift: iOS native code entry point.
D1Plugin.js: JavaScript interface.
D1.xcframework, SecureLogAPI.xcframework: iOS binaries in debug and release mode.
d1-libs-debug.podspec: Podspec for the Pod wrapping D1 SDK Debug version.
d1-libs-release.podspec: Podspec for the Pod wrapping D1 SDK Release version.
JavaScript interface
After the structure is set up, the JavaScript method prototypes will be called from the Cordova project.
The following code snippet shows how to create the method prototypes for the SDK login and Android initialization use cases:
Android platform
Java source code
For the JavaScript method prototypes, it is necessary to create the approriate entry point in the Android Native code. To implement the Native Android entry point of the plugin, extend the Cordova Java class CordovaPlugin and everride the execute method.
Adding D1 SDK binaries to the plugin module
Add the D1 SDK binaries to the d1-build.gradle file of the Plugin module. You may also add the other plugin dependencies in this file.
Updating the plugin manifest file for Android platform
The last step is to specify all files in the Plugin manifest file. You may also specify all additional Android Manfiest items (permissions and so on) in this file.
iOS platform
Swift source code
For the JavaScript method prototypes, it is necessary to create the approriate entry point in the iOS Native code. To implement the Native iOS entry point of the plugin, extend the Cordova Objective-C class CDVPlugin.
Updating the plugin manifest file for iOS platform
The last step is to specify all files in the Plugin manifest file.
D1 SDK Pod wrapper
The most simple way to differentiate between the Debug and Release version of D1 SDK on the iOS platform, is to wrap the D1 SDK binaries in to Pods.
Debug Podspec
Release Podspec
Integrating plugin module to Cordova project
Create a new Cordova project. To configure the D1 SDK on the Android platform for the D1 Push use case, you need to register the application ID for Google Pay. Use the application ID
com.thalesgroup.gemalto.d1.validationfor the Sandbox.
Add the D1 plugin to the Cordova project.
Add the Android and iOS platforms.
Add other plugins and platforms.
Android application signing
To run the NFC payment use case on the Android platform, the application needs to be signed with a specific keystore.
To sign an Android application with a specific keystore:
Copy the keystore file to the Cordova application folder and create a new
build.configfile.
Build the Android application with the specific
build.configfile.
Minimum Android SDK version supported for Android apps
D1 SDK requires AndroidX and minSdk=24. To enable AndroidX, update the config.xml file.
To set the minimum Android SDK version, export the ORG_GRADLE_PROJECT_cdvMinSdkVersion=24 enviroment variable before building the Android application.
Firebase Cloud Messaging
As D1 Pay on the Android platform uses Firebase Cloud Messaging, Google Messaging Services has to be enabled in the Android application and the google-services.json file needs to be added.
Calling the D1 plugin API from the Cordova project
After the D1 plugin has been added to the Cordova project, the D1 API can be accessed from JavaScript.
Integrating plugin module to Ionic Cordova project
The Cordova plugin can be also used in Ionic Cordova projects.
Create a new Ionic Cordova application.
Add the D1 plugin to the Ionic Cordova project.
Add the Android and iOS platforms.
Build the web assets and copy them to the respective platforms.
Troubleshooting
If the ionic cordova build android --buildConfig build.config command returns the error Error: Unknown argument: platform ionic cordova, you will need to install cordova-builders.
References
D1 portal
D1 Android Sample application
D1 iOS Sample application
Apache Cordova
Ionic
Última actualización
¿Te fue útil?