RSS

Category Archives: payment gateway

Processing a refund on a card present transaction in Authorized.Net

Below is a source code to do refund for card reader present transactions in asp.net:

System.Collections.Specialized.NameValueCollection objPayInf = new System.Collections.Specialized.NameValueCollection(30);

objPayInf.Add(“x_cpversion”, “1.0”);
objPayInf.Add(“x_login”, “7G6Ux97Sqyst”);
objPayInf.Add(“x_amount”, “10.00”);
objPayInf.Add(“x_tran_key”, “76kf798S7RtqEyxQ”);
objPayInf.Add(“x_delim_data”, “TRUE”);
objPayInf.Add(“x_delim_char”, “|”);
objPayInf.Add(“x_relay_response”, “FALSE”);
objPayInf.Add(“x_response_format”, “1”);
objPayInf.Add(“x_test_request”, “FALSE”);
objPayInf.Add(“x_type”, “CREDIT”);
objPayInf.Add(“x_card_num”, “1111”); // Last for digits of credit card number
objPayInf.Add(“x_ref_trans_id”, “123456789”); // Transaction-ID of original settled transaction

// Call the webservice and pass the above given parameters
WebClient objRequest = new WebClient();
byte[] objRetBytes = null;
string[] objRetVals = null;
objRequest.BaseAddress = “https://cardpresent.authorize.net/gateway/transact.dll”;
objRetBytes = objRequest.UploadValues(objRequest.BaseAddress, “POST”, objPayInf);
objRetVals = System.Text.Encoding.ASCII.GetString(objRetBytes).Split(“|”.ToCharArray());

Enjoy. Happy Programming!!!

 
Leave a comment

Posted by on July 19, 2011 in payment gateway

 

Tags: , , , , ,

Card present transactions / Credit Card Swiping in ASP.NET

There are two types of transactions for credit card processing.

1. Card Present Transactions (Credit Card Reader required).

2. Card does not present transactions.

Following are the steps to achieve Card Present transactions using Authorized.Net

1. Purchase a credit card reader. Open the authorized.net merchant account with card present option. Once the account will be created then it will give you the LOGIN ID and TRANSACTION KEY which you need to pass as a parameters in the web service.

2. By swiping the credit card in card reader it will return following text and automatically press enter than after.
%B12345678912345678^DAVE/NISHANT ^14011234026132600000?;12345678912345678=14011234026132600000?
3.  You have to pass following parameters to the web service.

objPayInf.Add(“x_cpversion”, “1.0”);
objPayInf.Add(“x_login”, “YourLoginID”);
objPayInf.Add(“x_amount”, Amount.ToString());
objPayInf.Add(“x_tran_key”, “YourTransactionKey”);
objPayInf.Add(“x_first_name”, oFirstName.ToString());
objPayInf.Add(“x_last_name”, oLastName.ToString());
objPayInf.Add(“x_delim_data”, “TRUE”);
objPayInf.Add(“x_delim_char”, mDelimChar.ToString());
objPayInf.Add(“x_relay_response”, “FALSE”);
objPayInf.Add(“x_response_format”, “1”);
objPayInf.Add(“x_test_request”, TRUE);
objPayInf.Add(“x_type”, “AUTH_CAPTURE”);

objPayInf.Add(“x_currency_code”, “USD”);

objPayInf.Add(“x_market_type”, “2”);

objPayInf.Add(“x_device_type”, “8”);

// You need to parse the string return by the card reader and pass it to the web service using following way.
objPayInf.Add(“x_track2”, “12345678912345678=14011234026132600000“);

4). The web service base URL should be the following:
https://cardpresent.authorize.net/gateway/transact.dll
5). You can get more information by visiting following link:

http://www.authorize.net/support/CP_guide.pdf

Happy Programming!!!!!!!!.

 
Leave a comment

Posted by on March 22, 2010 in payment gateway

 

Tags: , , , , , , ,

Authorized.Net payment gateway implementation

Copy paste following code to implement payment gateway using c#.net:

 String post_url = “https://test.authorize.net/gateway/transact.dll“;

            Hashtable post_values = new Hashtable();

            //the API Login ID and Transaction Key must be replaced with valid values
            post_values.Add(“x_login”, “6zz6m5N4Et”);
            post_values.Add(“x_tran_key”, “9V9wUv6Yd92t27t5”);

            post_values.Add(“x_delim_data”, “TRUE”);
            post_values.Add(“x_delim_char”, ‘|’);
            post_values.Add(“x_relay_response”, “FALSE”);

            post_values.Add(“x_type”, “AUTH_CAPTURE”);
            post_values.Add(“x_method”, “CC”);
            post_values.Add(“x_card_num”, “378282246310005”);
            post_values.Add(“x_exp_date”, “0809”);

            post_values.Add(“x_amount”, “99999.00”);
            post_values.Add(“x_description”, “Sample Transaction”);

            post_values.Add(“x_first_name”, “John”);
            post_values.Add(“x_last_name”, “Doe”);
            post_values.Add(“x_address”, “1234 Street”);
            post_values.Add(“x_state”, “WA”);
            post_values.Add(“x_zip”, “98004”);
            // Additional fields can be added here as outlined in the AIM integration
            // guide at: http://developer.authorize.net

            // This section takes the input fields and converts them to the proper format
            // for an http post.  For example: “x_login=username&x_tran_key=a1B2c3D4”
            String post_string = “”;
            foreach(DictionaryEntry field in post_values)
            {
                post_string += field.Key + “=” + field.Value + “&”;
            }
            post_string = post_string.TrimEnd(‘&’);
           
            // create an HttpWebRequest object to communicate with Authorize.net
            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(post_url);
            objRequest.Method = “POST”;
            objRequest.ContentLength = post_string.Length;
            objRequest.ContentType = “application/x-www-form-urlencoded”;

            // post data is sent as a stream
            StreamWriter myWriter  = null;
            myWriter = new StreamWriter(objRequest.GetRequestStream());
            myWriter.Write(post_string);
            myWriter.Close();

            // returned values are returned as a stream, then read into a string
            String post_response;
            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()) )
            {
                post_response = responseStream.ReadToEnd();
                responseStream.Close();
            }

            // the response string is broken into an array
            // The split character specified here must match the delimiting character specified above
            Array response_array = post_response.Split(‘|’);

            // the results are output to the screen in the form of an html numbered list.
            resultSpan.InnerHtml += “<OL> \n”;
            foreach (string value in response_array)
            {
                resultSpan.InnerHtml += “<LI>” + value + “&nbsp;</LI> \n”;
            }
            resultSpan.InnerHtml += “</OL> \n”;
            // individual elements of the array could be accessed to read certain response
            // fields.  For example, response_array[0] would return the Response Code,
            // response_array[2] would return the Response Reason Code.
            // for a list of response fields, please review the AIM Implementation Guide

 

 

