Tokenize your customer's account
Once the device is ready with a secure device wallet provisioned, it’s time to tokenize the customer’s account into the secure device wallet.
We tokenize a customer’s account and bind it to a secure device wallet by initiating an API call to Open Fabric.
For security reasons, it is essential to make the API call from the backend.
The Provision account API allows you to tokenize the customer's account. Please make sure you include the secure device wallet identifier as wallet_id. The API will respond back to you with device opaque data (sdk_tokenize_account_device_data) which then needs to be handed back to the SDK for the next step.
The tenant_customer_ref and tenant_account_ref are required fields and need to be filled with a reference to your customer and their account.
Use the tenant_account_ref if you want to distinguish different funding sources. But if customers do not have multiple accounts in your system, you may also choose to copy the value of tenant_customer_ref in this field.
Sample request
Headers:
Idempotency-Key: 40709949-0712-487c-a2fe-1dd2e64af506
{
"tenant_customer_ref": "of_customer_1",
"tenant_account_ref": "FR123456789054001111012345672509",
"wallet_id": "7867519840724679119",
"billing_currency": "SGD",
"billing_address": {
"address_line_1": "Singapore",
"post_code": "000001"
},
"device_name": "Test Device"
}
Sample response
{
"tenant_account_ref": "FR123456789054001111012345672509",
"sdk_tokenize_account_device_data": "eyJ4NWMiOlsiTUlJQzNqQ0NBY2FnQXdJQkFnSUpBT1FDdnc2Tjh4WFRNQTBH...",
"customer_id": "fd2b8723-0a5a-4fd5-8efc-b82d0316c621",
"account_id": "58d74bf2-eb6c-4eeb-9561-f1d3007b5d46",
"device_id": "4eda3b53-1dd9-4c09-b892-362cc2dcbf52"
}
Enroll the tokenized account into the secure device wallet
Now that we have tokenized the customer’s account and generated the device opaque data (sdk_tokenize_account_device_data), it is time to enroll the tokenized account into the secure device wallet.
To complete the setup, the device opaque data (sdk_tokenize_account_device_data) should be injected into the SDK. Use the enrollAccount() method to inject sdk_tokenize_account_device_data received in the previous step.
If all goes well, the callback OpenfabricCallback#onSuccess() is called. We will initiate the process of asynchronously pulling the payment cryptograms generated for the tokenized account. When this is complete, the app is notified with the callback CardEventListener#onCardsUpdated().
If an error occurs anytime during the above process, the callback OpenfabricCallback#onError() is called, passing the reason for the error.
wallet.enrollAccount(context, sdk_tokenize_account_device_data), object : OpenfabricCallback<DigitizeAccountResponse> {
override fun onSuccess(response: DigitizeAccountResponse) {
// update provisioning state with enrollment succeeded
}
override fun onError(error: OpenFabricError) {
displayError(RuntimeException(error.message))
}
})
class CardListener: CardEventListener {
override fun onCardsUpdated(context: Context) {
val intent = Intent(context, MainActivity::class.java)
intent.setAction(CardEventsReceiver.CARD_UPDATED)
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
}
...
}
The registration of the listener is done by declaring the listener class in your manifest file under the key co.openfabric.nfc.CardEventListener, as shown below:
<meta-data
android:name="co.openfabric.nfc.CardEventListener"
android:value="mypackage.CardListener" />
After this step is done, you can continue with card activation and setting preference as described here