forked from LiveCarta/PayPal-PHP-SDK
@@ -166,7 +166,7 @@ class VerifyWebhookSignature extends PayPalResourceModel
|
||||
|
||||
/**
|
||||
* The webhook notification, which is the content of the HTTP `POST` request body.
|
||||
*
|
||||
* @deprecated Please use setRequestBody($request_body) instead.
|
||||
* @param \PayPal\Api\WebhookEvent $webhook_event
|
||||
*
|
||||
* @return $this
|
||||
@@ -187,6 +187,29 @@ class VerifyWebhookSignature extends PayPalResourceModel
|
||||
return $this->webhook_event;
|
||||
}
|
||||
|
||||
/**
|
||||
* The content of the HTTP `POST` request body of the webhook notification you received as a string.
|
||||
*
|
||||
* @param string $request_body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRequestBody($request_body)
|
||||
{
|
||||
$this->request_body = $request_body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The content of the HTTP `POST` request body of the webhook notification you received as a string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestBody()
|
||||
{
|
||||
return $this->request_body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies a webhook signature.
|
||||
*
|
||||
@@ -197,6 +220,7 @@ class VerifyWebhookSignature extends PayPalResourceModel
|
||||
public function post($apiContext = null, $restCall = null)
|
||||
{
|
||||
$payLoad = $this->toJSON();
|
||||
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/verify-webhook-signature",
|
||||
"POST",
|
||||
@@ -210,4 +234,23 @@ class VerifyWebhookSignature extends PayPalResourceModel
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function toJSON($options = 0)
|
||||
{
|
||||
if (!is_null($this->request_body)) {
|
||||
$valuesToEncode = $this->toArray();
|
||||
unset($valuesToEncode['webhook_event']);
|
||||
unset($valuesToEncode['request_body']);
|
||||
|
||||
$payLoad = "{";
|
||||
foreach ($valuesToEncode as $field => $value) {
|
||||
$payLoad .= "\"$field\": \"$value\",";
|
||||
}
|
||||
$payLoad .= "\"webhook_event\": $this->request_body";
|
||||
$payLoad .= "}";
|
||||
return $payLoad;
|
||||
} else {
|
||||
$payLoad = parent::toJSON($options);
|
||||
return $payLoad;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,9 +57,7 @@ $signatureVerification->setWebhookId("9XL90610J3647323C"); // Note that the Webh
|
||||
$signatureVerification->setTransmissionSig($headers['PAYPAL-TRANSMISSION-SIG']);
|
||||
$signatureVerification->setTransmissionTime($headers['PAYPAL-TRANSMISSION-TIME']);
|
||||
|
||||
$webhookEvent = new WebhookEvent();
|
||||
$webhookEvent->fromJson($requestBody);
|
||||
$signatureVerification->setWebhookEvent($webhookEvent);
|
||||
$signatureVerification->setRequestBody($requestBody);
|
||||
$request = clone $signatureVerification;
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user