Beispiel #1
0
        public PaymentToken GetToken(
            string cardNumber,
            int?expMonth        = null,
            int?expYear         = null,
            string cvc          = null,
            string addressLine1 = null,
            string addressLine2 = null,
            string city         = null,
            string state        = null,
            string country      = null,
            string zip          = null)
        {
            var card = new TokenCardOptions()
            {
                Number         = cardNumber,
                ExpMonth       = expMonth ?? PaymentDefaults.ExpMonth,
                ExpYear        = expYear ?? PaymentDefaults.ExpYear,
                Cvc            = cvc ?? PaymentDefaults.Cvc,
                AddressCity    = city ?? PaymentDefaults.City,
                AddressLine1   = addressLine1 ?? PaymentDefaults.AddressLine1,
                AddressLine2   = addressLine2 ?? PaymentDefaults.AddressLine2,
                AddressState   = state ?? PaymentDefaults.State,
                AddressCountry = country ?? PaymentDefaults.Country,
                AddressZip     = zip ?? PaymentDefaults.Zip
            };

            return(new PaymentToken(_tokenService.Create(new TokenCreateOptions()
            {
                Card = card
            }).Id, card.Number, card.ExpMonth, card.ExpYear, card.Cvc, card.AddressLine1, card.AddressLine2, card.AddressCity, card.AddressState, card.AddressCountry, card.AddressZip));
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public bool StripePay(Android.Content.Context acc)
        {
            try
            {
                StripeConfiguration.ApiKey = "sk_test_51If20qKme4ylLpJqCqLr2nw0chcXSm6zi0vCffHptgB8xa1wSUH3qbxCvsSFIHvP6ZLSi1tuXqhFzNApyB4XIEC6001UUZghYc";
                //Step 1: Create Card Options
                TokenCardOptions stripeOptions = new TokenCardOptions();
                stripeOptions.Number   = CardNumber;
                stripeOptions.Cvc      = Cvc;
                stripeOptions.ExpMonth = int.Parse(ExpMonth);
                stripeOptions.ExpYear  = int.Parse(ExpYear);

                //Step 2: Assign Card to a Token
                TokenCreateOptions stripeCard = new TokenCreateOptions();
                stripeCard.Card = stripeOptions;

                TokenService service  = new TokenService();
                Token        newToken = service.Create(stripeCard);

                //Step 3: Assign Token to the source
                var Options = new SourceCreateOptions
                {
                    Type     = SourceType.Card,
                    Currency = "pkr",
                    Token    = newToken.Id
                };

                var sourceService = new SourceService();
                var source        = sourceService.Create(Options);

                //Step 4: Create Customer Options
                CustomerCreateOptions customerOptions = new CustomerCreateOptions
                {
                    Name    = "",
                    Email   = "",
                    Address = new AddressOptions {
                        Country = "Pakistan"
                    }
                };

                var customerService = new CustomerService();
                var Customer        = customerService.Create(customerOptions);


                //Step 5: Charge Options
                var ChargeOptions = new ChargeCreateOptions
                {
                    Amount       = long.Parse(Amount),
                    Currency     = "PKR",
                    ReceiptEmail = "*****@*****.**", //user Email will be provided
                    Customer     = Customer.Id,
                    Source       = source.Id
                };

                //Step 6: Charge the Customer
                var    chargeService = new ChargeService();
                Charge charge        = chargeService.Create(ChargeOptions);
                if (charge.Status == "succeeded")
                {
                    return(true);

                    Toast.MakeText(acc, "Payment successfull", ToastLength.Long).Show();
                }
                else
                {
                    //Payment declined
                    return(true);

                    Toast.MakeText(acc, "Payment declined", ToastLength.Long).Show();
                }
            }
            catch (Exception)
            {
                return(false);

                Toast.MakeText(acc, "Payment Declined", ToastLength.Long).Show();
            }
        }
Beispiel #4
0
        public async void PayViaStripe()
        {
            //GetUserInfo();

            try
            {
                //Hemlig nyckel bör inte lagras här
                StripeConfiguration.ApiKey = "sk_test_51Iegu7KmvdxedTl5ip7GihXrL1wRf2MR2ATxllYpffbDUkiRuDQre1zoIbUoRL1qPFovl0UOwjNGUpMd259Jp3UQ00Q6X3y5Mi";

                string cardno   = cardNo.Text;
                string expMonth = expireMonth.Text;
                string expYear  = expireYear.Text;
                string cardCvv  = cvv.Text;

                // TokenCardOptions

                TokenCardOptions stripeOption = new TokenCardOptions();
                stripeOption.Number   = cardno;
                stripeOption.ExpYear  = Convert.ToInt64(expYear);
                stripeOption.ExpMonth = Convert.ToInt64(expMonth);
                stripeOption.Cvc      = cardCvv;

                // Assign card to token object
                TokenCreateOptions stripeCard = new TokenCreateOptions();
                stripeCard.Card = stripeOption;

                TokenService service  = new TokenService();
                Token        newToken = service.Create(stripeCard);

                // Assigning the token to the source
                var option = new SourceCreateOptions
                {
                    Type     = SourceType.Card,
                    Currency = "sek",
                    Token    = newToken.Id
                };

                var    sourceService = new SourceService();
                Source source        = sourceService.Create(option);



                TestSum();
                GetUserInfo();
                GetShippingInfo();
                // Skapar testkund
                CustomerCreateOptions customer = new CustomerCreateOptions
                {
                    Name        = Fullname,
                    Email       = "*****@*****.**", //test email can be changed
                    Description = "Paying " + Price + " sek",
                    // Address = new AddressOptions { City = "Sthlm", Country = "Sweden", Line1 = "Sample Address", Line2 = "Sample Address 2", PostalCode = "10030" }
                    Address = new AddressOptions {
                        City = CityName, Country = "Sweden", Line1 = StreetName, Line2 = "Sample Address 2", PostalCode = PostalCode
                    }
                };

                var customerService = new CustomerService();
                var cust            = customerService.Create(customer);



                // Charge option
                var chargeoption = new ChargeCreateOptions
                {
                    Amount       = ResultCurrency, //Måste vara högre än 3,00 dvs 300 //3000=30
                    Currency     = "SEK",
                    ReceiptEmail = "*****@*****.**",
                    Customer     = cust.Id,
                    Source       = source.Id
                };

                // Charge the customer
                var    chargeService = new ChargeService();
                Charge charge        = chargeService.Create(chargeoption);
                if (charge.Status == "succeeded")
                {
                    Console.WriteLine("Success");
                    RemoveFromShoppingCart();
                    await Navigation.PushAsync(new PaymentSuccesfulPage());
                }
                else
                {
                    Console.WriteLine("Payment failed");
                    await Shell.Current.GoToAsync($"//{nameof(PaymentFailedPage)}");
                }
            }
            catch (Exception ex) {
                await DisplayAlert("Alert", ex.ToString(), "OK");

                Console.WriteLine(ex);
            }
        }