#Magic Mage
1 messages · Page 1 of 1 (latest)
Ok, so what are you seeing happen? Are they any errors in your developer console you can share?
Nope, it just seems like it refuses to run the submit code in the js.
when I press on the button labeled Subscripe
the other "button" seems to work however.
Are you sure you're triggering a form submit?
Your subscribeBtn element is just an a, not a button
so might not be triggering the form submit youre expecting
Instead you could add an event listener for click on the a/subscribeBtn
hmm or this might be the only way:
That's another option, sure
Welp I have committed that fix now: now to debug it.
oh cool
it might be the redirect url
as I want to make it redirect to the homepage.
from that to https://localhost:44372/
You should be able to set the return_url as you need it
yeah, I tried that, but it seems to not like the fact that I set it to '/'
Can you show your code?
sure, it should be on the server side part of it.
Oh, right: return_url: "/"
You need a valid complete url there
not a relative path
return_url: "https://example.com/"
Is it ok if I leave in the just the price id's and the product ids? I scrubbed from it the api keys and secrets though.
so there is no way of getting the actual base url then in case of localhost / on the college issued webserver?
oh wait it was in the js part of the application.
Well you could control that in your code based on an environment variable etc
if live mode, use real URL, if test mode use local host
I mean that could help with the possibility that the debug build will need to be pushed to the webserver now because the account I made for it only allows for test mode only (plus the project is technically in testing right now anyways there).
Since its client side code you can also look at the URL/hostname and reflect that
hmm could
not sure if window.location.origin could help with this 🤔 especially when the "live" page is something like http://dotnet.<college name>.edu/<capstone project name>/ (yes they do not have https enabled for our pages yet).
yeah, hence why I would need use it in test mode there too with debug builds only so we got to push the debug builds or it there too.
Hi there 👋 taking over, as my colleague needs to step away
It sounds like the resolution is: you must find a way for your local host to serve over HTTPS. Your live mode website would also need to server over HTTPS. Are there any outstanding questions that I'm missing?
I will ask my instructor if they can enable https for us.
Apologies, I forgot that HTTP is okay for test mode (instead of HTTPS), but you would still need to not use a relative URL, so you need some mechanism or system that exposes your localhost to the internet and has a non-relative URL
// handle webserver version and localhost version.
const url = (window.location.hostname == '127.0.0.1' || window.location.hostname == 'localhost')
? window.location.origin + '/' : window.location.origin + '/<project name>/';
I have modified the js code to basically assign the url to a variable and then have the submit event use said variable when doing the payment confirmation.
it worked lol
nice
Right on!
Also I tested with the 42 card.
oh no
it keeps failing to post to the webhook.
🤔
But now I know that there is only about a few events to worry about customer.subscription.updated, customer.subscription.deleted, customer.subscription.paused, and customer.subscription.resumed the created one can technically be ignored but I think there are cases where it is instantly in paid status?
Yeah, you could listen for invoice.paid in that case
yeah, I guess so.
But now need to figure out why the webhook is failing locally with Failed to POST: Post "http://localhost:44372/webhook": read tcp [::1]:13507->[::1]:44372: wsarecv: An existing connection was forcibly closed by the remote host.
I guess I could skip the webhook though and on the root page redirect have it check the subscription by fetching it like normal and then if it's in active status manually update the database.
since I do have my ERD with email and name for customers so it's easy to fetch the stripe customer object for them without the stripe customer id, then fetch their subscription and then it should be ok.
I suspect that's because Stripe doesn't know where "http://localhost:44372/webhook" is, right? Like, the request has to go through DNS and there's no way to associate your localhost with an IP address or hosted URL.
So yeah, you could rely on the redirect in this case, or use a domain URL or IP address that's specific to your machine in order to expose it to the internet
yeah I guess
perhaps it might be the cli itself needing to convert localhost to an ip address however it might be a problem because our ISP issues only ipv6 now.
or so it seems so that is
Yeah, actually I think it’s best to skip webhooks and actually just update the db records by fetching the subscription when the payment redirects to the home index page on the site.
It would also make it simpler as well too.
If this is eventually going to go into production, I would recommend not relying on the redirect to perform business logic, and instead focus on fixing the webhooks issue, since redirects can be sloppy (e.g. what happens if the user closes the page or the redirect fails?)
true
but even then the next time they visit the site it would still be able to grab the subscription data.
I'm not sure I follow
I still don't understand what the question is. Sorry, I'm trying to infer where the issue/question is in your messages, but I can't.
Basically for some reason the webhook seems to not be working so I guess doing this could be a good fallback though.
Right, but that's because Stripe doesn't know where "http://localhost:44372/webhook" is, right? The request has to go through DNS and there's no way for it to associate your localhost with an IP address or hosted URL. You'd have to use a URL the DNS can lookup and route the request to
yeah