FabienPapet/stripe-bundle

how to use ?? need more infos

Closed this issue · 17 comments

hi it looking attractive to use !! but to be honnest there is not very mutch instruction to use this bundle. as i unsterdund we have to dispatch in the "Handle stripe" but still can be more information on this.

for exemple : where and how das control of signature ? automatic in cas of "prod", "webhook" ....

regards

Hello,

Thank you for testing the bundle :)

Can you explain what is missing, i'll do my best to update the related docs

Thank you

Hi Fabien, still there is no info on how to process with response from Stripe.

    /**
     * @Route("/handle", name="app_home_ecommerce_stripe_handle")
     * @param Request $request
     * @return Response
     */
    public function handle(Request $request): Response{
//        $request->server['HTTP_STRIPE_SIGNATURE']; //
        $header             = 'Stripe-Signature';
        $signature          = $request->headers->get($header);
        $payload            = $request->getContent();
        $endpoint_secret    = $this->StripeKeyControl;  // $this->StripeS
        $event              = null;

        if ($signature == null) {
            http_response_code(200);
            exit();
        }
        try {
            $event = Event::constructFrom(
                json_decode($payload, true)
            );
        } catch(UnexpectedValueException $e) {
            // Invalid payload
            echo '⚠️  Webhook error while parsing basic request.';
            http_response_code(400);
            exit();
        }
        if ($endpoint_secret) {
            // Only verify the event if there is an endpoint secret defined
            // Otherwise use the basic decoded event
            $sig_header = $signature;
            try {
                $event = Webhook::constructEvent(
                    $payload, $sig_header, $endpoint_secret
                );
            } catch(SignatureVerificationException $e) {
                // Invalid signature
                echo '⚠️  Webhook error while validating signature.';
                http_response_code(400);
                exit();
            }
        }

    return new Response();
    }

do we still need to check ? on handle response stripe webhook

       $event = Webhook::constructEvent(
                    $payload, $sig_header, $endpoint_secret
                );

Them as i understand we have to provide a dispatch to handle response ? i think that can be nice to have explained on all the processes to handle stash process handle webhook.

Regards

I see that you have implemented a custom controller to handle webhooks, but the aim of this bundle is to provide a controller that does it for you.

All you have to do is use this controller. It will handle webhooks for you and dispatch symfony events for you

YES. but one question do we still need to check signature on the webhook handle response form stripe before dispatching? or this check signature is maid by your bundle.

can you provide exemple webhook handle response stripe?

This check is done by the bundle and can be disabled. By default, the controller returns empty response

https://github.com/FabienPapet/stripe-bundle/blob/main/src/Controller/WebhookController.php#L63

that what i have see whem i look all the code in bundle. but it was not realy clean for me, how and what can be the "step" process of this bundle. and how to interact with.

second question how to interact to render to client success, complite page it as to be before the dispatch! them the question is 1 - check the signature one time before dispatch them one time more in the dispatch ? how do we process this "switch" render ?

I don't understand your questions. As you can see in the controller, the controller decodes the webhook content from the request, then processes to validates its signature.

If the signature is valid, then the controller dispatches a webhook event with the name of the webhook you just received.

You don't have to dispatch anything, the controller does it for you

ok them how in dispatch you can render page to client to say success or complite ....

HAAAAA ok i have just see how it work we have to implement are owne "final class WebhookController" base on your and just before

   $webhookEvent = new StripeWebhook($event);
            $this->webhookDispatcher->dispatch($webhookEvent);

after add code to manage the render to client.

No, as it is a webhook you don't have to render anything as nothing will be sent to the client. This is a server to server endpoint

Ok all my mistek !!!

    $Success            = $this->generateUrl("app_home_ecommerce_stripe_handle",[], UrlGeneratorInterface::ABSOLUTE_URL);
    $Cancel             = $this->generateUrl("app_home_ecommerce_stripe_cancel",[], UrlGeneratorInterface::ABSOLUTE_URL);

to manage client response page
and "URL d'endpoint" that we have to setup in dashboard on stripe web site to manage Webhook handle !!! I thought that $Success manage all abort this.

this is why i de not understand ....
Thank you for your patience.

Maybe it can be good to informe that this bundle have require minimum PHP-80.

Pity in my case project is PHP 7.4

Well I guess it's time to upgrade :-) there is no need for attributes in this bundle yet but I don't want to add annotations to this bundle.

Thank you for the suggestion about adding supported versions, I'll add them. If you have other suggestions feel free to create an issue or even better start a PR for your need.

As there are no more issues i'm closing here.