PayPal\Api\VerifyWebhookSignature::post PHP Method

post() public method

Verifies a webhook signature.
public post ( ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : VerifyWebhookSignatureResponse
$apiContext PayPal\Rest\ApiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
$restCall PayPalRestCall is the Rest Call Service that is used to make rest calls
return VerifyWebhookSignatureResponse
    public function post($apiContext = null, $restCall = null)
    {
        $payLoad = $this->toJSON();
        $json = self::executeCall("/v1/notifications/verify-webhook-signature", "POST", $payLoad, null, $apiContext, $restCall);
        $ret = new VerifyWebhookSignatureResponse();
        $ret->fromJson($json);
        return $ret;
    }

Usage Example

* Just uncomment the below line to read the data from actual request.
*/
/** @var Array $headers */
//$headers = getallheaders();
/**
* In Documentions https://developer.paypal.com/docs/api/webhooks/#verify-webhook-signature_post 
* All header keys as UPPERCASE, but I recive the header key as the example array, First letter as UPPERCASE
*/
$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("9XL90610J3647323C");
// Note that the Webhook ID must be a currently valid Webhook that you created with your client ID/secret.
$signatureVerification->setTransmissionSig($headers['PAYPAL-TRANSMISSION-SIG']);
$signatureVerification->setTransmissionTime($headers['PAYPAL-TRANSMISSION-TIME']);
$webhookEvent = new WebhookEvent();
$webhookEvent->fromJson($requestBody);
$signatureVerification->setWebhookEvent($webhookEvent);
$request = clone $signatureVerification;
try {
    /** @var \PayPal\Api\VerifyWebhookSignatureResponse $output */
    $output = $signatureVerification->post($apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Validate Received Webhook Event", "WebhookEvent", null, $request->toJSON(), $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Validate Received Webhook Event", "WebhookEvent", $output->getVerificationStatus(), $request->toJSON(), $output);
All Usage Examples Of PayPal\Api\VerifyWebhookSignature::post