internal void UpdateExistingTransaction(RecurringPaymentOutput response)
 {
     if (Transaction != null && response != null)
     {
         UpdateTransactionFromPaymentResponse(Transaction, response);
         Transaction.SyncDate = null;
     }
 }
        private void UpdateTransactionFromPaymentResponse(Transaction transaction, RecurringPaymentOutput paymentResponse)
        {
            transaction.LastFailedRetry       = paymentResponse.LastFailedRetry;
            transaction.NextFailedRetry       = paymentResponse.NextFailedRetry;
            transaction.CurrentRetry          = paymentResponse.CurrentRetry;
            transaction.InvoiceIdentifier     = paymentResponse.InvoiceIdentifier;
            transaction.TransactionIdentifier = paymentResponse.TransactionIdentifier;
            transaction.TransactionResult     = paymentResponse.TransactionResult;
            transaction.TransactionNumber     = paymentResponse.TransactionNumber;
            transaction.TransactionFraudCode  = paymentResponse.TransactionFraudCode;
            transaction.StatusCode            = paymentResponse.IsSuccessful ? StatusCode.Completed : StatusCode.Failed;

            Response = new Response
            {
                CreatedOn       = DateTime.Now,
                Result          = paymentResponse.TransactionResult,
                Identifier      = paymentResponse.TransactionIdentifier,
                PaymentSchedule = PaymentSchedule,
                Transaction     = transaction,
                StateCode       = 0,
                StatusCode      = StatusCode.Active,
                SyncDate        = ShouldSyncResponse ? default(DateTime?) : DateTime.Now
            };
        }
        internal Transaction CreateNewTransaction(RecurringPaymentOutput paymentResponse)
        {
            var transaction = new Transaction
            {
                Amount = PaymentSchedule.RecurringAmount,
                TransactionCurrencyId      = TransactionCurrencyId,
                TransactionPaymentSchedule = PaymentSchedule,
                TransactionPaymentMethodId = PaymentMethodId,
                PaymentProcessorId         = PaymentProcessorId,
                ConfigurationId            = ConfigurationId,
                DesignationId        = PaymentSchedule.DesignationId,
                MembershipId         = PaymentSchedule.MembershipCategoryId,
                MembershipInstanceId = PaymentSchedule.MembershipId,
                Event     = null,
                StateCode = 0,
            };

            transaction.AppealId = PaymentSchedule.AppealId;
            transaction.OriginatingCampaignId  = PaymentSchedule.OriginatingCampaignId;
            transaction.ConstituentId          = PaymentSchedule.ConstituentId;
            transaction.CustomerId             = PaymentSchedule.CustomerId;
            transaction.CustomerIdType         = PaymentSchedule.CustomerIdType;
            transaction.GiftBatchId            = PaymentSchedule.GiftBatchId;
            transaction.PackageId              = PaymentSchedule.PackageId;
            transaction.TaxReceiptId           = PaymentSchedule.TaxReceiptId;
            transaction.TributeId              = PaymentSchedule.TributeId;
            transaction.TransactionBatchId     = PaymentSchedule.TransactionBatchId;
            transaction.AmountReceipted        = PaymentSchedule.AmountReceipted;
            transaction.AmountMembership       = PaymentSchedule.AmountMembership;
            transaction.AmountNonReceiptable   = PaymentSchedule.AmountNonReceiptable;
            transaction.AmountTax              = PaymentSchedule.AmountTax;
            transaction.Anonymous              = PaymentSchedule.Anonymity;
            transaction.Appraiser              = PaymentSchedule.Appraiser;
            transaction.BillingCity            = PaymentSchedule.BillingCity;
            transaction.BillingCountry         = PaymentSchedule.BillingCountry;
            transaction.BillingLine1           = PaymentSchedule.BillingLine1;
            transaction.BillingLine2           = PaymentSchedule.BillingLine2;
            transaction.BillingLine3           = PaymentSchedule.BillingLine3;
            transaction.BillingPostalCode      = PaymentSchedule.BillingPostalCode;
            transaction.BillingStateorProvince = PaymentSchedule.BillingStateorProvince;
            transaction.CcBrandCode            = PaymentSchedule.CcBrandCode;
            transaction.ChargeonCreate         = PaymentSchedule.ChargeonCreate;
            transaction.BookDate              = PaymentSchedule.BookDate;
            transaction.DepositDate           = PaymentSchedule.DepositDate;
            transaction.GaDeliveryCode        = PaymentSchedule.GaDeliveryCode;
            transaction.ReceiptPreferenceCode = PaymentSchedule.ReceiptPreferenceCode;
            transaction.DataEntrySource       = PaymentSchedule.DataEntrySource;
            transaction.DataEntryReference    = PaymentSchedule.DataEntryReference;
            transaction.FirstName             = PaymentSchedule.FirstName;
            transaction.LastName              = PaymentSchedule.LastName;
            transaction.Name                   = PaymentSchedule.Name;
            transaction.OrganizationName       = PaymentSchedule.OrganizationName;
            transaction.Telephone1             = PaymentSchedule.Telephone1;
            transaction.Telephone2             = PaymentSchedule.Telephone2;
            transaction.MobilePhone            = PaymentSchedule.MobilePhone;
            transaction.Emailaddress1          = PaymentSchedule.EmailAddress1;
            transaction.InvoiceIdentifier      = PaymentSchedule.InvoiceIdentifier;
            transaction.PaymentTypeCode        = PaymentSchedule.PaymentTypeCode;
            transaction.TransactionDescription = PaymentSchedule.TransactionDescription;
            transaction.TransactionFraudCode   = PaymentSchedule.TransactionFraudCode;
            transaction.TransactionIdentifier  = PaymentSchedule.TransactionIdentifier;
            transaction.TransactionResult      = PaymentSchedule.TransactionResult;
            transaction.TributeCode            = PaymentSchedule.TributeCode;
            transaction.TributeAcknowledgement = PaymentSchedule.TributeAcknowledgement;
            transaction.TributeMessage         = PaymentSchedule.TributeMessage;
            transaction.Response               = new Collection <Response>();

            UpdateTransactionFromPaymentResponse(transaction, paymentResponse);

            var now = DateTime.Now;

            transaction.DepositDate = now;
            transaction.BookDate    = now;
            transaction.CreatedOn   = now;
            transaction.SyncDate    = null;

            return(transaction);
        }