Im very new to programing and new to stripe. i am currently trying to create a basic page where i can just create the customers. Im currently using the stripe.net dll and am having a hard time getting this page to work correctly. Here is what i have. I get no errors and no records get created.
Using Stripe;
private StripeCustomer GetCustomer()
{
var mycust = new StripeCustomerCreateOptions();
mycust.Email = "thisisit#overhere.com";
mycust.Description = "One Time";
mycust.CardName = "Full Name";
var customerservice = new StripeCustomerService(System.Web.Configuration.WebConfigurationManager.AppSettings["StripeApiKey"]);
return customerservice.Create(mycust);
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
StripeCustomer current = GetCustomer();
var mycharge = new StripeChargeCreateOptions();
string key = System.Web.Configuration.WebConfigurationManager.AppSettings["StripeApiKey"];
Response.Redirect("/services/donate/thanks.aspx");
}
catch (StripeException ex)
{
//lblerror.Text = (ex.Message);
}
}
Also a little help (as i am lost an nothing i try works) as to how i would go about pulling a list of the current customs i have and display them would be great.
I'm guessing you're using this: https://github.com/jaymedavis/stripe.net#list-all-customers
In your GetCustomer method you are creating a customer, instead, you want to do something like the following:
private IEnumerable<StripeCustomer> GetCustomers()
{
var customerservice = new StripeCustomerService(System.Web.Configuration.WebConfigurationManager.AppSettings["StripeApiKey"]);
return customerservice.List();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
StripeCustomer list = GetCustomers();
//show this list somewhere
}
catch (StripeException ex)
{
//lblerror.Text = (ex.Message);
}
}
Makre sure StripeApiKey exists in your configuration file.
Related
Error: Invalid column name 'Id'.'
I've been trying to make an update function, the logic behind it I think is fine, but it keeps throwing me this error mentioned above.
internal static void Uredi(Zahtjev odabraniZapis)
{
DB.OpenConnection();
string sql = $"UPDATE Zahtjev_za_nabavu SET Ponuda = '{odabraniZapis.Ponuda}', Opis_predmeta = '{odabraniZapis.Opis_predmeta}', Cijena = '{odabraniZapis.Cijena}', ID_zaposlenika = {odabraniZapis.ID_zaposlenika} WHERE ID_zahtjeva = {odabraniZapis.ID_zahtjeva};";
DB.ExecuteCommand(sql);
DB.CloseConnection();
}
This above is the function that I call to Update existing data.
I get the row that i want to change through ID_zahtjeva .
And this is the function that calls the UPDATE function.
private void btnAzuriraj_Click(object sender, EventArgs e)
{
Zahtjev noviZahtjev = new Zahtjev(int.Parse(txtZahtjev.Text), txtPonuda.Text, txtOpis.Text, txtCijena.Text, int.Parse(txtZaposlenik.Text));
var provjera = ZahtjeviRepository.GetZahtjevi(noviZahtjev.ID_zahtjeva);
if(provjera == null)
{
ZahtjeviRepository.Kreiraj(noviZahtjev);
this.Close();
}
else
{
ZahtjeviRepository.Uredi(noviZahtjev);
this.Close();
}
}
I have an app I'm building for automating the process of creating media kits when promoting a show or local event and I've hit something weird.
In my application, I have two web forms ~/KitInfo.aspx and ~/Photo.aspx.
In my ~\App_Start\RouteConfig.cs I have the following boiler plate code.
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
}
}
In my Global.asax.cs I have the following routes registered:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// Add Custom Routes
RegisterCustomRoutes(RouteTable.Routes);
}
private void RegisterCustomRoutes(RouteCollection routes)
{
routes.MapPageRoute("MediaKitInforRoute", "Kit/{show}", "~/KitInfo.aspx");
routes.MapPageRoute("PhotoRoute", "Photo/{show}/{photo}/{medium}/{size}/{download}", "~/Photo.aspx");
}
I have a utility method for accessing the route data values:
public static T GetRouteData<T>(string segmentName, T defaultValue)
{
var result = defaultValue;
try
{
var textValue = HttpContext.Current.Request.RequestContext.RouteData.Values[segmentName].ToString();
result = (T)Convert.ChangeType(textValue, typeof(T));
}
catch (Exception)
{
// Do nothing
}
return result;
}
KitInfo.aspx.cs has the following code:
protected void Page_Load(object sender, EventArgs e)
{
var show = Utility.GetRouteData("show", string.Empty);
var path = Server.MapPath("~/KitArchives/" + show);
var kitPath = Path.Combine(path, show + ".kit");
var kit = Kit.Load(kitPath);
KitName.Text = kit.ShowTitle;
}
Photo.aspx.cs has this code in the Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
var show = Utility.GetRouteData("show", string.Empty);
var photo = Utility.GetRouteData("photo", string.Empty);
var medium = Utility.GetRouteData("medium", string.Empty);
var maxSize = Utility.GetRouteData("size", -1);
var download = Utility.GetRouteData("download", 1);
if (show.Length == 0)
{
SendImageNotFound();
return;
}
Navigating to http://mediakits.server.com/kit/queen, the page will successfully load the media kit for the show value of queen. Any other value will fail with expected results as the queen show is my test kit.
Navigating to http://mediakits.server.com/Photo/queen/ShowPoster/print/900/0 fails because all of the route data is empty and Utility.GetRouteData("show", string.Empty) returns the default value of string.Empty, tripping that error check.
I'm baffled as to why it would work on one page and not the other. Do you have any thoughts?
In a Windows Runtime app, I load data like this:
private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
var userId = e.NavigationParameter as string;
List<User> followers = GetFollowers(userId);
this.DefaultViewModel["Followers"] = followers;
}
then user can select an item from ListView:
private void ContentListView_ItemClick(object sender, ItemClickEventArgs e)
{
var selectedItem = e.ClickedItem as User;
if (!Frame.Navigate(typeof(FollowersPage), selectedItem.UserId))
{
throw new Exception(this.resourceLoader.GetString("NavigationFailedExceptionMessage"));
}
}
So it navigates forward to the same page, but shows new followers.
The problem is that when it navigates back, it loads data again and shows from the beginning of the list rather than showing the last item selected.
So how to save a List of data in NavigationHelper_SaveState and how to load it again in NavigationHelper_LoadState with last position in the list? thanks.
Here's a basic semi-tested example you can start from. You'll need to modify it to fit your exact circumstances. Some of it is adapted from here.
void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
var isp = (ItemsStackPanel)listview.ItemsPanelRoot;
int firstVisibleItem = isp.FirstVisibleIndex;
e.PageState["FirstVisibleItemIndex"] = firstVisibleItem;
// This must be serializable according to the SuspensionManager
e.PageState["Followers"] = this.DefaultViewModel["Followers"];
}
void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
// Do we have saved state to restore?
if (e.PageState != null)
{
// Restore list view items
this.DefaultViewModel["Followers"] = (WhateverType)e.PageState["Followers"];
// Restore scroll offset
var index = (int)e.PageState["FirstVisibleItemIndex"];
var container = listview.ContainerFromIndex(index);
listview.ScrollIntoView(container);
}
else
{
// Load data for the first time
var userId = e.NavigationParameter as string;
List<User> followers = GetFollowers(userId);
this.DefaultViewModel["Followers"] = followers;
}
}
First off, I'm on a Win7 laptop using Chrome in my IE.
I can store the data I have with a session variable but cannot get it to work with a cookie.
I attempt to set the cookie in a button click event and then attempt to read it in a textChanged event. I can see the cookie object get populated in the IE but it never seems to actually get created when I look for it with chrome://settings/cookies.
Here is my code:
protected void btnSubmitQuery_Click(object sender, EventArgs e)
{
List<string> geometryList = new List<string>();
try
{
using (SqlConnection conn = new SqlConnection(this.SqlQri.ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(this.tbxSQLQri.Text, conn))
{
object result = cmd.ExecuteScalar();
Session["polys"] = result.ToString();
HttpCookie myPolys = new HttpCookie("polys"); // This seems to work
myPolys.Value = result.ToString();
myPolys.Expires = DateTime.Now.AddDays(1);
Response.SetCookie(myPolys);
}
conn.Close();
}
}
catch (SqlException ex)
{
this.tbxSQLQri.Text = "Query Exception";
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
// Read Session val
string looky = (string)(Session["polys"]);
this.TextBox1.Text = looky;
string lookyHere = "";
if (HttpContext.Current.Request.Cookies["polys"] != null) // This is never true!
{
lookyHere = Request.Cookies["polys"].Value;
}
this.TextBox2.Text = lookyHere;
}
I declare a Private constant string with the name as follows
private const string cnstLoginCookieName = "Super-User";
inside of my Page_load I have the following declared
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie objCookie = new HttpCookie(cnstLoginCookieName);
objCookie.Values["Login"] = username.Trim();
objCookie.Values["Company"] = "CoolFirm";
objCookie.Expires = DateTime.MaxValue;
Response.Cookies.Add(objCookie);
}
OK, This part of my problem was solved. My string was too long to go in a cookie.
POLYGON ((-122.143636 47.257808, -122.143685 47.257807, -122.143877 47.257802, -122.143993 47.257799, -122.143989 47.257746,
If I changed the value to "hello world" the cookie was successful.
Thank you for your help on this.
Having a lot of trouble with this. I'm working on a large project, so there's only a few classes I'm interested in and working on. Basically, these are forms - one is a main editor where a user edits details and the other is used to assign a pin number. In the main editor form, if the user has a pin, they can choose to edit this pin. Here's where my problem lies - if I edit the pin, what I'm doing in the code is deleting the old pin and adding the new one. However, the database doesn't update until AFTER the editor form is closed. Therefore, I'd like to call the method that does change the database on the OKButton click, if I could. The problem I'm facing is I don't know how.
Here is the DB code, we'll say the class is called DetailsConn:
public string editPin(int driverID)
{
if (SchemaChecker.PINAvailable())
{
string sql = "EditPIN";
using (SqlCommand cmd = new SqlCommand(sql, base.connection))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Remove("#nDriverID");
cmd.Parameters.AddWithValue("#nDriverID", driverID);
cmd.Parameters.Remove("#nPIN");
SqlParameter pinParameter = cmd.Parameters.Add("#nPIN", SqlDbType.Char);
pinParameter.Direction = ParameterDirection.Output;
pinParameter.Size = 32;
cmd.ExecuteNonQuery();
return pinParameter.Value.ToString();
}
}
return "";
}
Here's the code for my edit:
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.listViewDriverTags.SelectedItems.Count > 0)
{
ListViewItem lvi = this.listViewDriverTags.SelectedItems[0];
DriverTag driverTag = lvi.Tag as DriverTag;
else if (blahTag.blahType == 2)
{
buttonAssignPIN_Click(sender, e);
}
//message stuff and dialog boxes with localization info
if (dr == DialogResult.Yes)
{
this.listViewDriverTags.Items.Remove(lvi);
if (Tag.id != -1)
{
TagsToBeDeleted.Add(driverTag);
}
}
if (dr == DialogResult.No)
{
this.listViewTags.Items.Clear();
this.listViewTags.Items.Add(lvi);
}
}
}
Here's my buttonAssignPIN stuff:
private void buttonAssignPIN_Click(object sender, EventArgs e)
{
using (AssignPINForm form = new AssignPINForm())
{
if (form.ShowDialog(this) == DialogResult.OK)
{
DriverTag PIN = DriverTag.GetNewPIN(form.DriverTag);
ListViewItem lvi = this.listViewTags.Items.Add(PIN.driverTag);
lvi.SubItems.Add(this.TagTypes[PIN.TagType]);
lvi.Tag = PIN;
}
}
}
And finally, here's my AssignPINForm code:
public partial class AssignPINForm : Form
{
public AssignPINForm()
{
InitializeComponent();
this.buttonOK.Click += new EventHandler(buttonOK_Click);
this.buttonCancel.Click += new EventHandler(buttonCancel_Click);
this.buttonOK.Enabled = false;
this.textBoxPin.TextChanged += delegate(object sender, EventArgs e)
{
String pattern = #"^[0-9]{4,20}$";
Regex regex = new Regex(pattern);
buttonOK.Enabled = regex.IsMatch(textBoxPin.Text);
};
LoadStrings();
}
public void LoadStrings()
{
//stome stuff
}
public string DriverTag
{
get { return this.textBoxPin.Text; }
set { this.textBoxPin.Text = value; }
}
private void buttonOK_Click(object sender, EventArgs e)
{
}
private void buttonCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void AssignPINForm_Load(object sender, EventArgs e)
{
}
}
I know it's kind of all over the place but I've provided everything I think is relevant. The middle two snippets are in the same class too, and the DB stuff is the same solution but a different project. I'd be grateful if someone can decipher what I'm after and help me out, it's the only thing I have left to do on this particular bit!
Thanks!
Not sure I fully got what you're after and I agree with some of the comments that this isn't the best of practice but I guess what you're after is to update the buttonOK_Click method to something like this:
private void buttonOK_Click(object sender, EventArgs e)
{
using(DetailsConn connection = new DetailsConn())
{
int driver = -1;
if(int.TryParse(this.DriverTag, out driver)) {
connection.editPin(driver);
}
}
}
Also, you may want to remove any other possible references to the editPin() function.
I actually figured out that even if I got that working correctly, it wasn't going to solve my problem. I've had to call a new procedure and declare that in the database schema - basically it was a lot more complicated than what I was giving it credit for. Thanks for the responses nonetheless.