public static StripeOutcome ChargeSource(string source, bool livemode, string client_secret, long id, string idType)
        {
            // Set your secret key: remember to change this to your live secret key in production
            // See your keys here: https://dashboard.stripe.com/account/apikeys
            StripeConfiguration.SetApiKey(MasterStrings.StripeSecretKey);

            var          service       = new StripeSourceService();
            StripeSource sourceService = service.Get(source);

            if (sourceService.Status == "chargeable")
            {
                var options = new StripeChargeCreateOptions
                {
                    Amount   = sourceService.Amount,
                    Currency = sourceService.Currency,
                    SourceTokenOrExistingSourceId = source,
                    Description = "Charge for Order Id " + id.ToString(),
                    Metadata    = new Dictionary <String, String>()
                    {
                        { idType, id.ToString() }
                    }
                };

                var serviceCharge = new StripeChargeService();

                try
                {
                    StripeCharge charge = serviceCharge.Create(options);

                    if (charge.Outcome.Reason == "approve_with_id" || charge.Outcome.Reason == "issuer_not_available" ||
                        charge.Outcome.Reason == "processing_error" || charge.Outcome.Reason == "reenter_transaction" ||
                        charge.Outcome.Reason == "try_again_later")
                    {
                        charge = serviceCharge.Create(options);
                    }

                    charge.Outcome.Id = charge.Id;
                    return(charge.Outcome);
                }
                catch (Exception ex)
                {
                    throw new StripeException(ex.Message);
                }
            }

            return(new StripeOutcome()
            {
                NetworkStatus = MasterStrings.StripeNotSent,
                SellerMessage = "Card not yet chargeable.",
                Type = "pending"
            });
        }
Пример #2
0
        public ActionResult Charge(string stripeEmail, string stripeToken /*Tenant tenant*/)
        {
            var user         = User.Identity.GetUserId();
            var loggedInUser = db.Tenants.Where(c => c.ApplicationUserId == user).Single();

            var cost      = loggedInUser.BalanceDue;
            var customers = new StripeCustomerService();
            var charges   = new StripeChargeService();

            var customer = customers.Create(new StripeCustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });

            var charge = charges.Create(new StripeChargeCreateOptions
            {
                Amount      = cost,//charge in cents
                Description = "Rent Charge",
                Currency    = "usd",
                CustomerId  = customer.Id
            });

            loggedInUser.BalanceDue -= 1875;
            return(RedirectToAction("Details"));
        }
Пример #3
0
        public ActionResult Charge(string stripeEmail, string stripeToken, int amount)
        {
            Information($"stripeEmail: {stripeEmail}, stripeToken: {stripeToken}, amount: {amount}");
            StripeConfiguration.SetApiKey(MyStripeSettings.SiteName);

            var customers = new StripeCustomerService();
            var charges   = new StripeChargeService();

            var customer = customers.Create(new StripeCustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });

            var charge = charges.Create(new StripeChargeCreateOptions
            {
                Amount      = amount,
                Description = "Sample Charge",
                Currency    = "usd",
                CustomerId  = customer.Id
            });

            //return View();

            Information($"Transaction completed");
            return(RedirectToAction("Index"));
        }
