PayPal沙盒验证Webhook始终返回失败。

huangapple go评论170阅读模式
英文:

Paypal sandbox verify webhook always return FAILURE

问题

我在golang中运行它,使用沙箱,没有使用webhooks模拟器,并使用http.NewRequest POST /v1/notifications/verify-webhook-signature进行验证。

头部已经使用access_token。

var verifyData struct {
	AuthAlgo         string                 `json:"auth_algo"`
	CertUrl          string                 `json:"cert_url"`
	TransmissionId   string                 `json:"transmission_id"`
	TransmissionSig  string                 `json:"transmission_sig"`
	TransmissionTime string                 `json:"transmission_time"`
	WebhookEvent     map[string]interface{} `json:"webhook_event"`
	WebhookId        string                 `json:"webhook_id"`
}

但它总是返回{"verification_status":"FAILURE"},所有的webhook验证都是一样的。

我尝试打印日志。

WebhookEvent与webhook的http.Body()数据相同。

其他数据与webhook的http.Header数据相同。

来自webhook头部的数据

Paypal-Auth-Algo:SHA256withRSA 
Paypal-Cert-Url:https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-******** 
Paypal-Transmission-Id:422dea50-c3ac-****-****-b9f65296f9e3 
Paypal-Transmission-Sig:Col8aQ2wP+qVt6Xe8XBXwWX6ANyFVlEfdTCgScqRD3mbCYZb0p5yh5uWNLQ8sPAbIXByuOrYs7+******+Ty+5UpFyj+x3CTTXlQgyAmWdiETlfE93tpjVY1OZhLDYDrdUVdF9PIT1snS0pmRX17vVcxN9GooqFd7BeZCJoPo83MWxV2V+0wcpGtxG2V5tw17xTF9XLiTIAsnNVZw/*********/NMvopi3P7EJUWteqtxrow/fmf27uUhTmLtF9sNFcOP2nBKIPDo0Wearf78P1Yr2gLDxfis3s8d/qNWqSs75Mk7wOm/YQrj2R74jikQFU46v3UD5tYrwIBh77Hg== 
Paypal-Transmission-Time:2023-03-16T03:40:13Z 

webhook_event来自http.Body(),它使用json.Unmarshal转换为map[string]interface{}

webhook_id来自应用程序,沙箱webhooks。

我尝试了各种方法来更改webhook_event,但仍然不起作用。

我不知道如何在golang中使用<transmissionId>|<timeStamp>|<webhookId>|<crc32>,所以我现在使用http.post,请帮忙。

英文:

I was run it in golang, sandbox, not use the webhooks simulator, and use http.NewRequest POST /v1/notifications/verify-webhook-signature to verify

header are already use access_token

var verifyData struct {
		AuthAlgo         string                 `json:&quot;auth_algo&quot;`
		CertUrl          string                 `json:&quot;cert_url&quot;`
		TransmissionId   string                 `json:&quot;transmission_id&quot;`
		TransmissionSig  string                 `json:&quot;transmission_sig&quot;`
		TransmissionTime string                 `json:&quot;transmission_time&quot;`
		WebhookEvent     map[string]interface{} `json:&quot;webhook_event&quot;`
		WebhookId        string                 `json:&quot;webhook_id&quot;`
	}

but it always return {&quot;verification_status&quot;:&quot;FAILURE&quot;}, all webhook verify are the same

i try to Println logs

but the WebhookEvent are the same as webhook http.Body() data

other data are the same as webhook http.Header data

data from webhook header

