Exemple #1
0
 /// <summary>
 /// Caches any values/fields to be used during processing.
 /// </summary>
 /// <param name="transaction">The transaction object.</param>
 private void CacheTransactionFields(Realisable.Data.Transform.Transaction transaction)
 {
     // Cache the fields to be used later on.
     _tranHasReferenceFld = transaction.HasField("Reference");
 }
        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();
                }
            }
        }