Exemplo n.º 1
0
        public TokenServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new TokenService(this.StripeClient);

            this.createOptions = new TokenCreateOptions
            {
                Card = new CreditCardOptions
                {
                    AddressCity    = "City",
                    AddressCountry = "US",
                    AddressLine1   = "Line 1",
                    AddressLine2   = "Line 2",
                    AddressState   = "CA",
                    AddressZip     = "90210",
                    Cvc            = "123",
                    ExpMonth       = 10,
                    ExpYear        = DateTime.Now.Year + 1,
                    Name           = "Name",
                    Number         = "4242424242424242",
                },
            };
        }
Exemplo n.º 2
0
        public Token GetMemberChargeToken(string CustomerId, string CustomerAccountId)
        {
            //Making tokens
            //-------------------------------
            //  When you’re ready to create a charge on a connected account using a customer saved
            //  on Sm platform account, create a new token for that purpose.
            //  Need:
            //     - The Stripe account ID—something like acct_5Be23LrR9CajZbmp—of the connected account
            //          for whom you’re making the charge
            //     - The customer ID—something like cus_WsV53JxavIqlrm—of the
            //          customer(in your platform account) being charged
            //     - The card or bank account ID for that customer, if you want to charge a specific card
            //          or bank account rather than the default

            // 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


            var options = new TokenCreateOptions
            {
                Customer = CustomerId
            };
            var requestOptions = new RequestOptions
            {
                StripeAccount = CustomerAccountId
            };
            var service = new TokenService();

            return(service.Create(options, requestOptions));
        }
