Beispiel #1
0
        public int?CreatePaymentForBankAccountErrorRefund(StripeRefund refund)
        {
            if (refund.Data[0].BalanceTransaction == null || !"payment_failure_refund".Equals(refund.Data[0].BalanceTransaction.Type))
            {
                _logger.Error($"Balance transaction was not set, or was not a payment_failure_refund for refund ID {refund.Data[0].Id}");
                return(null);
            }

            if (string.IsNullOrWhiteSpace(refund.Data[0].Charge?.Id))
            {
                _logger.Error($"No associated Charge for Refund {refund.Data[0].Id}");
                return(null);
            }

            MpPayment payment;

            try
            {
                payment = _paymentRepository.GetPaymentByTransactionCode(refund.Data[0].Charge.Id);
            }
            catch (PaymentNotFoundException)
            {
                _logger.Error($"No Payment with payment processor ID {refund.Data[0].Charge.Id} in MP for Refund {refund.Data[0].Id}");
                return(null);
            }
            _paymentRepository.UpdatePaymentStatus(payment.PaymentId, (int)DonationStatus.Declined);  // update the original payment to declined
            var paymentReverse = new MpPayment
            {
                InvoiceNumber      = payment.InvoiceNumber,
                PaymentDate        = DateTime.Now,
                PaymentStatus      = (int)DonationStatus.Declined,
                ContactId          = _bankErrorRefundContactId,
                ProcessorFeeAmount = refund.Data[0].BalanceTransaction.Fee / Constants.StripeDecimalConversionValue,
                Notes           = $"Reversed from PaymentID {payment.PaymentId}",
                PaymentTypeId   = payment.PaymentTypeId,
                TransactionCode = refund.Data[0].Id,
                PaymentTotal    = -(int.Parse(refund.Data[0].Amount) / Constants.StripeDecimalConversionValue),
                BatchId         = payment.BatchId
            };

            var invoicedetail = _invoiceRepository.GetInvoiceDetailForInvoice(Convert.ToInt32(payment.InvoiceNumber));

            var detail = new MpPaymentDetail
            {
                PaymentAmount   = -(int.Parse(refund.Data[0].Amount) / Constants.StripeDecimalConversionValue),
                InvoiceDetailId = invoicedetail.InvoiceDetailId,
                Payment         = paymentReverse,
                CongregationId  = _contactRepository.GetContactById(invoicedetail.RecipientContactId).Congregation_ID ?? _configWrapper.GetConfigIntValue("Congregation_Default_ID")
            };

            return(_paymentRepository.CreatePaymentAndDetail(detail).Value.PaymentId);
        }
Beispiel #2
0
        private static MpPaymentDetail FakePaymentInfo()
        {
            var payment = new MpPayment
            {
                PaymentTotal  = 123.45M,
                ContactId     = 3717387,
                PaymentDate   = DateTime.Now,
                PaymentTypeId = 11
            };

            var paymentDetail = new MpPaymentDetail
            {
                Payment         = payment,
                PaymentAmount   = 123.45M,
                InvoiceDetailId = 19
            };

            return(paymentDetail);
        }
Beispiel #3
0
        public void ShouldCreateARecord()
        {
            var payment = new MpPayment
            {
                PaymentTotal  = 123.45M,
                ContactId     = 3717387,
                PaymentDate   = DateTime.Now,
                PaymentTypeId = 11
            };

            var paymentDetail = new MpPaymentDetail
            {
                Payment         = payment,
                PaymentAmount   = 123.45M,
                InvoiceDetailId = 19
            };
            var resp = _fixture.UsingAuthenticationToken(_authToken).Post(new List <MpPaymentDetail> {
                paymentDetail
            });
        }
Beispiel #4
0
        public MpPaymentDetailReturn PostPayment(MpDonationAndDistributionRecord paymentRecord)
        {
            //check if invoice exists
            if (!_invoiceRepository.InvoiceExists(paymentRecord.InvoiceId))
            {
                throw new InvoiceNotFoundException(paymentRecord.InvoiceId);
            }

            //check if contact exists
            if (_contactRepository.GetContactById(paymentRecord.ContactId) == null)
            {
                throw new ContactNotFoundException(paymentRecord.ContactId);
            }

            if (paymentRecord.ProcessorId.Length > 50)
            {
                throw new Exception("Max length of 50 exceeded for transaction code");
            }

            var pymtId = PaymentType.GetPaymentType(paymentRecord.PymtType).id;
            var fee    = paymentRecord.FeeAmt.HasValue ? paymentRecord.FeeAmt / Constants.StripeDecimalConversionValue : null;

            //check if payment type exists
            if (!_paymentTypeRepository.PaymentTypeExists(pymtId))
            {
                throw new PaymentTypeNotFoundException(pymtId);
            }

            //create payment -- send model
            var payment = new MpPayment
            {
                InvoiceNumber      = paymentRecord.InvoiceId.ToString(),
                ContactId          = paymentRecord.ContactId,
                TransactionCode    = paymentRecord.ProcessorId,
                PaymentDate        = DateTime.Now,
                PaymentTotal       = paymentRecord.DonationAmt,
                PaymentTypeId      = pymtId,
                PaymentStatus      = _defaultPaymentStatus,
                ProcessorFeeAmount = fee
            };
            var paymentDetail = new MpPaymentDetail
            {
                Payment         = payment,
                PaymentAmount   = paymentRecord.DonationAmt,
                InvoiceDetailId = _invoiceRepository.GetInvoiceDetailForInvoice(paymentRecord.InvoiceId).InvoiceDetailId
            };

            var result = _paymentRepository.CreatePaymentAndDetail(paymentDetail);

            if (result.Status)
            {
                //update invoice payment status
                var invoice  = _invoiceRepository.GetInvoice(paymentRecord.InvoiceId);
                var payments = _paymentRepository.GetPaymentsForInvoice(paymentRecord.InvoiceId);
                payments = payments.Where(p => p.PaymentStatus != _declinedPaymentStatus).ToList();
                var paymentTotal = payments.Sum(p => p.PaymentTotal);

                _invoiceRepository.SetInvoiceStatus(paymentRecord.InvoiceId, paymentTotal >= invoice.InvoiceTotal ? _paidinfullStatus : _somepaidStatus);
                return(result.Value);
            }
            else
            {
                throw new Exception("Unable to save payment data");
            }
        }