You are here

function commerce_mollie_request_status in Commerce Mollie 7

Request new payment status.

Parameters

$order:

$transaction:

return stdClass Returns updated transaction object.

2 calls to commerce_mollie_request_status()
commerce_mollie_request_payment_status_form in ./commerce_mollie.module
Retrieve a new status update about the payment.
commerce_mollie_return in ./commerce_mollie.module
Response return url for Mollie.

File

./commerce_mollie.module, line 373

Code

function commerce_mollie_request_status($order, $transaction) {
  $payment_method = _commerce_mollie_get_payment_method_instance();
  try {
    $mollie = new Mollie_API_Client();
    $mollie
      ->setApiKey($payment_method['settings']['commerce_mollie_test_mode'] ? $payment_method['settings']['commerce_mollie_api_key_test'] : $payment_method['settings']['commerce_mollie_api_key_live']);
    $payment = $mollie->payments
      ->get($transaction->remote_id);
    if (!empty($payment)) {

      // Set status
      switch ($payment->status) {

        // Awaiting = COMMERCE_PAYMENT_STATUS_PENDING
        case 'open':
        case 'pending':
          $transaction->status = COMMERCE_PAYMENT_STATUS_PENDING;
          $transaction->remote_status = $payment->status;
          $transaction->message = commerce_mollie_status_explained($payment->status);
          break;

        // Cancelled = COMMERCE_PAYMENT_STATUS_FAILURE
        case 'cancelled':
        case 'expired':
          $transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
          $transaction->remote_status = $payment->status;
          $transaction->message = commerce_mollie_status_explained($payment->status);
          break;

        // Paid = COMMERCE_PAYMENT_STATUS_SUCCESS
        case 'paid':
        case 'paidout':
          $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
          $transaction->remote_status = $payment->status;
          $transaction->message = commerce_mollie_status_explained($payment->status);
          break;
        default:
          break;
      }
      return $transaction;
    }
  } catch (Mollie_API_Exception $e) {
    watchdog('commerce_mollie', 'Could not retrieve payment information. Error: %error', array(
      '%error' => htmlspecialchars($e
        ->getMessage()),
    ), WATCHDOG_ERROR);
    drupal_set_message(t('An error occured while retrieving payment status information from Mollie. Please try again later or contact your webmaster.'), 'error');
  }
  return $transaction;
}