* 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);
/** * Retrieves the Webhooks event resource identified by event_id. Can be used to retrieve the payload for an event. * * @param string $eventId * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls * @return WebhookEvent */ public static function get($eventId, $apiContext = null, $restCall = null) { ArgumentValidator::validate($eventId, 'eventId'); $payLoad = ""; $json = self::executeCall("/v1/notifications/webhooks-events/{$eventId}", "GET", $payLoad, null, $apiContext, $restCall); $ret = new WebhookEvent(); $ret->fromJson($json); return $ret; }