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, but it is possible to schedule a payment without one. 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 schedule 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 proceed with scheduling a payment. Below is the code to schedule the payment.
const token = 'YOUR TOKEN HERE (FROM STEP 1)'; const cardToken = 'CARD TOKEN HERE'; const amount = 2500; // Amount in minor units (e.g., cents) const response = await axios.post( 'https://api.felloh.com/payment/scheduled-payment', { token: cardToken, amount: amount, }, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, } ); const paymentId = response.data.data.id;
More information on this endpoint can be found here