Tilled-Node

This page covers the steps to process your first payment using the tilled-node SDK. You can find comprehensive documentation on Github Pages.

This SDK is still in beta. It has been tested and used in internal projects, but it is still a work in progress and we cannot guarantee it will perform to the same standard as our core services.

Initial Setup

Install the NPM Package

In your root directory, run the following command:

1npm install tilled-node --save

Import the Necessary Modules

To use any of the modules in this SDK, will need to import an ApiKeys module in addition to the module you are attempting to use. To create and confirm a payment intent, you will need to import the PaymentIntentsApi and PaymentIntentsApiKeys modules like so:

1import {
2	PaymentIntentsApi,
3	PaymentIntentsApiApiKeys,
4	PaymentIntentCreateParams,
5	PaymentIntentConfirmParams,
6} from 'tilled-node';
These examples only feature the PaymentIntentsApi, but this SDK is capable of making any of our other documented API calls. Our other APIs can be found in the api directory.

Set up Your Request Configuration

Once you have imported both modules, Set This SDK Axios to make HTTP requests.

1const config = new Configuration({
2	apiKey: process.env.TILLED_SECRET_KEY,
3	basePath: 'https://sandbox-api.tilled.com', // defaults to https://api.tilled.com
4	baseOptions: { timeout: 2000 }, // override default settings with an Axios config
5});
This SDK's basePath defaults to the production environment. The example above reassigns this property to the sandbox URL. Be sure to verify that you are using the correct credentials for the environment you are working in.

Configuring Your Class Instance

Use your newly created config to create a new class instance of the API module:

1const paymentIntentsApi = new PaymentIntentsApi(config);

Process a Payment

Creating a Payment Intent

We are now ready to make a payment. First, we need to create a payment intent. This should be done as soon as your checkout page or component is loaded. You can set up the endpoint for your frontend like so:

 1app.post(
 2	'/payment-intents',
 3	(
 4		req: Request & {
 5			headers: {
 6				tilled_account: string;
 7			};
 8			body: PaymentIntentCreateParams;
 9		},
10		res: Response & {
11			json: any;
12			send: any;
13			status: any;
14		}
15	) => {
16		const { tilled_account } = req.headers;
17
18		paymentIntentsApi
19			.createPaymentIntent({
20				tilled_account,
21				PaymentIntentCreateParams: req.body,
22			})
23			.then((response) => {
24				return response.data;
25			})
26			.then((data) => {
27				res.json(data);
28				console.log(data);
29			})
30			.catch((error) => {
31				console.error(error);
32				res.status(404).json(error);
33			});
34	}
35);

In this example, we are passing the payment intent parameter in the request body from our frontend. Note that we are using the PaymentIntentCreateParams type that we imported earlier.

Confirming the Payment Intent

Now that we have a payment intent, let's confirm it:

 1app.post(
 2	'/payment-intents/:id/confirm',
 3	(
 4		req: Request & {
 5			headers: {
 6				tilled_account: string;
 7			};
 8			params: {
 9				id: string;
10			};
11			body: PaymentIntentConfirmParams;
12		},
13		res: Response & {
14			json: any;
15			send: any;
16			status: any;
17		}
18	) => {
19		const { tilled_account } = req.headers;
20		const { id } = req.params;
21
22		paymentIntentsApi
23			.confirmPaymentIntent({
24				tilled_account,
25				id,
26				PaymentIntentConfirmParams: req.body,
27			})
28			.then((response) => {
29				return response.data;
30			})
31			.then((data) => {
32				res.json(data);
33				console.log(data);
34			})
35			.catch((error) => {
36				console.error(error);
37				res.status(404).json(error);
38			});
39	}
40);
This example assumes that you are creating a payment intent on the client with Tilled.js and passing it your request body. If you meet the PCI requirements to use the Create a Payment Method endpoint and choose to use it, you will need to import the modules for the PaymentMethodsApi and create your payment method with the createPaymentMethod method.