Happy programming!.

 
Leave a comment

Posted by on September 4, 2009 in payment gateway

 

Tags: , , ,

Payment Gateway implementation using PayPal

You can use paypal API to pay the amount from your website. There is no need to redirect to paypal site for the same.

prerequisite:

1. The paypal test account is required to test the code.

2. Capicom dll is required

3. Log4net dll is required

4. paypal_base dll is required

Copy past following code in to the CS file:

/*
 * Copyright 2005, 2008 PayPal, Inc. All Rights Reserved.
 *
 * DoDirectPayment SOAP example; last modified 08MAY23.
 *
 * Process a credit card payment. 
 */
using System;
using com.paypal.sdk.services;
using com.paypal.soap.api;
using com.paypal.sdk.profiles;
using System.Configuration;
/**
 * PayPal .NET SDK sample code
 */
namespace GenerateCodeSOAP
{
 public class DoDirectPayment
 {
  public DoDirectPayment()
  {
  }
  public string DoDirectPaymentCode(string paymentAmount, string buyerLastName, string buyerFirstName, string buyerAddress1, string buyerAddress2, string buyerCity, string buyerState, string buyerZipCode, string creditCardType, string creditCardNumber, string CVV2, int expMonth, int expYear, PaymentActionCodeType paymentAction)
  {
   CallerServices caller = new CallerServices();

   IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
   /*
    WARNING: Do not embed plaintext credentials in your application code.
    Doing so is insecure and against best practices.
    Your API credentials must be handled securely. Please consider
    encrypting them for use in any production environment, and ensure
    that only authorized individuals may view or modify them.
    */

              // Set up your API credentials, PayPal end point, and API version.
              profile.APIUsername = “sdk-three_api1.sdk.com”;
              profile.APIPassword = “QFZCWN5HZM8VBG7Q”;
              profile.APISignature = “A.d9eRKfd1yVkRrtmMfCFLTqa6M9AyodL0SJkhYztxUi8W9pCXF6.4NI”;

          

          
   profile.Environment=”sandbox”;           
   caller.APIProfile = profile;
   // Create the request object.
   DoDirectPaymentRequestType pp_Request = new DoDirectPaymentRequestType();
   pp_Request.Version=”3.0″;
           

   // Add request-specific fields to the request.
   // Create the request details object.
   pp_Request.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();

              pp_Request.DoDirectPaymentRequestDetails.IPAddress = “127.0.0.1”;
   /*pp_Request.DoDirectPaymentRequestDetails.MerchantSessionId = “1X911810264059026”;*/
   pp_Request.DoDirectPaymentRequestDetails.PaymentAction = paymentAction;
   
   pp_Request.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType();
   
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = creditCardNumber; 
           
   switch (creditCardType)
   {
    case “Visa”:
     pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Visa;
     break;
    case “MasterCard”:
     pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.MasterCard;
     break;
    case “Discover”:
     pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Discover;
     break;
    case “Amex”:
     pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Amex;
     break;
   }
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CVV2 = CVV2;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = expMonth;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpYear = expYear;
   
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType();
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Payer = “”;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerID = “”;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerStatus = PayPalUserStatusCodeType.unverified;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerCountry = CountryCodeType.US;

   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = new AddressType();
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 = buyerAddress1;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2 = buyerAddress2;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = buyerCity;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince= buyerState;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = buyerZipCode;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountryName = “USA”;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = CountryCodeType.US;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = true;
  
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType();
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = buyerFirstName;
   pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = buyerLastName;
   pp_Request.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();
   pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();
   // NOTE: The only currency supported by the Direct Payment API at this time is US dollars (USD).

   pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD;
   pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = paymentAmount;

              // Execute the API operation and obtain the response.
   DoDirectPaymentResponseType pp_response =new DoDirectPaymentResponseType();
   pp_response= (DoDirectPaymentResponseType) caller.Call(“DoDirectPayment”, pp_Request);
   return pp_response.Ack.ToString();
  }
 }
}

 
Leave a comment

Posted by on September 4, 2009 in payment gateway

 

Tags: , , , ,