コード例 #1
0
ファイル: PaymentService.cs プロジェクト: tczhd/DoraApf
        public PaymentResultModel DoPayment(PaymentModel paymentModel)
        {
            var result = new PaymentResultModel();

            try
            {
                var createDate = DateTime.UtcNow;

                var billingInfo = new BillingInfo()
                {
                    FirstName  = paymentModel.FirstName,
                    Email      = paymentModel.Email,
                    CreatedOn  = createDate,
                    Country    = paymentModel.Country,
                    Active     = false,
                    Address1   = paymentModel.Address1,
                    Address2   = paymentModel.Address2,
                    City       = paymentModel.City,
                    LastName   = paymentModel.LastName,
                    Phone      = paymentModel.Phone,
                    PostalCode = paymentModel.PostalCode,
                    State      = paymentModel.State,
                    Title      = paymentModel.Title,
                    Payment    = new List <Payment> {
                    }
                };

                var payment = new Payment
                {
                    Active         = false,
                    TransactionId  = string.Empty,
                    AuthCode       = string.Empty,
                    AmountPaid     = decimal.Parse(paymentModel.PaymentAmount),
                    CardHolderName = paymentModel.CardHolderName,
                    CardF4L4       = paymentModel.CardNumber.Substring(0, 4) + paymentModel.CardNumber.Substring(paymentModel.CardNumber.Length - 4, 4),
                    CurrencyId     = (int)Currency.CAD,
                    PaymentDate    = createDate,
                    PaymentType    = (int)PaymentType.Purchase
                };

                billingInfo.Payment.Add(payment);

                var data = _billingRepository.Add(billingInfo);

                var request = new HelcimBasicRequestModel()
                {
                    OrderNumber = "Dora-" + DateTime.Now.ToString("yyyyMMddhhmmss"),
                    Amount      = decimal.Parse(paymentModel.PaymentAmount),
                    CreditCard  = new HelcimCreditCardRequestModel()
                    {
                        CardHolderName       = paymentModel.CardHolderName,
                        CardNumber           = paymentModel.CardNumber,
                        CardExpiry           = paymentModel.CardExpiry,
                        CardCVV              = paymentModel.CardCVV,
                        CardHolderAddress    = paymentModel.Address1,
                        CardHolderPostalCode = paymentModel.PostalCode
                    }
                };

                result = (PaymentResultModel)_helcimPaymentService.ProcessPayment(request);

                if (result.Success && result.Approved)
                {
                    billingInfo.Active    = true;
                    payment.Active        = true;
                    payment.TransactionId = result.TransactionId;
                    payment.AuthCode      = result.AuthCode;

                    _billingRepository.Update(billingInfo);

                    result.PaymentId = payment.Id;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }
コード例 #2
0
        public PaymentResultModel ApplyPayment(PaymentDataModel requestMdoel)
        {
            var result = new PaymentResultModel();

            var userContext = _userHandler.GetUserContext();
            var invoiceDetailSpecification = new InvoiceSpecification(_clinicId);

            invoiceDetailSpecification.AddInvoiceId(requestMdoel.InvoiceId);
            var invoice = _invoiceRepository.GetSingleBySpec(invoiceDetailSpecification);

            if (invoice != null)
            {
                var payementResult = _stripePaymentService.ProcessPayment((StripeBasicRequestModel)requestMdoel);
                result = payementResult;
                var cardLast4 = requestMdoel.CreditCard.GetCardF4L4();
                result.CardLast4 = cardLast4;

                if (payementResult.Success && payementResult.Approved)
                {
                    var payment = new Payment
                    {
                        ClinicId            = _clinicId,
                        Description         = requestMdoel.Note,
                        PaymentDate         = DateTime.UtcNow,
                        PaymentMethodTypeId = (int)PaymentMethodType.Visa,
                        PaymentStatusTypeId = (int)requestMdoel.PaymentStatusType,
                        PaymentTypeId       = (int)requestMdoel.PaymentType,
                        UpdatedBy           = userContext.SiteUserId,
                        UpdatedDateUtc      = DateTime.UtcNow,
                        Amount            = requestMdoel.PaymentAmount,
                        TransactionId     = payementResult.TransactionId,
                        AuthorizationCode = payementResult.AuthCode,
                        CardToken         = payementResult.CardToken,
                        CardF4L4          = cardLast4
                    };

                    var invoicePayment = new InvoicePayment
                    {
                        AmountPaid = requestMdoel.PaymentAmount,
                        InvoiceId  = requestMdoel.InvoiceId,
                        Payment    = payment,
                        Note       = requestMdoel.Note
                    };

                    _invoicePaymentRepository.AddOnly(invoicePayment);

                    var patientCardOnFile = new PatientCardOnFile {
                        Active         = true,
                        CardF4L4       = requestMdoel.CreditCard.GetCardF4L4(),
                        CardToken      = payementResult.CardToken,
                        UpdatedDateUtc = DateTime.UtcNow,
                        PatientId      = invoice.PatientId,
                        UpdatedBy      = userContext.SiteUserId
                    };

                    _patientCardOnFileRepository.AddOnly(patientCardOnFile);

                    invoice.AmountPaid += requestMdoel.PaymentAmount;

                    _invoicePaymentRepository.SaveAll();

                    result.AmountPaidTotal = invoice.AmountPaid;
                }
                else
                {
                    result.Message = "Process payment failed. ";
                }
            }
            else
            {
                result.Message = "Invalid invoice Id, Please choose right one and try again. ";
            }

            return(result);
        }