Creating a Payment with a Tokenised Card
In order to create a payment for your customer, you will need to follow a series of steps. This guide assumes that you already have a booking for your customer with a tokenised card attached. The steps are as follows:
1. Authenticating
You first need to authenticate and get the bearer token, which will be used for all subsequent API calls.
import axios from 'axios'; const getToken = async () => { const response = await axios({ method: 'post', url: 'https://api.felloh.com/token', headers: { 'Content-Type': 'application/json' }, data: JSON.stringify({ public_key: process.env.PUBLIC_KEY, private_key: process.env.PRIVATE_KEY, }, ), }); return response.data.data; }; const { token } = await getToken();
More information on authentication can be found here.
2. Finding Card Tokens Associated with a Booking
Once you have the authentication token, you can retrieve the card tokens associated with a booking. This is essential if you need to take a payment using a saved card.
import axios from 'axios'; const bookingId = 'd8529e8d-dbfd-41fc-bc35-71bbe91ab719'; const response = await axios.get( `https://api.felloh.com/payment/booking/${bookingId}/available-tokens`, { headers: { 'Authorization': `Bearer <YOUR TOKEN HERE>` } } ); console.log(response.data);
More information on this endpoint can be found here.
3. Create a Payment
After you've retrieved the card tokens, you can create a payment against the booking using one of them. The booking ID is passed in the URL, and the card token (the id of one of the tokenised cards returned in step 2) and the amount are passed in the body. If no date is supplied, the payment is taken immediately. To take it at a later date instead, add an ISO 8601 date field to the payload, as shown in the scheduling a payment guide.
On success the endpoint returns an empty data object.
const token = 'YOUR TOKEN HERE (FROM STEP 1)'; const bookingId = 'd8529e8d-dbfd-41fc-bc35-71bbe91ab719'; const cardToken = 'CARD TOKEN ID HERE (FROM STEP 2)'; const amount = 2500; // Amount in minor units (e.g., pence) const response = await axios.post( `https://api.felloh.com/payment/booking/${bookingId}/payment`, { token: cardToken, amount: amount, }, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, } ); console.log(response.data);
More information on this endpoint can be found here
