I thought to share my work experience of Cybersource payment gateway integration. I have developed the project through asp.net(C#). Below I'll show way of integration process step by step.
Cybersource have different integration methods . Among those , I have used “SCMP API” method for integration process.
As a first step, user need to create Merchant account through this URL.(Cybersource Register URL)
After that user need to crate testing account . Once you created testing account you can log in to that account through this URL.(Login Screen).
After that you need to generate certificate as below screens. Site will ask to save 3 type of files. Save those files in a secure place.Later these certificates are used to call payment gateway through our site.
Step 1
Site will give 3 types of file formats as below.
Now let come for developing part.
I have used html page like below to gather user information and credit card information.
Complete code is below for sending credit card details to Cybersource payment gateway. (payment.aspx.cs)
private void Authorize()
{
try
{
// create request object
ICSRequest request = new ICSRequest();
request["ics_applications"] = "ics_auth,ics_bill";//ics_auth, ics_bill, and ics_credit,ics_score
request["merchant_ref_number"] = ShopperDetails.ClientCode;
request["customer_firstname"] = ShopperDetails.FirstName;
request["customer_lastname"] = ShopperDetails.LastName; ;
request["customer_email"] = ShopperDetails.Email;
request["customer_phone"] = ShopperDetails.Phone;
request["bill_address1"] = ShopperDetails.Address1;
request["bill_city"] = ShopperDetails.City;
request["bill_state"] = ShopperDetails.State;
request["bill_zip"] = ShopperDetails.Zip;
request["bill_country"] = ShopperDetails.Country;
request["customer_cc_number"] = CreditCardDetails.Number;
request["customer_cc_expmo"] = CreditCardDetails.ExpMonth;
request["customer_cc_expyr"] = CreditCardDetails.ExpYear;
// add an offer for each item in the shopping cart
ICSOffer offer;
int i = 0;
foreach (Item item in shoppingCartCollection)
{
offer = new ICSOffer();
offer["product_name"] = item.InvoiceNo;
offer["amount"] = item.UnitPrice.ToString();
offer["quantity"] = "1";
offer["product_code"] = item.ItemName;
offer["merchant_product_sku"] = item.InvoiceNo;
request.SetOffer(i++, offer);
}
request["currency"] = "AUD";
// select client and send request
string configFile = Server.MapPath(OrganizationDetails.CyberSourceAccountDetailPath);
ICSClient client = new ICSClient(configFile);
mReply = client.Send(request);
//// extract needed information from mReply. A couple of reply fields
//// are extracted below for example.
string requestId = mReply["request_id"];
string authCode = mReply["auth_auth_code"];
HandleReply();
}
catch (BugException e)
{
divMsg.Attributes.Add("class", "error_massage");
lblMsg.Text = e.Message;
divMsg.Visible = true;
}
private void HandleReply()
{
string rFlag = mReply["ics_rflag"];
string rMsg = mReply["ics_rmsg"];
if (rFlag.Equals("SOK"))
{
divMsg.Attributes.Add("class", "success_massage");
lblMsg.Text = rMsg;
divMsg.Visible = true;
SendEmailToAdmin();
SendEmailToClient();
ClearForm();
}
else {
divMsg.Attributes.Add("class", "error_massage");
lblMsg.Text = rMsg;
divMsg.Visible = true;
}
}
Some important details
If you want to debit payment amount automatically to merchant account’s bank ,then you can set below values.
request["ics_applications"] = "ics_auth,ics_bill";//ics_auth, ics_bill,
If you want to debit the amount manually, then you can set below values. Manually means, site administrator has to login to Cybersource account and each transaction is processed one by one through that account.
request["ics_applications"] = "ics_auth ";//ics_auth, ics_bill,
According to below code I set Cybersource account details in a xml file.
string configFile =Server.MapPath(OrganizationDetails.CyberSourceAccountDetailPath );
ICSClient client = new ICSClient(configFile);
mReply = client.Send(request);
Config file consists the setting of payment gateway. In </KeysDir> tag ,I have set the location path of above generated 3 files (CyberSource_SJC_US.crt,/.crt,*.pvt) which we have generated form Cybersource account.
If you want to test live environment, please change this tag as below
<ServerHost>ics2.ic3.com</ServerHost>
Config file tags (configuration.xml)
<?xml version="1.0"?>
<ICSClientConfig>
<MerchantId>Dumithu</MerchantId>
<ServerHost>ics2test.ic3.com</ServerHost>
<ServerPort>80</ServerPort>
<ServerId>CyberSource_SJC_US</ServerId>
<KeysDir>E:\inetpub\wwwroot\w3svc1369\Keys\Dumithu</KeysDir>
<Timeout>90</Timeout>
<RetryEnabled>no</RetryEnabled>
<RetryStart>30</RetryStart>
<LogLevel>LOG_NONE</LogLevel>
<LogFile>\icstest.log</LogFile>
<LogMaxSize>1</LogMaxSize>
<ThrowLogException>no</ThrowLogException>
<!-- Optional Proxy Information
<HTTPProxyURL>your_proxy_server_url_here</HTTPProxyURL>
<HTTPProxyUsername>username_here</HTTPProxyUsername>
<HTTPProxyPassword>password_here</HTTPProxyPassword>
-->
</ICSClientConfig>
After that you need to generate certificate as below screens. Site will ask to save 3 type of files. Save those files in a secure place.Later these certificates are used to call payment gateway through our site.
Step 1
Step 2
Step 3
I have used html page like below to gather user information and credit card information.
Complete code is below for sending credit card details to Cybersource payment gateway. (payment.aspx.cs)
private void Authorize()
{
try
{
// create request object
ICSRequest request = new ICSRequest();
request["ics_applications"] = "ics_auth,ics_bill";//ics_auth, ics_bill, and ics_credit,ics_score
request["merchant_ref_number"] = ShopperDetails.ClientCode;
request["customer_firstname"] = ShopperDetails.FirstName;
request["customer_lastname"] = ShopperDetails.LastName; ;
request["customer_email"] = ShopperDetails.Email;
request["customer_phone"] = ShopperDetails.Phone;
request["bill_address1"] = ShopperDetails.Address1;
request["bill_city"] = ShopperDetails.City;
request["bill_state"] = ShopperDetails.State;
request["bill_zip"] = ShopperDetails.Zip;
request["bill_country"] = ShopperDetails.Country;
request["customer_cc_number"] = CreditCardDetails.Number;
request["customer_cc_expmo"] = CreditCardDetails.ExpMonth;
request["customer_cc_expyr"] = CreditCardDetails.ExpYear;
// add an offer for each item in the shopping cart
ICSOffer offer;
int i = 0;
foreach (Item item in shoppingCartCollection)
{
offer = new ICSOffer();
offer["product_name"] = item.InvoiceNo;
offer["amount"] = item.UnitPrice.ToString();
offer["quantity"] = "1";
offer["product_code"] = item.ItemName;
offer["merchant_product_sku"] = item.InvoiceNo;
request.SetOffer(i++, offer);
}
request["currency"] = "AUD";
// select client and send request
string configFile = Server.MapPath(OrganizationDetails.CyberSourceAccountDetailPath);
ICSClient client = new ICSClient(configFile);
mReply = client.Send(request);
//// extract needed information from mReply. A couple of reply fields
//// are extracted below for example.
string requestId = mReply["request_id"];
string authCode = mReply["auth_auth_code"];
HandleReply();
}
catch (BugException e)
{
divMsg.Attributes.Add("class", "error_massage");
lblMsg.Text = e.Message;
divMsg.Visible = true;
}
private void HandleReply()
{
string rFlag = mReply["ics_rflag"];
string rMsg = mReply["ics_rmsg"];
if (rFlag.Equals("SOK"))
{
divMsg.Attributes.Add("class", "success_massage");
lblMsg.Text = rMsg;
divMsg.Visible = true;
SendEmailToAdmin();
SendEmailToClient();
ClearForm();
}
else {
divMsg.Attributes.Add("class", "error_massage");
lblMsg.Text = rMsg;
divMsg.Visible = true;
}
}
Some important details
If you want to debit payment amount automatically to merchant account’s bank ,then you can set below values.
request["ics_applications"] = "ics_auth,ics_bill";//ics_auth, ics_bill,
If you want to debit the amount manually, then you can set below values. Manually means, site administrator has to login to Cybersource account and each transaction is processed one by one through that account.
request["ics_applications"] = "ics_auth ";//ics_auth, ics_bill,
According to below code I set Cybersource account details in a xml file.
string configFile =Server.MapPath(OrganizationDetails.CyberSourceAccountDetailPath );
ICSClient client = new ICSClient(configFile);
mReply = client.Send(request);
Config file consists the setting of payment gateway. In </KeysDir> tag ,I have set the location path of above generated 3 files (CyberSource_SJC_US.crt,/.crt,*.pvt) which we have generated form Cybersource account.
If you want to test live environment, please change this tag as below
<ServerHost>ics2.ic3.com</ServerHost>
Config file tags (configuration.xml)
<?xml version="1.0"?>
<ICSClientConfig>
<MerchantId>Dumithu</MerchantId>
<ServerHost>ics2test.ic3.com</ServerHost>
<ServerPort>80</ServerPort>
<ServerId>CyberSource_SJC_US</ServerId>
<KeysDir>E:\inetpub\wwwroot\w3svc1369\Keys\Dumithu</KeysDir>
<Timeout>90</Timeout>
<RetryEnabled>no</RetryEnabled>
<RetryStart>30</RetryStart>
<LogLevel>LOG_NONE</LogLevel>
<LogFile>\icstest.log</LogFile>
<LogMaxSize>1</LogMaxSize>
<ThrowLogException>no</ThrowLogException>
<!-- Optional Proxy Information
<HTTPProxyURL>your_proxy_server_url_here</HTTPProxyURL>
<HTTPProxyUsername>username_here</HTTPProxyUsername>
<HTTPProxyPassword>password_here</HTTPProxyPassword>
-->
</ICSClientConfig>
Each transaction can be checked (whether it is error or not) through Cybersource account.
I hope this post might help you to integrate the Cybersource payment gateway with your site. :)
Sources
Integration methods
Account create
Login
Another important factor in selecting a Global Payments Provider is how much they cost. Find out what they charge in startup or initial fees, recurring monthly charges, and ask about any hidden fees you may encounter in the future.
ReplyDelete