tokenize EBTCard
Tokenizes an EBT Card via a ForagePANEditText Element.
On success, the object includes a
ref
token that represents an instance of a ForagePaymentMethod
. You can store the token for future transactions, like tocheckBalance
or to create aPayment
in Forage's database.On failure, for example in the case of
unsupported_bin
, 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 tokenizeEBTCard call in a TokenizeViewModel.kt
class TokenizeViewModel : ViewModel() {
val merchantId = "<merchant_id>"
val sessionToken = "<session_token>"
fun tokenizeEBTCard(foragePanEditText: ForagePANEditText) = viewModelScope.launch {
val response = ForageSDK().tokenizeEBTCard(
TokenizeEBTCardParams(
foragePanEditText = foragePanEditText,
reusable = true,
customerId = "<hash_of_customer_id>"
)
)
when (response) {
is ForageApiResponse.Success -> {
val paymentMethod = response.toPaymentMethod()
// Unpack paymentMethod.ref, paymentMethod.card, etc.
val card = paymentMethod.card
// Unpack card.last4, ...
if (card is EbtCard) {
// Unpack card.usState
}
}
is ForageApiResponse.Failure -> {
val error = response.error
// handle error.code here
}
}
}
}
Return
A ForageApiResponse object. Use toPaymentMethod() to convert the data
string to a PaymentMethod.
Parameters
A TokenizeEBTCardParams model that passes a foragePanEditText
instance, a customerId
, and a reusable
boolean that Forage uses to tokenize an EBT Card.
See also
SDK errors for more information on error handling.
Throws
If the ForageConfig is not set for the provided foragePanEditText
.