This example repository shows how to perform Optical Character Recognition (OCR) in virtual credit card image using Tesseract.js, by leveraging Basis Theory CDE.
In this setup, a virtual credit card image is provided via a URL. The Cardholder Data contained in the image is considered sensitive and regulated by PCI DSS, so the image will be downloaded and analyzed in a Basis Theory Reactor, which will tokenize the image data into a card token by executing custom code (formula.js).
Create a new Management Application with full application
and reactor
permissions.
Paste the API key to a new terraform.tfvars
file at this repository root:
management_api_key = "key_W8wA8CmcbwXxJsomxeWHVy"
Initialize Terraform:
terraform init
And run Terraform to provision all the required resources:
terraform apply
Using the reactor_id
and reactor_api_key
generated as a Terraform state outputs, make the following request passing the example image url in the payload:
curl -L -X POST 'https://api-dev.basistheory.com/reactors/{{reactor_id}}/react' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'BT-API-KEY: {{reactor_api_key}}' \
--data-raw '{
"args": {
"url": "https://raw.githubusercontent.com/Basis-Theory-Labs/ocr-example/dc7a8dfcc5a837352fa502c2b2d270e0868dd8ae/card.png"
}
}'
Make sure to replace the variables above with the Terraform outputs stored in Terraform state.
You should receive a Create Token Response in a token
raw attribute.
The formula.test.js file shows how the response transform code can be tested. To run it, install dependencies with:
yarn install
And run the command:
yarn test