You are here

function mollie_payment_return in Mollie Payment 7.2

Same name and namespace in other branches
  1. 7 mollie_payment.module \mollie_payment_return()

Return callback.

Parameters

string $pid: The id of the payment.

Mollie is redirecting the visitor here after the payment process. At this point we don't know the status of the payment yet so we can only load the payment and call its finish callback.

1 string reference to 'mollie_payment_return'
mollie_payment_menu in ./mollie_payment.module
Implements hook_menu().

File

./mollie_payment.module, line 362
Provides Mollie integration for the Payment platform.

Code

function mollie_payment_return($pid) {

  // Load the Payment payment.
  $payment = entity_load_single('payment', $pid);

  // Fetch the Mollie payment id.
  $id = $payment->context_data['payment']['id'];

  // Initialize the client.
  $client = mollie_payment_get_client($payment);
  if ($payment && $client) {

    // Load the Mollie payment.
    $mollie_payment = $client->payments
      ->get($id);

    // Update the status of the Payment payment.
    mollie_payment_update_status($payment, $mollie_payment->status);

    // At this moment this does not work in test mode.
    if (!$payment->method->controller_data['test_mode'] && $mollie_payment->method) {

      // Load the Mollie payment method.
      $method = $client->methods
        ->get($mollie_payment->method);

      // Store the Mollie payment method id and name.
      $payment->context_data['payment']['method'] = $method->id;
      $payment->context_data['payment']['method_name'] = $method->description;
      entity_save('payment', $payment);
    }
  }

  // Finish the Payment payment and hand control back over to the context.
  $payment
    ->finish();
}