You are here

public function Webhook::execute in Mollie Payment 8.2

Mollie calls this after the payment status has been changed. Mollie only gives us an id leaving us with the responsibility to get the payment status.

Parameters

\Drupal\payment\Entity\PaymentInterface $payment:

1 string reference to 'Webhook::execute'
mollie_payment.routing.yml in ./mollie_payment.routing.yml
mollie_payment.routing.yml

File

src/Controller/Webhook.php, line 25

Class

Webhook
Handles the "webhook" route.

Namespace

Drupal\mollie_payment\Controller

Code

public function execute(PaymentInterface $payment) {

  // Get the id of the Mollie transaction from the request.
  $request = \Drupal::request();
  $mollie_transaction_id = $request->request
    ->get('id');

  // Get the Mollie profile.
  $mollie_client = $payment
    ->getPaymentMethod()
    ->getMollieClient();
  try {

    // Load the Mollie transaction.
    $mollie_payment = $mollie_client->payments
      ->get($mollie_transaction_id);

    // Payment status mapping.
    $payment_status = [
      'open' => 'payment_pending',
      'cancelled' => 'payment_cancelled',
      'paid' => 'payment_success',
      'paidout' => 'payment_success',
      'refunded' => 'payment_refunded',
      'expired' => 'payment_expired',
    ];
    $payment
      ->getPaymentMethod()
      ->updatePaymentStatus($payment, $payment_status[$mollie_payment->status]);
  } catch (Mollie_API_Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'error');
  }
  return new Response();
}