Stripe Simple Checkout integration with cancel button - c#

I am trying to integrate Stripe with my website with "Simple" checkout as described at https://stripe.com/docs/checkout . I have created a summary page on which I have added script tag. This shows the Pay With Card and it works fine.
However, I need a "Cancel" or "Back" button on this summary page so as to give user chance to go back to previous page or cancel online booking. But even when this other button is clicked, the Payment pop-up is opened and it is not raising the back button event.
What am I missing? Why even other buttons are hijacked by Stripe JS. Please help.

Simple Checkout allows the user to enter their credit card, then creates a token, then immediately submits the <form></form> which encloses it. If you need more customizability than that, you'll need to use the Custom Checkout integration.
With the Custom integration, the user is presented with Checkout, Stripe generates a token, then it is up to you to decide what to do next --- you could write JS in the token creation callback to append a hidden field with the token and then immediately submit the form, or you could land the user back on your summary page and wait for the user to give an additional confirmation before submitting your form, or 'go back.'
var handler = StripeCheckout.configure({
key: 'pk_test_xxxyyyyzz',
token: function(token) {
// You can access the token ID with `token.id`.
// Do something with that token (append a hidden input + submit the form?)
}
});

Related

How to invoke HTTP PUT from URL?

Scenario:-
I have a form, once user submits this form, a mail is sent to user.
As usual an activation link is present in the mail body.
And if the user click on the Link, he is redirected to the page,now on visit of the url, I want to update the field in my DB table :-
isEmailVerfied to true
DateOfVerification
I am using WebAPI and HTTPPUT action to update the database.
ControllerName is Registration, I don't want the user to click on any extra button to update, I want if the user visits the url, HTTPPut(or update) operation should be called and that links to be invalid, once user clicked.
I'm assuming the flow of actions in this scenario is something like this:
User fills out a form on a webpage
User submits form to your web api backend
The backend saves the data submitted from the form
The backend sends out an email containing a link to your application
User reads email and clicks on the link
And you want the action in step 5 here to trigger some other action in your backend, which is to update some data in your database which you have already implemented and have exposed as as a http PUT method in your api.
The problem is that clicking on a link from an email that opens up in a browser is that you cannot specify the http method. Navigating to URLs in a browser, which is what you are doing, is a GET request. So your PUT action will never get hit.
To resolve this you can just change your action from PUT to GET.
change this:
[HttpPut]
[Route("verify/{hash}")
public void VerifyEmail(string hash){
// your implementation logic
}
to this:
[HttpGet]
[Route("verify/{hash}")
public void VerifyEmail(string hash){
// your implementation logic
}

Browser Back Button issue in asp.net

I have registration form, suppose there are 5 fields, and all are required i.e. mandatory.
My problem is that when user login & fill 2 fields of that registration form & click browser back button, then I want to restrict user to same form & Show requiredField Validator messages of incomplete fields. So How can I fire Validation on browser back button & restrict user on same form.
You cannot affect browser behavior when the user clicks the Back button.
The correct solution is to check right after user have been login, if he has complete the registration entries on database, and if not you redirect him to fill that data.
From your comments, to alert them a solution is to capture the onbeforeunload and check there if they have fill out everything or not, show your message.
Simple example, you just need here to place your conditions.
window.onbeforeunload = function() {
return 'You have unsaved changes!';
}
You can't disable the back button (see the other answers and their comments).
What you can do is check on every page whether the user is logged in. If not, redirect him to your login page. This way the user can't access the site without logging in, which I guess is what your client is really after.

Refresh after postback causes the same data to be sent again

I have a form to edit employee information. If the user wishes to enter a new e-mail address for the selected employee, there is a textbox and a button that says "Add Email Address." Very simple, you enter the e-mail address, click Add Email Address. It postsback and that button's event handler executes the INSERT to the database.
The problem:
If you press F5 to refresh the page after that postback, it causes the same postback to occur, even if the textbox is blank. In other words, for every time you hit F5, the actions in the event handler for that Add Email Address button occur again. If I hit F5 ten times, the same e-mail address shows up in the database ten times.
One suggestion I found said, "just re-direct to the same page after you apply your changes." The reason this is not ideal in our case is that it's a rather lengthy form of employee data --- if the user makes a bunch of changes to the overall form (such as FirstName, LastName, etc.), then makes an e-mail addition before applying the changes elsewhere, those changes elsewhere would be lost if we re-directed to the same page.
The very long winded solution I can think of is, capture all of the data in ViewState, carry it across the re-direct to the same page, then use a query string in the URL to determine if we want to fill in the data from ViewState. Before I embark on that path, I'm hoping that instead of that, there is some method I just don't know that says like, PostbackButDontRetainPostbackData() (wishful thinking, I know).
In the handler for that Add Email Address button check if the email already exists in the database. If it does, do not add the email again and display an appropriate message to the user. Usually forms have a reserved area like a hidden div for this purpose so in case anything goes wrong the div will be populated with error messages and displayed to the user.
Also, it would help to display a confirmation message to the user when their data is successfully received and processed.
UPDATE
If you don't like to show any messages to the user, simply do nothing after you find out that the email already exists in the database. e.g.:
public void AddEmailToDB(string email)
{
// first find out if the email already exists in the database
bool isDuplicate = ...;
// if it does, simply return and do nothing
if(isDuplicate) return;
// if control reaches here then the email is not
// a duplicate and you can do your normal processing
}
UPDATE II
If you don't want the browsers to show a messagebox everytime a user presses F5 after a postback, you can do a partial postback using AJAX by wrapping your email textbox and add button in an UpdatePanel, it's very easy to use.

Identify sender in http module

I am developing a page tracker app where i need the login time,log out time ,session id,logged in user and each page accessed by user,time spent on that page and the list of event's in a page that are fired when controls are clicked,checked or selected.i dont want to use google analytics
For now i am accessing all the details by writing session start etc in http modules and everything is achieved.i am storing all the data in a hashtable and throwing them into db when logout is clicked or session time's out.i am struck on how to identify if logout button is pressed .
i can directely write the piece of code for inserting the statistics on the click of logout button itself but i dont want to do so as i want to capture the logout button id or text in http modules and then write the logic in http module.i tried to capture the sender but it's throwing an error by referring the asax reference instead of button reference
how can i acheieve this(track which button is clicked on a page and get the id in http module because the http module triggers for every postback or load)?
You could use your HttpContext.Request.Form object. It contains Key "__EVENTTARGET", which value equals to ID of object that sends POST to Server.

asp:CreateUserWizard Redirecting After Complete

I have an asp registration page using a custom asp:CreateUserWizard.
Once the registration is completed successfully (RegisterUser_CreatedUser for example) I want to redirect the user to another page, be it a welcome screen, etc... (using Response.Redirect(URL); I guess), but I also want to, some how, popup a new window with the login page.
Is it possible to popup a screen from an external url using this method, or is there another way I should go about it?
I did try creating a custom button which calls this js function for registration:
function redirectAfterRegister() {
Page_ClientValidate();
if (Page_IsValid) {
window.open('/Account/Login.aspx?UserCreated=True');
$('#CreateUserButton').click();
}
return false;
}
This popup works because its called off a click, but the problem with this is the popup is always called even if the creation of the user was unsuccessful - which is wrong.
Any help is highly appreciated.
The problem is that popups only work when a user actually clicks in external sites. This prevents spammers from popping up ads all the time. Once another function is called after the click it is considered unfriendly and therefore to allowed externally.
I think it best to let the user know the registration was successful and give them navigation options from there. If anything, at least its user friendly that way, without confusion.
The asp:CompleteWizardStep can be used to redirect after successful registration, and provide extra navigation where needed.
Good Luck, and let me know if you find an alternate solution.
Why not use the CreateUserWizard.ContinueDestinationPageUrl property to go to your welcome page. You can then place your javascript to open a new window in the onload event of the Body element.

Categories

Resources