Sample Integration

Sample integration using javascript

Copy paste the code below in your webpage

<script type="text/javascript" src="https://www.foloosi.com/js/foloosipay.v2.js"></script>
<script>
        // post data for create order id
        data = {
            transaction_amount : "YOUR INITIAL SUBSCRIPTION AMOUNT",
            currency : "YOUR CURRENCY",
            customer_name : "YOUR CUSTOMER NAME",
            customer_email : "YOUR CUSTOMER EMAIL",
            customer_mobile : "YOUR CUSTOMER MOBILE NO",
            customer_address: "YOUR CUSTOMER ADDRESS",
            customer_city: "YOUR CUSTOMER CITY",
            billing_country: "YOUR CUSTOMER COUNTRY",
            billing_state: "YOUR CUSTOMER STATE",
            billing_postal_code: "YOUR CUSTOMER POSTAL CODE",
            source: "api subscription",
            api_subscription :  "Yes", /**NOTE- THIS FIELD MUST BE IN YES */
            recurring_data : {
                plan : {
                    name : "Api new plan", /** YOUR PLAN NAME*/
                    billing_type : "day", /** value must be day/week/month/year */
                    billing_cycle : 1, /** it only applicable for week and month billing type.ex Every 1 weeks */
                    billing_currency : "AED", //it should be 3 digit code and other than AED you should enabled multi currency option from Foloosi
                    billing_amount : "SUBSCRIPTION AMOUNT",
                    setup_fee : "SETUP FEE", //which is subscription setup one time fee
                    total_count : 10, //number of deductions
                    description : "daily demo plan",
                    start_date : "dd-mm-yyyy" //which is optional param.if you given value should be in the format
                                              //Note : if you given date means .at the time of payment will be charged by transaction
                                              //amount as you given .subscription recurring will start on the given date and given billing amount
                },
                customer : {
                    name : "CUSTOMER NAME",
                    email : "CUSTOMER EMAIL ID"',
                    mobile : "CUSTOMER MOBILE NO",
                }
            }
        }
	let fetchRes = fetch(
            "https://api.foloosi.com/aggregatorapi/web/initialize-setup",{
            method: "POST",
            headers: {
              "Content-Type": "application/json",
              "merchant_key": "YOUR_MERCHANT_KEY" /** get the merchant key from foloosi panel*/
            },
            body: JSON.stringify(data)
         });

	fetchRes.then(res =>
	  res.json()).then(d => {
  	    console.log(d.data);
            var options = {
                "reference_token" : d.data.reference_token, //which is get from step2
                "merchant_key" : "YOUR_MERCHANT_KEY",/** get the merchant key from foloosi panel*/
            }
            var fp1 = new Foloosipay(options);
            fp1.open();
        })
        foloosiHandler(response, function (e) {
          if(e.data.status == 'success'){
            //responde success code
            //console.log(e.data.status);
            //console.log(e.data.data.transaction_no);
          }
          if(e.data.status == 'error'){
            //responde success code
            //console.log(e.data.status);
            //console.log(e.data.data.payment_status);
          }
          if(e.data.status == 'closed'){
            //Payment Popup Closed
            //console.log(e.data);
          }
        });
</script>

Last updated