You're developing a web application, website or a mobile application and would like to to add a payment method. What's more, you'd like your users to be able to pay with the FPay UI.
Next, please select the type of client application you are developing
You are developing a Web Site
1 - Your user has to pay. Let's imagine he's on your site in front of the “pay” button. The user clicks to pay.
2 - Following the click, your server retrieves a payment url using the FPay SDK, then redirects the user to the retrieved url.
3 - The user pays, and at the end of the payment FPay redirects the user to your website.
4 - Your server checks whether the payment was a success or a failure using the FPay SDK.
You can trigger delivery of the product that has just been paid for, or you can inform the user that payment has failed.
5 - Et voilà
Assume you've defined the following routes. Of course, you can name them anything you like, but for the purposes of this documentation, let's consider the following names for a moment:
ROUTE | DESCRIPTION |
---|---|
/recap | Route to the page containing the payment summary and the 'Pay' button |
/pay | Route of the page that will be called when the user clicks on the 'Pay' button |
/pay-completed/:payId | Route of the page to which the user will be redirected when payment is complete |
We will explain how to interact with the FPay SDK and do the following 2 routes :
/pay
/pay-completed/:payId
AuthAccess
object as explained on the Authentication page.AuthAccess
object, the value of the field named secretKey
must be kept absolutely secret and used only on your servers. This implies that you should never use the value of this field as a variable or constant in the source code of a mobile application, a web application or in the source code of any application whose binary may be public and visible to all. There are many tools to access strings in the source code from a binary around here.const fPay = sdk.FPayClient(sdk.Auth({token: '<token>', secretKey: '<secretKey>' }));
For the user to make a payment, we'll create a FundRequest
object to aks him money. The object FundRequest
thus created will contain a url to which we should redirect the user to.
/pay
// Generate an ID for the payment. The 'payId' value seen above
// It's should be uniq and Random
// ... <generate pay id code here>
// After you have generated the payId, create the FundRequest object
const fundRequestPromise =
fPay.fundRequest.create({
amount: {
currency: "XOF",
value: "10_000"
},
h1: "Shopping cart payment #12",
onFailure: {
redirectUserTo: "https://your-server.com/pay-completed/:payId"
},
onSuccess: {
redirectUserTo: "https://your-server.com/pay-completed/:payId"
}
});
// Please save the .id of the returned FundRequest along with the 'payId'
// so that it will be possible to Get the FundRequest id by the 'payId'
const fundRequestId = fundRequest.id;
// ... <save payId, fundRequestId code here>
const paymentUrl = fundRequest.securePay.link;
// Now, you can redirect the user to the value of paymentUrl
// ... <redirect user to paymentUrl code here>
/pay-completed/:payId
// With the submitted payId,Get the previously saved id of the FundRequest
const fundRequestPromise = fPay.fundRequest.get("<fundRequest.id>");
fundRequestPromise.then(fundRequest => {
// Inspect the 'status' of the FundRequest and if successful, do the stuff...
const isCompleted = fundRequest.status.isSuccessful() || fundRequest.status.isFailure();
});
When creating the FundRequest
object , you can specify the time on which the fund request expires.
This can be useful, for example, if you're making promotional offers and the payment of the user is about a limited reduced price.
It can also be useful if you're asking the user to pay for a reservation: You reserve the item for sale until the user has paid, after expire time, if the user has not paid yet, the item becomes available to another potential user.
<after><space><$number><$timeUnit>
<on><space><$iso8601Datetime>
never
never
is the default value if none specified."after 15m"
"after 90s"
"after 1h"
"after 2d"
"after 1w"
"on 2028-05-19T01:13Z"
"on 2028-05-19"
"on 15:30"
const fundRequestPromise =
fPay.fundRequest.create({
amount: {
currency: "XOF",
value: "10_000"
},
expire: "after 45m"
});
When creating the FundRequest
object, if you specify the h1
field , the value entered will be displayed to your user as the reason for payment. It is possible to specify a value in English and a value in French.In this way, the user will be able to change language, and the default language displayed will be that of his browser: If you're selling to an French-speaking user, the text entered in French will be displayed to him automatically.
const fundRequestPromise =
fPay.fundRequest.create({
h1: {
fr: "Paiement panier #12",
en: "Shopping cart payment #12"
},
amount: {
currency: "XOF",
value: "10_000"
}
});
Whenever money is added to your account, the funds collected will be deposited in your main Wallet
by default. Because you can create several additional Wallet
, you can also choose where the funds arrives once the user has paid.
So, you can have one Wallet
for your savings, or one Wallet per store if you have several stores, and choose where the funds received will go.
To specify the destination of the funds, you need the MARS
of the Wallet
, available vie the mars.alpha
field.
For example, if the Wallet's MARS is "CI FPay W09POT"
, then you would enter the following code:
const fundRequestPromise =
fPay.fundRequest.create({
destination: "CI FPay W09POT",
amount: {
currency: "XOF",
value: "10_000"
}
});
By default, transactions fees are paid by your customer. You can specify specify who pays them to change this default behavior according to the situations you need to manage.
For example, suppose you want to make a cash inflow to your FPay account in the amount of ₣ 10,000
The question you need to ask yourself is How much money my user should pay ? If the answer is ₣ 10,000
, then then you pay the fees.
You can also ask the question the other way around: How much money should arrive on my FPay account? If the answer is ₣ 10,000
, then it's your user who will pay the fees.
To specify who pays the fees, 4 values are possible:
"Me"
"CounterPart"
"Sender"
"Receiver"
const fundRequestPromise =
fPay.fundRequest.create({
fees: {
payer: "CounterPart"
},
amount: {
currency: "XOF",
value: "10_000"
}
});
When creating the FundRequest
object, you can attach your own internal ID. In this way, When retrieving the FundRequest
object, you will be able to use your own id
instead of the one generated by FPay. The ID you submit must be unique for each object type.
One of the advantages of submitting your own unique identifier is that you can carry outidempotent queries. In fact, if your submitted foreignId
is unique, then you're protected against duplications due to networks, for example, and you'll be able to control retries without worrying about repeating the same operation several times.
const fundRequestPromise =
fPay.fundRequest.create({
foreignId: "<my internal id>"
});
With the previous code, you now have the right to do the following code to retrieve FundRequest
object.
const fundRequestPromise = fPay.fundRequest.get("<my internal id>");
When creating FundRequest
object, you can add your own data to tag the object you've created.
For example, you can add the following data:
{"myKey": 19, "myOtherKey": "myOtherValue"}
<xml><myKey>myValue</myKey></xml>
myValue1, myValue2, myValue3
const fundRequestPromise =
fPay.fundRequest.create({
foreignData: "<xml><myKey>myValue</myKey></xml>"
});
const fundRequestPromise = fPay.fundRequest.get("<fundRequest.id | foreignId>");
fundRequestPromise.then(fundRequest => {
// Inspect the 'foreignData' field of the FundRequest ...
const xmlData = fundRequest.foreignData;
// xmlData = "<xml><myKey>myValue</myKey></xml>"
});