Пример #4
0
        //Collect single charge for coupon
        //public static bool Charge(string stripeToken, Offer offer)
        //{
        //    StripeConfiguration.SetApiKey(WebConfigurationManager.AppSettings["StripeSecretKey"]);

        //    var token = stripeToken;
        //    var loginUser = _context.Merchants.Include(c => c.User).FirstOrDefault(c => c.MerchantID == offer.MerchantID);
        //    //Create stripe customerID
        //    var customerId = CreateStripeCustomer(loginUser.User.Id, token);

        //    var option = new StripeChargeCreateOptions
        //    {
        //        Amount = Convert.ToInt32(offer.CouponPrice * 100),
        //        Currency = "usd",
        //        Description = "Veme",
        //        ReceiptEmail = loginUser.User.Email, // returns the email address
        //        //SourceTokenOrExistingSourceId = token,
        //        CustomerId = customerId
        //    };
        //    var service = new StripeChargeService();
        //    StripeCharge charge = service.Create(option);
        //    //if (charge.Paid)
        //    //return Json(new { charge.Paid});
        //    return charge.Paid;
        //}

        public async static Task <bool> Charge(string stripeToken, CouponValidationPackage package, string MerchantId)
        {
            StripeConfiguration.SetApiKey(WebConfigurationManager.AppSettings["StripeSecretKey"]);

            var token     = stripeToken;
            var loginUser = _context.Merchants.Include(c => c.User).FirstOrDefault(c => c.MerchantID == MerchantId);
            //Create stripe customerID
            //var customerId = CreateStripeCustomer(loginUser.User.Id, token);

            var option = new StripeChargeCreateOptions
            {
                Amount       = Convert.ToInt32(package.PackagePrice * 100),
                Currency     = "usd",
                Description  = "Veme - " + package.PackageName,
                ReceiptEmail = loginUser.User.Email, // returns the email address
                SourceTokenOrExistingSourceId = token,
                Capture = true,
            };
            var          service = new StripeChargeService();
            StripeCharge charge  = service.Create(option);

            //Assign Package to Merchant if charge successful
            if (charge.Paid)
            {
                await Payment.AssignPackage(package.Id, loginUser.MerchantID);
            }
            //return Json(new { charge.Paid});
            return(charge.Paid);
        }
