This is an example of how to create a custom hosted capture form for PCI Vault. It uses React to render a form and post the data to the vault.
Vite is utilised to bundle your app as a library that can be loaded in the custom form.
npm installIn order to test the form we need to first create a capture endpoint using the PCI Vault API in the staging environment.
The process for creating the endpoint is as follows:
- Go to [https://docs.pcivault.io] and make sure to select the
Stagingenvironment using the toggle on the bottom left of the page. - Generate a capture endpoint and keep the
unique_idandsecretobtained from this step.
Now we have a test capture endpoint where the test data can be saved.
Update index.html to use this new endpoint's details:
window.custom_form(element, {
"submit_secret": "{secret}",
"submit_url": "/v1/capture/{unique_id}",
"force_keypad": false,
"show_card": true,
...
});While developing, we'll use Vite to package and serve our app, it will also do hot reloads which speed up development.
npm run devAny forms that get submitted will go to the capture endpoint in the staging environmet which was created in the previous step.
In order to load our custom react app in the hosted form, we first need to build the JavaScript and CSS artifacts that will be loaded on the page.
npm run buildVite will package the application and output the artifacts in /dist/custom-form.
These need to be publically accessible and hosted somewhere by you on a URL, for example:
- Go to [https://docs.pcivault.io] and make sure to select the
Productionenvironment using the toggle on the bottom left of the page. - Generate a capture endpoint and keep the
unique_idandsecretobtained from this step. - Create your customised hosted form, making sure to keep the returned
idvalue.
- set the
form_typetocustom - set
js_linksandcss_linksto the URLs where your artifacts can be publically accessed
- Load the configured form using a URL with the form
id, the capture endpointunique_idandsecret. For example: https://api.pcivault.io/v1/capture/iframe/{id}?unique_id={unique_id}&secret={secret}
When you access the form with the URL, you also have the following options that you can specify in the query string:
titlewill set the page title if the form is displayed in a browser window or tab.testinggets passed to our app in the options towindow.custom_form(element, options).referencegets passed to our app in the options towindow.custom_form(element, options)(our example app displays this as a disabled field)- Any other query string parameter will be added to an
extra_dataobject inoptions