Paypal-Auth-Algo:SHA256withRSA 
Paypal-Cert-Url:https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-******** 
Paypal-Transmission-Id:422dea50-c3ac-****-****-b9f65296f9e3 
Paypal-Transmission-Sig:Col8aQ2wP+qVt6Xe8XBXwWX6ANyFVlEfdTCgScqRD3mbCYZb0p5yh5uWNLQ8sPAbIXByuOrYs7+******+Ty+5UpFyj+x3CTTXlQgyAmWdiETlfE93tpjVY1OZhLDYDrdUVdF9PIT1snS0pmRX17vVcxN9GooqFd7BeZCJoPo83MWxV2V+0wcpGtxG2V5tw17xTF9XLiTIAsnNVZw/*********/NMvopi3P7EJUWteqtxrow/fmf27uUhTmLtF9sNFcOP2nBKIPDo0Wearf78P1Yr2gLDxfis3s8d/qNWqSs75Mk7wOm/YQrj2R74jikQFU46v3UD5tYrwIBh77Hg== 
Paypal-Transmission-Time:2023-03-16T03:40:13Z 

and webhook_event are from http.Body(), it's use json.Unmarshal to map[string]interface{}

webhook_id from apps,SANDBOX WEBHOOKS

i try any ways to change webhook_event, still not work

i don't know how to use &lt;transmissionId&gt;|&lt;timeStamp&gt;|&lt;webhookId&gt;|&lt;crc32&gt; in golang, so i use http.post now, please help

答案1

得分: 1

我从头部中使用了Paypal-Auth-AlgoPaypal-Cert-UrlPaypal-Transmission-IdPaypal-Transmission-SigPaypal-Transmission-Time,以及所有的webhook body interface{}和来自应用程序/ webhook的webhook_id。

英文:

my example from sandbox

--webhook request headers--

