Beispiel #1
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;
                }
            }
        }
        private void CreateEntry(Realisable.Data.Transform.Transaction transaction)
        {
            ApplicationObject auth = ApplicationObject.Create();

            try
            {
                if (TransactionHasStatusUpdateFields(transaction))
                {
                    string ApiLoginID        = _client._APILoginKey;
                    string ApiTransactionKey = _client._ApiTransactionKey;
                    bool   sandbox           = _client._Sandbox;

                    string  _transactionAmount = transaction.GetValue("TransactionAmount").ToString();
                    decimal transactionAmount  = 0.00M;
                    if (!decimal.TryParse(_transactionAmount, out transactionAmount))
                    {
                        throw new Exception(string.Format("Unable to parse transaction amount [{0}]", _transactionAmount));
                    }

                    string TransactionID = transaction.GetValue("TransactionID").ToString();

                    Capture response = Client.Capture(ApiLoginID, ApiTransactionKey, transactionAmount, TransactionID, sandbox);

                    if (response != null)
                    {
                        TraceWriter.Write("Authorize.Net capture response:\n" + response.ToTraceOutput());
                        if (transaction.HasField(nameof(Capture.ResponseCode)))
                        {
                            transaction.SetFieldValue(nameof(Capture.ResponseCode), response.ResponseCode, true);
                        }
                        if (transaction.HasField(nameof(Capture.MessageCode)))
                        {
                            transaction.SetFieldValue(nameof(Capture.MessageCode), response.MessageCode, true);
                        }
                        if (transaction.HasField(nameof(Capture.Description)))
                        {
                            transaction.SetFieldValue(nameof(Capture.Description), response.Description, true);
                        }
                        if (transaction.HasField(nameof(Capture.AuthCode)))
                        {
                            transaction.SetFieldValue(nameof(Capture.AuthCode), response.AuthCode, true);
                        }
                        if (transaction.HasField(nameof(Capture.ErrorCode)))
                        {
                            transaction.SetFieldValue(nameof(Capture.ErrorCode), response.ErrorCode, true);
                        }
                        if (transaction.HasField(nameof(Capture.CaptureErrorMessage)))
                        {
                            transaction.SetFieldValue(nameof(Capture.CaptureErrorMessage), response.CaptureErrorMessage, true);
                        }
                    }
                    else
                    {
                        TraceWriter.Write("Authorize.Net capture response is NULL.");
                    }

                    // Being a good citizen.
                    _auditController.OnUpdate(_transformId, transaction);
                }
                else
                {
                    throw new Exception("'Id' and 'OrderStatus' must both be set.");
                }

                _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));
                    //auth.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;
                }
            }
            finally
            {
                // Check the iterator is back at the header; move the parent if it is not.
                if (_iterator.Item().TransactionId != ENTITY)
                {
                    _iterator.MoveParent();
                }
            }
        }