mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 12:42:36 +01:00
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Ninja\PaymentDrivers;
|
|
|
|
use Exception;
|
|
use App\Models\Invitation;
|
|
use App\Models\Payment;
|
|
|
|
class MolliePaymentDriver extends BasePaymentDriver
|
|
{
|
|
protected function paymentDetails($paymentMethod = false)
|
|
{
|
|
$data = parent::paymentDetails($paymentMethod);
|
|
|
|
// Enable webhooks
|
|
$data['notifyUrl'] = url('/payment_hook/'. $this->account()->account_key . '/' . GATEWAY_MOLLIE);
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function completeOffsitePurchase($input)
|
|
{
|
|
// payment is created by the webhook
|
|
return false;
|
|
}
|
|
|
|
public function handleWebHook($input)
|
|
{
|
|
$ref = array_get($input, 'id');
|
|
$data = [
|
|
'transactionReference' => $ref
|
|
];
|
|
|
|
$response = $this->gateway()->fetchTransaction($data)->send();
|
|
|
|
if ($response->isPaid() || $response->isPaidOut()) {
|
|
$invitation = Invitation::whereAccountId($this->accountGateway->account_id)
|
|
->whereTransactionReference($ref)
|
|
->first();
|
|
if ($invitation) {
|
|
$this->invitation = $invitation;
|
|
$this->createPayment($ref);
|
|
}
|
|
} else {
|
|
// check if payment has failed
|
|
$payment = Payment::whereAccountId($this->accountGateway->account_id)
|
|
->whereTransactionReference($ref)
|
|
->first();
|
|
if ($payment) {
|
|
$payment->markFailed($response->getStatus());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
}
|
|
|
|
}
|