checkBalance

open suspend override fun checkBalance(params: CheckBalanceParams): ForageApiResponse<String>

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 and cash 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 the ForageError.code.

// Example checkBalance call in a BalanceCheckViewModel.kt
class BalanceCheckViewModel : ViewModel() {
val paymentMethodRef = "020xlaldfh"

fun checkBalance(foragePinEditText: ForagePINEditText) = viewModelScope.launch {
val response = forageTerminalSdk.checkBalance(
CheckBalanceParams(
foragePinEditText = 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

params

A CheckBalanceParams model that passes a 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

Throws

If the PosForageConfig is not set for the provided foragePinEditText.