Exemplo n.º 3
0
        private string CreateToken()
        {
            try
            {
                StripeConfiguration.ApiKey = StripeTestApiKey;
                var service      = new ChargeService();
                var Tokenoptions = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number         = KreditnaKartica.Broj,
                        ExpYear        = KreditnaKartica.ExpYear,
                        ExpMonth       = KreditnaKartica.ExpMonth,
                        Cvc            = KreditnaKartica.Cvc,
                        Name           = APIService.LogiraniKorisnik.Ime + " " + APIService.LogiraniKorisnik.Prezime,
                        AddressCity    = APIService.LogiraniKorisnik.Grad.Naziv,
                        AddressCountry = APIService.LogiraniKorisnik.Grad.Drzava.Naziv,
                        Currency       = "bam",
                    }
                };

                Tokenservice = new TokenService();
                stripeToken  = Tokenservice.Create(Tokenoptions);
                return(stripeToken.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 4
0
        public async Task <Charge> Charge(long cost, string number, long expYear, long expMonth, string cvc, string description, CancellationToken cancellationToken)
        {
            var optionsToken = new TokenCreateOptions()
            {
                Card = new AnyOf <string, TokenCardOptions>(new TokenCardOptions
                {
                    Number   = number,
                    ExpYear  = expYear,
                    ExpMonth = expMonth,
                    Cvc      = cvc
                })
            };

            var serviceToken = new TokenService();

            var stripeToken = await serviceToken.CreateAsync(optionsToken, cancellationToken : cancellationToken);

            var options = new ChargeCreateOptions
            {
                Amount      = cost,
                Currency    = Constants.Currency.CDN,
                Description = description,
                Source      = stripeToken.Id
            };

            var service = new ChargeService();

            return(await service.CreateAsync(options, cancellationToken : cancellationToken));
        }
Exemplo n.º 5
0
        private async Task <string> CreateTokenAsync()
        {
            try
            {
                StripeConfiguration.ApiKey = StripeTestApiKey;

                var Tokenoptions = new TokenCreateOptions()
                {
                    Card = new TokenCardOptions()
                    {
                        Number         = CreditCardModel.Number,
                        ExpYear        = CreditCardModel.ExpYear,
                        ExpMonth       = CreditCardModel.ExpMonth,
                        Cvc            = CreditCardModel.Cvc,
                        Name           = user.FirstName + " " + user.LastName,
                        AddressLine1   = "Adema Buce 13",
                        AddressLine2   = "",
                        AddressCity    = "Sarajevo",
                        AddressZip     = "71000",
                        AddressState   = "Sarajevo",
                        AddressCountry = "Bosna i Hercegovina",
                        Currency       = "usd",
                    }
                };

                Tokenservice = new TokenService();
                stripeToken  = Tokenservice.Create(Tokenoptions);
                return(stripeToken.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 6
0
        public string CreateToken(string cardNumber, long cardExpMonth, long cardExpYear, string cardCVC)
        {
            try
            {
                StripeConfiguration.ApiKey = ApiKey;

                var tokenOptions = new TokenCreateOptions()
                {
                    Card = new TokenCardOptions()
                    {
                        Number   = cardNumber,
                        ExpYear  = cardExpYear,
                        ExpMonth = cardExpMonth,
                        Cvc      = cardCVC
                    }
                };
                var   tokenService = new TokenService();
                Token stripeToken  = tokenService.Create(tokenOptions);
                return(stripeToken.Id);
            }
            catch (Exception exc)
            {
                DisplayAlert("Alert", "Token creation failed", "Ok");
                return("");
            }
        }
Exemplo n.º 7
0
        private string CreateToken()
        {
            try
            {
                StripeConfiguration.SetApiKey(StripeTestApiKey);
                var service      = new ChargeService();
                var Tokenoptions = new TokenCreateOptions
                {
                    Card = new CreditCardOptions
                    {
                        Number         = KreditnaKartica.Broj,
                        ExpYear        = KreditnaKartica.ExpYear,
                        ExpMonth       = KreditnaKartica.ExpMonth,
                        Cvc            = KreditnaKartica.Cvc,
                        Name           = Global.LogiraniClan.Ime + " " + Global.LogiraniClan.Prezime,
                        AddressCity    = Global.LogiraniClan.Grad.Naziv,
                        AddressCountry = "Bosna i Hercegovina",
                        Currency       = "bam",
                    }
                };

                Tokenservice = new TokenService();
                stripeToken  = Tokenservice.Create(Tokenoptions);
                return(stripeToken.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        private string CreateToken()
        {
            try
            {
                StripeConfiguration.ApiKey = StripeTestApiKey;
                var service      = new ChargeService();
                var Tokenoptions = new TokenCreateOptions
                {
                    Card = new CreditCardOptions
                    {
                        Number   = CCNumberEntry.Text,
                        ExpYear  = long.Parse(ExpiryYearEntry.Text),
                        ExpMonth = long.Parse(ExpiryMonthEntry.Text),
                        Cvc      = CVCEntry.Text
                    }
                };

                Tokenservice = new TokenService();
                stripeToken  = Tokenservice.Create(Tokenoptions);
                return(stripeToken.Id);
            }
            catch (Exception ex)
            {
                DisplayAlert("Warning", "Something went wrong... Please try again later!", "OK");
                Console.WriteLine(ex.Message);
                throw;
            }
        }
Exemplo n.º 9
0
        public static string GetTokenCard(CardModel card)
        {
            // Set your secret key: remember to change this to your live secret key in production
            // See your keys here: https://dashboard.stripe.com/Card/apikeys

            StripeConfiguration.SetApiKey(SecretKey);

            var TokenOptions = new TokenCreateOptions
            {
                Card = new CreditCardOptions
                {
                    Name           = card.Name,
                    ExpMonth       = card.Exp_Month,
                    Number         = card.CardNumber,
                    ExpYear        = card.Exp_Year,
                    Cvc            = card.CVC,
                    AddressCity    = card.City,
                    AddressLine1   = card.Address1,
                    AddressLine2   = card.Address2,
                    AddressCountry = card.Country,
                    AddressZip     = card.ZipCode,
                }
            };
            var TokenService = new TokenService();
            var token        = TokenService.Create(TokenOptions);

            return(token.Id);
        }
        public string CreateCustomer()
        {
            StripeConfiguration.ApiKey = "sk_test_xx"; //Stripe secret key
            var optionsToken = new TokenCreateOptions()
            {
                Card = new TokenCardOptions()
                {
                    Number   = "4242424242424242",
                    ExpMonth = 9,
                    ExpYear  = 2022,
                    Cvc      = "123"
                }
            };
            var   serviceToken       = new TokenService();
            Token stripeTokenFromApi = serviceToken.CreateAsync(optionsToken).Result;
            var   customers          = new CustomerService();
            var   charges            = new ChargeService();

            var customer = customers.Create(new CustomerCreateOptions
            {
                Email  = "*****@*****.**",
                Source = stripeTokenFromApi.Id
            });

            return(customer.Id);
            //save customer.Id in database
        }
        public string KreirajToken()
        {
            try
            {
#pragma warning disable CS0618 // 'StripeConfiguration.SetApiKey(string)' is obsolete: 'Use StripeConfiguration.ApiKey setter instead.'
                StripeConfiguration.SetApiKey(ApiKey);
#pragma warning restore CS0618 // 'StripeConfiguration.SetApiKey(string)' is obsolete: 'Use StripeConfiguration.ApiKey setter instead.'
                var service = new ChargeService();
                var token   = new TokenCreateOptions()
                {
                    Card = new CreditCardOptions()
                    {
                        Number   = BrojKartice.Text,
                        ExpMonth = int.Parse(MjesecIsteka.Text),
                        ExpYear  = int.Parse(GodinaIsteka.Text),
                        Cvc      = CVV.Text
                    }
                };
                TokenService = new TokenService();
                StripeToken  = TokenService.Create(token);
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.Alert(ex.Message, null, "OK");
            }
            return(StripeToken.Id);
        }
Exemplo n.º 12
0
        private string CreateToken()
        {
            try
            {
                StripeConfiguration.SetApiKey(StripeTestApiKey);
                var service      = new ChargeService();
                var Tokenoptions = new TokenCreateOptions
                {
                    Card = new CreditCardOptions
                    {
                        Number         = CreditCardModel.Number,
                        ExpYear        = CreditCardModel.ExpYear,
                        ExpMonth       = CreditCardModel.ExpMonth,
                        Cvc            = CreditCardModel.Cvc,
                        Name           = Global.prijavljeniKupac.KorisnickoIme + " : " + Global.aktivnaNarudzba.BrojNarudzbe,
                        AddressLine1   = "Adresa 1",
                        AddressLine2   = "",
                        AddressCity    = "",
                        AddressZip     = "",
                        AddressState   = "",
                        AddressCountry = "Bosnia and Herzegovina",
                        Currency       = "bam",
                    }
                };

                Tokenservice = new TokenService();
                stripeToken  = Tokenservice.Create(Tokenoptions);
                return(stripeToken.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 13
0
 public static string CreateToken(PaymentInformation paymentInfo)
 {
     try
     {
         StripeConfiguration.ApiKey = TestApiKey;
         var service      = new ChargeService();
         var tokenoptions = new TokenCreateOptions
         {
             Card = new TokenCardOptions
             {
                 Number   = paymentInfo.CardNumber,
                 Cvc      = paymentInfo.SecurityCode,
                 ExpMonth = paymentInfo.ExpMonth,
                 ExpYear  = paymentInfo.ExpYear
             }
         };
         TokenService TokenService = new TokenService();
         Token        stripeToken  = TokenService.Create(tokenoptions);
         return(stripeToken.Id);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw ex;
     }
 }
Exemplo n.º 14
0
 public string CreateToken()
 {
     try
     {
         StripeConfiguration.ApiKey = TestApiKey;
         var service     = new ChargeService();
         var tokenOption = new TokenCreateOptions
         {
             Card = new CreditCardOptions
             {
                 Number         = "4242424242424242",
                 ExpYear        = 22,
                 ExpMonth       = 12,
                 Cvc            = "889",
                 Name           = APIService.username.ToString(),
                 AddressLine1   = "Skolska",
                 AddressCity    = "Mostar",
                 AddressCountry = "BiH",
                 Currency       = "BAM"
             }
         };
         TokenService = new TokenService();
         stripeToken  = TokenService.Create(tokenOption);
         return(stripeToken.Id);
     }
     catch (Exception)
     {
         throw;
     }
 }
        public Card CreateCartdStripe(StripeCardDTO dto, string customerid)
        {
            var tokenCreate = new TokenCreateOptions
            {
                Card = new TokenCardOptions
                {
                    Number   = dto.Cardnumber,
                    ExpMonth = dto.Month,
                    ExpYear  = dto.Year,
                    Cvc      = dto.CVC,
                    Name     = dto.CardHolderName
                },
            };
            var tokenService = new TokenService();
            var token        = tokenService.Create(tokenCreate);

            var options = new CardCreateOptions
            {
                Source = token.Id
            };
            var service  = new Stripe.CardService();
            var response = service.Create(customerid, options);

            return(response);
        }
Exemplo n.º 16
0
        private async Task <string> CreateTokenAsync()
        {
            try
            {
                StripeConfiguration.ApiKey = StripeTestApiKey;

                var Tokenoptions = new TokenCreateOptions
                {
                    Card = new CreditCardOptions
                    {
                        Number         = CreditCardModel.Number,
                        ExpYear        = CreditCardModel.ExpYear,
                        ExpMonth       = CreditCardModel.ExpMonth,
                        Cvc            = CreditCardModel.Cvc,
                        Name           = korisnik.Ime + " " + korisnik.Prezime,
                        AddressLine1   = "Marka Marulića",
                        AddressLine2   = "23",
                        AddressCity    = "Grad",
                        AddressZip     = "88000",
                        AddressState   = "Starmo",
                        AddressCountry = "Bosna i Hercegovina",
                        Currency       = "bam",
                    }
                };

                Tokenservice = new TokenService();
                stripeToken  = Tokenservice.Create(Tokenoptions);
                return(stripeToken.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 17
0
        private string CreateToken()
        {
            try
            {
                StripeConfiguration.ApiKey = StripeTestApiKey;
                var service      = new ChargeService();
                var Tokenoptions = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number         = CreditCardModel.Number,
                        ExpYear        = CreditCardModel.ExpYear,
                        ExpMonth       = CreditCardModel.ExpMonth,
                        Cvc            = CreditCardModel.Cvc,
                        Name           = APIService.KorisnickoIme,
                        AddressLine1   = "Adresa 1",
                        AddressLine2   = "Adresa 2",
                        AddressCity    = "Mostar",
                        AddressZip     = "88000",
                        AddressState   = "HNK",
                        AddressCountry = "Bosnia and Herzegovina",
                        Currency       = "bam",
                    }
                };

                Tokenservice = new TokenService();
                stripeToken  = Tokenservice.Create(Tokenoptions);
                return(stripeToken.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 18
0
        private string CreateToken()
        {
            try
            {
                var service      = new ChargeService();
                var Tokenoptions = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number         = CreditCardModel.Number,
                        ExpYear        = CreditCardModel.ExpYear,
                        ExpMonth       = CreditCardModel.ExpMonth,
                        Cvc            = CreditCardModel.Cvc,
                        Name           = "Ahmed Ždralović",
                        AddressLine1   = "18",
                        AddressLine2   = "19",
                        AddressCity    = "Bugojno",
                        AddressZip     = "70230",
                        AddressState   = "Bosna",
                        AddressCountry = "Bosnia and Herzegovina",
                        Currency       = "BAM",
                    }
                };

                Tokenservice = new TokenService();
                stripeToken  = Tokenservice.Create(Tokenoptions);
                return(stripeToken.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 19
0
        private string CreateToken()
        {
            try
            {
                StripeConfiguration.SetApiKey(StripeTestApiKey);
                var service      = new ChargeService();
                var Tokenoptions = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number         = CreditCardModel.Number,
                        ExpYear        = CreditCardModel.ExpYear,
                        ExpMonth       = CreditCardModel.ExpMonth,
                        Cvc            = CreditCardModel.Cvc,
                        Name           = Ime + " " + Prezime,
                        AddressLine1   = Email,
                        AddressLine2   = KorisnickoIme,
                        AddressCity    = "Maglaj",
                        AddressZip     = "74250",
                        AddressState   = "BiH",
                        AddressCountry = "Bosna i Hercegovina",
                        Currency       = "bam",
                    }
                };

                Tokenservice = new TokenService();
                stripeToken  = Tokenservice.Create(Tokenoptions);
                return(stripeToken.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 20
0
 private string CreateToken()
 {
     try
     {
         StripeConfiguration.ApiKey = TestApiKey;
         var service     = new ChargeService();
         var tokenOption = new TokenCreateOptions
         {
             Card = new TokenCardOptions
             {
                 Number       = brojKartice.Text.ToString(),
                 ExpYear      = 21,
                 ExpMonth     = 12,
                 Cvc          = cvcKartice.Text.ToString(),
                 Name         = "Kupovina paketa eKino - " + model.Paket.Opis,
                 AddressLine1 = "Adresa",
                 AddressLine2 = "Adresa"
             }
         };
         TokenService = new TokenService();
         stripeToken  = TokenService.Create(tokenOption);
         return(stripeToken.Id);
     }
     catch (Exception ex)
     {
         Application.Current.MainPage.DisplayAlert("Greska", ex.Message, "Ok");
     }
     return(string.Empty);
 }
Exemplo n.º 21
0
 public string CreateToken()
 {
     try
     {
         StripeConfiguration.SetApiKey(TestApiKey);
         var service      = new ChargeService();
         var tokenoptions = new TokenCreateOptions
         {
             Card = new TokenCardOptions
             {
                 Number   = CardNumber,
                 Cvc      = SecurityCode,
                 ExpMonth = ExpMonth,
                 ExpYear  = ExpYear
             }
         };
         TokenService = new TokenService();
         stripeToken  = TokenService.Create(tokenoptions);
         return(stripeToken.Id);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw ex;
     }
 }
Exemplo n.º 22
0
        public static async Task <dynamic> PayAsync(string cardNumber, int month, int year, string cvv, long value, string name, string zipcode, string city)
        {
            try
            {
                Stripe.StripeConfiguration.ApiKey = "sk_test_51J0ADgL3k8dMVzvmykGCbIgxGWs9gsmmhZLvfVTJNzAhOwSqhdAYZaI1DSbn6OJ0B1ngeDMevuimOKX8wqtprrx2006tVUuHRm";

                var optionsToken = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number       = cardNumber,
                        ExpMonth     = month,
                        ExpYear      = year,
                        Cvc          = cvv,
                        Name         = name,
                        AddressState = city,
                        AddressZip   = zipcode,
                    }
                };

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

                var optionsCharge = new ChargeCreateOptions
                {
                    Amount      = value,
                    Currency    = "usd",
                    Description = "Booking Payment",
                    Source      = stripeToken.Id,
                };

                var    chargeServices = new ChargeService();
                Charge stripeCharge   = await chargeServices.CreateAsync(optionsCharge);

                if (stripeCharge.Paid)
                {
                    string transactionId = stripeCharge.BalanceTransactionId;
                    return(new
                    {
                        transactionId,
                        amount = value,
                        state = "Success",
                    });
                }
                else
                {
                    return(new
                    {
                        state = "Failed",
                    });
                }
            } catch (Exception e)
            {
                return(new
                {
                    state = e.Message,
                });
            }
        }
Exemplo n.º 23
0
        public virtual async Task <Token> Create(TokenCreateOptions createOptions)
        {
            var url = this.ApplyAllParameters(createOptions, Urls.Tokens, false);

            var response = await Requestor.Post(url);

            return(Mapper <Token> .MapFromJson(response));
        }
Exemplo n.º 24
0
        public static Token CreateToken(CreditCardOptions cardDetails = null)
        {
            TokenService       serviceToken = new TokenService();
            TokenCreateOptions token        = new TokenCreateOptions {
                Card = cardDetails
            };

            return(serviceToken.Create(token));
        }
        /// <summary>
        /// Creates a payment. Creates new customer or adds payment to existing customer
        /// </summary>
        /// <param name="id"></param>
        /// <param name="email"></param>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="cardnumber"></param>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="cvc"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task <dynamic> PayByCreditCard(string id, string email, string firstName, string lastName, string cardnumber, int month, int year, string cvc, int value)
        {
            try
            {
                StripeConfiguration.ApiKey = key;
                Models.Customer customer = await context.customers.Where(c => c.accountId == id).FirstOrDefaultAsync();

                Stripe.Customer paymentCustomer = new Stripe.Customer();

                //create new customer if it doesn't exists
                if (customer == null)
                {
                    paymentCustomer = await PostCustomer(id, email, firstName, lastName);

                    customer            = new Models.Customer();
                    customer.accountId  = id;
                    customer.customerId = paymentCustomer.Id;
                    await context.customers.AddAsync(customer);

                    context.SaveChanges();
                }

                //setup token options
                TokenCreateOptions optionstoken = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number   = cardnumber,
                        ExpMonth = month,
                        ExpYear  = year,
                        Cvc      = cvc
                    }
                };

                TokenService tokenService = new TokenService();
                Token        token        = await tokenService.CreateAsync(optionstoken);

                //setup payment options
                ChargeCreateOptions options = new ChargeCreateOptions
                {
                    Amount      = value,
                    Currency    = "eur",
                    Description = "Parking spot reservation. Date: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm"),
                    Source      = token.Id,
                    Customer    = customer.customerId
                };

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

                return(charge.Paid);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 26
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);
        }
        public async Task <StripePaymentCardResult> InsertStripeCardToStripeUser(PaymentCard paymentCard, string stripeuserId)
        {
            try
            {
                //Insertar tarjeta a un customer
                StripeConfiguration.ApiKey = this._configuration.GetSection("Stripe")["SecretKey"];

                //Obtenemos los valores de la tarjeta
                var tokenoptions = new TokenCreateOptions()
                {
                    Card = new CreditCardOptions()
                    {
                        Number   = paymentCard.CardNumber,
                        ExpYear  = long.Parse(paymentCard.Year),
                        ExpMonth = long.Parse(paymentCard.Month),
                        Cvc      = paymentCard.Cvc,
                        Name     = paymentCard.HolderName,
                    },
                };

                //Creamos el token de la tarjeta
                var tokenService = new TokenService();

                var stripeToken = await tokenService.CreateAsync(tokenoptions);


                //El token pasara la informacion necesaria de la tarjeta
                var CardCreateoptions = new CardCreateOptions
                {
                    Source = stripeToken.Id,
                };

                //Comenzamos a usar el servicio de la tarjeta.
                var cardservice = new CardService();

                //Creamos la tarjeta para un el customer de stripe
                var cardserviceToken = await cardservice.CreateAsync(stripeuserId, CardCreateoptions);


                //Verificamos los valores si son correctos.
                if (!string.IsNullOrEmpty(cardserviceToken.Id))
                {
                    var result = new StripePaymentCardResult(cardserviceToken.Id);
                    return(result);
                }
                else
                {
                    return(new StripePaymentCardResult(true, "Token could not be creted try again."));
                }
            }
            catch (Exception e)
            {
                return(new StripePaymentCardResult(true, e.Message));
            }
        }
Exemplo n.º 28
0
        public void ConnectionTest_InvalidKey()
        {
            // Arrange
            var service = new TokenService();
            var options = new TokenCreateOptions();
            // Act
            TestDelegate testDelegate = () => service.Create(options);
            // Assert
            var ex = Assert.Throws <StripeException>(testDelegate);

            StringAssert.Contains("Invalid API Key provided", ex.Message);
        }
Exemplo n.º 29
0
        public void Charge(CreditCard creditCard, int amount)
        {
            StripeConfiguration.ApiKey = "sk_test_51I16Y9E8wOwlqFibK2LgGaeO3Cl2Lm5cuHykaLkxZUvtLcdXnlespd1oisJcx3l5GJaL9NYsUjmp6dOoGwL3EvCi00j5FSSKaN";

            TokenCardOptions stripeCard = new TokenCardOptions
            {
                Number   = creditCard.Number,
                ExpYear  = creditCard.ExpirationYear,
                ExpMonth = creditCard.ExpirationMounth,
                Cvc      = creditCard.Cvc
            };

            TokenCreateOptions token = new TokenCreateOptions
            {
                Card = stripeCard
            };

            TokenService serviceToken = new TokenService();
            Token        newToken     = serviceToken.Create(token);

            var options = new SourceCreateOptions
            {
                Type     = SourceType.Card,
                Currency = "RON",
                Token    = newToken.Id
            };

            var    service = new SourceService();
            Source source  = service.Create(options);

            Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions()
            {
                Name        = "Radu Balauroiu",
                Email       = "*****@*****.**",
                Description = "Test",
            };

            CustomerService customerService = new CustomerService();
            Customer        stripeCustomer  = customerService.Create(myCustomer);

            ChargeCreateOptions chargeoptions = new ChargeCreateOptions
            {
                Amount       = amount,
                Currency     = "RON",
                ReceiptEmail = "*****@*****.**",
                Customer     = stripeCustomer.Id,
                Source       = source.Id,
                Description  = "Test"
            };

            ChargeService service1 = new ChargeService();
            Charge        charge   = service1.Create(chargeoptions);
        }
        //then make entry into bank transaction at endpoint

        // async standalone charge method
        public static async Task <dynamic> ChargeAsync(string cardNumber, long month, long year, string cvc, string zip, int value)
        {
            try
            {
                // use secret (test) key
                StripeConfiguration.ApiKey = "sk_test_51IPcYzEaVFltQHPezdflBTQkF7dWeii1TG5Du6Cvgc95VETYsz1VC0YzAmG2u" +
                                             "XVoVIfHLypXdm8ghoqwgS0BLvfn00ZSfKjjZG";

                // capture card ( card is captured, sent to stripe, returned as token to charger to run payment

                var tokenCreateOptions = new TokenCreateOptions
                {
                    // TokenCardOptions changed from CreditCardOptions

                    Card = new TokenCardOptions
                    {
                        Number     = cardNumber,
                        ExpMonth   = month,
                        ExpYear    = year,
                        Cvc        = cvc,
                        AddressZip = zip
                    }
                };

                var   tokenService   = new TokenService();
                Token newStripeToken = await tokenService.CreateAsync(tokenCreateOptions);


                var chargeOptions = new ChargeCreateOptions
                {
                    Amount      = value,
                    Currency    = "usd",
                    Description = "test",           // put playerId
                    Source      = newStripeToken.Id // generated token's id from the captured card
                };

                // make the charge
                var    service = new ChargeService();
                Charge charge  = await service.CreateAsync(chargeOptions);

                if (charge.Paid)
                {
                    return($"Card successfully charged ${charge.Amount / 100}");
                }
            }
            catch (Exception error)
            {
                return(error.Message);
            }

            // return null to finish off code paths - should be changed to something better???
            return(null);
        }