Пример #5
0
        protected override bool HandleCore(Donate request)
        {
            var fundraiser = _fundraiserRepository.FindById(request.FundraiserId);
            var campaign   = _campaignRepository.FindById(fundraiser.CampaignId);

            if (request.DonationAmount > 0)
            {
                try
                {
                    var chargeService = new StripeChargeService();
                    var charge        = chargeService.Create(new StripeChargeCreateOptions()
                    {
                        Amount      = request.DonationAmount * 100,
                        Currency    = "usd",
                        Description = fundraiser.Name,
                        SourceTokenOrExistingSourceId = request.StripeToken
                    });
                    var donation = _donationRepository.Create(campaign, fundraiser, DonationStatus.Completed, request.DonationAmount, "usd", request.DonationAmount, request.UserId, request.DonorDisplayName, charge.Id);

                    var integrationEvent = new DonationCreatedIntegrationEvent(donation.DonorUserId,
                                                                               donation.FundraiserId, donation.Amount, donation.DonorDisplayName);

                    _eventBus.Publish(integrationEvent); // not tested; maybe IEventBus should be named something else since EasyNetQ already has an IEventBus; perhaps Publish(e) should be Publish<T>(e)?
                }
                catch (InvalidOperationException)
                {
                    return(false); // maybe should return json with validation info?
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public ActionResult CreateClient(string clientName, int numberOfMonths, string stripeEmail, string stripeToken)
        {
            var customers = new StripeCustomerService();
            var charges   = new StripeChargeService();

            var customer = customers.Create(new StripeCustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });

            var charge = charges.Create(new StripeChargeCreateOptions
            {
                Amount      = numberOfMonths * 389,
                Description = "Client creation",
                Currency    = "eur",
                CustomerId  = customer.Id
            });

            try
            {
                _clientManager.CreateNew(clientName, DateTime.UtcNow.AddMonths(numberOfMonths), _membership.CurrentUser.Id);
            }
            catch (BusinessException be)
            {
                ///TODO Log error.

                return(RedirectToAction("Index", "Error"));
            }

            return(RedirectToAction("Index", "Profile"));
        }
Пример #7
0
        private IHttpActionResult StripeCheckout(ChargeDtos charge)
        {
            try
            {
                var customer = _customers.Create(new StripeCustomerCreateOptions
                {
                    Email       = charge.Email,
                    SourceToken = charge.Token
                });

                var chargeOptions = new StripeChargeCreateOptions()
                {
                    Amount      = charge.Amount,
                    Currency    = "usd",
                    Description = "Charge for " + charge.Email ?? charge.Name,
                    CustomerId  = customer.Id,
                    SourceTokenOrExistingSourceId = charge.Token // obtained with Stripe.js
                };

                var stripeCharge = _charges.Create(chargeOptions);

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode(HttpStatusCode.InternalServerError));
            }
        }
        public bool StripePay(string orderId, string stripeToken, string email)
        {
            var applicationManager = DomainHub.GetDomain <IApplicationManager>();

            var order = applicationManager.GetOrder(orderId);

            var options = new StripeChargeCreateOptions
            {
                Amount   = (int)(order.Amount * 100),
                Currency = EUR,
                SourceTokenOrExistingSourceId = stripeToken
            };

            var service = new StripeChargeService();
            var charge  = service.Create(options);

            if (charge.Paid)
            {
                var payment = new DataAccess.Model.Storage.Payment
                {
                    PartitionKey = orderId,
                    ChargeId     = charge.Id,
                    RowKey       = charge.Id,
                    Time         = DateTime.Now,
                    Type         = Stripe,
                    Currency     = charge.Currency,
                    Amount       = ((double)charge.Amount) / 100,
                    Payer        = charge.Customer?.Email ?? email
                };

                PaymentTable.Insert(payment);
            }

            return(charge.Paid);
        }
Пример #9
0
        public async Task <Tuple <bool, string> > TryChargeUsingConnet(string customerId, string userId, int amount, string currency)
        {
            try
            {
                var applicationFeePercentage =
                    Convert.ToInt32(ConfigurationManager.AppSettings["ApplicationFeePercentage"]);
                var applicationFee      = (amount / 100) * applicationFeePercentage;
                var chargeCreateOptions = new StripeChargeCreateOptions
                {
                    CustomerId     = customerId,
                    Amount         = amount,
                    Currency       = currency,
                    Destination    = userId,
                    ApplicationFee = applicationFee
                };

                var chargeService = new StripeChargeService();

                chargeService.Create(chargeCreateOptions);
            }
            catch (Exception exception)
            {
                return(Tuple.Create(false, exception.Message));
            }
            return(Tuple.Create(true, "success!"));

            ;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                StripeCustomer current = GetCustomer();
                // int? days = getaTraildays();
                //if (days != null)
                //{
                int chargetotal = 500;//Convert.ToInt32((3.33*Convert.ToInt32(days)*100));
                var mycharge    = new StripeChargeCreateOptions();
                mycharge.Amount     = chargetotal;
                mycharge.Currency   = "USD";
                mycharge.CustomerId = current.Id;
                string       key           = "sk_test_5jzcBuYhyxAk08sB8mT7KL43";
                var          chargeservice = new StripeChargeService(key);
                StripeCharge currentcharge = chargeservice.Create(mycharge);
                error.Visible   = true;
                error.InnerText = "La transacción se realizo con éxito";
            }
            catch (StripeException ex)
            {
                error.Visible   = true;
                error.InnerText = ex.Message;
            }
            catch
            {
                error.Visible = true;

                error.InnerText = "Error en la transacción";
            }
            //}
        }
Пример #11
0
        protected bool chargeCard(string tokenId, int amount)
        {
            var pinzeyCharge = new StripeChargeCreateOptions();

            // always set these properties
            pinzeyCharge.Amount   = amount;
            pinzeyCharge.Currency = "usd";

            // set this if you want to
            pinzeyCharge.Description = "Charge it like it's hot";

            // setting up the card
            pinzeyCharge.Source = new StripeSourceOptions()
            {
                // set this property if using a token
                TokenId = tokenId
            };


            // set this if you have your own application fees (you must have your application configured first within Stripe)
            //myCharge.ApplicationFee = 25;

            // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
            //myCharge.Capture = true;

            var          chargeService = new StripeChargeService();
            StripeCharge stripeCharge  = chargeService.Create(pinzeyCharge);

            return(stripeCharge.Paid);
        }
