/// <summary>
        /// Loops the form request and pushes the data into the request, if preset.
        /// </summary>
        static void SerializeForm(IGatewayRequest request, NameValueCollection collection)
        {
            var api = new ApiFields();

            foreach (string item in collection.Keys)
            {
                //always send the keys to the API - this allows for Merchant Custom Keys
                request.Queue(item, collection[item]);
            }
        }
Exemple #2
0
        private void buttonAuthorize_Click(object sender, EventArgs e)
        {
            //pull from the store

            //build the request from the Form post
            //var apiRequest = CheckoutFormReaders.BuildAuthAndCaptureFromPost();
            //validate the request first

            NameValueCollection post = new NameValueCollection();
            var apiRequest           = new AuthorizationRequest(post);

            var api = new ApiFields();

            foreach (string item in post.Keys)
            {
                //always send the keys to the API - this allows for Merchant Custom Keys
                apiRequest.Queue(item, post[item]);
            }

            //set the amount - you can also set this from the page itself
            //you have to have a field named "x_amount"
            apiRequest.Queue(ApiFields.Amount, "1.23");
            //You can set your solution ID here.
            apiRequest.SolutionID = "AAA100302";

            //send to Auth.NET
            var response = gate.Send(apiRequest);

            string authCode;
            string transactionID;
            string orderMessage;

            if (response.Approved)
            {
                authCode      = response.AuthorizationCode;
                transactionID = response.TransactionID;
                orderMessage  = string.Format("Thank you! Order approved: {0}", response.AuthorizationCode);
            }
            else
            {
                //error... oops. Reload the page
                orderMessage = response.Message;
            }
        }
Exemple #3
0
//		public void Authorize()
//		{
//			//pull from the store
//			AuthorizeNetCommon authnetCommon = new AuthorizeNetCommon();
//			var gate = authnetCommon.OpenGateway();

//			//build the request from the Form post
//			//var apiRequest = CheckoutFormReaders.BuildAuthAndCaptureFromPost();
//			//validate the request first

//			NameValueCollection post = new NameValueCollection();
//			var apiRequest = new AuthorizationRequest(post);

//			var api = new ApiFields();
//			foreach (string item in post.Keys)
//			{

//				//always send the keys to the API - this allows for Merchant Custom Keys
//				apiRequest.Queue(item, post[item]);
//			}

//			//set the amount - you can also set this from the page itself
//			//you have to have a field named "x_amount"
//			apiRequest.Queue(ApiFields.Amount, "1.23");
//			//You can set your solution ID here.
//			apiRequest.SolutionID = "AAA100302";

//			//send to Auth.NET
//			var response = gate.Send(apiRequest);

//			// Example from Randy (from PushDataCustomer)
//			//apiResponse = apiRequest.Request;
//			//transaction.SetFieldValue("Response", apiResponse.GetFieldValue("Response"), true);

//			string authCode;
//			string transactionID;
//			string orderMessage;
//			if (response.Approved)
//			{
//				authCode = response.AuthorizationCode;
////				transaction.SetFieldValue("AuthCode",
//				transactionID = response.TransactionID;
//				orderMessage = string.Format("Thank you! Order approved: {0}", response.AuthorizationCode);
//			}
//			else
//			{
//				//error... oops. Reload the page
//				orderMessage = response.Message;
//			}
//		}

        /// <summary>
        /// Updates/Inserts the customer record
        /// </summary>
        /// <param name="transaction">The transaction being processed.</param>
        private void CreateEntry(Realisable.Data.Transform.Transaction transaction)
        {
            // A mock call to whatever API.
            // Essentially get an object so the values of the dataset can be set to it.
            AuthorizeNetCommon authnetCommon = new AuthorizeNetCommon();

            try
            {
                //pull from the store
                var gate = authnetCommon.OpenGateway();

                //build the request from the Form post
                //var apiRequest = CheckoutFormReaders.BuildAuthAndCaptureFromPost();
                //validate the request first

                NameValueCollection post = new NameValueCollection();
                var apiRequest           = new AuthorizationRequest(post);

                var api = new ApiFields();
                foreach (string item in post.Keys)
                {
                    //always send the keys to the API - this allows for Merchant Custom Keys
                    apiRequest.Queue(item, post[item]);
                }
                apiRequest.Queue(ApiFields.Amount, transaction.GetValue("Amount").ToString());
                apiRequest.Queue(ApiFields.SolutionID, transaction.GetValue("SolutionID").ToString());
                //set the amount - you can also set this from the page itself
                //you have to have a field named "x_amount"
                //				apiRequest.Queue(ApiFields.Amount, "1.23");
                //You can set your solution ID here.
                //apiRequest.SolutionID = "AAA100302";


                //send to Auth.NET
                var response = gate.Send(apiRequest);

                // Example from Randy (from PushDataCustomer)
                //apiResponse = apiRequest.Request;
                transaction.SetFieldValue("ResponseCode", response.ResponseCode, true);
                transaction.SetFieldValue("Approved", response.Approved, true);
                transaction.SetFieldValue("Message", response.Message, true);

                if (response.Approved)
                {
                    transaction.SetFieldValue("TransactionID", response.TransactionID, true);
                    transaction.SetFieldValue("AuthorizationCode", response.AuthorizationCode, true);
                }
                else
                {
                    //error... oops. Reload the page
                    throw new Exception(response.Message);
                }

                // Now update the AuditController
                _wrapper.AuditController.OnInsert(_transformId, transaction);
            }
            catch (Exception ex)
            {
                string errorText = string.Format("Error while processing {0} record.", ENTITY_DESC);

                // There's an error based on the error action.
                switch (_errAction)
                {
                // If the error action is set to Abort: Log the error and re-raise the exception.
                case eTransformErrorAction.eTransformErrorActionAbort:
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will be discarded.", errorText));
                    throw;

                // If the error action is set to Continue: CHAOS mode.
                // Try to save/update again and see what happens.
                // An exception will probably be generated, causing the transform to terminate unexpectedly.
                case eTransformErrorAction.eTransformErrorActionContinue:
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will attempt to re-save.", errorText));
                    //customer.Update();

                    _wrapper.AuditController.OnInsert(_transformId, transaction);

                    break;

                // If the error action is Reject Record: Log the error and no update will occur.
                // Exit the method gracefully so the next record can be processed.
                case eTransformErrorAction.eTransformErrorActionRejectRecord:
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will be discarded.", errorText));

                    break;
                }
            }
        }