Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/PPL-164' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasmht committed May 21, 2019
2 parents ee3c976 + 34ba738 commit aa3f7fc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
20 changes: 11 additions & 9 deletions samples/rest/notifications/VerifyWebhookSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@

$PayPal = new \angelleye\PayPal\rest\notifications\NotificationsAPI($configArray);

$params =array(
'auth_algo' => '', // The algorithm that PayPal uses to generate the signature and that you can use to verify the signature. Extract this value from the PAYPAL-AUTH-ALGO response header, which is received with the webhook notification.
'cert_url' => '', // The X.509 public key certificate. Download the certificate from this URL and use it to verify the signature. Extract this value from the PAYPAL-CERT-URL response header, which is received with the webhook notification.
'transmission_id' => '', // The ID of the HTTP transmission. Contained in the PAYPAL-TRANSMISSION-ID header of the notification message.
'transmission_sig' => '', // The PayPal-generated asymmetric signature. Appears in the PAYPAL-TRANSMISSION-SIG header of the notification message.
'transmission_time' => '', // The date and time of the HTTP transmission, in Internet date and time format. Appears in the PAYPAL-TRANSMISSION-TIME header of the notification message.
'webhook_id' => '', // The ID of the webhook as configured in your Developer Portal account.
'webhook_event' => '' // A webhook event notification.
$headers =array(
'auth_algo' => 'SHA256withRSA', // The algorithm that PayPal uses to generate the signature and that you can use to verify the signature. Extract this value from the PAYPAL-AUTH-ALGO response header, which is received with the webhook notification.
'cert_url' => 'https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-1d93a270', // The X.509 public key certificate. Download the certificate from this URL and use it to verify the signature. Extract this value from the PAYPAL-CERT-URL response header, which is received with the webhook notification.
'transmission_id' => '28559930-7bbb-11e9-9556-0b8753ae570e', // The ID of the HTTP transmission. Contained in the PAYPAL-TRANSMISSION-ID header of the notification message.
'transmission_sig' => 'UyGFLQPLgB/ucPt8pRXq9+69NKA8X9x7BNJCNgM9ei2zyPnPgE/higerPvpmD/J/VWFtpcLFUPe3WPh9X5Amr4uBbFR3mG1rR8E4jK43adAk9+Pcx9CAazykMwJ/VZYsUMgyGPMhRUofbrtI7sLclh+OULCFMz23wd04TJItYS/n+slkOfmUtqc4+5RVzNqsA1HYaKwZ3eZi6pRU2WYzsg/CltPLFenqCek6wHAIVOdH0HIBCqUtj2XQjtRBPzDZ6FZtCLnqpZ7MlSRCu0a0eJ7eySb0okDfmdTyfLmgsVdkSSTnNivYMU1f4rc3zUrCcFKSXBeSjHN1sZj5v3sJuw==',
// The PayPal-generated asymmetric signature. Appears in the PAYPAL-TRANSMISSION-SIG header of the notification message.
'transmission_time' => '2019-05-21T11:25:37Z', // The date and time of the HTTP transmission, in Internet date and time format. Appears in the PAYPAL-TRANSMISSION-TIME header of the notification message.
);

$returnArray = $PayPal->VerifyWebhookSignature($params);
$webhook_id = '43023250MX034900R'; // The ID of the webhook as configured in your Developer Portal account.
$webhook_event = file_get_contents('php://input'); // A webhook event notification.

$returnArray = $PayPal->VerifyWebhookSignature($headers, $webhook_id,$webhook_content);

echo "<pre>";
print_r($returnArray);
24 changes: 19 additions & 5 deletions src/angelleye/PayPal/rest/notifications/NotificationsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
use PayPal\Api\Webhook;
use PayPal\Api\WebhookEventType;
use PayPal\Api\WebhookEvent;
use PayPal\Api\Notification;
use PayPal\Api\CancelNotification;
use PayPal\Api\VerifyWebhookSignature;

/**
* NotificationsAPI.
Expand Down Expand Up @@ -317,16 +320,27 @@ public function WebhooksEventTypesById($webhook_id){
* @param array $params
* @return Array|Object
*/
public function VerifyWebhookSignature($params){
$object = new \angelleye\PayPal\EventTypesClass();
public function VerifyWebhookSignature($headers,$webhook_id,$request_body){

try {
$output = $object->verify_webhook_signature_api($params,$this->_api_context);
$signatureVerification = new VerifyWebhookSignature();
$signatureVerification->setAuthAlgo($headers['PAYPAL-AUTH-ALGO']);
$signatureVerification->setTransmissionId($headers['PAYPAL-TRANSMISSION-ID']);
$signatureVerification->setCertUrl($headers['PAYPAL-CERT-URL']);
$signatureVerification->setWebhookId($webhook_id);
$signatureVerification->setTransmissionSig($headers['PAYPAL-TRANSMISSION-SIG']);
$signatureVerification->setTransmissionTime($headers['PAYPAL-TRANSMISSION-TIME']);
$signatureVerification->setRequestBody($request_body);
$output = $signatureVerification->post($this->_api_context);
$status = $output->getVerificationStatus();

$returnArray['RESULT'] = 'Success';
$returnArray['EVENT']=$output->toArray();
$returnArray['STATUS']= $status;
$returnArray['RAWREQUEST']= '';
$returnArray['RAWRESPONSE']=$output->toJSON();
return $returnArray;
} catch (Exception $ex) {
}
catch (Exception $ex){
return $this->createErrorResponse($ex);
}
}
Expand Down
11 changes: 6 additions & 5 deletions templates/rest/notifications/VerifyWebhookSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@

$PayPal = new \angelleye\PayPal\rest\notifications\NotificationsAPI($configArray);

$params =array(
$headers =array(
'auth_algo' => '', // The algorithm that PayPal uses to generate the signature and that you can use to verify the signature. Extract this value from the PAYPAL-AUTH-ALGO response header, which is received with the webhook notification.
'cert_url' => '', // The X.509 public key certificate. Download the certificate from this URL and use it to verify the signature. Extract this value from the PAYPAL-CERT-URL response header, which is received with the webhook notification.
'transmission_id' => '', // The ID of the HTTP transmission. Contained in the PAYPAL-TRANSMISSION-ID header of the notification message.
'transmission_sig' => '', // The PayPal-generated asymmetric signature. Appears in the PAYPAL-TRANSMISSION-SIG header of the notification message.
'transmission_time' => '', // The date and time of the HTTP transmission, in Internet date and time format. Appears in the PAYPAL-TRANSMISSION-TIME header of the notification message.
'webhook_id' => '', // The ID of the webhook as configured in your Developer Portal account.
'webhook_event' => '' // A webhook event notification.
'transmission_time' => '', // The date and time of the HTTP transmission, in Internet date and time format. Appears in the PAYPAL-TRANSMISSION-TIME header of the notification message.
);

$returnArray = $PayPal->VerifyWebhookSignature($params);
$webhook_id = ''; // The ID of the webhook as configured in your Developer Portal account.
$webhook_event = file_get_contents('php://input'); // A webhook event notification.

$returnArray = $PayPal->VerifyWebhookSignature($headers, $webhook_id,$webhook_content);

echo "<pre>";
print_r($returnArray);

0 comments on commit aa3f7fc

Please sign in to comment.