check Balance
Checks the balance of a previously created PaymentMethod
via a ForageVaultElement (either a ForagePINEditText or a ForagePinPad).
⚠️ FNS prohibits balance inquiries on sites and apps that offer guest checkout. Skip this method if your customers can opt for guest checkout. If guest checkout is not an option, then it's up to you whether or not to add a balance inquiry feature. No FNS regulations apply.
On success, the response object includes
snap
andcash
fields that indicate the EBT Card's current SNAP and EBT Cash balances. (Example BalanceCheck class)On failure, for example in the case of
ebt_error_14
, the response includes a list of ForageError objects that you can unpack to programmatically handle the error and display the appropriate customer-facing message based on theForageError.code
.
// Example checkBalance call in a BalanceCheckViewModel.kt
class BalanceCheckViewModel : ViewModel() {
val paymentMethodRef = "020xlaldfh"
fun checkBalance(forageVaultElement: ForagePINEditText) = viewModelScope.launch {
val response = forageTerminalSdk.checkBalance(
CheckBalanceParams(
forageVaultElement = foragePinEditText,
paymentMethodRef = paymentMethodRef
)
)
when (response) {
is ForageApiResponse.Success -> {
// response.data will have a .snap and a .cash value
}
is ForageApiResponse.Failure -> {
// do something with error text (i.e. response.message)
}
}
}
}
Return
A ForageApiResponse object.
Parameters
A CheckBalanceParams model that passes a ForageVaultElement (either a ForagePINEditText or a ForagePinPad) and a paymentMethodRef
, found in the response from a call to tokenizeCard or the Create a PaymentMethod
endpoint, that Forage uses to check the payment method's balance.
See also
SDK errors for more information on error handling.
Test EBT Cards to trigger balance inquiry exceptions during testing.