// GET: StripeAPI public ActionResult Charge(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 = 500, // Description = "Sample Charge", // Currency = "usd", // CustomerId = customer.Id //}); string apiKey = "sk_test_au9OvT8hhccPg1LdlKZ3nYX6"; var stripeClient = new Stripe.StripeClient(apiKey); dynamic response = stripeClient.CreateChargeWithToken(2500, stripeToken, "GBP", stripeEmail); if (response.IsError == false && response.Paid) { // success } return(View()); }
public BillingProcessorResult Charge(string ForeignCustomerID, decimal Amount, string Reason=null) { StripeClient client = new StripeClient("LB3kUwdhiUlPlNl1UYW52NLn4q88QsFT"); dynamic resp=client.CreateCharge(Amount, "usd", ForeignCustomerID, Reason); BillingProcessorResult result = new BillingProcessorResult(); result.ForeignTransactionID = resp.id; if (resp.Paid) result.Result = BillingProcessorResult.BillingProcessorResultCode.Paid; else result.Result = BillingProcessorResult.BillingProcessorResultCode.Declined; return result; }
public static void Main() { var apiKey = "Your API Key"; // can be found here https://manage.stripe.com/#account/apikeys var api = new StripeClient(apiKey); // you can learn more about the api here https://stripe.com/docs/api var card = new CreditCard { Number = "4111111111111111", ExpMonth = 3, ExpYear = 2015 }; dynamic response = api.CreateCharge( amount: 10000, // $100 currency: "usd", card: card); if (response.Paid) Console.WriteLine("Whoo Hoo... We made our first sale!"); else Console.WriteLine("Payment failed. :("); Console.Read(); }
public ActionResult BillingOnboard(OnboardToken token) { OnboardToken retrievedToken = RepoFactory.GetOnboardTokenRepo().Get(token.VerificationString); Customer cust = RepoFactory.GetCustomerRepo().GetWithID(retrievedToken.CustomerID); // hardcode stripe for now, sucka StripeClient client = new StripeClient("LB3kUwdhiUlPlNl1UYW52NLn4q88QsFT"); Stripe.CreditCardToken ccToken = new Stripe.CreditCardToken(token.BillingID); var stripeCustomer = client.CreateCustomer(ccToken, email: cust.EmailAddress); cust.BillingType = (int)BillingSystem.BillingProcessorFactory.SupportedBillingProcessor.Stripe; cust.BillingID = stripeCustomer.GetProperty("ID").ToString(); RepoFactory.GetCustomerRepo().Update(cust); CustomerController.CustomerSignupResult result = new CustomerController.CustomerSignupResult(); result.Result = CustomerController.CustomerSignupResult.ResultCode.Success; result.Customer = cust; if (retrievedToken.ChallengeID != 0) { Security s = new Security(); Authorization a=s.AuthorizeCustomer(new Login { EmailAddress = cust.EmailAddress, Password = cust.Password }); return Redirect("http://dareme.to/authorize?id="+a.CustomerID.ToString()+"&session_token="+a.Token+"&dare=" + retrievedToken.ChallengeID.ToString()); } else { return View("SignupComplete", result); } }
/// <summary> /// Returns a JavaScript function call getter that opens a Stripe Checkout modal window. If the window's submit button is clicked, the credit card is /// charged or otherwise used. Do not execute the getter before all controls have IDs. /// </summary> /// <param name="etherealControlParent">The control to which any necessary ethereal controls will be added.</param> /// <param name="testPublishableKey">Your test publishable API key. Will be used in non-live installations. Do not pass null.</param> /// <param name="livePublishableKey">Your live publishable API key. Will be used in live installations. Do not pass null.</param> /// <param name="name">See https://stripe.com/docs/checkout. Do not pass null.</param> /// <param name="description">See https://stripe.com/docs/checkout. Do not pass null.</param> /// <param name="amountInDollars">See https://stripe.com/docs/checkout, but note that this parameter is in dollars, not cents</param> /// <param name="testSecretKey">Your test secret API key. Will be used in non-live installations. Do not pass null.</param> /// <param name="liveSecretKey">Your live secret API key. Will be used in live installations. Do not pass null.</param> /// <param name="successHandler">A method that executes if the credit-card submission is successful. The first parameter is the charge ID and the second /// parameter is the amount of the charge, in dollars.</param> /// <param name="prefilledEmailAddressOverride">By default, the email will be prefilled with AppTools.User.Email if AppTools.User is not null. You can /// override this with either a specified email address (if user is paying on behalf of someone else) or the empty string (to force the user to type in the /// email address).</param> public static Func<string> GetCreditCardCollectionJsFunctionCall( Control etherealControlParent, string testPublishableKey, string livePublishableKey, string name, string description, decimal? amountInDollars, string testSecretKey, string liveSecretKey, Func<string, decimal, StatusMessageAndDestination> successHandler, string prefilledEmailAddressOverride = null) { if( !EwfApp.Instance.RequestIsSecure( HttpContext.Current.Request ) ) throw new ApplicationException( "Credit-card collection can only be done from secure pages." ); EwfPage.Instance.ClientScript.RegisterClientScriptInclude( typeof( PaymentProcessingStatics ), "Stripe Checkout", "https://checkout.stripe.com/v2/checkout.js" ); if( amountInDollars.HasValue && amountInDollars.Value.DollarValueHasFractionalCents() ) throw new ApplicationException( "Amount must not include fractional cents." ); ResourceInfo successDestination = null; var postBack = PostBack.CreateFull( id: PostBack.GetCompositeId( "ewfCreditCardCollection", description ), actionGetter: () => new PostBackAction( successDestination ) ); var token = new DataValue<string>(); Func<PostBackValueDictionary, string> tokenHiddenFieldValueGetter; // unused Func<string> tokenHiddenFieldClientIdGetter; EwfHiddenField.Create( etherealControlParent, "", postBackValue => token.Value = postBackValue, postBack, out tokenHiddenFieldValueGetter, out tokenHiddenFieldClientIdGetter ); postBack.AddModificationMethod( () => { // We can add support later for customer creation, subscriptions, etc. as needs arise. if( !amountInDollars.HasValue ) throw new ApplicationException( "Only simple charges are supported at this time." ); var apiKey = ConfigurationStatics.IsLiveInstallation ? liveSecretKey : testSecretKey; dynamic response = new StripeClient( apiKey ).CreateCharge( amountInDollars.Value, "usd", new CreditCardToken( token.Value ), description: description.Any() ? description : null ); if( response.IsError ) { if( response.error.type == "card_error" ) throw new DataModificationException( response.error.message ); throw new ApplicationException( "Stripe error: " + response ); } try { var messageAndDestination = successHandler( (string)response.id, amountInDollars.Value ); if( messageAndDestination.Message.Any() ) EwfPage.AddStatusMessage( StatusMessageType.Info, messageAndDestination.Message ); successDestination = messageAndDestination.Destination; } catch( Exception e ) { throw new ApplicationException( "An exception occurred after a credit card was charged.", e ); } } ); EwfPage.Instance.AddPostBack( postBack ); return () => { var jsTokenHandler = "function( res ) { $( '#" + tokenHiddenFieldClientIdGetter() + "' ).val( res.id ); " + PostBackButton.GetPostBackScript( postBack, includeReturnFalse: false ) + "; }"; return "StripeCheckout.open( { key: '" + ( ConfigurationStatics.IsLiveInstallation ? livePublishableKey : testPublishableKey ) + "', name: '" + name + "', description: '" + description + "', " + ( amountInDollars.HasValue ? "amount: " + amountInDollars.Value * 100 + ", " : "" ) + "token: " + jsTokenHandler + ", email: '" + ( prefilledEmailAddressOverride ?? ( AppTools.User == null ? "" : AppTools.User.Email ) ) + "' } )"; }; }