This repository has been archived on 2026-04-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PayPal-PHP-SDK/sample/doc/notifications/ValidateWebhookEvent.html
Bhavani Bheemanadham d62e8db407 Preparing for 1.7.4
- Updated Changelog
- Updated PayPalConstants.php with latest version
- Added new line at the end of file
2016-07-15 15:42:18 -05:00

20 lines
5.5 KiB
HTML

<!DOCTYPE html><html lang="en"><head><title>notifications/ValidateWebhookEvent</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/ValidateWebhookEvent"><meta name="groc-project-path" content="notifications/ValidateWebhookEvent.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/ValidateWebhookEvent.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span>
<span class="hljs-variable">$apiContext</span> = <span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="validate-webhook">Validate Webhook</h1>
<p>PHP Currently does not support certificate chain validation, that is necessary to validate webhook directly, from received data
To resolve that, we need to use alternative, which includes making a GET call to obtain the data directly from PayPal.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="received-body-from-webhook">Received Body from Webhook</h2>
<p>Body received from webhook. This would be the data that you receive in the post request that comes from PayPal, to your webhook set URL.
This is a sample data, that represents the webhook event data.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$bodyReceived</span> = <span class="hljs-string">'{"id":"WH-36G56432PK518391U-9HW18392D95289106","create_time":"2015-06-01T20:21:13Z","resource_type":"sale","event_type":"PAYMENT.SALE.COMPLETED","summary":"Payment completed for $ 20.0 USD","resource":{"id":"2FY57107YS3937627","create_time":"2015-06-01T20:20:28Z","update_time":"2015-06-01T20:20:46Z","amount":{"total":"20.00","currency":"USD"},"payment_mode":"INSTANT_TRANSFER","state":"completed","protection_eligibility":"ELIGIBLE","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","parent_payment":"PAY-2SV945219E505370PKVWL5DA","transaction_fee":{"value":"0.88","currency":"USD"},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/2FY57107YS3937627","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/2FY57107YS3937627/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-2SV945219E505370PKVWL5DA","rel":"parent_payment","method":"GET"}]},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-36G56432PK518391U-9HW18392D95289106","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-36G56432PK518391U-9HW18392D95289106/resend","rel":"resend","method":"POST"}]}'</span>;
<span class="hljs-comment">/**
* This is one way to receive the entire body that you received from PayPal webhook. This is one of the way to retrieve that information.
* Just uncomment the below line to read the data from actual request.
*/</span>
<span class="hljs-comment">/** <span class="hljs-doctag">@var</span> String $bodyReceived */</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>$bodyReceived = file_get_contents(&#39;php://input&#39;);</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="validate-received-event-method">Validate Received Event Method</h3>
<p>Call the validateReceivedEvent() method with provided body, and apiContext object to validate</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-comment">/** <span class="hljs-doctag">@var</span> \PayPal\Api\WebhookEvent $output */</span>
<span class="hljs-variable">$output</span> = \PayPal\Api\WebhookEvent::validateAndGetReceivedEvent(<span class="hljs-variable">$bodyReceived</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Validate Received Webhook Event"</span>, <span class="hljs-string">"WebhookEvent"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$bodyReceived</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper">ResultPrinter::printResult(<span class="hljs-string">"Validate Received Webhook Event"</span>, <span class="hljs-string">"WebhookEvent"</span>, <span class="hljs-variable">$output</span>-&gt;getId(), <span class="hljs-variable">$bodyReceived</span>, <span class="hljs-variable">$output</span>);</div></div></div></div></body></html>