DeunaSDK is a Android-based SDK designed to facilitate integration with the DEUNA. This SDK provides a seamless way to initialize payments, handle success, error, and close actions, and manage configurations.
Get started with our 📚 integration guides and example projects
You can install DeunaSDK using by adding the following dependency to your build.gradle
file:
implementation("com.deuna.maven:deunasdk:2.1.1")
To use the SDK you need to create one instance of DeunaSDK
. There are 2 ways that you can create an instance of DeunaSDK
:
-
Registing a singleton to use the same instance in any part of your code
DeunaSDK.initialize( environment = Environment.SANDBOX, // Environment.PRODUCTION , etc publicApiKey = "YOUR_PUBLIC_API_KEY" )
Now you can use the same instance of DeunaSDK using
DeunaSDK.shared
DeunaSDK.shared.initCheckout(...)
-
Instantiation
class MyClass { private lateinit val deunaSDK: DeunaSDK init { deunaSDK = DeunaSDK( environment = Environment.SANDBOX, publicApiKey = "YOUR_PUBLIC_API_KEY" ) } fun buy(){ deunaSdk.initCheckout(...) } }
To launch the checkout process you must use the initCheckout
function. It sets up the WebView, checks for internet connectivity, and loads the payment link.
Parameters:
-
orderToken: The token representing the order.
-
callbacks: An instance of the
CheckoutCallbacks
class, which contains closures that will be called on success, error, or when the WebView is closed. -
closeEvents: A set of
CheckoutEvent
values specifying when to automatically close the checkout.NOTE: By default, the WebView modal is only closed when the user presses the close button. You can use the
closeEvents
parameter to close the WebView without having to call thecloseCheckout
function.class MyClass: AppCompatActivity() { val deunaSDK: DeunaSDK .... fun buy(orderToken:String){ val callbacks = CheckoutCallbacks().apply { onSuccess = { response -> deunaSDK.closeCheckout(...) // show the success view } onError = { error -> // your logic deunaSDK.closeCheckout(...) } onCanceled = { // called when the payment process was canceled by user // Calling closeCheckout(...) is unnecessary here. } eventListener = { type, response -> when(type){ ... } } onClosed = { // DEUNA widget was closed } } deunaSDK.initCheckout( context = this, orderToken = orderToken, callbacks = callbacks ) } }
To launch the vault widget you must use the initElements
function. It sets up the WebView, checks for internet connectivity, and loads the elements link.
Parameters:
-
userToken: The token representing the user.
-
callbacks: An instance of the
ElementsCallbacks
class, which contains closures that will be called on success, error, or when the WebView is closed. -
closeEvents: A set of
ElementsEvent
values specifying when to automatically close the checkout.NOTE: By default, the WebView modal is only closed when the user presses the close button. You can use the
closeEvents
parameter to close the WebView without having to call thecloseElements
function.class MyClass: AppCompatActivity() { val deunaSDK: DeunaSDK .... fun saveCard(userToken:String){ val callbacks = ElementsCallbacks().apply { onSuccess = { response -> deunaSDK.closeElements(...) // show the success view } onError = { error -> // your logic deunaSDK.closeElements(...) } onCanceled = { // called when the elements process was canceled by user // Calling closeElements(...) is unnecessary here. } eventListener = { type, response -> when(type){ ... } } onClosed = { // the elements view was closed } } deunaSDK.initElements( context = this, orderToken = userToken, callbacks = callbacks ) } }
To enable or disable logging:
DeunaLogs.isEnabled = false // or true
The SDK automatically checks for network availability before initializing the checkout process.
-
To generate an order token, refer to our API documentation on our API Referece
-
You'll need a registered user in DEUNA. Follow the instructions for "User Registration" in our API reference.
Once you have a registered user, you can obtain an access token through a two-step process:
Request an OTP code: Use our API for "Requesting an OTP Code" via email.
Login with OTP code: Use the retrieved code to "Log in with OTP" and get an access token for your user.
Check all changes here
DUENA Inc.
DEUNA's SDKs and Libraries are available under the MIT license. See the LICENSE file for more info.