class MolliePaymentMethodController in Mollie Payment 7.2
Same name and namespace in other branches
- 7 includes/mollie_payment.class.inc \MolliePaymentMethodController
Mollie payment method controller.
Hierarchy
- class \PaymentMethodController
Expanded class hierarchy of MolliePaymentMethodController
1 file declares its use of MolliePaymentMethodController
5 string references to 'MolliePaymentMethodController'
- mollie_payment_entity_load in ./
mollie_payment.module - Implements hook_entity_load().
- mollie_payment_payment_method_controller_info in ./
mollie_payment.module - Implements hook_payment_method_controller_info().
- mollie_payment_payment_method_delete in ./
mollie_payment.module - Implements hook_ENTITY_TYPE_ACTION().
- mollie_payment_payment_method_insert in ./
mollie_payment.module - Implements hook_ENTITY_TYPE_ACTION().
- mollie_payment_payment_method_update in ./
mollie_payment.module - Implements hook_ENTITY_TYPE_ACTION().
File
- includes/
mollie_payment.class.inc, line 10
View source
class MolliePaymentMethodController extends PaymentMethodController {
public $payment_method_configuration_form_elements_callback = 'mollie_payment_method_configuration';
public $payment_configuration_form_elements_callback = 'mollie_payment_configuration';
/**
* Class constructor.
*/
public function __construct() {
$this->title = t('Mollie');
}
/**
* Implements PaymentMethodController::execute().
*/
public function execute(Payment $payment) {
try {
$method_data = $payment->method_data;
$controller_data = $payment->method->controller_data;
$client = mollie_payment_get_client($payment);
if (!$client) {
return;
}
$return_path = MOLLIE_PAYMENT_RETURN_PATH;
$listener_path = MOLLIE_PAYMENT_LISTENER_PATH;
$recurring_listener_path = MOLLIE_PAYMENT_RECURRING_LISTENER_PATH;
if (!empty($controller_data['webhook_base_url'])) {
$return_path = $controller_data['webhook_base_url'] . '/' . $return_path;
$listener_path = $controller_data['webhook_base_url'] . '/' . $listener_path;
$recurring_listener_path = $controller_data['webhook_base_url'] . '/' . $recurring_listener_path;
}
$payment_data = array(
'amount' => array(
'value' => number_format(floatval($payment
->totalAmount(TRUE)), 2, '.', ''),
'currency' => $payment->currency_code,
),
'description' => $payment->description,
'redirectUrl' => url($return_path . '/' . $payment->pid, array(
'absolute' => TRUE,
)),
'webhookUrl' => url($listener_path . '/' . $payment->pid, array(
'absolute' => TRUE,
)),
);
// Do not include the webhook in test mode when no webhook base URL is
// configured. But inform the use about the consequences.
if ($controller_data['test_mode'] && empty($controller_data['webhook_base_url'])) {
unset($payment_data['webhookUrl']);
drupal_set_message(t('No webhook URL was send to Mollie because you are in test mode without a webhook base URL configured. Mollie cannot report status updated on this payment.'), 'warning');
}
if (isset($method_data['mollie_payment_method'])) {
$payment_data['method'] = $method_data['mollie_payment_method'];
}
if (isset($method_data['mollie_payment_issuer'])) {
$payment_data['issuer'] = $method_data['mollie_payment_issuer'];
}
if (module_exists('payment_recurring')) {
$recurring_info = payment_recurring_recurring_payment_info($payment);
if (!empty($recurring_info)) {
// This is a recurring payment.
$payment_data['sequenceType'] = \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST;
/** @var \Mollie\Api\Resources\Customer $customer */
// We need to created a customer first.
$customer = $client->customers
->create(array(
'name' => $recurring_info['name'],
'email' => $recurring_info['email'],
));
/** @var \Mollie\Api\Resources\Payment $mollie_payment */
$mollie_payment = $customer
->createPayment($payment_data);
}
}
if (!isset($mollie_payment)) {
/** @var \Mollie\Api\Resources\Payment $mollie_payment */
// Create the payment in the Mollie system.
$mollie_payment = $client->payments
->create($payment_data);
}
// Context data might not be the best location to store this information
// because in fact it is not related to the context. We might consider
// storing it in a separate database table just like the controller data
// of the payment method. (The method_data in the payment object is
// currently not stored.)
$payment->context_data['payment'] = array(
'id' => $mollie_payment->id,
);
entity_save('payment', $payment);
$redirect_url = $mollie_payment
->getCheckoutUrl();
if (module_exists('payment_context')) {
/** @var \Drupal\payment_context\PaymentContextInterface $context */
$context = $payment->contextObj;
$context
->redirect($redirect_url);
}
else {
drupal_goto($redirect_url, array(), 303);
}
} catch (Exception $e) {
watchdog('mollie_payment', 'Payment execution failed: <pre>@data</pre>', array(
'@data' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MolliePaymentMethodController:: |
public | property |
The function name of the payment configuration form elements. Overrides PaymentMethodController:: |
|
MolliePaymentMethodController:: |
public | property |
The function name of the payment method configuration form elements. Overrides PaymentMethodController:: |
|
MolliePaymentMethodController:: |
public | function |
Implements PaymentMethodController::execute(). Overrides PaymentMethodController:: |
|
MolliePaymentMethodController:: |
public | function | Class constructor. | |
PaymentMethodController:: |
public | property | Default values for the controller_data property of a PaymentMethod that uses this controller. | 1 |
PaymentMethodController:: |
public | property | An array with ISO 4217 currency codes that this controller supports. | |
PaymentMethodController:: |
public | property | A human-readable plain text description of this payment method controller. | |
PaymentMethodController:: |
public | property | The machine name. | |
PaymentMethodController:: |
public | property | The human-readable plain text title. | |
PaymentMethodController:: |
static | function | Returns an array with the names of all available payment method controllers that inherit of this one. | |
PaymentMethodController:: |
function | Validate a payment against a payment method and this controller. Don't call directly. Use PaymentMethod::validate() instead. | 2 |