Offline Payment
This feature is experimental.
Introduction
Offline payments enable Business users and Customers to complete transactions when neither device has an internet connection.
The Vipaso Android SDK uses a pre-authorization mechanism: Customers allocate funds on an instrument while online, so the funds can be spent later when offline.
Overview
- Pre-authorization
- Offline Payment Flow
- Automatic Synchronization
Prerequisites
- SDK initialized and configured. See: Android VipasoSDK
- Customer has an instrument with
preAuthCapable = true
- Business and Customer devices are authenticated
Flow overview
- Customer pre-authorizes funds on a selected instrument while online
- Customer listens for payment requests via BLE
- Business initiates a payment request via BLE
- Customer accepts the payment using pre-authorized funds (no internet required on either side)
- When connectivity is restored, the SDK synchronizes the transaction with the backend
1) Pre-authorization (Customer)
For customers to make payments without an internet connection, they must have a pre-authorized balance on their payment instrument. Pre-authorization allocates funds while online that can later be spent when offline.
import io.vipaso.vipaso.sdkApi.payment.customer.instrument.request.PreAuthorizationRequest
import io.vipaso.vipaso.sdkApi.payment.customer.instrument.response.VipasoPreAuthorization
val request = PreAuthorizationRequest(
instrumentId = "instrument_id",
amount = "100.00",
currency = "USD"
)
val preAuth: VipasoPreAuthorization =
Vipaso.payment.customer.paymentInstrument.preAuthorizeInstrument(request)
Possible VipasoPreAuthorizationStatus
values:
AVAILABLE
: Pre-authorized funds are available for offline paymentsVOIDED
: Pre-authorization voided (no longer usable)EXPIRED
: Pre-authorization expired
2) Offline Payment Flow
For setup and processing, refer to the Online payment Use Case — the flow is identical. The difference is that the Customer must use an instrument with available pre-authorization when both devices are offline.
import io.vipaso.vipaso.sdkApi.payment.customer.response.VipasoCustomerPaymentEvent
import kotlinx.coroutines.flow.Flow
val bleEvents: Flow<VipasoCustomerPaymentEvent> = Vipaso.payment.customer.receivePaymentRequestsViaBle()
scope.launch {
bleEvents.collect { event ->
when (event) {
is VipasoCustomerPaymentEvent.PaymentRequestReceived -> {
val paymentId = event.paymentId
// Show UI, confirm, and then accept using the pre-authorized instrument
}
is VipasoCustomerPaymentEvent.PaymentSuccessful -> { /* ... */ }
is VipasoCustomerPaymentEvent.PaymentCancelled -> { /* ... */ }
is VipasoCustomerPaymentEvent.AnotherUserPaid -> { /* ... */ }
is VipasoCustomerPaymentEvent.PaymentFailed -> { /* ... */ }
}
}
}
Accept the payment:
import io.vipaso.vipaso.sdkApi.payment.customer.response.VipasoPaymentAcceptanceRequest
import java.util.UUID
val acceptance = VipasoPaymentAcceptanceRequest(
paymentId = UUID.fromString("<payment-id-from-event>"),
amount = "12.00",
tip = "0.00",
currency = "USD",
instrumentId = "instrument-id",
isDelegatedInstrument = false
)
Vipaso.payment.customer.acceptPayment(acceptance)
3) Business — Initiate and finalize (offline context)
From the Business device, initiating a payment mirrors the online flow. When both devices are offline, finalization is deferred until connectivity returns.
import io.vipaso.vipaso.sdkApi.payment.business.response.VipasoPaymentResult
val result: VipasoPaymentResult = Vipaso.payment.business.sendPaymentRequestViaBle(
amount = "12.00",
currency = "USD",
paymentReference = null
)
Automatic Synchronization
When connectivity is restored, the SDK automatically synchronizes offline payments with the backend. No additional public API calls are required.