map[
    Accept:*/* Content-Length:1142
    Content-Type:application/json
    Correlation-Id:f941618bd2165
    Host:filepipe.dev
    Paypal-Auth-Algo:SHA256withRSA
    Paypal-Auth-Version:v2
    Paypal-Cert-Url:https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-5a29e601
    Paypal-Transmission-Id:99d97fc0-c3ad-11ed-8ada-d722609ae478
    Paypal-Transmission-Sig:PrZDo9fmpTshwt/JY6/HvJDceR5kCj3GhAxdiBSIdtsC7Y91+ww6hd8Qk5zpnJ3KN1itLYSxFnTQLOgtOYZtSzXsQaAeo7oSqxUAaV+jXtF3a63zR0zg9NRHfNjf4L7JuGJ0WDz2I4d4026GZ4yXjr3sNc3zN6dEwZBEQT0zc+bwZjariIC3WQv7uLCPKbvl6g49OhQC6xS5cJkB837D3svUIlT/9PEJ5mp1WCCijwOypUpCoP1lXGWHx1pVvtTPd4Q3ANSSASFJDs4ubJKgH5CPNiv+eT9GNs5JGXQv/1qlvCN+Ph2v/OKgz6yM5gbPS3XnldccXwnzeGcenPvl5w==
    Paypal-Transmission-Time:2023-03-16T03:49:49Z
    User-Agent:PayPal/AUHR-214.0-58031014
    X-B3-Spanid:3d19edb457d98398
    X-Forwarded-For:173.0.80.116
    X-Forwarded-Host:filepipe.dev
    X-Forwarded-Port:443
    X-Forwarded-Proto:https
    X-Forwarded-Scheme:https
    X-Real-Ip:173.0.80.116
    X-Request-Id:fd024917ba5320920ea36735f2460a47
    X-Scheme:https
]

--webhook body json--

{
    &quot;id&quot;: &quot;WH-47139463N7609432M-6FD472938E900521U&quot;,
    &quot;event_version&quot;: &quot;1.0&quot;,
    &quot;create_time&quot;: &quot;2023-03-16T03:49:46.098Z&quot;,
    &quot;resource_type&quot;: &quot;subscription&quot;,
    &quot;resource_version&quot;: &quot;2.0&quot;,
    &quot;event_type&quot;: &quot;BILLING.SUBSCRIPTION.CREATED&quot;,
    &quot;summary&quot;: &quot;Subscription created&quot;,
    &quot;resource&quot;: {
        &quot;start_time&quot;: &quot;2023-03-16T03:49:45Z&quot;,
        &quot;quantity&quot;: &quot;1&quot;,
        &quot;create_time&quot;: &quot;2023-03-16T03:49:45Z&quot;,
        &quot;custom_id&quot;: &quot;3&quot;,
        &quot;links&quot;: [
            {
                &quot;href&quot;: &quot;https://www.sandbox.paypal.com/webapps/billing/subscriptions?ba_token=BA-7RE73133KF159744D&quot;,
                &quot;rel&quot;: &quot;approve&quot;,
                &quot;method&quot;: &quot;GET&quot;
            },
            {
                &quot;href&quot;: &quot;https://api.sandbox.paypal.com/v1/billing/subscriptions/I-LMA62KG79TL5&quot;,
                &quot;rel&quot;: &quot;edit&quot;,
                &quot;method&quot;: &quot;PATCH&quot;
            },
            {
                &quot;href&quot;: &quot;https://api.sandbox.paypal.com/v1/billing/subscriptions/I-LMA62KG79TL5&quot;,
                &quot;rel&quot;: &quot;self&quot;,
                &quot;method&quot;: &quot;GET&quot;
            }
        ],
        &quot;id&quot;: &quot;I-LMA62KG79TL5&quot;,
        &quot;plan_overridden&quot;: false,
        &quot;plan_id&quot;: &quot;P-2M355934NH158234GMQIXO2Q&quot;,
        &quot;status&quot;: &quot;APPROVAL_PENDING&quot;
    },
    &quot;links&quot;: [
        {
            &quot;href&quot;: &quot;https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-47139463N7609432M-6FD472938E900521U&quot;,
            &quot;rel&quot;: &quot;self&quot;,
            &quot;method&quot;: &quot;GET&quot;
        },
        {
            &quot;href&quot;: &quot;https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-47139463N7609432M-6FD472938E900521U/resend&quot;,
            &quot;rel&quot;: &quot;resend&quot;,
            &quot;method&quot;: &quot;POST&quot;
        }
    ]
}

--webhook body interface{}--

map[
    create_time:2023-03-16T03:49:46.098Z 
    event_type:BILLING.SUBSCRIPTION.CREATED 
    event_version:1.0 
    id:WH-47139463N7609432M-6FD472938E900521U 
    links:[
        map[
            href:https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-47139463N7609432M-6FD472938E900521U 
            method:GET 
            rel:self
        ] 
        map[
            href:https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-47139463N7609432M-6FD472938E900521U/resend 
            method:POST 
            rel:resend
        ]
    ] 
    resource:
        map[
            create_time:2023-03-16T03:49:45Z 
            custom_id:3 
            id:I-LMA62KG79TL5 
            links:[
                map[
                    href:https://www.sandbox.paypal.com/webapps/billing/subscriptions?ba_token=BA-7RE73133KF159744D 
                    method:GET 
                    rel:approve
                ] 
                map[
                    href:https://api.sandbox.paypal.com/v1/billing/subscriptions/I-LMA62KG79TL5 
                    method:PATCH 
                    rel:edit
                ] 
                map[
                    href:https://api.sandbox.paypal.com/v1/billing/subscriptions/I-LMA62KG79TL5 
                    method:GET 
                    rel:self
                ]
            ] 
            plan_id:P-2M355934NH158234GMQIXO2Q 
            plan_overridden:false 
            quantity:1 
            start_time:2023-03-16T03:49:45Z 
            status:APPROVAL_PENDING
        ] 
    resource_type:subscription 
    resource_version:2.0 
    summary:Subscription created
]

--send verify data--

{
    &quot;auth_algo&quot;: &quot;SHA256withRSA&quot;,
    &quot;cert_url&quot;: &quot;https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-5a29e601&quot;,
    &quot;transmission_id&quot;: &quot;99d97fc0-c3ad-11ed-8ada-d722609ae478&quot;,
    &quot;transmission_sig&quot;: &quot;PrZDo9fmpTshwt/JY6/HvJDceR5kCj3GhAxdiBSIdtsC7Y91+ww6hd8Qk5zpnJ3KN1itLYSxFnTQLOgtOYZtSzXsQaAeo7oSqxUAaV+jXtF3a63zR0zg9NRHfNjf4L7JuGJ0WDz2I4d4026GZ4yXjr3sNc3zN6dEwZBEQT0zc+bwZjariIC3WQv7uLCPKbvl6g49OhQC6xS5cJkB837D3svUIlT/9PEJ5mp1WCCijwOypUpCoP1lXGWHx1pVvtTPd4Q3ANSSASFJDs4ubJKgH5CPNiv+eT9GNs5JGXQv/1qlvCN+Ph2v/OKgz6yM5gbPS3XnldccXwnzeGcenPvl5w==&quot;,
    &quot;transmission_time&quot;: &quot;2023-03-16T03:49:49Z&quot;,
    &quot;webhook_event&quot;: {
        &quot;create_time&quot;: &quot;2023-03-16T03:49:46.098Z&quot;,
        &quot;event_type&quot;: &quot;BILLING.SUBSCRIPTION.CREATED&quot;,
        &quot;event_version&quot;: &quot;1.0&quot;,
        &quot;id&quot;: &quot;WH-47139463N7609432M-6FD472938E900521U&quot;,
        &quot;links&quot;: [
            {
                &quot;href&quot;: &quot;https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-47139463N7609432M-6FD472938E900521U&quot;,
                &quot;method&quot;: &quot;GET&quot;,
                &quot;rel&quot;: &quot;self&quot;
            },
            {
                &quot;href&quot;: &quot;https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-47139463N7609432M-6FD472938E900521U/resend&quot;,
                &quot;method&quot;: &quot;POST&quot;,
                &quot;rel&quot;: &quot;resend&quot;
            }
        ],
        &quot;resource&quot;: {
            &quot;create_time&quot;: &quot;2023-03-16T03:49:45Z&quot;,
            &quot;custom_id&quot;: &quot;3&quot;,
            &quot;id&quot;: &quot;I-LMA62KG79TL5&quot;,
            &quot;links&quot;: [
                {
                    &quot;href&quot;: &quot;https://www.sandbox.paypal.com/webapps/billing/subscriptions?ba_token=BA-7RE73133KF159744D&quot;,
                    &quot;method&quot;: &quot;GET&quot;,
                    &quot;rel&quot;: &quot;approve&quot;
                },
                {
                    &quot;href&quot;: &quot;https://api.sandbox.paypal.com/v1/billing/subscriptions/I-LMA62KG79TL5&quot;,
                    &quot;method&quot;: &quot;PATCH&quot;,
                    &quot;rel&quot;: &quot;edit&quot;
                },
                {
                    &quot;href&quot;: &quot;https://api.sandbox.paypal.com/v1/billing/subscriptions/I-LMA62KG79TL5&quot;,
                    &quot;method&quot;: &quot;GET&quot;,
                    &quot;rel&quot;: &quot;self&quot;
                }
            ],
            &quot;plan_id&quot;: &quot;P-2M355934NH158234GMQIXO2Q&quot;,
            &quot;plan_overridden&quot;: false,
            &quot;quantity&quot;: &quot;1&quot;,
            &quot;start_time&quot;: &quot;2023-03-16T03:49:45Z&quot;,
            &quot;status&quot;: &quot;APPROVAL_PENDING&quot;
        },
        &quot;resource_type&quot;: &quot;subscription&quot;,
        &quot;resource_version&quot;: &quot;2.0&quot;,
        &quot;summary&quot;: &quot;Subscription created&quot;
    },
    &quot;webhook_id&quot;: &quot;9FU18601MK8788***&quot; (webhook id)
}

--verify data--

{&quot;verification_status&quot;:&quot;FAILURE&quot;}

i was use Paypal-Auth-Algo Paypal-Cert-Url Paypal-Transmission-Id Paypal-Transmission-Sig Paypal-Transmission-Time from header, and all webhook body interface{}, and the webhook_id from apps/webhook

huangapple
  • 本文由 发表于 2023年3月16日 12:35:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75752209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定