PayPal Rest API webhook签名验证始终将verify_status返回为FAILURE

时间:2016-11-07 13:44:36

标签: paypal-webhooks

我有paypal集成应用程序,它接收来自paypal的webhook通知,我想根据文档验证签名:

Verify signature rest api link

这是我写的代码:

public async Task<ActionResult> Index()
    {
        var stream = this.Request.InputStream;

        var requestheaders = HttpContext.Request.Headers;
        var reader = new StreamReader(stream);
        var jsonReader = new JsonTextReader(reader);
        var serializer = new JsonSerializer();
        var webhook = serializer.Deserialize<Models.Event>(jsonReader); 

        var webhookSignature = new WebhookSignature();
        webhookSignature.TransmissionId = requestheaders["PAYPAL-TRANSMISSION-ID"];
        webhookSignature.TransmissionTime = requestheaders["PAYPAL-TRANSMISSION-TIME"];
        webhookSignature.TransmissionSig = requestheaders["PAYPAL-TRANSMISSION-SIG"];
        webhookSignature.WebhookId = "My actual webhookid from paypal account";
        webhookSignature.CertUrl = requestheaders["PAYPAL-CERT-URL"];
        webhookSignature.AuthAlgo = requestheaders["PAYPAL-AUTH-ALGO"];
        webhookSignature.WebhookEvent = webhook;
        var jsonStr2 = JsonConvert.SerializeObject(webhookSignature);
        var result = await _webhookService.VerifyWebhookSignatureAsync(webhookSignature);
        var jsonStr3 = JsonConvert.SerializeObject(result);

        return Content(jsonStr3, "application/json");
    }


  public async Task<Models.SignatureResponse> VerifyWebhookSignatureAsync(Models.WebhookSignature webhook, CancellationToken cancellationToken = default(CancellationToken))
    {
        var accessTokenDetails = await this.CreateAccessTokenAsync();
        _httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessTokenDetails.AccessToken);
        try
        {
            string jsonStr = JsonConvert.SerializeObject(webhook);
            var content = new StringContent(jsonStr, Encoding.UTF8, "application/json");
            string url = $"{_baseUrl}notifications/verify-webhook-signature";
            var response = await _httpClient.PostAsync(url, content);
            if (!response.IsSuccessStatusCode)
            {
                var error = await response.Content.ReadAsStringAsync();
                throw new Exception(error);
            }
            string jsonContent = response.Content.ReadAsStringAsync().Result;
            return JsonConvert.DeserializeObject<Models.SignatureResponse>(jsonContent);
        }
        catch (Exception ex)
        {
            throw new InvalidOperationException("Request to Create payment Service failed.", ex);
        }

    }

Webhook签名验证响应:

{&#34; verification_status&#34;:&#34; FAILURE&#34;}

我从api得到200K ok响应但是响应中的验证状态总是失败。我尝试了很多不同的请求。

我不确定我的请求是否有问题。寻求帮助。

0 个答案:

没有答案