public SourceServiceTest() { this.service = new SourceService(); this.attachOptions = new SourceAttachOptions { Source = SourceId, }; this.createOptions = new SourceCreateOptions { Type = SourceType.AchCreditTransfer, Currency = "usd", Mandate = new SourceMandateOptions { Acceptance = new SourceMandateAcceptanceOptions { Date = DateTime.Parse("Mon, 01 Jan 2001 00:00:00Z"), Ip = "127.0.0.1", NotificationMethod = "manual", Status = "accepted", UserAgent = "User-Agent", }, }, Owner = new SourceOwnerOptions { Address = new AddressOptions { State = "CA", City = "City", Line1 = "Line1", Line2 = "Line2", PostalCode = "90210", Country = "US", }, Email = "*****@*****.**", Name = "Owner Name", Phone = "5555555555", }, Receiver = new SourceReceiverOptions { RefundAttributesMethod = "manual", }, }; this.updateOptions = new SourceUpdateOptions { Metadata = new Dictionary <string, string> { { "key", "value" }, }, }; this.listOptions = new SourceListOptions { Limit = 1, }; }
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); }
public bool Pay( string stripeToken, decimal amount, string currency, string receiptEmail = "", string description = "") { try { var cardOption = new SourceCreateOptions { Type = SourceType.Card, Currency = currency, Token = stripeToken }; var sourceService = new SourceService(); Source source = sourceService.Create(cardOption); var chargeoption = new ChargeCreateOptions { Amount = Convert.ToInt32(amount * 100), Currency = currency, Description = description, ReceiptEmail = receiptEmail, Source = source.Id }; var chargeService = new ChargeService(); Charge charge = chargeService.Create(chargeoption); if (charge.Status == "succeeded") { return(true); } else { return(false); } } catch (Exception e) { Console.WriteLine(e); return(false); } }
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(); } }
private async Task PostIDealProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest, string bank) { var secretKey = _stripePaymentSettings.SecretKey; var clientSecret = _httpContextAccessor.HttpContext.Request.Query["client_secret"].ToString(); string source; if (string.IsNullOrWhiteSpace(clientSecret)) { if (!string.IsNullOrWhiteSpace(secretKey)) { //get store location var storeLocation = _webHelper.GetStoreLocation(); StripeConfiguration.ApiKey = secretKey; if (!string.IsNullOrWhiteSpace(postProcessPaymentRequest.Order.CustomValuesXml)) { var options = new SourceCreateOptions() { Amount = (long)postProcessPaymentRequest.Order.OrderTotal, Currency = postProcessPaymentRequest.Order.CustomerCurrencyCode.ToLower(), Type = SourceType.Ideal, Redirect = new SourceRedirectOptions { ReturnUrl = $"{storeLocation}checkout/OpcCompleteRedirectionPayment", }, Ideal = new SourceIdealCreateOptions { Bank = bank } }; var service = new SourceService(); Source charge = await service.CreateAsync(options); if (charge.StripeResponse.StatusCode == System.Net.HttpStatusCode.OK) { var jObject = JObject.Parse(charge.StripeResponse.Content); string value = (string)jObject.SelectToken("redirect.url"); source = (string)jObject.SelectToken("id"); _httpContextAccessor.HttpContext.Session.SetString("source", source); _httpContextAccessor.HttpContext.Response.Redirect(value); } } } else { await Task.FromException(new Exception("secret key canot be null or empty")); } } else { source = _httpContextAccessor.HttpContext.Session.GetString("source"); var options = new ChargeCreateOptions { Amount = (long)postProcessPaymentRequest.Order.OrderTotal, Currency = postProcessPaymentRequest.Order.CustomerCurrencyCode.ToLower(), Source = source, }; var service = new ChargeService(); Charge charge = await service.CreateAsync(options); if (charge.StripeResponse.StatusCode == System.Net.HttpStatusCode.OK) { postProcessPaymentRequest.Order.PaymentStatus = PaymentStatus.Paid; _httpContextAccessor.HttpContext.Session.Remove("source"); } } }
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); } }
private async void Button_Clicked(object sender, EventArgs e) { try { StripeConfiguration.SetApiKey("sk_test_51H7Lu7KJ3FKVwUnlPU8EUYuDPU0UMWNajFeHpVYzqwLkpKFRk9480iV54ZvAIPy4J0xYlKoN9IQaGMoyhhcaxOgl003Kz8FIdL"); //This are the sample test data use MVVM bindings to send data to the ViewModel Stripe.CreditCardOptions stripcard = new Stripe.CreditCardOptions(); stripcard.Number = cardNumberEntry.Text; stripcard.ExpYear = Convert.ToInt32(expiryDate.Text.Split('/')[1]); stripcard.ExpMonth = Convert.ToInt32(expiryDate.Text.Split('/')[0]); stripcard.Cvc = cvvEntry.Text; //Step 1 : Assign Card to Token Object and create Token Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions(); token.Card = stripcard; Stripe.TokenService serviceToken = new Stripe.TokenService(); Stripe.Token newToken = serviceToken.Create(token); // Step 2 : Assign Token to the Source var options = new SourceCreateOptions { Type = SourceType.Card, Currency = "usd", Token = newToken.Id }; var service = new SourceService(); Source source = service.Create(options); //Step 3 : Now generate the customer who is doing the payment Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions() { Name = nameEntry.Text, Email = emailEntry.Text, Description = "Amare Payment", }; var customerService = new Stripe.CustomerService(); Stripe.Customer stripeCustomer = customerService.Create(myCustomer); mycustomer = stripeCustomer.Id; // Not needed //Step 4 : Now Create Charge Options for the customer. var chargeoptions = new Stripe.ChargeCreateOptions { Amount = 100, Currency = "USD", ReceiptEmail = emailEntry.Text, Customer = stripeCustomer.Id, Source = source.Id }; //Step 5 : Perform the payment by Charging the customer with the payment. var service1 = new Stripe.ChargeService(); Stripe.Charge charge = service1.Create(chargeoptions); // This will do the Payment getchargedID = charge.Id; // Not needed await DisplayAlert("Payment", "Payment Success", "Okay"); await Navigation.PopAsync(); } catch (Stripe.StripeException ex) { await DisplayAlert("Payment Error", ex.Message, "Okay"); } }
private void MakePayment(string tokenId) { try { //create customer info CustomerCreateOptions customer = new CustomerCreateOptions { Name = "Test Stripe", Email = "*****@*****.**", Description = "test", Address = new AddressOptions { City = "Kolkata", Country = "India", Line1 = "Sample Address", Line2 = "Sample Address 2", PostalCode = "700030", State = "WB" } }; var customerService = new CustomerService(); var cust = customerService.Create(customer); //create source options var option = new SourceCreateOptions { Type = SourceType.Card, Currency = "INR", // the currency you are dealing with Token = tokenId, }; var sourceService = new SourceService(); Source source = sourceService.Create(option); long amt = 0; if (!string.IsNullOrEmpty(entryPrice.Text)) { amt = Convert.ToInt64(entryPrice.Text); } var chargeoption = new ChargeCreateOptions { Amount = amt * 100, Currency = "INR", ReceiptEmail = "*****@*****.**", Customer = cust.Id, Source = source.Id, Description = "test" }; var chargeService = new ChargeService(); Charge charge = chargeService.Create(chargeoption); if (charge.Status == "succeeded") { DisplayAlert("Info", "Your Payment is successfully done", "Ok"); // success } else { DisplayAlert("Alert", "Your Payment is not done", "Ok"); // failed } } catch (Exception exc) { DisplayAlert("Alert", exc.Message, "Ok"); } }
public void PayViaStripe() { StripeConfiguration.ApiKey = "sk_test_LJ2dJvulsi1f4rsGrqLHCKGC*****"; string cardno = cardNo.Text; string expMonth = expireMonth.Text; string expYear = expireYear.Text; string cardCvv = cvv.Text; // Step 1: create card option CreditCardOptions stripeOption = new CreditCardOptions(); stripeOption.Number = cardno; stripeOption.ExpYear = Convert.ToInt64(expYear); stripeOption.ExpMonth = Convert.ToInt64(expMonth); stripeOption.Cvc = cardCvv; // step 2: Assign card to token object TokenCreateOptions stripeCard = new TokenCreateOptions(); stripeCard.Card = stripeOption; TokenService service = new TokenService(); Token newToken = service.Create(stripeCard); // step 3: assign the token to the source var option = new SourceCreateOptions { Type = SourceType.Card, Currency = "inr", Token = newToken.Id }; var sourceService = new SourceService(); Source source = sourceService.Create(option); // step 4: create customer CustomerCreateOptions customer = new CustomerCreateOptions { Name = "SP Tutorial", Email = "*****@*****.**", Description = "Paying 10 Rs", Address = new AddressOptions { City = "Kolkata", Country = "India", Line1 = "Sample Address", Line2 = "Sample Address 2", PostalCode = "700030", State = "WB" } }; var customerService = new CustomerService(); var cust = customerService.Create(customer); // step 5: charge option var chargeoption = new ChargeCreateOptions { Amount = 45000, Currency = "INR", ReceiptEmail = "*****@*****.**", Customer = cust.Id, Source = source.Id }; // step 6: charge the customer var chargeService = new ChargeService(); Charge charge = chargeService.Create(chargeoption); if (charge.Status == "succeeded") { // success } else { // failed } }
public PaymentView(DateTime bookingDate, string centerName, string sportName, string courtName, string startingBookingTime, string endingBookingTime, double TotalPaymentAmount) { InitializeComponent(); //startingBookingTime AND endingBookingTime are TimeSpan not DateTime ...... Done var uname = Preferences.Get("UserName", String.Empty); if (String.IsNullOrEmpty(uname)) { username.Text = "Guest"; } else { username.Text = uname; } centername.Text = centerName; courtname.Text = courtName; //bookingdate.Text = bookingDate.Date.ToString(); cvm = new PaymentViewModel(bookingDate); this.BindingContext = cvm; bookingtime.Text = startingBookingTime.ToString() + " - " + endingBookingTime.ToString(); double RoundedTotalPaymentAmount = Math.Round(TotalPaymentAmount, 1, MidpointRounding.ToEven); totalpaymentamount.Text = "RM " + RoundedTotalPaymentAmount.ToString(); string totalp = totalpaymentamount.Text; DateTime s = Convert.ToDateTime(startingBookingTime); DateTime d = Convert.ToDateTime(endingBookingTime); NewEventHandler.Clicked += async(sender, args) => { // if check payment from Moustafa is true, then add booking to firebase try { //StripeConfiguration.SetApiKey("sk_test_51IpayhGP2IgUXM55te5JbGRu14MOp6AU6GORVFhqpOilEOp96ERDzKCi1VN9rDLrOmOEwNPqgOvQuIyaNg8YKfkL00Qoq8a7QX"); StripeConfiguration.SetApiKey("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"); //This are the sample test data use MVVM bindings to send data to the ViewModel Stripe.TokenCardOptions stripcard = new Stripe.TokenCardOptions(); stripcard.Number = cardnumber.Text; stripcard.ExpYear = Int64.Parse(expiryYear.Text); stripcard.ExpMonth = Int64.Parse(expirymonth.Text); stripcard.Cvc = cvv.Text; //stripcard.Cvc = Int64.Parse(cvv.Text); //Step 1 : Assign Card to Token Object and create Token Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions(); token.Card = stripcard; Stripe.TokenService serviceToken = new Stripe.TokenService(); Stripe.Token newToken = serviceToken.Create(token); // Step 2 : Assign Token to the Source var options = new SourceCreateOptions { Type = SourceType.Card, Currency = "myr", Token = newToken.Id }; var service = new SourceService(); Source source = service.Create(options); //Step 3 : Now generate the customer who is doing the payment Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions() { Name = "Moustafa", Email = "*****@*****.**", Description = "Customer for [email protected]", }; var customerService = new Stripe.CustomerService(); Stripe.Customer stripeCustomer = customerService.Create(myCustomer); mycustomer = stripeCustomer.Id; // Not needed //Step 4 : Now Create Charge Options for the customer. var chargeoptions = new Stripe.ChargeCreateOptions { //Amount = (Int64.Parse(RoundedTotalPaymentAmount)) * 100, //(int(RoundedTotalPaymentAmount)) //Amount = Convert.ToInt32(RoundedTotalPaymentAmount) * 100, //Amount = (long?)(double.Parse(RoundedTotalPaymentAmount) * 100), Amount = (long?)(double.Parse(totalp) * 100), Currency = "MYR", ReceiptEmail = "*****@*****.**", Customer = stripeCustomer.Id, Source = source.Id }; //Step 5 : Perform the payment by Charging the customer with the payment. var service1 = new Stripe.ChargeService(); Stripe.Charge charge = service1.Create(chargeoptions); // This will do the Payment getchargedID = charge.Id; // Not needed } catch (Exception ex) { UserDialogs.Instance.Alert(ex.Message, null, "ok"); Console.Write("error" + ex.Message); //await Application.Current.MainPage.DisplayAlert("error ", ex.Message, "OK"); } finally { //if (getchargedID != null) if (getchargedID != null) { var acd = new AddBookingData(sportName, courtName, username.Text, centerName, s, d, bookingDate, RoundedTotalPaymentAmount); await acd.AddBookingDataAsync(); UserDialogs.Instance.Alert("Payment Successed", "Success", "Ok"); Xamarin.Forms.Application.Current.MainPage = new MainTabbedView(); //await Application.Current.MainPage.DisplayAlert("Payment Successed ", "Success", "OK"); } else { UserDialogs.Instance.Alert("Something Wrong", "Faild", "OK"); //await Application.Current.MainPage.DisplayAlert("Payment Error ", "faild", "OK"); } } /* * var acd = new AddBookingData(sportName, courtName, username.Text, centerName, s, d, bookingDate, RoundedTotalPaymentAmount); * await acd.AddBookingDataAsync(); * /* * * * //Application.Current.MainPage = new MainTabbedView(); * * //await Navigation.PopModalAsync(); * //await Navigation.PopToRootAsync(); * /* * Navigation.InsertPageBefore(new NewPage(), Navigation.NavigationStack[0]); * await Navigation.PopToRootAsync(); */ }; /* * public void GetCustomerInformationID(object sender, EventArgs e) * { * var service = new CustomerService(); * var customer = service.Get(mycustomer); * var serializedCustomer = JsonConvert.SerializeObject(customer); * // var UserDetails = JsonConvert.DeserializeObject<CustomerRetriveModel>(serializedCustomer); * * } * * * public void GetAllCustomerInformation(object sender, EventArgs e) * { * var service = new CustomerService(); * var options = new CustomerListOptions * { * Limit = 3, * }; * var customers = service.List(options); * var serializedCustomer = JsonConvert.SerializeObject(customers); * } * * * public void GetRefundForSpecificTransaction(object sender, EventArgs e) * { * var refundService = new RefundService(); * var refundOptions = new RefundCreateOptions * { * Charge = getchargedID, * }; * Refund refund = refundService.Create(refundOptions); * refundID = refund.Id; * } * * * public void GetRefundInformation(object sender, EventArgs e) * { * var service = new RefundService(); * var refund = service.Get(refundID); * var serializedCustomer = JsonConvert.SerializeObject(refund); * * } */ /* * * async Task NewEventHandler(object sender, EventArgs e) * { * // if check payment from Moustafa is true, then * * // add booking to firebase * * var acd = new AddBookingData(sportName, courtName, username.Text, centerName, s, d, bookingDate, TotalPaymentAmount); * await acd.AddBookingDataAsync(); * } */ }
public bool Pay( string CardNo, int ExpiredYear, int ExpiredMonth, string CVV, decimal amount, string currency, string receiptEmail = "", string description = "") { try { TokenCreateOptions stripeCard = new TokenCreateOptions { Card = new TokenCardOptions { Number = CardNo, ExpMonth = Convert.ToInt64(ExpiredMonth), ExpYear = Convert.ToInt64(ExpiredYear), Cvc = CVV, }, }; TokenService service = new TokenService(); Token newToken = service.Create(stripeCard); var cardOption = new SourceCreateOptions { Type = SourceType.Card, Currency = currency, Token = newToken.Id }; var sourceService = new SourceService(); Source source = sourceService.Create(cardOption); /* * CustomerCreateOptions customerInfo = new CustomerCreateOptions * { * Name = "SP Tutorial", * Email = stripeEmail, * Description = "Paying 10 Rs", * Address = new AddressOptions { * City = "Kolkata", * Country = "India", * Line1 = "Sample Address", * Line2 = "Sample Address 2", * PostalCode = "700030", * State = "WB" * } * }; * * //var customerService = new CustomerService(); * //var customer = customerService.Create(customerInfo); */ var chargeoption = new ChargeCreateOptions { Amount = Convert.ToInt32(amount * 100), Currency = currency, Description = description, ReceiptEmail = receiptEmail, Source = source.Id }; var chargeService = new ChargeService(); Charge charge = chargeService.Create(chargeoption); if (charge.Status == "succeeded") { return(true); } else { return(false); } } catch (Exception e) { Console.WriteLine(e); return(false); } }