Пример #12
0
        public ActionResult Charge(string stripeEmail, string stripeToken)
        {
            string    userId    = User.Identity.GetUserId();
            Customer  cust      = db.Customers.Where(u => u.UserId == userId).FirstOrDefault();
            ToDeliver Del       = db.ToDelivers.Where(i => i.CustomerId == cust.Id).FirstOrDefault();
            var       customers = new StripeCustomerService();
            var       charges   = new StripeChargeService();


            var customer = customers.Create(new StripeCustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });
            decimal amount = Del.OrderCost * 100;
            int     Total  = Decimal.ToInt32(amount);
            var     charge = charges.Create(new StripeChargeCreateOptions
            {
                Amount      = Total,
                Description = "Sample Charge",
                Currency    = "usd",
                CustomerId  = customer.Id
            });

            return(RedirectToAction("Index", "Home"));
        }
Пример #13
0
        public static bool Pay(string id, decimal amount, string token)
        {
            // See your keys here: https://dashboard.stripe.com/account/apikeys
            //StripeConfiguration.SetApiKey();

            // Charge the user's card:
            var charges = new StripeChargeService("sk_test_kgte8BanAYo8UxwTzojJjwDm");
            var charge  = charges.Create(new StripeChargeCreateOptions
            {
                Amount      = (int)(amount * 100),
                Currency    = "aud",
                Description = "Meerkat Charge",
                Metadata    = new Dictionary <String, String>()
                {
                    { "OrderId", id }
                },
                SourceTokenOrExistingSourceId = token
            });

            var r = charge.StripeResponse.ResponseJson;

            _log.Info($"Stripe: {r}");

            return(charge.Status == "succeeded");
        }
Пример #14
0
        public static bool Charge(Customer customer, CreditCard creditCard, decimal amount)
        {
            var chargeDetails = new StripeChargeCreateOptions();

            chargeDetails.Amount   = (int)amount * 100;
            chargeDetails.Currency = "usd";

            chargeDetails.Source = new StripeSourceOptions
            {
                Object          = "card",
                Number          = creditCard.CardNumber,
                ExpirationMonth = creditCard.ExpireyDate.Month.ToString(),
                ExpirationYear  = creditCard.ExpireyDate.Year.ToString(),
                Cvc             = creditCard.Cvc,
            };

            var chargeService = new StripeChargeService(StripeApiKey);
            var response      = chargeService.Create(chargeDetails);

            if (response.Paid == false)
            {
                throw new Exception(response.FailureMessage);
            }

            return(response.Paid);
        }
Пример #15
0
        public ActionResult Donate(DonateFormViewModel model)
        {
            var fundraiser = _fundraiserRepository.FindById(model.FundraiserId);
            var campaign   = _campaignRepository.FindById(fundraiser.CampaignId);

            if (model.DonationAmount > 0)
            {
                var chargeService = new StripeChargeService();
                var charge        = chargeService.Create(new StripeChargeCreateOptions()
                {
                    Amount      = model.DonationAmount * 100,
                    Currency    = "usd",
                    Description = fundraiser.Name,
                    SourceTokenOrExistingSourceId = model.StripeToken
                });
                string userid = null;
                if (User.Identity.IsAuthenticated)
                {
                    userid = User.Identity.GetUserId();
                }
                _donationRepository.Create(campaign, fundraiser, DonationStatus.Completed, model.DonationAmount, "usd", model.DonationAmount, userid, model.DonorDisplayName, charge.Id);
            }

            var fundraiserViewModel = AutoMapper.Mapper.Map <Fundraiser, FundraiserFormViewModel>(fundraiser);

            return(View("Thanks", fundraiserViewModel));
        }
