| Server IP : 103.161.17.216 / Your IP : 216.73.216.1 Web Server : nginx/1.18.0 System : Linux tipsysaigoncharming 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/app.houseland.info/application/libraries/gateways/ |
Upload File : |
<?php
defined('BASEPATH') or exit('No direct script access allowed');
use Omnipay\Omnipay;
use Money\Exception\UnknownCurrencyException;
class Mollie_gateway extends App_gateway
{
public bool $processingFees = false;
public function __construct()
{
/**
* Call App_gateway __construct function
*/
parent::__construct();
/**
* REQUIRED
* Gateway unique id
* The ID must be alpha/alphanumeric
*/
$this->setId('mollie');
/**
* REQUIRED
* Gateway name
*/
$this->setName('Mollie');
/**
* Add gateway settings
*/
$this->setSettings([
[
'name' => 'api_key',
'encrypted' => true,
'label' => 'settings_paymentmethod_mollie_api_key',
],
[
'name' => 'description_dashboard',
'label' => 'settings_paymentmethod_description',
'type' => 'textarea',
'default_value' => 'Payment for Invoice {invoice_number}',
],
[
'name' => 'currencies',
'label' => 'currency',
'default_value' => 'EUR',
],
[
'name' => 'test_mode_enabled',
'type' => 'yes_no',
'default_value' => 1,
'label' => 'settings_paymentmethod_testing_mode',
],
]);
}
/**
* Process the payment
*
* @param array $data
*
* @return mixed
*/
public function process_payment($data)
{
$gateway = Omnipay::create('Mollie');
$gateway->setApiKey($this->decryptSetting('api_key'));
$webhookKey = app_generate_hash();
$invoiceNumber = format_invoice_number($data['invoice']->id);
$description = str_replace('{invoice_number}', $invoiceNumber, $this->getSetting('description_dashboard'));
$returnUrl = site_url('gateways/mollie/verify_payment?invoiceid=' . $data['invoice']->id . '&hash=' . $data['invoice']->hash);
$webhookUrl = site_url('gateways/mollie/webhook/' . $webhookKey);
$invoiceUrl = site_url('invoice/' . $data['invoice']->id . '/' . $data['invoice']->hash);
try {
$oResponse = $gateway->purchase([
'amount' => number_format($data['amount'], 2, '.', ''),
'currency' => $data['invoice']->currency_name,
'description' => $description,
'returnUrl' => $returnUrl,
'notifyUrl' => $webhookUrl,
'metadata' => [
'order_id' => $data['invoice']->id,
'webhookKey' => $webhookKey,
],
])->send();
} catch (UnknownCurrencyException $e) {
set_alert('danger', 'Invalid currency, ' . $e->getMessage());
redirect($invoiceUrl);
}
// Add the token to database
$this->ci->db->where('id', $data['invoiceid']);
$this->ci->db->update(db_prefix() . 'invoices', [
'token' => $oResponse->getTransactionReference(),
]);
if ($oResponse->isRedirect()) {
$oResponse->redirect();
} elseif ($oResponse->isPending()) {
echo 'Pending, Reference: ' . $oResponse->getTransactionReference();
} else {
set_alert('danger', $oResponse->getData()['detail']);
redirect($invoiceUrl);
}
}
/**
* Retrieve payment from Mollie
*
* @param string $transactionId
*
* @return mixed
*/
public function fetch_payment($transactionId)
{
$gateway = Omnipay::create('Mollie');
$gateway->setApiKey($this->decryptSetting('api_key'));
return $gateway->fetchTransaction([
'transactionReference' => $transactionId,
])->send();
}
}