예제 #1
0
        public async Task <OrderModel> PayAsync(PaymentModel model)
        {
            StripeConfiguration.ApiKey = _key;

            var card = new CreditCardOptions
            {
                Number   = model.CardNumber,
                ExpMonth = model.Month,
                ExpYear  = model.Year,
                Cvc      = model.CVC
            };

            var optionsToken = new TokenCreateOptions
            {
                Card = card
            };

            var serviceToken = new Stripe.TokenService();
            var stripeToken  = await serviceToken.CreateAsync(optionsToken);


            var options = new ChargeCreateOptions
            {
                Amount      = model.Value * Constants.Numbers.CONVERT_TO_PRICE,
                Currency    = CurrencyType.USD.ToString(),
                Description = model.Description,
                Source      = stripeToken.Id
            };


            var service = new ChargeService();
            var charge  = await service.CreateAsync(options);


            var payment = await _orderRepository.GetPaymentByOrderIdAsync(model.OrderId);

            payment.TransactionId = charge.Id;

            await _paymentRepository.UpdateAsync(payment);

            var order = await _orderRepository.GetOrderByIdAsync(model.OrderId);

            order.Description = model.Description;
            order.Status      = StatusType.Paid;

            await _orderRepository.UpdateAsync(order);

            if (!charge.Paid)
            {
                throw new ServerException(Constants.Success.UNPAID_ORDER);
            }

            var orderModel = _mapper.Map <OrderModel>(order);

            return(orderModel);
        }
예제 #2
0
        public async Task <dynamic> PayAsync(string cardNumber, int month, int year, string cvc, long value)
        {
            try
            {
                var optionsToken = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number   = cardNumber,
                        ExpMonth = month,
                        ExpYear  = year,
                        Cvc      = cvc
                    }
                };

                var   serviceToken = new Stripe.TokenService();
                Token stripeToken  = await serviceToken.CreateAsync(optionsToken);

                var option = new ChargeCreateOptions
                {
                    Amount      = value,
                    Currency    = "eur",
                    Description = "droga",
                    Source      = stripeToken.Id
                };

                var    service = new ChargeService();
                Charge charge  = await service.CreateAsync(option);

                if (charge.Paid)
                {
                    return("Success");
                }
                else
                {
                    return("Failed");
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
예제 #3
0
        private async Task <Charge> MakePayment2(PaymentInputModel payModel)
        {
            try
            {
                StripeConfiguration.ApiKey = this.SecretKey;; // "pk_test_51HiQuVAFZv6rpRFk3K1JeutsplKLBU7nFnti3wi6xZ6YW7sHUPJl433JQF4K9kSO0VsxX3edkIgrJrrbdzFPSGdt00a6LlFJ7W";
                var optionsToken = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number   = payModel.cardNumber,
                        ExpMonth = payModel.month,
                        ExpYear  = payModel.year,
                        Cvc      = payModel.cvc
                    },
                };


                var   serviceToken = new Stripe.TokenService();
                Token stripeToken  = await serviceToken.CreateAsync(optionsToken);

                var options = new ChargeCreateOptions
                {
                    Amount      = GetFormattedAmount((long)payModel.value),
                    Currency    = "USD",
                    Description = $"Payment taken by Moo-In at {payModel.RestaurantName}",
                    Source      = stripeToken.Id,
                    Metadata    = new Dictionary <string, string>
                    {
                        { "OrderId", payModel.Order.rec_id.ToString() },
                    },
                    ApplicationFeeAmount = GetShareAmount(payModel.value)
                };
                var    service = new ChargeService();
                Charge charge  = await service.CreateAsync(options, new RequestOptions { StripeAccount = payModel.StripeAccountId });

                return(charge);
            }
            catch (Exception e)
            {
                throw;
            }
        }
예제 #4
0
        private async Task <string> CreateStripeClient(string email, string name, string cardNumber, int month, int year, string cvv)
        {
            var optionstoken = new TokenCreateOptions
            {
                Card = new TokenCardOptions
                {
                    Number   = cardNumber,
                    ExpMonth = month,
                    ExpYear  = year,
                    Cvc      = cvv
                }
            };

            var   servicetoken = new Stripe.TokenService();
            Token stripetoken  = await servicetoken.CreateAsync(optionstoken);

            var customer = new CustomerCreateOptions
            {
                Email  = email,
                Name   = name,
                Source = stripetoken.Id,
            };

            Console.WriteLine(" stripetoken attributes :" + stripetoken);

            var services = new CustomerService();
            var created  = services.Create(customer);


            var option = new PaymentMethodCreateOptions
            {
                Type = "card",
                Card = new PaymentMethodCardOptions
                {
                    Number   = cardNumber,
                    ExpMonth = month,
                    ExpYear  = year,
                    Cvc      = cvv,
                },
            };

            var service = new PaymentMethodService();
            var result  = service.Create(option);

            Console.WriteLine(" PaymentMethodService attributes :" + result);

            var options = new PaymentMethodAttachOptions
            {
                Customer = created.Id,
            };
            var method = new PaymentMethodService();

            method.Attach(
                result.Id,
                options
                );

            if (created.Id == null)
            {
                return("Failed");
            }
            else
            {
                return(created.Id);
            }
        }
예제 #5
0
        public async Task <IActionResult> ProcessingAsync()
        {
            PayModel paymodel     = getPayModel();
            var      tokenoptions = new TokenCreateOptions
            {
                Card = new TokenCardOptions
                {
                    AddressLine1 = paymodel.AddressLine1,
                    AddressLine2 = paymodel.AddressLine2,
                    AddressCity  = paymodel.AddressCity,
                    AddressState = paymodel.AddressState,
                    AddressZip   = paymodel.AddressZip,
                    Name         = paymodel.Name,
                    Number       = paymodel.CardNumder,
                    ExpMonth     = paymodel.ExpMonth,
                    ExpYear      = paymodel.ExpYear,
                    Cvc          = paymodel.CVC
                },
            };

            var   serviceToken = new Stripe.TokenService();
            Token stripeToken  = await serviceToken.CreateAsync(tokenoptions);


            paymodel.OrderName        = "OrderName";
            paymodel.OrderDescription = "OrderDescription";
            paymodel.StripeToken      = stripeToken.Id;
            var Metadata = new Dictionary <string, string>
            {
                { "Name", paymodel.OrderName },
                { "Price", paymodel.Amount.ToString() },
                { "Description", paymodel.OrderDescription }
            };


            var chargeOptions = new ChargeCreateOptions
            {
                Amount       = paymodel.Amount,
                Currency     = "USD",
                Description  = $"Buying {paymodel.OrderName} {paymodel.OrderDescription}",
                Source       = new AnyOf <string, CardCreateNestedOptions>(paymodel.StripeToken),
                ReceiptEmail = paymodel.Email,
                Metadata     = Metadata
            };
            var    chargeService = new ChargeService();
            Charge charge        = chargeService.Create(chargeOptions);

            //foreach (var product in model.Products)
            //{
            //    ProductModel correctProduct = await _productsService.RetrieveAsync(product.Id);
            //    if (correctProduct != product)
            //    {
            //        throw new CustomServerException("invalid order data");
            //    }


            //    product.Id = default(int);
            //    await CreateOrderAsync(product);

            //    var transaction = new TransactionModel { Currency = charge.Currency, Amount = charge.Amount, Status = charge.Status, Created = charge.Created, Description = charge.Description, Object = charge.Object, SourceId = charge.Source.Id };
            //    await _transactionsService.CreateAsync(transaction);
            //}
            var response = await Task.FromResult(charge);

            return(Ok(response));
        }