Пример #16
0
        public ActionResult Index(FormCollection tokenString)
        {
            if (tokenString == null)
            {
                return(View("SecurePayment"));
            }

            else
            {
                try
                {
                    var myCharge = new StripeChargeCreateOptions();

                    // always set these properties
                    myCharge.Amount   = 120;
                    myCharge.Currency = "eur";

                    // set this if you want to
                    myCharge.Description = "Charge it like it's hot";

                    // setting up the card
                    myCharge.Source = new StripeSourceOptions()
                    {
                        // set this property if using a token
                        TokenId = tokenString[0],

                        // set these properties if passing full card details (do not
                        // set these properties if you set TokenId)
                        //Number = "4242424242424242",
                        //ExpirationYear = "2022",
                        //ExpirationMonth = "10",
                        //AddressCountry = "US",                // optional
                        //AddressLine1 = "24 Beef Flank St",    // optional
                        //AddressLine2 = "Apt 24",              // optional
                        //AddressCity = "Biggie Smalls",        // optional
                        //AddressState = "NC",                  // optional
                        //AddressZip = "27617",                 // optional
                        //Name = "Joe Meatballs",               // optional
                        //Cvc = "1223"                          // optional
                    };

                    // set this property if using a customer
                    //myCharge.CustomerId = *customerId*;

                    // set this if you have your own application fees (you must have your application configured first within Stripe)
                    //myCharge.ApplicationFee = 25;

                    // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
                    myCharge.Capture = true;

                    var          chargeService = new StripeChargeService();
                    StripeCharge stripeCharge  = chargeService.Create(myCharge);
                    return(View("PaymentSuccess"));
                }
                catch
                {
                    return(View("SecurePayment"));
                }
            }
        }
Пример #17
0
        public OrderDto ChargeOrder(string stripeToken, OrderDto orderDto)
        {
            Order order          = _orderDataProvider.GetOrderById(orderDto.OrderId);
            int   amountToCharge = (int)(Math.Round(order.Amount, 2) * 100);
            int   applicationFee = (int)(Math.Round(order.Amount, 1) * 10);
            var   chargeOptions  = new StripeChargeCreateOptions()
            {
                //required
                Amount   = amountToCharge,
                Currency = "gbp",
                SourceTokenOrExistingSourceId = stripeToken,
                //optional
                Description  = $"{order.User.Email} ordered {order.OrderDetails.SelectMany(x => x.ItemsPurchased).Count()} items from {order.Restaurant.Name}",
                ReceiptEmail = order.User.Email,
                //Add destination account and application fee to charge restaurant
                Destination    = order.Restaurant.StripeAccountId,
                ApplicationFee = applicationFee
            };

            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
            var chargeService = new StripeChargeService();
            var stripeCharge  = chargeService.Create(chargeOptions);

            order.OrderStatus   = OrderStatus.Paid;
            order.PaymentStatus = OrderStatus.Paid;
            order.PaymentToken  = stripeCharge.Id;
            _orderDataProvider.SaveOrder(order);
            return(Mapper.Map <OrderDto>(order));
        }
Пример #18
0
        private async Task <string> ProcessPayment(StripeChargeModel model)
        {
            //TODO
            if (model.Amount == 0)
            {
                model.Amount = 1900;
            }
            model.Card.TokenId = model.Id;
            return(await Task.Run(() =>
            {
                var myCharge = new StripeChargeCreateOptions
                {
                    // convert the amount of £12.50 to pennies i.e. 1250
                    Amount = model.Amount, //in pence
                    Currency = "gbp",
                    Description = "Charged £19 one-off up to 1000",
                    Card = model.Card,
                    ReceiptEmail = model.Email
                                   // TokenId = model.Token
                };

                var chargeService = new StripeChargeService(ConfigurationManager.AppSettings["StripeApiKey"]);
                var stripeCharge = chargeService.Create(myCharge);

                return stripeCharge.Id;
            }));
        }
