check Balance
Checks the balance of a previously created PaymentMethod
via a ForagePINEditText Element.
⚠️ 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.On failure, for example in the case of
ebt_error_14
, the response includes a list of com.joinforage.forage.android.core.services.forageapi.network.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(foragePinEditText: ForagePINEditText) = viewModelScope.launch {
val response = ForageSDK().checkBalance(
CheckBalanceParams(
foragePinEditText = foragePinEditText,
paymentMethodRef = paymentMethodRef
)
)
when (response) {
is ForageApiResponse.Success -> {
val balance = response.toBalance()
if (balance is EbtBalance) {
// Unpack balance.snap, ebtBalance.cash
}
}
is ForageApiResponse.Failure -> {
val error = response.error
// handle error.code here
}
}
}
}
Return
A ForageApiResponse object. Use toBalance() to convert the data
string to a Balance.
Parameters
A CheckBalanceParams model that passes a com.joinforage.forage.android.ui.ForagePINEditText instance and a paymentMethodRef
, found in the response from a call to tokenizeEBTCard 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.
Throws
If the ForageConfig is not set for the provided foragePinEditText
.