コード例 #1
0
        /// <summary>
        /// https://developer.paypal.com/docs/api/#create-a-payment
        /// </summary>
        /// <param name="payment"></param>
        /// <returns></returns>
        public PayPal <Payment> Create(Payment payment)
        {
            PayPal <Payment> paypal = new PayPal <Payment>();

            try
            {
                PaymentRepository paymentRepository = new PaymentRepository();

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    payment = DEBUG_Create();
                }

                paypal.Object = paymentRepository.Create(payment);

                return(paypal);
            }
            catch (PayPal.HttpException he)
            {
                //{"name":"INVALID_RESOURCE_ID","message":"The requested resource ID was not found","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID","debug_id":"e035690ac842e"}
                if (he.Response.Contains("INVALID_RESOURCE_ID"))
                {
                    paypal.Validations.Add("paymentCode", "Invalid ID");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(paypal);
        }
コード例 #2
0
        public Payment AddPayment(int indication, Payment payment)
        {
            PaymentUtil Util = new PaymentService();

            if (indication == 0)
            {
                throw new BadRequestException("Indicação é null");
            }

            payment.IndicationId = indication;

            Indication indicationCanPay = _indicationService.GetById(indication);

            if (Util.ObjectIsNull(indicationCanPay))
            {
                throw new NotFoundException("Nenhum indicação encontrada");
            }
            else if (!indicationCanPay.Status.Equals(IndicationStatus.SUCCESS))
            {
                throw new BadRequestException("Esta indicação não tem status pra ser paga!");
            }

            //string imageURI = null;

            //if (file != null)
            //{
            //    using (var stream = file.OpenReadStream())
            //    {
            //        imageURI = await UploadToBlob(file.FileName, null, stream);
            //    }
            //}

            //if (imageURI != null)
            //{
            //    payment.ImageURIOne = imageURI;
            //}

            try
            {
                _repository.Create(payment);
            }
            catch (Exception e)
            {
                throw new Exception($"Algo deu errado {e}");
            }

            return(payment);
        }
コード例 #3
0
        public IHttpActionResult Post(PaymentDto paymentDto)
        {
            AdvertisementRepository adRepo = new AdvertisementRepository();
            var     Id      = adRepo.GetId(paymentDto.Name);
            Payment payment = new Payment
            {
                AdvertisementId = Id,
                Amount          = paymentDto.Amount,
                PaymentDate     = paymentDto.PaymentDate
            };

            try
            {
                repo.Create(payment);
                return(Ok());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
コード例 #4
0
        public IHttpActionResult CreatePayments(PaymentDto newPaymentDto)
        {
            if (newPaymentDto.SavingsAccountId <= 0)
            {
                return(BadRequest("Savings Account is not available"));
            }
            else if (newPaymentDto.Amount <= 0)
            {
                return(BadRequest("Amount must be greater than zero"));
            }
            var newPayment = new Payment
            {
                SavingAccountId = newPaymentDto.SavingsAccountId,
                Amount          = newPaymentDto.Amount
            };

            using (var repository = new PaymentRepository())
            {
                repository.Create(newPayment);
            }

            return(Ok());
        }
コード例 #5
0
        public OperationResult SavePayment(PatientLoginInfo patientLoginInfo, PaymentCreationParameters paymentCreationParameters, int?managementUserId)
        {
            if (patientLoginInfo == null)
            {
                throw new ArgumentNullException(nameof(patientLoginInfo));
            }
            if (paymentCreationParameters == null)
            {
                throw new ArgumentNullException(nameof(paymentCreationParameters));
            }
            ValidatePaymentCreationParameters(paymentCreationParameters);

            try
            {
                //save payment data locally
                var paymentDb = PaymentRepository.Create();
                Mapper.ToPayment(paymentCreationParameters, paymentDb);
                paymentDb.Active           = true;
                paymentDb.LoginId          = patientLoginInfo.ID;
                paymentDb.ManagementUserId = managementUserId;
                PaymentRepository.Insert(paymentDb);

                //create the customer in stripe
                var r = PaymentGateway.Customer(patientLoginInfo.ID, patientLoginInfo.FirstName + " " + patientLoginInfo.LastName, patientLoginInfo.Email);
                if (r["error"] != null)
                {
                    throw new Exception(r.error.message.ToString());
                }

                //create the card in stripe
                var c = PaymentGateway.CreateCard(patientLoginInfo.ID, paymentCreationParameters.CardHolder, paymentCreationParameters.CardNumber, paymentCreationParameters.CardExpiryMonth, paymentCreationParameters.CardExpiryYear, paymentCreationParameters.CardSecurityCode);
                if (c["error"] != null)
                {
                    throw new Exception(r.error.message.ToString());
                }

                //save cc data locally
                var card = CreditCardRepository.Create();
                Mapper.ToCreditCard(paymentCreationParameters, card);
                card.LoginId       = patientLoginInfo.ID;
                card.GatewayType   = PaymentGateway.GetId();
                card.GatewayCardId = c["id"];
                card.CardType      = c["brand"];
                CreditCardRepository.Insert(card);

                //update payment with cc data
                paymentDb.CreditCardId = card.Id;
                PaymentRepository.Save(paymentDb);

                if (paymentCreationParameters.PaymentType == PaymentType.recurring)
                {
                    //create instance of a recurring payment
                    var start = paymentCreationParameters.RecurringDateStart.Value;
                    var end   = paymentCreationParameters.RecurringDateEnd.Value;
                    var dates = DatesGenerator.GetDates(start, end, paymentCreationParameters.RecurringFrequency.Value).Select((m, i) => new { date = m, index = i });
                    if (dates.Count() == 0)
                    {
                        throw new InvalidOperationException("No payments to schedule.");
                    }
                    var schedules = new List <PaymentSchedule>();
                    foreach (var d in dates)
                    {
                        var schedule = PaymentScheduleRepository.Create();
                        schedule.PaymentId      = paymentDb.Id;
                        schedule.ScheduledDate  = d.date;
                        schedule.ScheduleNumber = d.index + 1;
                        schedules.Add(schedule);
                    }
                    PaymentScheduleRepository.Insert(schedules);
                }
                else
                {
                    if (paymentCreationParameters.OneTimePaymentDate.Value.Date == DateTime.Today)
                    {
                        //charge to cc since this is a onetime payment scheduled for today
                        var chargeParameters = new PaymentChargeParameters
                        {
                            Description   = "One Time Charge -  Payment Id " + paymentDb.Id.ToString("D5"),
                            Amount        = paymentCreationParameters.Amount,
                            CustomerId    = patientLoginInfo.ID,
                            GatewayCardId = card.GatewayCardId,
                            PaymentId     = paymentDb.Id,
                            CardId        = card.Id,
                            ReferenceType = "Payment",
                            ReferenceId   = paymentDb.Id
                        };
                        return(Charge(chargeParameters));
                    }
                    else
                    {
                        var schedule = PaymentScheduleRepository.Create();
                        schedule.PaymentId      = paymentDb.Id;
                        schedule.ScheduledDate  = paymentCreationParameters.OneTimePaymentDate.Value.Date;
                        schedule.ScheduleNumber = 1;
                        PaymentScheduleRepository.Insert(schedule);
                    }
                }
            }
            catch (Exception e)
            {
                return(new OperationResult {
                    Success = false, Message = e.Message
                });
            }
            return(new OperationResult {
                Success = true
            });
        }