#mtalhaabbas-connect-disputes

1 messages · Page 1 of 1 (latest)

hazy zealot
#

Hey, can you share a pi_xxx of a disputed payment?

errant heart
#

ch_3LIpEFG0wc579BBy1iEEgT7W

#

@hazy zealot

hazy zealot
#

Taking a look now

#

Can you share the evt_xxx of the webhook you're referring to?

#

It's not immediately clear what you're trying to do. Reverse the transfer to the connected account?

errant heart
#

yes

#

evt_1LIpEHG0wc579BByuJTvQt5F

#

@hazy zealot

hazy zealot
#

So from that event you want to be able to reverse the transfer but there's no reference to it on the event payload. Correct?

errant heart
#

exactly

#

@hazy zealot

hazy zealot
#

So you'd need to retrieve the Charge object using the ch_xxx ID in the event payload, and expanding the transfer field on the Charge object

errant heart
#

ok, I will try and let you know

errant heart
#

@hazy zealot I'm getting an invalid signature error message

hazy zealot
errant heart
#

@csrf_exempt
def stripe_webhook_view(request):
stripe.api_key = settings.STRIPE_SECRET_KEY
endpoint_secret = settings.STRIPE_ENDPOINT_SECRET
payload = request.body
sig_header = request.META['HTTP_STRIPE_SIGNATURE']
event = None
try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret
)
except ValueError as e:
# Invalid payload
return HttpResponse("Invalid payload",status=400)
except stripe.error.SignatureVerificationError as e:
# Invalid signature
return HttpResponse("Invalid signature",status=400)
# Fetch all the required data from session

if event['type'] == 'checkout.session.completed':
    session = event['data']['object']
elif event['type'] == 'invoice.created':
    invoice = event['data']['object']
elif event['type'] == 'invoice.paid':
    invoice = event['data']['object']
    period = invoice.get('period_end')
    print("paid invoice",period)
elif event['type'] == 'charge.dispute.created':
    dispute = event['data']['object']
    charge=dispute.get("charge")
    ch=stripe.Charge.retrieve(charge)
    reveral=stripe.Transfer.create_reversal(
        ch.transfer,
        amount=ch.transfer_data.amount
        )
else:
  print('Unhandled event type {}'.format(event['type']))

return HttpResponse(status=200)
#

@hazy zealot can you check it?

hazy zealot
#

Is your endpoint_secret the correct webhook secret from your Dashboard?

errant heart
#

yes I have checked

#

it's working with CLI but not working with API

#

as you can see, it's working fine with CLI

hazy zealot
#

The secret from the CLI will be different from the one from your real Dashboard webhook

errant heart
#

now, I'm using test mode

#

@hazy zealot

hazy zealot
#

Can you share an evt_xxx?

errant heart
#

evt_1LIpEHG0wc579BByuJTvQt5F

#

@hazy zealot

hazy zealot
#

You don't need to @ me every time 😛

errant heart
#

ok

hazy zealot
#

In your webhook handler (endpoint_secret)

errant heart
#

yes

#

I have used the same one

hazy zealot
#

I'm not sure then. You need to work on debugging that locally as your code is failing when trying to verify the signature

errant heart
#

I have checked and not found any mistake

#

can you please check?

#

I have shared the code screenshot with youi

hazy zealot
#

Your code looks fine. As stated, I expect your endpoint_secret is the wrong value that does not match the value used to sign the event for that specific webhook

errant heart
#

we_1LIpAOG0wc579BByqcEk3jCH this one is the endpoint secret?

#

for me?

hazy zealot
#

No, that's the webhook ID. The secret is at the URL I shared above:

errant heart
#

okay, Thanks for confirmation

#

I will try and let you know

#

I'm getting an Attribute error when I'm trying to use singing secret

#

can you create endpoint_secret for me?

#

please

#

@hazy zealot

late sentinel
#

Hi! I'm taking over this thread.