Comment on page
Sample Integration
Copy paste the code below in your webpage
1
<script type="text/javascript" src="https://www.foloosi.com/js/foloosipay.v2.js"></script>
2
<script>
3
// post data for create order id
4
data = {
5
transaction_amount : "YOUR INITIAL SUBSCRIPTION AMOUNT",
6
currency : "YOUR CURRENCY",
7
customer_name : "YOUR CUSTOMER NAME",
8
customer_email : "YOUR CUSTOMER EMAIL",
9
customer_mobile : "YOUR CUSTOMER MOBILE NO",
10
customer_address: "YOUR CUSTOMER ADDRESS",
11
customer_city: "YOUR CUSTOMER CITY",
12
billing_country: "YOUR CUSTOMER COUNTRY",
13
billing_state: "YOUR CUSTOMER STATE",
14
billing_postal_code: "YOUR CUSTOMER POSTAL CODE",
15
source: "api subscription",
16
api_subscription : "Yes", /**NOTE- THIS FIELD MUST BE IN YES */
17
recurring_data : {
18
plan : {
19
name : "Api new plan", /** YOUR PLAN NAME*/
20
billing_type : "day", /** value must be day/week/month/year */
21
billing_cycle : 1, /** it only applicable for week and month billing type.ex Every 1 weeks */
22
billing_currency : "AED", //it should be 3 digit code and other than AED you should enabled multi currency option from Foloosi
23
billing_amount : "SUBSCRIPTION AMOUNT",
24
setup_fee : "SETUP FEE", //which is subscription setup one time fee
25
total_count : 10, //number of deductions
26
description : "daily demo plan",
27
start_date : "dd-mm-yyyy" //which is optional param.if you given value should be in the format
28
//Note : if you given date means .at the time of payment will be charged by transaction
29
//amount as you given .subscription recurring will start on the given date and given billing amount
30
},
31
customer : {
32
name : "CUSTOMER NAME",
33
email : "CUSTOMER EMAIL ID"',
34
mobile : "CUSTOMER MOBILE NO",
35
}
36
}
37
}
38
let fetchRes = fetch(
39
"https://api.foloosi.com/aggregatorapi/web/initialize-setup",{
40
method: "POST",
41
headers: {
42
"Content-Type": "application/json",
43
"merchant_key": "YOUR_MERCHANT_KEY" /** get the merchant key from foloosi panel*/
44
},
45
body: JSON.stringify(data)
46
});
47
48
fetchRes.then(res =>
49
res.json()).then(d => {
50
console.log(d.data);
51
var options = {
52
"reference_token" : d.data.reference_token, //which is get from step2
53
"merchant_key" : "YOUR_MERCHANT_KEY",/** get the merchant key from foloosi panel*/
54
}
55
var fp1 = new Foloosipay(options);
56
fp1.open();
57
})
58
foloosiHandler(response, function (e) {
59
if(e.data.status == 'success'){
60
//responde success code
61
//console.log(e.data.status);
62
//console.log(e.data.data.transaction_no);
63
}
64
if(e.data.status == 'error'){
65
//responde success code
66
//console.log(e.data.status);
67
//console.log(e.data.data.payment_status);
68
}
69
if(e.data.status == 'closed'){
70
//Payment Popup Closed
71
//console.log(e.data);
72
}
73
});
74
</script>
Last modified 1yr ago