#tbm-subscription-php
1 messages · Page 1 of 1 (latest)
Where does the $app variable come from?
please redact
Also please be a lot more specific. "I get an error" doesn't really tell me what the problem is
And $app in that code is really just your own server/app/framework. It's whatever you're familiar with/use to run your website
Give me an example for setting the $app variable.
there's no example. It depends on what, as the PHP developer, are familiar with and what you use as a framework
tbm-subscription-php
I need to set the variable in order to stop getting the server failed php error.
I dont know what to set it as.
hum yeah you're not understanding what this means at all. Are you an experienced web/php developer or just new/learning?
Perfect. So how did you build your website in PHP? Which framework are you using to show pages, display specific routes, etc.
I dont think im using any. I code in raw php.
Okay, so most PHP developers nowadays have a framework or their own router. So you can do https://example.com/login without the .php at the end and then your server-side code is like "Oh /login okay let me call my code to handle this and render the right view UI"
Since you use none of this you have to tweak/adapt the code. I assume you have a separate PHP file for all your pages (which is not really the right way to do PHP anymore). Is that correct?
yes
Okay so you can see the example code client-side does fetch('/create-subscription', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ priceId: priceId, customerId: customerId, }), }) and then server-side there's $app->post('/create-subscription', function ( Request $request, Response $response, array $args ) {
So you need to adapt the code to your older way of doing PHP. The client-side code would do fetch('/create-subscription.php', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ priceId: priceId, customerId: customerId, }), }) and then your server would have a file called create-subscription.php that would create the Subscription (what's inside the $app->(...) that you aren't familiar with
This looks like im learning something new. Im not familiar with anything your saying.
Sorry im still lost. Is there a video i could look at or something?
Not really, not with the way you write PHP code sorry
All our examples expect you to have a framework or some router
So does that mean i need to download a something? like a framework or something?
No, it means you need to adapt the code to work in your case. You said you have years of experience already so it shouldn't be too hard
Mostly: your client-side code tells you server "hey create a subscription" and that server-side code needs to do it
Like the step https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements&element=card#create-subscription
All it says is "have client-side code call your server to create a Subscription and return the right information"
and then the server part all it does is create a Subscription and return the Subscription id and its client_secret as JSON: return $response->withJson([ 'subscriptionId' => $subscription->id, 'clientSecret' => $subscription->latest_invoice->payment_intent->client_secret ]);
you can ignore the $app part of it. This works exactly the same way as you would build anything in yoiur website where the client sends a request in Javascript to your server
i have to run unfortunately and the channel will be closed until tomorrow