You are here

private function Webhook::verify in PayPal for Payment 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/Webhook.php \Drupal\paypal_payment\Controller\Webhook::verify()

Parameters

string $payment_method_id:

Return value

bool

1 call to Webhook::verify()
Webhook::access in src/Controller/Webhook.php

File

src/Controller/Webhook.php, line 60

Class

Webhook
Handles the "webhook" route.

Namespace

Drupal\paypal_payment\Controller

Code

private function verify(string $payment_method_id) : bool {
  try {

    /** @var PayPalBasic $payment_method */
    $payment_method = Payment::methodManager()
      ->createInstance('paypal_payment_express:' . $payment_method_id);
    if (!$payment_method instanceof PayPalBasic) {
      throw new RuntimeException('Unsupported web hook');
    }
    $body = $this->request
      ->getContent();
    $resource = new VerifyWebhookSignature();
    $resource
      ->setAuthAlgo($this->request->headers
      ->get('paypal-auth-algo'));
    $resource
      ->setCertUrl($this->request->headers
      ->get('paypal-cert-url'));
    $resource
      ->setTransmissionId($this->request->headers
      ->get('paypal-transmission-id'));
    $resource
      ->setTransmissionSig($this->request->headers
      ->get('paypal-transmission-sig'));
    $resource
      ->setTransmissionTime($this->request->headers
      ->get('paypal-transmission-time'));
    $resource
      ->setRequestBody($body);
    $resource
      ->setWebhookId($payment_method
      ->getWebhookId());
    $response = $resource
      ->post($payment_method
      ->getApiContext($payment_method::PAYPAL_CONTEXT_TYPE_WEBHOOK));
    if ($response
      ->getVerificationStatus() === 'SUCCESS') {
      return TRUE;
    }
  } catch (Exception $ex) {

    // TODO: Error handling
  }
  return FALSE;
}