#DeepCuts

1 messages · Page 1 of 1 (latest)

shut timberBOT
mystic steeple
#

hello mr stripe

long dock
#

hello! when the customer clicks on the button, that would send a request to your backend server to create the Checkout Session, you would then redirect the customer to the Checkout Session page to make payment. Once the payment is completed, Stripe will send a webhook event and you would process the webhook to fulfil the order

mystic steeple
#

Ok so if you dont mind, let me repeat this out loud in my own words so i can make sure i understand it

#

I have a button, created from a payment link I made for simplicity first. I copied the code for it - now alot of guides ive seen have front end code that uses stripe js

#

is it secure to send the publishable key to the front end ?

long dock
#

ah, okay, so you're using payment links instead

mystic steeple
#

im not married to either oe

#

one

long dock
#

yes, the publishable key is expected to be loaded in the frontend

mystic steeple
#

im just confused

long dock
#

and yes, it's safe

mystic steeple
#

ok , so I should , on my page with the button, use the loadStripe('publishablekey) function from stripe js ?

#

not new Stripe(secretKey)

#

this is where im getting confused

#

cause ive seen examples of both and dont know which one is right

#

then when the button gets pressed, its going to go to a checkout page, do i run the post request to /stripe/checkout ``` public function createPaymentIntent(Request $request)
{
Stripe::setApiKey(env('STRIPE_SECRET_KEY'));

    $paymentIntent = \Stripe\PaymentIntent::create([
        'amount' => $request->input('amount'),
        'currency' => $request->input('currency'),
        'payment_method' => $request->input('payment_method'),
        'confirmation_method' => 'manual',
        'confirm' => true,
        'description' => $request->input('description')
    ]);

    return response()->json([
        'clientSecret' => $paymentIntent->client_secret,
    ]);
}```
#

where does this function from my paymentIntentController come in

#

is it run before the checkout page loads or in response to someone clicking pay

#

ty btw

long dock
#

on my page with the button, use the loadStripe('publishablekey) function from stripe js

yes, the publishable key is used on the frontend

not new Stripe(secretKey)

you should never put / save your secretkey on your frontend

mystic steeple
#

ok yes thats what i thought

long dock
#

you don't use a PaymentIntent if you're using Checkout Sessions or Payment Links. That's only if you're building your own custom flow.

mystic steeple
#

ok so if i only have those 3 products, its probably more of a hassle to do it that way right ?

long dock
#

yep. Checkout Sessions is easier to integrate

mystic steeple
#
    {
        Stripe::setApiKey(env('STRIPE_SECRET_KEY'));

        $session = Session::create([
            'payment_method_types' => ['card'],
            'line_items' => [
                [
                    'name' => 'Example Item',
                    'description' => 'An example item for testing Stripe Checkout',
                    'images' => ['https://example.com/images/example.png'],
                    'amount' => 1000,
                    'currency' => 'usd',
                    'quantity' => 1,
                ],
            ],
            'success_url' => route('checkout.success'),
            'cancel_url' => route('checkout.cancel'),
        ]);

        return Inertia::render('Checkout/Index', [
            'sessionId' => $session->id,
            'publicKey' => env('STRIPE_PUBLISHABLE_KEY'),
            'secretKey'=>env('STRIPE_SECRET')
        ]);
    }```
#

this is from a checkout controller

#

yeah ive been looking at it , which is part of the reason im getting twisted up, because I'm confusing different things. Would in your opinion, since there are only 3 products, use payment links rather than creating payment intents ?

#

im fine with a prebuilt checkout page

#

the goal is just to be able to raise money

long dock
#

can the customer select only 1 product?

mystic steeple
#

when they click the donate button, the donation is the product

#

then theres donated artwork that they are selling that will be at 2 price points

#

which were 500 and 1k but theyre lowering them

#

lets just focus on the donation button

#

cause the product creation actually seemed more straightforward to me

#

never worked with anything like this before in a financial sense

#

so the product is a donation with a variable payment, i copied the code from the site here for the button and I was going to wrap it

#

so when I click this donation button, do I use a post Route that implements that code I used on top to create the session ?

#

I made a table in my db to store these links

long dock
#

if you're using a payment link - then you can set that link as an anchor (button)

#

you don't need a post Route

mystic steeple
#

and how does the webhook fit into this, because im assuming because im doing it this way, the webhook is going to be the way that alerts the application as to the details of the payment

#

havent created a webhook before, I have code to set up the endpoint but Im not exactly clear as to when or how it loads

#
{
    /**
     * Create a new webhook endpoint for Stripe.
     */
    public function createEndpoint()
    {
        $endpoint = new WebhookEndpoint('we_1MvIDJDxs152QbBrli3IMN6U');
        return $endpoint;
    }

    /**
     * Handle a Stripe webhook request.
     */
    public function handleWebhook(Request $request)
    {
        $payload = $request->getContent();
        $sigHeader = $request->server('HTTP_STRIPE_SIGNATURE');

        try {
            $event = Webhook::constructEvent($payload, $sigHeader, env('STRIPE_WEBHOOK_SECRET'));
        } catch (SignatureVerificationException $e) {
            return response()->json(['error' => $e->getMessage()], 400);
        }

        // Record the webhook event in your database or log file
        // For example:
        \Log::info('Webhook received: ' . $event->type);

        // Handle the Stripe webhook event
        switch ($event->type) {
            case 'payment_intent.succeeded':
                $this->paymentSucceeded($event->data->object);
                break;
            case 'payment_intent.failed':
                $this->paymentFailed($event->data->object);
                break;
            // Handle other events as needed
            default:
                // Ignore unsupported events
                break;
        }

        return response()->json(['success' => true]);
    }```
long dock
mystic steeple
#

ok, that makes sense

#

thank you for your assistance

#

was crossing too many things

long dock
#

my suggestion is for you to download that sample i provided before, then use that to understand how it works

#

might be easier that way

mystic steeple
#

is it the one with the html js and php files ?

long dock
mystic steeple
#

right right, ive been looking at that - the only thing that im confused with on that end is, that its not really made for a laravel app its more made for a html page that integrates php and js - php doesnt really get used in the front end in laravel

#

theres an entry point into the app and thats where all the php code in the front end lives, the framework otherwise is all php besides the front end which is vuejs so html and js

#

cause if you look at the code i posted last, its basically that code

#

I think i know what to do now though, I can use the payment link to get the backend data

#

only confusion as , the line item, what does that correspond to exactly