tokenizeCard

Tokenizes a card via manual entry into a ForagePANEdit Text Element.

  • On success, the object includes a ref token that represents an instance of a Forage PaymentMethod. You can store the token in your database and reference it for future transactions, like to call checkBalance or to create a Payment in Forage's database. (Example PosPaymentMethod class)

  • On failure, for example in the case of unsupported_bin, 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 tokenizeCard call in a TokenizeViewModel.kt
class TokenizeViewMode : ViewModel() {
val merchantId = "<merchant_id>"
val sessionToken = "<session_token>"

fun tokenizeCard(foragePanEditText: ForagePANEditText) = viewModelScope.launch {
val response = forageTerminalSdk.tokenizeCard(
foragePanEditText = foragePanEditText,
reusable = true
)

when (response) {
is ForageApiResponse.Success -> {
// parse response.data for the PaymentMethod object
}
is ForageApiResponse.Failure -> {
// do something with error text (i.e. response.message)
}
}
}
}

Return

A ForageApiResponse object.

Parameters

params

Required. A TokenizeManualEntryParams model that passes a reference to a ForagePANEditText instance that collects the customer's card number and an optional reusable boolean that Forage uses to tokenize the card. setForageConfig must have been called on the instance before it can be passed.

Throws

If the ForageConfig is not set for the provided ForagePANEditText instance.


Tokenizes a card via a magnetic swipe from a physical POS Terminal.

  • On success, the object includes a ref token that represents an instance of a Forage PaymentMethod. You can store the token for future transactions, like to call checkBalance or to create a Payment in Forage's database.

  • On failure, for example in the case of unsupported_bin, 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 tokenizeCard(TokenizeMagSwipeParams) call in a TokenizePosViewModel.kt
class TokenizePosViewModel : ViewModel() {
val merchantId = "<merchant_id>"
val sessionToken = "<session_token>"

fun tokenizePosCard(foragePinEditText: ForagePINEditText) = viewModelScope.launch {
val response = forageTerminalSdk.tokenizeCard(
TokenizeMagSwipeParams(
forageConfig = ForageConfig(
merchantId = merchantId,
sessionToken = sessionToken
),
track2Data = "<read_track_2_data>" // "123456789123456789=123456789123",
// reusable = true
)
)

when (response) {
is ForageApiResponse.Success -> {
// parse response.data for the PaymentMethod object
}
is ForageApiResponse.Failure -> {
// do something with error text (i.e. response.message)
}
}
}
}

Return

A ForageAPIResponse object.

Parameters

params

Required. A TokenizeMagSwipeParams model that passes the ForageConfig, the card's track2Data, and a reusable boolean that Forage uses to tokenize the card.

Throws

If the ForageConfig is not set for the provided ForagePANEditText instance.