Integration Guide using C# ASP.NET¶
A Payment Request Form¶
The first step in integrating with the FloCash gateway is to create a payment form in the checkout page. A payment form collects order information from the customer and invokes the FloCash Express Checkout page. In addition to order data, the customer designates the method of payment with which he or she wishes to pay. The order information can include a billing address and a shipping address. The customers card or mobile wallet details needs to be sent in the authorization request the payment page provides a form for the customer to enter these details securely. Further details on correctly formatting and sending the authorization request are shown in the API section of this manual.
The information collected from the form should be posted to the flocash through HTTPPost. The submit action of this form sends data to the FloCash payment gateway, where a payment page is dynamically created for the customer.
An example of this form is as follows:
Set Form action to https://fcms.flocash.com/ecom/ecommerce.do
Set Form method to ‘’POST’’ or ‘’GET’‘
Input parameters:
No. | Field Name | Description | Note |
---|---|---|---|
1 | amount | The total amount the buyer needs to pay | Total amount to pay |
2 | currency_code | 3-letter code of the currency of the amount based on ISO 4217 | Currency for the transaction |
3 | custom | Customer Id | This is a custom field that the merchant can pass to the FloCash gateway |
4 | item_name | Item description which will be displayed to buyer atcheck out |
|
5 | item_price | Price per item | |
6 | merchant | Merchant email(which was registered at FloCash) |
This field is used by FloCash gateway to identify the merchant. |
7 | order_id | Order Id | Used for managing orders |
8 | quantity | The number of items | |
9 | notify_url | The url that FloCash should send notifica tion to |
This parameter is optional can also be set under merchant profile |
10 | Cancel_url | The url that FloCash should redirect user if payment is cancelled by buyer | This parameter is optional canalso be set under merchant profile |
11 | return_url | The url that FloCash should redirect user if payment is successfully completed | This parameter is optional can also be set under merchant profile |
Example
Default.aspx :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Flocash.Ecom.Web.UI._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Flocash Payment on merchant site</title>
<script type="text/javascript">
window.onload = function() {
calculate();
}
function calculate() {
var amount = document.getElementById('totalamount');
var itemPrice = document.getElementById('ItemPrice');
var quantity = document.getElementById('ItemQuantity');
amount.value = itemPrice.value * quantity.value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
Item
</td>
<td>
<asp:TextBox ID="Itemname" runat="server" Text="Merchant Credit" ReadOnly="true"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Price
</td>
<td>
<asp:DropDownList runat="server" ID="ItemPrice">
<asp:ListItem Value="0.1" Text="0.1"></asp:ListItem>
<asp:ListItem Value="0.2" Text="0.2"></asp:ListItem>
<asp:ListItem Value="0.5" Text="0.5"></asp:ListItem>
<asp:ListItem Value="1" Text="1"></asp:ListItem>
<asp:ListItem Value="2" Text="2"></asp:ListItem>
<asp:ListItem Value="5" Text="5"></asp:ListItem>
<asp:ListItem Value="10" Text="10"></asp:ListItem>
<asp:ListItem Value="20" Text="20"></asp:ListItem>
<asp:ListItem Value="50" Text="50"></asp:ListItem>
<asp:ListItem Value="100" Text="100"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Quantity
</td>
<td>
<asp:DropDownList ID="ItemQuantity" runat="server">
<asp:ListItem Value="1" Text="1"></asp:ListItem>
<asp:ListItem Value="2" Text="2"></asp:ListItem>
<asp:ListItem Value="3" Text="3"></asp:ListItem>
<asp:ListItem Value="4" Text="4"></asp:ListItem>
<asp:ListItem Value="5" Text="5"></asp:ListItem>
<asp:ListItem Value="6" Text="6"></asp:ListItem>
<asp:ListItem Value="7" Text="7"></asp:ListItem>
<asp:ListItem Value="8" Text="8"></asp:ListItem>
<asp:ListItem Value="9" Text="9"></asp:ListItem>
<asp:ListItem Value="9" Text="9"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Total Amount
</td>
<td>
<asp:TextBox ID="totalamount" runat="server" ReadOnly="true"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnCheckout" runat="server" Text="Checkout" OnClick="btnCheckout_Click" />
</td>
</tr>
</table>
</form>
</body>
</html>
Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Flocash.Ecom.Web.UI
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/// Javascript call on client side
ItemPrice.Attributes.Add("OnChange", "return calculate();");
ItemQuantity.Attributes.Add("OnChange", "return calculate();");
}
/// <summary>
/// When the checkout button is clicked on the merchant side by a customer,
/// it takes to the flocash payment option
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCheckout_Click(object sender, EventArgs e)
{
/// sample code
string amount = Convert.ToString(float.Parse(ItemPrice.SelectedItem.Value) * float.Parse( ItemQuantity.SelectedItem.Value));
string currencycode = "USD";/// can be configured for dynamic value
string custom = "Customer ID"; /// dynamic value can be assigned
string itemname = Itemname.Text;
string itemprice = ItemPrice.SelectedItem.Value;
string merchant = "eeranjitranjan@gmail.com";/// Merchant regiestered email with flocash
string orderied = "WO" + RandomOrder();
string itemquant = ItemQuantity.SelectedItem.Value;
if (!string.IsNullOrEmpty(merchant) && !string.IsNullOrEmpty(amount))
{
FCpost myremotepost = new FCpost();
myremotepost.Url = "http://sandbox.flocash.com/ecom/ecommerce.do";/// the post url of flocash
myremotepost.Add("amount", amount);
myremotepost.Add("currency_code", currencycode);
myremotepost.Add("custom", custom);
myremotepost.Add("item_name", itemname);
myremotepost.Add("item_price", itemprice);
myremotepost.Add("merchant", merchant);
myremotepost.Add("order_id", orderied);
myremotepost.Add("quantity", itemquant);
myremotepost.Add("notify_url", "http://www.yourdomain.com/notify.aspx");/// this setting must be configured for the live URL in the flocash profile setting
myremotepost.Add("cancel_url", "http://localhost:4537/cancel.aspx");/// change it to your url
myremotepost.Add("return_url", "http://localhost:4537/result.aspx");///change it to your url
/// post the input parameters to flocash gateway
myremotepost.Post();
}
}
/// <summary>
/// To generate a random order
/// </summary>
/// <returns></returns>
protected int RandomOrder()
{
Random random = new Random();
return random.Next(1, 1000);
}
}
}
FCPost.cs: This is a common class file which does HTTP Post on a specified URL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Flocash.Ecom.Web.UI
{
public class FCpost
{
private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
public string Url = "";
public string Method = "post";
public string FormName = "form1";
public void Add(string name, string value)
{
Inputs.Add(name, value);
}
public void Post()
{
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Write("<html><head>");
System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
for (int i = 0; i < Inputs.Keys.Count; i++)
{
System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
}
System.Web.HttpContext.Current.Response.Write("</form>");
System.Web.HttpContext.Current.Response.Write("</body></html>");
System.Web.HttpContext.Current.Response.End();
}
}
}
when you checkout on the page, it will take you to the flocash payment page,where a customer will do the payment using flocash wallet.On completion of the payment, it will reidirect to your return url page.
Handling Notification from FloCash Gateway¶
After the buyer fills out and submits the Checkout Form, he or she will be forwarded to FloCash web site to complete transaction. If an existing FloCash customer, then the buyer will log in to his or her FloCash account and review the purchase. Once payment is confirmed, FloCash Gateway will send a notification to the URL which is set on ‘’Notify URL’’ field of merchant account. A server-side listener needs to be created to handle this Notification. The information may also be stored into your database for further processing ‘’such as verifying transaction etc…’‘.
POST Parameters:
No. | Field Name | Description |
---|---|---|
1 | trans_id | Transaction Id (Generated by FloCash) |
2 | fpn_id | Transaction Number (Generated by FloCash) |
3 | Merchant | Merchant Email (which is the merchant’s accou nt ID registered at FloCash) |
4 | item_price | Item Price |
5 | sender_acct | Sender Email |
6 | retunr_url | Return url specified during checkout. |
7 | order_id | Order Id (Generated by Merchant Site) |
8 | item_name | Item Name |
9 | currency_code | Currency Code |
10 | Quantity | Number of Items |
11 | Amount | Amount |
12 | payer_email | Customer email which was used for payment on wallet |
13 | payment_channel | Normally value , Wallet |
14 | custom | Custom field provided by merchant |
15 | customer | Customer Email (which is registered at FloCash when create an account) |
16 | Status | Return code |
17 | txn_partner_ref | Transaction reference number |
18 | partner_message | Partner message |
19 | status_msg | Return message |
Example code to handle Notification and process payment:
Notify.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Flocash.Ecom.Web.UI
{
public partial class Notify : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/// store all the posted form variables in an object to use later
FCResponse fcnotifyresponse = new FCResponse();
fcnotifyresponse.TransactionID = GetFormVariableOrNull(Request.Form["trans_id"]);
fcnotifyresponse.TransactionNumber = GetFormVariableOrNull(Request.Form["fpn_id"]);
fcnotifyresponse.MerchantEmail = GetFormVariableOrNull(Request.Form["merchant"]);
fcnotifyresponse.ItemPrice = GetFormVariableOrNull(Request.Form["item_price"]);
fcnotifyresponse.SenderAccount = GetFormVariableOrNull(Request.Form["sender_acct"]);
fcnotifyresponse.ReturnURL = GetFormVariableOrNull(Request.Form["retunr_url"]);
fcnotifyresponse.OrderID = GetFormVariableOrNull(Request.Form["order_id"]);
fcnotifyresponse.ItemName = GetFormVariableOrNull(Request.Form["item_name"]);
fcnotifyresponse.CurrencyCode = GetFormVariableOrNull(Request.Form["currency_code"]);
fcnotifyresponse.Quantity = GetFormVariableOrNull(Request.Form["quantity"]);
fcnotifyresponse.Amount = GetFormVariableOrNull(Request.Form["amount"]);
fcnotifyresponse.PayerEmail = GetFormVariableOrNull(Request.Form["payer_email"]);
fcnotifyresponse.PaymentChannel = GetFormVariableOrNull(Request.Form["payment_channel"]);
fcnotifyresponse.Custom = GetFormVariableOrNull(Request.Form["custom"]);
fcnotifyresponse.CustomerEmail = GetFormVariableOrNull(Request.Form["customer"]);
fcnotifyresponse.Status = GetFormVariableOrNull(Request.Form["status"]);
fcnotifyresponse.TxnPartnerRef = GetFormVariableOrNull(Request.Form["txn_partner_ref"]);
fcnotifyresponse.PartnerMessage = GetFormVariableOrNull(Request.Form["partner_message"]);
fcnotifyresponse.StatusMsg = GetFormVariableOrNull(Request.Form["status_msg"]);
/// validation of posted input form values from flocash before storing to the merchant system DB
string datatovalidate = string.Empty;
/// store all the posted variables to an array
if (Request.Form.Count > 0)
{
System.Collections.Specialized.NameValueCollection coll;
//Load Form variables into NameValueCollection variable.
coll = Request.Form;
// Get names of all form's variable into a string array.
String[] arryofname = coll.AllKeys;
datatovalidate = "cmd=notify-validate&";// set the initial value, it is mandate to send for validation
for (int i = 0; i < arryofname.Length; i++)
{
datatovalidate += coll.Keys[i] + "=" + coll[coll.Keys[i]] + "&";
}
/// remove the last character
datatovalidate = datatovalidate.Remove(datatovalidate.LastIndexOf("&"));
}
string serverreponse = null;
if (FCValidatepost.ValidateResponse(datatovalidate,out serverreponse))
{
/// you can validate any other form variables if you want to customize more
/// you can store the values in DB
/// write the logic to store the data in a DB
/// left for the developers
/// If VERIFIED, then FloCash Gateway confirmed that your previous post was valid. Now we proceed to verify rest of transaction data
/// check that merchant_email is your Primary FloCash email
/// check the payment_status is Completed
/// From here, you can be sure that payment has been successful and you can do additional check such as
/// check that txn_id has not been previously processed
/// check that payment_amount/payment_currency are correct
/// then process payment
}
else
{
/// write a logic to handle if validation is not success
/// the logic to handle error can be written
}
}
protected string GetFormVariableOrNull(object formvariable)
{
if (formvariable != null)
{
try
{
return formvariable.ToString();
}
catch (Exception ex)
{
/// log the exception in file or DB
Console.WriteLine(ex.Message);/// just for an example
return null;
}
}
else
return null;
}
}
}
FCResponse.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Flocash.Ecom.Web.UI
{
public class FCResponse
{
private string tranid = string.Empty;
public string TransactionID
{
get { return tranid; }
set { tranid = value; }
}
private string tranno = string.Empty;
public string TransactionNumber
{
get { return tranno; }
set { tranno = value; }
}
private string merchantemail = string.Empty;
public string MerchantEmail
{
get { return merchantemail; }
set { merchantemail = value; }
}
private string itemprice = string.Empty;
public string ItemPrice
{
get { return itemprice; }
set { itemprice = value; }
}
private string senderaccount = string.Empty;
public string SenderAccount
{
get { return senderaccount; }
set { senderaccount = value; }
}
private string returnurl = string.Empty;
public string ReturnURL
{
get { return returnurl; }
set { returnurl = value; }
}
private string orderid = string.Empty;
public string OrderID
{
get { return orderid; }
set { orderid = value; }
}
private string itemname = string.Empty;
public string ItemName
{
get { return itemname; }
set { itemname = value; }
}
private string currencycode = string.Empty;
public string CurrencyCode
{
get { return currencycode; }
set { currencycode = value; }
}
private string quantity = string.Empty;
public string Quantity
{
get { return quantity; }
set { quantity = value; }
}
private string amount = string.Empty;
public string Amount
{
get { return amount; }
set { amount = value; }
}
private string payeremail = string.Empty;
public string PayerEmail
{
get { return payeremail; }
set { payeremail = value; }
}
private string paymentchannel = string.Empty;
public string PaymentChannel
{
get { return paymentchannel; }
set { paymentchannel = value; }
}
private string custom = string.Empty;
public string Custom
{
get { return custom; }
set { custom = value; }
}
private string customeremail = string.Empty;
public string CustomerEmail
{
get { return customeremail; }
set { customeremail = value; }
}
private string status = string.Empty;
public string Status
{
get { return status; }
set { status = value; }
}
private string txnpartnerref = string.Empty;
public string TxnPartnerRef
{
get { return txnpartnerref; }
set { txnpartnerref = value; }
}
private string partnermessage = string.Empty;
public string PartnerMessage
{
get { return partnermessage; }
set { partnermessage = value; }
}
private string statusmsg = string.Empty;
public string StatusMsg
{
get { return statusmsg; }
set { statusmsg = value; }
}
}
}
FCValidatepost.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.IO;
using System.Net;
using System.Text;
using System.Web.Security;
namespace Flocash.Ecom.Web.UI
{
public static class FCValidatepost
{
private static string flocashvalidateurl = "http://sandbox.flocash.com/validateNotify.do"; /// it can be configured in web.config
private static bool isvalidate = false;
// private static string responsefromserver = string.Empty;
/// <summary>
/// To validate the notification sent from flocash
/// </summary>
/// <param name="postdata"></param>
/// <returns></returns>
public static bool ValidateResponse(string postdata,out string serverrespone)
{
Stream requestStream = null;
StreamReader reader = null;
HttpWebResponse response = null;
serverrespone = null;
try
{
// Create a request using a URL that can receive a post.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(flocashvalidateurl);
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] postBytes = Encoding.UTF8.GetBytes(postdata);
request.ContentLength = postBytes.Length;
requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
// Get the response.
response = (HttpWebResponse)request.GetResponse();
requestStream = response.GetResponseStream();
reader = new StreamReader(requestStream);
serverrespone = reader.ReadToEnd();
if (response.StatusCode == HttpStatusCode.OK && serverrespone.Equals("VERIFIED",StringComparison.OrdinalIgnoreCase))
{
isvalidate = true;
}
// Clean up the streams.
reader.Close();
requestStream.Close();
response.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);/// just sample
/// catch the excpetion and log it to a file or a db
}
return isvalidate;
}
}
}
Cancel/Decline/Success Pages¶
Flocash redirects your buyer back to your site at the end of the payment process. The return URL will depend on whether the transaction was successfully completed, declined or cancelled. Below is a sample result page which serves for success or decline payment.
Result.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Result.aspx.cs" Inherits="Flocash.Ecom.Web.UI.Success" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% if (Request.QueryString["Status"] == "0000")
{%>
Thank you for the purchase.Your order has been processed successfully.
<%}
else
{%>
Your payment has been declined , please conatct support team..
<%} %>
</div>
</form>
</body>
</html>
This page will be called in case a customer cancel his payment.
Cancel.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Cancel.aspx.cs" Inherits="Flocash.Ecom.Web.UI.Cancel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Your purchased has been cancelled. If you want to compelte your purchase , checkout again!
</div>
</form>
</body>
</html>