Friday, February 26, 2010

authorized.net complete

after including previous four classes call this function on button click




private void DoPayment()
{
AuthorizeNetRequest objAuthorizeNetRequest = new AuthorizeNetRequest();

// This is the account information for merchant account given by Authorize.Net people in email
// I can see transaction history here.

objAuthorizeNetRequest.Login = LOGINID;
objAuthorizeNetRequest.Amount = Convert.ToDouble(txtAmount.Text);
objAuthorizeNetRequest.CardNumber = txtCreditCardNo.Text;
objAuthorizeNetRequest.CardExpirationDate = drpExpirationDate.SelectedValue + drpYear.SelectedValue.Substring(2);

objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.AUTH_CAPTURE;

///transaction types
///default is auth capture


//objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.AUTH_ONLY;
//objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.CREDIT;
//objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.VOID;

///we can use other types but will have to provide transaction id if we are going to
///PRIOR_AUTH_CAPTURE type as this will capture prior authorized transaction.

//objAuthorizeNetRequest.TransactionId = "";
//objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.PRIOR_AUTH_CAPTURE;

objAuthorizeNetRequest.CcvNumber = txtCCV.Text;

// Below is the API created by me by registering for test account.
objAuthorizeNetRequest.TransactionKey = TRANSACTION_KEY;
AuthorizeNetFields allFields = new AuthorizeNetFields();

allFields.x_First_Name = txtCardName.Text;
allFields.x_Address = "";
allFields.x_City = "";
allFields.x_State = "";
allFields.x_Country = "U.S.A";
allFields.x_Phone = "";
allFields.x_Zip = "";
allFields.x_Tax = "";
allFields.x_Email = "";
allFields.x_Description = "";

allFields.x_Ship_to_first_name = txtCardName.Text;
allFields.x_Ship_to_address = "";
allFields.x_Ship_to_city = "";
allFields.x_Ship_to_state = "";
allFields.x_Ship_to_country = "U.S.A";
allFields.x_Ship_to_phone = "";
allFields.x_Ship_to_zip = "";

AuthorizeNetResponse objAuthorizeNetResponse = AuthorizeNet.CallAuthorizeNetMethod(objAuthorizeNetRequest, allFields);
if (objAuthorizeNetResponse.IsSuccess)
{
Response.Write(objAuthorizeNetResponse.SuccessMessage +" ID:"+ objAuthorizeNetResponse.TransactionId);
}
else
{
Response.Write("Error : " + objAuthorizeNetResponse.Errors);
}
}

No comments:

Post a Comment