Пример #19
0
        public StripeCharge CreateTransaction(string advertiserId, int totalAmount, int platformCharge, string influencerAccId)
        {
            StripeConfiguration.SetApiKey("");

            // direct charge from advertiser & deposit in influencer account
            // https://stripe.com/docs/connect/direct-charges
            // https://gist.github.com/jaymedavis/d969be13ca6019686a4e72b82e999546


            // Charge the Customer instead of the card
            var chargeOptions = new StripeChargeCreateOptions
            {
                Amount         = totalAmount,
                Currency       = "usd",
                CustomerId     = advertiserId,
                ApplicationFee = platformCharge
            };

            var requestOptions = new StripeRequestOptions();

            requestOptions.StripeConnectAccountId = influencerAccId;

            var          chargeService = new StripeChargeService();
            StripeCharge charge        = chargeService.Create(chargeOptions, requestOptions);

            return(charge);
        }
        public IActionResult Charge(string stripeEmail, string stripeToken, IFormCollection _form)
        {
            var idorder   = _form["orderid"];
            var customers = new StripeCustomerService();
            var charges   = new StripeChargeService();
            var order     = db.Orders.Where(u => u.Id.ToString() == idorder).SingleOrDefault();

            if (order != null)
            {
                order.Status = 2;
                db.Orders.Update(order);
                db.SaveChanges();
                ReduceQuantity(int.Parse(idorder));
                Success(string.Format("<b>Đơn hàng đã thanh toán thành công</b>", ""), true);
                var customer = customers.Create(new StripeCustomerCreateOptions
                {
                    Email       = stripeEmail,
                    SourceToken = stripeToken
                });

                var charge = charges.Create(new StripeChargeCreateOptions
                {
                    Amount      = (int)(order.Amount),
                    Description = "Đơn hàng " + order.CodeOrder.ToString() + " đã thanh toán",
                    Currency    = "vnd",
                    CustomerId  = customer.Id
                });
                return(RedirectToAction("Detail", new { id = order.Id }));
            }


            return(View());
        }
Пример #21
0
        public connect_fixture()
        {
            var accountService       = new StripeAccountService(Cache.ApiKey);
            var accountCreateOptions = new StripeAccountCreateOptions
            {
                DefaultCurrency = "usd",
                Email           = "*****@*****.**",
                Type            = StripeAccountType.Custom
            };

            Account = accountService.Create(accountCreateOptions);

            var chargeService = new StripeChargeService(Cache.ApiKey);

            chargeService.ExpandApplication    = true;
            chargeService.ExpandApplicationFee = true;
            Charge = chargeService.Create(
                new StripeChargeCreateOptions
            {
                SourceTokenOrExistingSourceId = "tok_visa",
                ApplicationFee = 10,
                Amount         = 100,
                Currency       = "usd"
            },
                new StripeRequestOptions
            {
                StripeConnectAccountId = Account.Id
            }
                );

            var applicationFeeService = new StripeApplicationFeeService(Cache.ApiKey);

            applicationFeeService.ExpandApplication = true;
            ApplicationFee = applicationFeeService.Get(Charge.ApplicationFeeId);
        }
Пример #22
0
        public async Task <StripeCharge> CreateChargeAsync(StripeChargeCreateOptions options, string apiKey)
        {
            var chargeService = new StripeChargeService(apiKey);
            var charge        = chargeService.Create(options);

            return(charge);
        }
Пример #23
0
        public charging_from_another_account()
        {
            var anotherAccount = new StripeAccountService(Cache.ApiKey).Create(new StripeAccountCreateOptions
            {
                DefaultCurrency = "usd",
                Email           = "*****@*****.**",
                Managed         = true
            }
                                                                               );

            var chargeService = new StripeChargeService(Cache.ApiKey);

            chargeService.ExpandApplicationFee = true;

            var charge = chargeService.Create(
                new StripeChargeCreateOptions
            {
                SourceTokenOrExistingSourceId = Cache.GetToken().Id,
                ApplicationFee = 10,
                Amount         = 100,
                Currency       = "usd"
            },
                new StripeRequestOptions
            {
                StripeConnectAccountId = anotherAccount.Id
            }
                );

            var appFeeService = new StripeApplicationFeeService(Cache.ApiKey);

            appFeeService.ExpandApplication = true;

            _appFee = appFeeService.Get(charge.ApplicationFeeId);
        }
