Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Webhook verification failure #1107

Closed
matthijsotterloo opened this issue May 22, 2018 · 7 comments
Closed

Webhook verification failure #1107

matthijsotterloo opened this issue May 22, 2018 · 7 comments

Comments

@matthijsotterloo
Copy link

Hi everyone!

I'm using the code below to validate a webhook response, the webhook is being called after the payment but for some reason the validation keeps returning a failure. Does anyone know what might be causing this?

Thanks!

`$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'myclientidhere', // ClientID
'myclientsecrethere' // ClientSecret
)
);

    $apiContext->setConfig(array('mode' => 'live',));
    $bodyReceived = file_get_contents('php://input');
    
    $headers = getallheaders();
    $headers = array_change_key_case($headers, CASE_UPPER);

    $signatureVerification = new VerifyWebhookSignature();
    $signatureVerification->setAuthAlgo($headers['PAYPAL-AUTH-ALGO']);
    $signatureVerification->setTransmissionId($headers['PAYPAL-TRANSMISSION-ID']);
    $signatureVerification->setCertUrl($headers['PAYPAL-CERT-URL']);
    $signatureVerification->setWebhookId("mywebhookidhere");
    $signatureVerification->setTransmissionSig($headers['PAYPAL-TRANSMISSION-SIG']);
    $signatureVerification->setTransmissionTime($headers['PAYPAL-TRANSMISSION-TIME']);

    $signatureVerification->setRequestBody($requestBody);
    $request = clone $signatureVerification;

    try {
        $output = $signatureVerification->post($apiContext);
    } catch (Exception $ex) {
        print_r($ex->getMessage());
        exit(1);
    }

    $verificationStatus = $output->getVerificationStatus();
    $responseArray = json_decode($request->toJSON(), true);

    $event = $responseArray['webhook_event']['resource']['event_type'];
    $outputArray = json_decode($output->toJSON(), true);

    if ($verificationStatus == 'SUCCESS') {`
@Ukuser36
Copy link

Is your webhook ID definitely correct? I deleted mine and forgot to update it in my code.

@trainerbill
Copy link

We have some issues currently with how SDKs handle the verification.

paypal/PayPal-node-SDK#294

Wondering if you can try to do the verification outside of the PHP SDK using straight REST api so we can narrow it down.

https://developer.paypal.com/docs/api/webhooks/#verify-webhook-signature_webhook

@matthijsotterloo
Copy link
Author

I resolved it. Made a stupid mistake

@razorsharpshady
Copy link

razorsharpshady commented Jan 9, 2019

I resolved it. Made a stupid mistake
@matthijsotterloo What was wrong?

@lyongdee
Copy link

lyongdee commented Apr 9, 2019

@matthijsotterloo How to solved it, what was wrong?

@lvzhiwei
Copy link

@matthijsotterloo How to solved it, what was wrong?

$signatureVerification->setWebhookId('your Webhook ID');

@KingaTheWitch
Copy link

Instead:
$bodyReceived = file_get_contents('php://input');
Should be:
$requestBody = file_get_contents('php://input');

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@lyongdee @trainerbill @matthijsotterloo @razorsharpshady @Ukuser36 @lvzhiwei @KingaTheWitch and others