EdfaPay Logo

SDK Initialization

Learn how to properly initialize the EdfaPay Soft POS SDK with your credentials.

Basic Setup

Call EdfaPayPlugin.initiate() from a FragmentActivity (for example AppCompatActivity) before any payment operation. All three callbacks are required: onSuccess receives the session ID, onTerminalBindingTask lets you bind a terminal, and onError reports a failure. With an auth token the SDK signs in without any UI, binds the terminal and downloads the terminal configuration. A terminal SDK token binds its own terminal; a merchant SDK token calls onTerminalBindingTask when this device has no terminal yet, so the user can pick one of the merchant's terminals. With an email and password, or with no credentials, it opens its own login screen instead (if a saved session exists, it renews it without UI).

Loading...

Important

Always initialize the SDK before attempting any payment operations. Calling payment methods before initialization will result in errors.

Flutter Note

In Flutter, use EdfaPayCredentials.withToken(environment:, token:) for a token (the authCode parameter is named token), or EdfaPayCredentials(environment:, email:, password:) for an email and password. Your Android MainActivity must extend FlutterFragmentActivity. See Authentication Options below.

Location permission

Payments need the ACCESS_FINE_LOCATION permission; initiate() does not. With a token the SDK does not ask for it (only its login screen does), so request it before initiate(), at the latest before the first payment. Without it the payment stops with "Location permission required to pay".

Network and cancellation

With a token, initiate() signs in to EdfaPay on every call, so it needs a network connection; if sign-in fails, onError is called and the SDK clears its session. Call initiate() again when the device is back online. Closing the SDK's login or terminal screen also calls onError, with "initialization canceled by user".

Authentication OptionsUpdated v1.0.7

The SDK signs in with an auth token (recommended, no UI) or with an email and password, which opens the SDK's own login screen. With no credentials, the same login screen lets the user choose how to sign in. Credentials come from EdfaPay and are issued for one environment, DEMO or PRODUCTION; they work only in that environment (see Environment Options). An API key is optional. Card payments do not use it; only txnDetailApi, searchTxnApi, pgTxnStatusApi, invoicePayment and invoiceRefund need it. Set it before initiate(): Kotlin, Flutter: the chainable setApiKey() method (Flutter also takes an apiKey: parameter); Java: the five-argument constructor new EdfaPayCredentials(env, null, null, token, apiKey).

On docs.edfapay.com

SDK tokens are created and managed in the EdfaPay dashboard: Token Management.

MethodKotlin ParameterFlutter ParameterWhat initiate() does
Auth TokenauthCode = "..."token: "..."Signs in without UI. A terminal SDK token binds its terminal; a merchant SDK token calls onTerminalBindingTask if this device has no terminal yet. Recommended.
Email + Passwordemail + passwordSame named paramsOpens the SDK login screen, filled in with the email and password, with its own terminal selection. The login screen asks for location permission; the user can cancel and still sign in. If a saved session exists, renews it without UI.
No credentialsEdfaPayCredentials(environment)EdfaPayCredentials.withInput(environment:)Opens the SDK login screen: the user signs in with email and password, a token (typed or scanned as a QR code) or phone and OTP, then picks a terminal on the SDK's own terminal selection. If a saved session exists, renews it without UI.
API Key (optional, v1.0.7 and above — Android/Flutter).setApiKey("...")apiKey: / .setApiKey("...")Not used for card payments. Needed only by txnDetailApi, searchTxnApi, pgTxnStatusApi, invoicePayment and invoiceRefund.
Loading...

Security Warning

Never hardcode credentials in your application. Use secure storage mechanisms like Android Keystore, or retrieve tokens from your backend server at runtime.

Terminal BindingNew in v1.0.5

On a sign-in with a merchant SDK token, onTerminalBindingTask is invoked when this device has no terminal bound yet. You must bind a terminal to continue; initiate() then finishes on its own onSuccess or onError. A terminal SDK token binds its own terminal and does not call it. This callback is triggered during: • First-time setup: when this device has no terminal bound yet • After an unbind: when this device's terminal was unbound Only a merchant SDK token sign-in uses this callback. With an email and password, or with no credentials, the SDK's login screen shows its own terminal selection instead. The SDK identifies the device by a value Android gives each app signing key. A build signed with another key (debug or release, or re-signed by Play App Signing) is a new device and binds a terminal again.

bind()

Shows the SDK's built-in terminal selection UI. Simplest approach for most integrations.

terminals

The list of available terminals, to build your own selection UI and bind the terminal the user picks. The Java, Flutter and React Native samples below show how to bind one of them directly; in Kotlin, use bind() to show the SDK picker. Each terminal has terminalId, trsm and providerTid.

refresh()

Fetch the latest terminals list from the server if the list may be stale.

Loading...

When is this callback triggered?

This callback is not always called. If a terminal is already bound and valid, the SDK proceeds directly to onSuccess. The callback is only triggered when terminal selection is needed.

Flutter Difference

In Flutter, onTerminalBindingTask passes a TerminalBindingTask object. Access task.terminals to get the list, then call task.bind() to show the SDK UI or task.bind(terminal: terminal) to bind a specific terminal.

TerminalBindingTask API Reference

Reference for the TerminalBindingTask and Terminal objects provided in the callback.

On docs.edfapay.com

The terminal picker lists the terminals of the merchant's branches, as set up in the dashboard: Terminal profile, Branch management.

Loading...

Environment Options

Use Env.DEMO while you integrate and test, and Env.PRODUCTION when you go live. The environment you pass decides which EdfaPay server the SDK signs in to, so a token or login works only in the environment that issued it: a DEMO token does not work with Env.PRODUCTION, and a PRODUCTION token does not work with Env.DEMO.

EnvironmentKotlin EnumUse for
DemoEnv.DEMOIntegration and testing. Never charges a card.
ProductionEnv.PRODUCTIONLive payments with real cards
SandboxEnv.SANDBOXLegacy, do not use

"Session expired and non renewable, Initialize the SDK again"

onError receives this message when EdfaPay rejects the session on a request and the SDK cannot renew it. Before an operation the SDK may report the same situation as "EdfaPay session has expired and cannot be renewed. Please initialize the SDK again." or "EdfaPay session cannot be renewed. Please initialize the SDK again." In each case, call initiate() again with credentials issued for the environment you pass in EdfaPayCredentials.