Пример #24
0
        public static StripeCharge GetStripeChargeInfo(string stripeEmail, string stripeToken, int amount)
        {
            var customers      = new StripeCustomerService();
            var charges        = new StripeChargeService();
            var stripeSettings = new StripeSettings();

            stripeSettings.ReloadStripeSettings();
            StripeConfiguration.SetApiKey(stripeSettings.SecretKey);

            var customer = customers.Create(new StripeCustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });

            var charge = charges.Create(new StripeChargeCreateOptions
            {
                Amount      = amount * 100, //charge in cents
                Description = "Dunkey Delivery",
                Currency    = "usd",
                CustomerId  = customer.Id,
            });

            return(charge);
        }
Пример #25
0
        public async void StripeProcess(string Token)
        {
            var charge = new StripeChargeCreateOptions
            {
                Amount      = Convert.ToInt32(Total * 100), // In cents, not dollars, times by 100 to convert
                Currency    = "usd",                        // or the currency you are dealing with
                Description = "StadiYUM Order",
                SourceTokenOrExistingSourceId = "tok_visa"
            };

            var service = new StripeChargeService("sk_test_fMQSO85L4eNQWH7LEESCbY71");

            try
            {
                var response = service.Create(charge);
                if (response.Paid)
                {
                    manager.CartFinished();
                    await DisplayAlert("Order Confirmed", "Go to Orders to view status", "OK");
                }
                // Record or do something with the charge information
            }
            catch (StripeException ex)
            {
                StripeError stripeError = ex.StripeError;
                DisplayAlert("Error", stripeError.Error, "OK");

                // Handle error
            }

            // Ideally you would put in additional information, but you can just return true or false for the moment.
        }
 private async Task <string> ProcessPayment(StripeChargeModel model)
 {
     //StripeConfiguration.SetApiKey("pk_test_ZwQQ3DpHRcIWDMKgVObfuSYl");
     return(await Task.Run(() =>
     {
         var myCharge = new StripeChargeCreateOptions
         {
             Amount = (int)(model.Amount * 1),
             Currency = "gbp",
             Description = "Description for test charge",
             // SourceTokenOrExistingSourceId = model.Token
         };
         try
         {
             var chargeService = new StripeChargeService("sk_test_sunSx6HuXZrAcIp2W8k7L4zk");
             var stripeCharge = chargeService.Create(myCharge);
             return stripeCharge.Id;
         }
         catch (Exception e)
         {
             Response.Write("<script>alert('Data Saved succesfully in Database but further transaction process  you must provide Cutomer or merchant.')</script>");
             return e.Message;
         }
     }));
 }
Пример #27
0
        public IActionResult CheckoutPayment(string StripeToken, string CustomerID, int ChargeAmount)
        {
            //var myCustomer = new StripeCustomerCreateOptions();
            //myCustomer.Email = "*****@*****.**";
            //myCustomer.Description = "Jonathan Tecson";
            //myCustomer.SourceToken = StripeToken;
            ////myCustomer.TrialEnd = DateTime.UtcNow.AddMonths(1);    // when the customers trial ends (overrides the plan if applicable)
            ////myCustomer.Quantity = 1;                               // optional, defaults to 1
            //var customerService = new StripeCustomerService("sk_test_qFGjHTjY0gFwJsqkpskaiTLP");
            //StripeCustomer stripeCustomer = customerService.Create(myCustomer);

            var StripeCharge = new StripeChargeCreateOptions();

            StripeCharge.Amount      = ChargeAmount;
            StripeCharge.Currency    = "aud";
            StripeCharge.Description = "Jupiter Subscription";
            StripeCharge.SourceTokenOrExistingSourceId = StripeToken;

            StripeCharge.Capture = true;

            var          StripeChargeService = new StripeChargeService("sk_test_qFGjHTjY0gFwJsqkpskaiTLP");
            StripeCharge StripeChargeTrans   = StripeChargeService.Create(StripeCharge);

            return(View());
        }
        public IActionResult orderstatus(string stripeToken, string address, string cardholdername, double amount, string description)
        {
            var myCharge = new StripeChargeCreateOptions();


            // when the customers trial ends (overrides the plan if applicable)
            // always set these properties
            myCharge.Amount   = (int)(amount * 100);
            myCharge.Currency = "usd";
            // set this if you want to
            myCharge.Description = description;



            myCharge.SourceTokenOrExistingSourceId = stripeToken;

            // set this property if using a customer - this MUST be set if you are using an existing source!

            // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
            myCharge.Capture = true;


            var          chargeService = new StripeChargeService();
            StripeCharge stripeCharge  = chargeService.Create(myCharge);

            if (stripeCharge.Status == "succeeded")
            {
                return(View());
            }
            return(RedirectToAction("orders"));
        }
