LANGUAGE JavascriptPHP

Creating a payment link

In order to create a payment link for your customer, there are a couple of steps you will need to undertake. This guide assumes that you have a booking for your customer, however you can create a payment link without one. The steps are as follows.

1. Authenticate - Authenticate your user and get a bearer token to be able to undertake actions against the API

2. Create a booking - Create a booking for your customer

3. Create a payment link - Create a payment link for your customer

1. Authenticating

Authenticating against the API

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();
use GuzzleHttp\Client;
function getToken() {
$client = new Client();
$response = $client->post('https://api.felloh.com/token', [
'headers' => [
'Content-Type' => 'application/json',
],
'json' => [
'public_key' => getenv('PUBLIC_KEY'),
'private_key' => getenv('PRIVATE_KEY'),
],
]);
$data = json_decode($response->getBody(), true);
return $data['data'];
}
$token = getToken()['token'];

The following code will authenticate you against the api and get the bearer token, you can then use this for all future calls against the API.

You will need to get your public and private keys from the dashboard and them set these either in the environment or via another method.

More information on authentication can be found here.

2. Creating a booking

Creating a booking

const response = await axios(
{
method: 'put',
url: `https://api.felloh.com/agent/bookings`,
data : JSON.stringify({
organisation: 'X9876',
customer_name: 'James Dean',
email: 'james@felloh.org',
booking_reference: 'XXX123789',
departure_date: '2022-07-18',
return_date: '2022-07-25',
gross_amount: 1000000,
}),
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
},
);
const bookingID = response.data.data.id;
use GuzzleHttp\Client;
function createBooking($token) {
$client = new Client();
$response = $client->put('https://api.felloh.com/agent/bookings', [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $token,
],
'json' => [
'organisation' => 'X9876',
'customer_name' => 'James Dean',
'email' => 'james@felloh.org',
'booking_reference' => 'XXX123789',
'departure_date' => '2022-07-18',
'return_date' => '2022-07-25',
'gross_amount' => 1000000,
],
]);
$data = json_decode($response->getBody(), true);
return $data['data']['id'];
}
$token = 'YOUR_TOKEN_HERE';
$bookingID = createBooking($token);

As mentioned, this step can be skipped if you do not currently have a booking and would just like to create a payment link, however you will need to use the assign endpoint at a later stage to get payouts on the booking.

More information on creating a booking can be found here.

Creating a payment link

const response = await axios(
{
method: 'put',
url: `https://api.felloh.com/agent/payment-links`,
data : JSON.stringify({
organisation: 'X9876',
customer_name: 'James Dean',
email: 'james@felloh.org',
booking_id: bookingID,
amount: 20000,
open_banking_enabled: true,
card_enabled: true,
description: 'Final payment for cruise holiday'
}),
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
},
);
const paymentLinkID = response.data.data.id;
const paymentURL = `https://pay.felloh.com/${paymentLinkID}`
use GuzzleHttp\Client;
function createPaymentLink($token, $bookingID) {
$client = new Client();
$response = $client->put('https://api.felloh.com/agent/payment-links', [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $token,
],
'json' => [
'organisation' => 'X9876',
'customer_name' => 'James Dean',
'email' => 'james@felloh.org',
'booking_id' => $bookingID,
'amount' => 20000,
'open_banking_enabled' => true,
'card_enabled' => true,
'description' => 'Final payment for cruise holiday',
],
]);
$data = json_decode($response->getBody(), true);
return $data['data']['id'];
}
$token = 'YOUR_TOKEN_HERE'; // Replace with the actual token obtained from the previous step
$bookingID = 'YOUR_BOOKING_ID_HERE'; // Replace with the actual booking ID obtained from the previous step
$paymentLinkID = createPaymentLink($token, $bookingID);
$paymentURL = "https://pay.felloh.com/$paymentLinkID";

You can now create the payment link, with this ID you can then send this link to the customer or alternatively display in your system.

More information on creating a payment link can be found here.