2017-10-28 11 views
2

로컬로 테스트 할 webhook 요청을 만들려고 시도했지만 라이브러리 에 오류가 있습니다. 요청을 전송하여 요청의 본문을 생성했습니다. balance.available webhook 여기 : https://dashboard.stripe.com/test/webhooks/we_1BI2E2IYOmXNPhc1uOyyRvHg 본문을 복사하여 /tmp/stripe.webhook.json.tmp 파일에 넣었습니다. 워드 프로세서는 서명을 생성하는 방법에 대해 설명합니다 https://stripe.com/docs/webhooks#signatures서명 된 Stripe rest webhook 요청을 로컬에서 어떻게 생성합니까?


$ date +%s 
1509229775 
$ cat /tmp/stripe.webhook.tmp | openssl dgst -hmac whsec_nRZzpzBajM5zBLxnyFAHNZLkLLEu5Xlj -sha256 
(stdin)= de2da72d739f0bdf0e2289eab5ac131f51cdd35af8f9c1f1224333b53abde9f7 
$ curl -s -X POST http://localhost:3000/stripe/webhook -H "Stripe-Signature: t=1509229775,v1=de2da72d739f0bdf0e2289eab5ac131f51cdd35af8f9c1f1224333b53abde9f7" -d @/tmp/stripe.webhook.json.tmp | head -2   
Invalid signature. 
$ head -2 /tmp/stripe.webhook.tmp 
1509229775.{ 
    "created": 1326853478, 
$ head -2 /tmp/stripe.webhook.json.tmp 
{ 
    "created": 1326853478, 

def webhook 
    payload = request.body.read 
    sig_header = request.env['HTTP_STRIPE_SIGNATURE'] 
    endpoint_secret = ENV['STRIPE_WEBHOOK'] 
    event = nil 
    begin 
     event = Stripe::Webhook.construct_event(payload, sig_header, 
endpoint_secret) 
    rescue JSON::ParserError => e 
     # Invalid payload 
     render plain: "Invalid JSON.", status: 400 
     return 
    rescue Stripe::SignatureVerificationError => e 
     # Invalid signature 
     render plain: "Invalid signature.", status: 400 
     return 
    end 

답변

1

나는 문제는 curl 호출과 관련이있다 생각합니다. -d/--data 인수는 json의 줄 바꿈을 제거하고 Stripe::Webhook.construct_event에 의해 계산 된 결과 요약은 사용자가 터미널에서 계산 한 것과 다릅니다.

다이제스트를 생성 한 후 나는 나의은 webhook 엔드 포인트에 말려 : 표준 -d를 사용

--data-binary을 지정하는 유효한 서명을 반환

curl -s -X POST http://localhost:3000/webhook -H "Stripe-Signature: t=1509309309,v1=a2e2776cd5a57ba60355f7cfa3bcdd1d69e773373a0da" -d @./webhook.json.tmp 

반면 서명이 유효 말하는 오류가 발생했습니다

curl -s -X POST http://localhost:3000/webhook -H "Stripe-Signature: t=1509309309,v1=a2e2776cd5a57ba60355f7cfa3bcdd1d69e773373a0da" --data-binary @./webhook.json.tmp 
+0

와우! 나는'-d' 문자를 제거하지 못했습니다! – Chloe

+0

맞습니까? 그것은 명백한 것이 아닙니다. 비슷한 문제로 고민하고 있었고 원시 요청을 검사하여이 사실을 알게되었습니다. – duck