Пример #29
0
        /// <summary>
        ///     Creates the charge.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <param name="capture">
        ///     Whether or not to immediately capture the charge. When false, the charge issues an
        ///     authorization(or pre-authorization), and will need to be captured later
        /// </param>
        private void CreateCharge(Transaction t, bool capture)
        {
            StripeConfiguration.SetApiKey(Settings.StripeApiKey);

            var chargeOptions = new StripeChargeCreateOptions();

            // always set these properties
            chargeOptions.Amount   = (int)(t.Amount * 100);
            chargeOptions.Currency = Settings.CurrencyCode;

            // set this if you want to
            chargeOptions.Capture     = capture;
            chargeOptions.Currency    = Settings.CurrencyCode;
            chargeOptions.Description = t.MerchantDescription;

            chargeOptions.Source = new StripeSourceOptions();

            // set these properties if using a card
            chargeOptions.Source.Number          = t.Card.CardNumber;
            chargeOptions.Source.ExpirationYear  = t.Card.ExpirationYear.ToString();
            chargeOptions.Source.ExpirationMonth = t.Card.ExpirationMonthPadded;
            //myCharge.CardAddressCountry = "US";             // optional
            if (t.Customer.Street.Length > 0)
            {
                chargeOptions.Source.AddressLine1 = t.Customer.Street; // optional
            }
            //myCharge.CardAddressLine2 = "Apt 24";           // optional
            //myCharge.CardAddressState = "NC";               // optional
            if (t.Customer.PostalCode.Length > 0)
            {
                chargeOptions.Source.AddressZip = t.Customer.PostalCode; // optional
            }
            chargeOptions.Source.Name = t.Card.CardHolderName;           // optional
            if (!string.IsNullOrEmpty(t.Card.SecurityCode))
            {
                chargeOptions.Source.Cvc = t.Card.SecurityCode; // optional
            }

            // set this property if using a customer
            //myCharge.CustomerId = *customerId*;

            // set this property if using a token
            //myCharge.TokenId = *tokenId*;

            var chargeService = new StripeChargeService();

            var stripeCharge = chargeService.Create(chargeOptions);

            if (stripeCharge.Id.Length > 0 && stripeCharge.Amount > 0)
            {
                t.Result.Succeeded       = true;
                t.Result.ReferenceNumber = stripeCharge.Id;
            }
            else
            {
                t.Result.Succeeded               = false;
                t.Result.ResponseCode            = "FAIL";
                t.Result.ResponseCodeDescription = "Stripe Failure";
            }
        }
        private String ChargeCard(String token)
        {
            var myCharge = new StripeChargeCreateOptions();

            // always set these properties
            myCharge.Amount   = (User.IsInRole("BasicUser") || User.IsInRole("Admin") || User.IsInRole("ProfileUser")) ? 19900 : User.IsInRole("ArchiveUser") ? 14900 : 19900;
            myCharge.Currency = "usd";

            // set this if you want to
            myCharge.Description = "Embracing Memories - New Profile";

            myCharge.SourceTokenOrExistingSourceId = token;

            // set this property if using a customer - this MUST be set if you are using an existing source!
            //myCharge.CustomerId = *customerId *;

            // set this if you have your own application fees (you must have your application configured first within Stripe)
            //myCharge.ApplicationFee = 25;

            // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
            myCharge.Capture = true;

            var chargeService = new StripeChargeService();

            try
            {
                StripeCharge stripeCharge = chargeService.Create(myCharge);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return(null);
        }