#Fubaibai-webhook

1 messages ยท Page 1 of 1 (latest)

distant pythonBOT
frank glen
#

Hello, what origin are you limiting here?

#

I think the error is coming from us sending the event encoded as UTF-8 but your code is trying to decode it as something slightly different.

brittle crow
#

In my NGINX Server i received this :

#

54.187.216.72 - - [03/Oct/2022:13:13:18 +0000] "POST /api/webhook HTTP/1.1" 404 0 "-" "Stripe/1.0 (+https://stripe.com/docs/webhooks)" "-"

#

My backend is developped in Java Spring

#

And I've limit origin to my REST API to my domain

#

It's weird because, in my QLF env I've no problem about decoding WH event

#

I'll try to allow Stripe WH IPs that I found here

#

And I'll tell you if it's ok

frank glen
#

Sounds good. Since it is a 404, it also sounds like your server might not have recognized the URL that Stripe was trying to reach

brittle crow
#

It's deploying soon ๐Ÿ™‚

#

Still getting the issue :/

#

๐Ÿ˜’

frank glen
#

Can you reach the URL that Stripe is reaching out to if you make a POST to that same URL yourself?

brittle crow
#

Yea using postman I can reach the URL

#

But got 500 because I can't simulate Stripe headers using postman

#

So It's seems to be a pb with encoding/decoding

tepid forge
#

Hello ๐Ÿ‘‹
Taking over as Pompey needs to step away
Yeah certainly looks like an issue with the encoding
Can you try changing the encoding config for your nginx server and see if it produces a different error?

#

or just a different behavior

brittle crow
#

Hello,
Thanks Pompey ๐Ÿ™‚
Ok I will try changing encoding conf

tepid forge
#

๐Ÿ‘

brittle crow
#

Same error :/

#
@PostMapping(value = "/webhook")
    public ResponseEntity<String> handleWebHook(@RequestBody final String json, HttpServletRequest request)
            throws StripeException {
        final String header = request.getHeader("Stripe-Signature");

        Event event;
        try {
            event = Webhook.constructEvent(json, header, this.webHookService.getSecret());
        } catch (SignatureVerificationException e) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
        }

        // Deserialize the nested object inside the event
        final EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
        StripeObject stripeObject;
        if (dataObjectDeserializer.getObject().isPresent()) {
            stripeObject = dataObjectDeserializer.getObject().get();
        } else {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
        }

        // Handle the event
        if (event.getType().equalsIgnoreCase("payment_intent.succeeded")) {
            this.stripeService.handlePaymentIntentSucceeded((PaymentIntent) stripeObject);
            return ResponseEntity.status(HttpStatus.OK).body("");
        } else if (event.getType().equalsIgnoreCase("account.updated")) {
            final ServiceResponse<Void> response = this.stripeService.handleAccountUpdated((Account) stripeObject);
            if (response.getCode().equals(ECodeResponse.NOT_FOUND)) {
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body("");
            } else {
                return ResponseEntity.status(HttpStatus.OK).body("");
            }
        } else if (event.getType().equalsIgnoreCase("checkout.session.completed")) {
            this.stripeService.handleCheckoutCompleted((Session) stripeObject);
        }

        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
    }

This is my webhook in my application, if it can help you

tepid forge
#

It doesn't look like its the code though.
As you mentioned earlier that you don't have such issue in your QLF env.
I'd recommend comparing the configuration for both and see if anything jumps out.

brittle crow
#

oh

#

I think I've found

#

In my Stripe dashboard I got this

#

If you read my code you will see return ResponseEntity.status(HttpStatus.NOT_FOUND).body("");

#

In fact, I got the answer from my server, it's normal, This event is triggered when I've configured my Stripe live account

#

But why Stripe is sending a webhook to my server ? I only want to use webhook for handling connected account update etc..

tepid forge
#

Ah I see.

But why Stripe is sending a webhook to my server ? I only want to use webhook for handling connected account update etc..
Sorry can you clarify what you mean here?
Are you receiving non-connect events on your connect webhook?

brittle crow
#

Stripe sent to my server webhook, the account updated event about my company informations updated on Stripe

tepid forge
#

Can you share your account ID?

brittle crow
#

Where can i have my account ID ?

tepid forge
#

Fubaibai-webhook

brittle crow
#

acct_1LQ5vLKgYp82lmK8

#

It's weird, so I confirm my theory

#

Stripe sent my company account updated event to my webhook server

#

But not connected account

tepid forge
#

So it seems like your webhook endpoint is registered as account/direct type and NOT connect type webhook.
In order to listen to only connected account webhook events, you'd need a connect type webhook endpoint.
https://stripe.com/docs/connect/webhooks

brittle crow
#

Ooooooh

brittle crow
#

Ok so it's worked ! thx a lot

#

I've try a payment in production mode

#

and I don't know why but Stripe did not sent the payment_intent.succeeded event

#

Any idea ?

tepid forge
#

do you have a payment intent ID I can take a look at?

brittle crow
#

Damn I think I know why, It's because payment_intent.succeeded is for account webhook type

#

damn pretty sure that is the pb ๐Ÿ˜„

tepid forge
#

Are you using Direct charges or destination charges?

brittle crow
#

I'm collecting the payment and then creating transfer

tepid forge
#

ah gotcha.
In that case yes, It would be generated on the platform account so you'd need an account/direct type webhook endpoint ๐Ÿ™‚

brittle crow
#

damn ahah

#

And is it possible to use the same WH or different WH is better ?

#

I mean same endpoint or different endpoint

tepid forge
#

I'd say having different endpoint would be easier to maintain

brittle crow
#

Ok

#

thx i will fix this

tepid forge
#

NP! ๐Ÿ™‚ Good luck