- The Toolkit’s JavaScript code, which you add to your application environment. This code is used to inject UX Toolkit UI components in your customer application as native web components, with any PCI data in iframes.
- Studio, a web-based environment you use to configure and style the theme applied to the UI components so they align with your customer application’s brand.
- The Marqeta platform’s APIs, to which you send your card program’s transaction- and account-related API calls. These interactions are presented by the UX Toolkit UI components and displayed for your cardholders in your customer application. You use the Marqeta platform to authenticate with Studio, and the Marqeta platform is where you upload your Studio theme to once it is finalized.
- The Marqeta platform’s private sandbox, a secure environment where you develop and test your code before deploying to production.
Installation
You must install UX Toolkit before it can be used in your customer application. To add UX Toolkit to your application, you can reference it by adding a script tag to the<head> element of your HTML.
In the example below, prgmshrtcde represents the short code associated with your card program, and 0 represents the major version number of the latest UX Toolkit web components release. To see the latest major.minor.patch version of the web components, access Studio. The version number is given at the top of the page. The script tag’s crossorigin property allows your site to store the exact version of the script you are using. This value is downloaded in a session cookie, for example uxToolKitVersion: 1.0.0, and is provided to ensure a consistent user experience.
HTML
Session integration tutorial
This section shows you how to create a session with a cardholder in Marqeta’s UX Toolkit, as well as how you should interact with the session. Session integration provides Marqeta with a secure way to expose sensitive card data directly to your cardholder, without requiring your servers or application to store, transmit, or process the card data in any way. Marqeta is fully PCI-Service Provider Level 1 compliant and provides the server with which your cardholders’ devices will interact. For a visual representation of how the native web components and iframes are displayed, see About UX Toolkit. Marqeta also hosts the JavaScript files for UX Toolkit, as well as the optional theme objects you upload to the Marqeta platform so they can be applied to the UI components used by your customer application. Theme objects are used to customize the UI components to match the style of your customer application. For more information on creating a Studio theme, see Designing a theme with Studio. UX Toolkit’s default language is American English. However, the UX Toolkit internationalization feature allows you to display UI components in any of Marqeta’s supported languages. For this, you can use Marqeta’s translation files, or you can upload custom translation files that will allow you to tailor UI components in your desired language. For a full list of keys that you can use in your custom translation files, contact your Marqeta onboarding specialist.Note
If you want to upload custom translation files, you must do this during the authentication process.For detailed information about uploading your custom translation files, see the Upload custom translation files section on the UX Toolkit SDK page.
If you want to upload custom translation files, you must do this during the authentication process.For detailed information about uploading your custom translation files, see the Upload custom translation files section on the UX Toolkit SDK page.
Note
This tutorial assumes you have already worked with Marqeta to enable UX Toolkit for your program. You cannot complete these steps in the public sandbox environment.
This tutorial assumes you have already worked with Marqeta to enable UX Toolkit for your program. You cannot complete these steps in the public sandbox environment.
Requirements
In order to begin implementation, your platform must be able to uniquely identify your cardholders on the platform by means of a user token. This unique user identifier is generated as part of creating a user via thePOST /users endpoint. For more information, see Users.
Authentication workflow
UX Toolkit uses a secure, Demonstrating Proof of Possession (DPoP)-based authentication methodology using OAuth 2.0. OAuth 2.0 is the industry-standard authorization framework that lets your application securely access data without ever handling users’ credentials directly. Instead of sending a username and password on every request, your server exchanges tokens with an authorization server, minimizing risk and giving you fine-grained control over who can do what, and for how long. DPoP is a security mechanism within OAuth 2.0 that enhances token security by requiring the client to prove it possesses the private key used to obtain the token. This mechanism prevents unauthorized use of leaked or stolen tokens by binding the token to the client’s private key. Below is an overview of the UX Toolkit authentication workflow.The customer’s web application renders their page and initializes bootstrapping, passing the URL to the Customer’s Authentication API as a parameter.
The UX Toolkit SDK generates a public/private key pair. The private key pair is used to sign the DPoP proof header, while the public key will be used later by the Identity Provider (IdP) or UX Toolkit API for validation.
The DPoP header is passed to the Customer’s Authentication API, and then passed through to the OAuth server (UX Toolkit API). The DPoP header is a short-lived JSON Web Token (JWT) that includes the public key and is signed by the private key. Along with the DPoP header, the Customer’s Authentication API will generate and pass an additional client assertion token in order to successfully request the access token.
The OAuth server issues a DPoP-bound OAuth token, which adds the thumbprint of the public key as one of the properties of the OAuth JWT token. Note that a new, unique DPoP proof token is generated for every request made to the UX Toolkit API. If the OAuth token is ever compromised, it cannot be used without the DPoP private key.
Note
UX Toolkit components automatically request a new access token from the Customer Authentication API when the access token nears expiration (within 60 seconds of expiration) or has already expired.
UX Toolkit components automatically request a new access token from the Customer Authentication API when the access token nears expiration (within 60 seconds of expiration) or has already expired.
Generate your RSA key pair
To authenticate UX Toolkit via OAuth, you must first generate a unique 2048-bit RSA key pair for each of your Marqeta programs. Marqeta recommends using OpenSSL to generate these RSA key pairs. When your Marqeta representative creates your program, you must provide them with the public key as an X.509 certificate encoded in Privacy Enhanced Mail (PEM) format. Step 1 Generate a private key in PEM format using the following command:Pem
Pem
myprogram_public_key.pem.pub PEM file as an X.509 certificate.
Pem
Set up your API URL
When configuring yourapiEndpoint, you must ensure that your API server allows cross-origin requests from Marqeta’s UX Toolkit web domain. To allow cross-origin requests, you must include the property Access-Control-Allow-Origin in the HTTP response header, as shown in the code example that follows.
Note
You should only add this property to the HTTP response header if you plan on using Marqeta’s iFrame content as mobile webviews.
You should only add this property to the HTTP response header if you plan on using Marqeta’s iFrame content as mobile webviews.
JavaScript
Pass your endpoint via the bootstrap function
After the Customer Authentication API endpoint is live, you must then pass the endpoint to thebootstrap() function.
To bootstrap UX Toolkit, call the bootstrap() function to initiate the session referenced by your apiEndpoint. Include any API headers at this point, load your theme for consumption by the UI components, and, optionally, upload any custom translation files that you need for your application.
You can call the bootstrap() function as shown below.
Note
The
The
apiHeadersResolver property can accept a HeadersInit object as shown in the following code example, or a method (synchronous or asynchronous) that returns a HeadersInit object.In this code sample, there are three optional fields: envName, themeName, and languageCode. Include these fields if you want to specify the environment in which you are working (sandbox or production), use a custom theme, or use custom translation files.bootstrap() function.
| Field | Description |
|---|---|
authParams | This object contains the following elements: - apiEndpoint (Required): The string value of a fully-qualified URL representing your authentication API endpoint. For more information about authentication, see Authentication workflow.- apiHeadersResolver (Optional): This object is used to pass any session or auth token headers to your authentication API endpoint for the purpose of authenticating users with your application. |
envName | (Optional) Indicates which environment is being targeted. Allowable values for this field are sandbox or production. The default value of this field is production. |
themeName | (Optional) The name of an existing theme that was created using the /theme endpoint. The default value of this field is default. For more information on the /theme endpoint, see Upload theme object. |
languageCode | (Optional) The language code representing the target language of the custom translation files you uploaded using the /translations endpoint. The default language of UX Toolkit web components is American English (en-US). For more information about the /translations endpoint, see Upload custom translation files. |
JavaScript
Create your client assertion token
The client assertion token must be signed with the private key that you generated in the Generate your RSA key pair section. Marqeta recommends that you construct the token using standard tooling or third-party libraries that support this functionality out of the box, rather than implementing them from scratch yourself. To learn more about supporting libraries, visit JWT.io. The Node.js script below uses ajose package to generate the assertion:
JavaScript
Request your OAuth access token
Send aPOST request to the /oauth/token endpoint with your client credentials and include the DPoP proof JWT in a DPoP header. Use this endpoint to generate your UX Toolkit OAuth access token. The token you generate enables access to the specified account and is returned to the UX Toolkit client.
For more information about working with the POST /oauth/token endpoint to create a UX Toolkit OAuth access token, see Generate UX Toolkit OAuth access token.
If you prefer to make the API call by executing a cURL command, use the sample cURL below:
cURL
Return your OAuth access token
After the Customer Authentication API has successfully generated the client assertion and exchanged it with the OAuth endpoint for an access token, you must send the resulting access token back to the UX Toolkit client.Rendering a UI component
Once you have bootstrapped UX Toolkit, rendering UI components in your application is straightforward. Place the HTML tags for the components into the body of your application code, as shown below. In this example,prgmshrtcde in the script tag represents the short code associated with your card program, and 1 represents the major version number of the latest UX Toolkit web components release. To see the latest major.minor.patch version of the web components, access Studio. The version number is given at the top of the page.
HTML
Listening to events
A custom UI component event is typically emitted whenever a noteworthy action or behavior occurs within that UI component. You can develop your application to listen and respond to whatever events matter to your use cases.Linking behavior between UI components
You can link the behavior between two UI components by adding event listeners for specific events. In the example below, an event listener is listening for anmqCardListActionHook event before setting the selected card’s unique token to the value stored in cardToken:
JavaScript
mqTransactionListHook event. If the requested operation is to view a transaction, a <div> element is created to contain the transaction. Your application can then display the transaction details in a modal window, including the Report a problem button for disputable transactions.
JavaScript
Working with themes
UX Toolkit UI components come with a default theme; however, you can choose to customize this theme so it aligns more closely with your brand. For more information, see Designing a theme with Studio. After you have developed your theme using the Studio interactive design environment, save it as a JSON file then upload a copy of it to the Marqeta platform, as described in Uploading a Studio theme. The example cURL below uploads a theme namednew-theme-name to the Marqeta platform:
cURL
bootstrap() method to include the theme:
JavaScript
Choosing card art
UX Toolkit’s web components allow you to upload suitable card art to enhance the cardholder experience offered by your application. You can submit up to three images for each of the card products in your program:- An image displayed on the front of the card
- An image displayed on the back of the card (digital cards only, not for virtual cards)
- A thumbnail-sized image of the image displayed on the front of the card
Digital (physical) cards
Front of card
This card art template is a digital version of the front of the physical card.Back of card
This card art template is a digital version of the back of the physical card.Thumbnail of card
The thumbnail is an optional scaled-down version of the card art representing the front of the physical card. If you do not submit a thumbnail for your theme, default imagery from the card network will be displayed instead.Virtual cards
Front of card
This card art template represents the virtual card. Virtual cards have no associated back-of-card image.Thumbnail of card
The thumbnail is an optional scaled-down version of the card art representing the virtual card. If you do not submit a thumbnail for your theme, default imagery from the card network will be displayed instead.Card art specifications
The images you submit must adhere to the following specifications:| Name | Description |
|---|---|
| File format | Portable network graphics file (*.PNG) |
| Image orientation | Landscape only |
| File size on disk | Maximum of 5 MB per image NOTE: Although the file you choose could be up to 5 MB in size, it will probably be much smaller than the permitted maximum. Avoid using a large file that must be resized for display by the UI components. |
| Image size on screen | - Front/back images: 1536 pixels x 969 pixels (proportional to an ISO ID-1 card size) - Thumbnail image: 60 pixels x 36 pixels |
| Corner radius | 0.1233” or 3.13182 millimeters |
| Resolution | 72 pixels per inch (PPI) |
| Color model | RGB |
| Color depth | 16+ bit depth, non-interlaced |
Uploading to the Marqeta platform
After you have selected your images and had them approved by Marqeta, your bank, and the card network, you are ready to upload them to the Marqeta platform for use in Studio. You can upload card art to the Marqeta platform using cURLs or by sending an API request to the/cardproducts/cardart endpoint of the UX Toolkit service.
The example cURL below uploads an image file named file.png to the Marqeta platform:
cURL
POST request to the /cardproducts/cardart endpoint as a multi-part form data request, as described in Upload card art.
Using custom translation files
UX Toolkit web components are automatically set to American English as the default. However, Marqeta enables you to change the language of web components as part of the UX Toolkit internationalization feature. You can change the language of web components by uploading custom translation files using the/translations endpoint and then including them in the bootstrap() function. For more information about the /translations endpoint, see the Upload custom translation files section on the UX Toolkit SDK page.
Working with custom translation files
Note
If you are using a custom theme, you must upload it as described in Uploading a Studio theme prior to calling the
If you are using a custom theme, you must upload it as described in Uploading a Studio theme prior to calling the
bootstrap() function.- Ensure that your custom translation files are linguistically accurate and representative of the user experience.
- Upload your custom translation files using the
translationsendpoint as described in the Upload custom translation files section on the UX Toolkit SDK page. - Test your files in Studio.
- Update the call you make to Marqeta’s
bootstrap()function to include the language code, as shown in the code example below. - Execute the
bootstrap()function.
JavaScript
Testing in UX Toolkit Studio
You can use Marqeta’s Studio interactive design environment to test translation values.Note
To perform a test of the custom translation files, you must be authenticated within Studio.
To perform a test of the custom translation files, you must be authenticated within Studio.
- Request the translations object file for your target language from Marqeta.
- Customize the values in the object file in your target language.
- Send a request using the object with customized values to the
/translationsendpoint, as described in the Upload custom translation files section on the UX Toolkit SDK page. This should return a successful response message.
- Authenticate in Studio using your access token.
- In Studio, click on the globe icon in the top menu navigation bar to confirm that changes to your custom translation files have been applied. Available languages are listed in the drop-down menu beneath the globe icon.
- Select a language from the list.
Note
The languages that Marqeta supports are listed under the globe icon. Use the Customize tab to view any updates that you have made to the web components’ display language.
The languages that Marqeta supports are listed under the globe icon. Use the Customize tab to view any updates that you have made to the web components’ display language.