#tbm-subscription-php

1 messages · Page 1 of 1 (latest)

rapid nestBOT
signal sail
#

Hey @mild wing what's your exact question?

#

you just leaked you key

mild wing
#

Where does the $app variable come from?

signal sail
#

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

mild wing
signal sail
#

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

mild wing
#

I dont know what to set it as.

signal sail
#

hum yeah you're not understanding what this means at all. Are you an experienced web/php developer or just new/learning?

mild wing
#

experienced.

#

years of experience.

signal sail
#

Perfect. So how did you build your website in PHP? Which framework are you using to show pages, display specific routes, etc.

mild wing
signal sail
#

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?

mild wing
#

yes

signal sail
#

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

mild wing
#

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?

signal sail
#

Not really, not with the way you write PHP code sorry

#

All our examples expect you to have a framework or some router

mild wing
signal sail
#

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

#

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