protected function MolliePayment::doExecutePayment in Mollie Payment 8.2
Performs the actual payment execution.
Overrides PaymentMethodBase::doExecutePayment
File
- src/
Plugin/ Payment/ Method/ MolliePayment.php, line 165
Class
- MolliePayment
- A payment method using Mollie.
Namespace
Drupal\mollie_payment\Plugin\Payment\MethodCode
protected function doExecutePayment() {
// Get the Mollie client.
$mollie_client = $this
->getMollieClient();
$redirect_url = new Url('mollie_payment.redirect', [
'payment' => $this
->getPayment()
->id(),
], [
'absolute' => TRUE,
]);
$webhook_url = new Url('mollie_payment.webhook', [
'payment' => $this
->getPayment()
->id(),
], [
'absolute' => TRUE,
]);
$payment_data = [
'amount' => $this
->getPayment()
->getAmount(),
'description' => $this
->getPayment()
->getPaymentType()
->getPaymentDescription(),
'redirectUrl' => $redirect_url
->toString(),
'webhookUrl' => $webhook_url
->toString(),
'metadata' => Json::encode([
'id' => $this
->getPayment()
->id(),
]),
];
try {
$mollie_payment = $mollie_client->payments
->create($payment_data);
// Store the Mollie payment id.
$this
->getPayment()
->set('mollie_payment_id', $mollie_payment->id)
->save();
// Redirect visitor to Mollie.
$redirect_url = $mollie_payment
->getPaymentUrl();
$url = Url::fromUri($redirect_url);
$response = new Response($url);
return new OperationResult($response);
} catch (Mollie_API_Exception $e) {
drupal_set_message($e
->getMessage(), 'error');
return;
}
}