1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Ninja/PaymentDrivers/MolliePaymentDriver.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Ninja\PaymentDrivers;
2016-06-20 16:14:43 +02:00
2016-08-11 12:17:01 +02:00
use Exception;
2017-07-06 22:12:09 +02:00
use App\Models\Invitation;
2017-07-17 10:07:53 +02:00
use App\Models\Payment;
2016-08-11 12:17:01 +02:00
2016-06-20 16:14:43 +02:00
class MolliePaymentDriver extends BasePaymentDriver
{
2017-07-06 11:45:44 +02:00
protected function paymentDetails($paymentMethod = false)
{
$data = parent::paymentDetails($paymentMethod);
2017-07-06 22:12:09 +02:00
// Enable webhooks
$data['notifyUrl'] = url('/payment_hook/'. $this->account()->account_key . '/' . GATEWAY_MOLLIE);
2017-07-06 11:45:44 +02:00
return $data;
}
2016-07-21 14:35:23 +02:00
public function completeOffsitePurchase($input)
2016-06-20 16:14:43 +02:00
{
2017-07-17 10:07:53 +02:00
// payment is created by the webhook
return false;
2016-06-20 16:14:43 +02:00
}
2017-07-06 12:10:54 +02:00
public function handleWebHook($input)
{
2017-07-06 22:12:09 +02:00
$ref = array_get($input, 'id');
$data = [
'transactionReference' => $ref
];
2017-07-17 10:07:53 +02:00
2017-07-06 22:12:09 +02:00
$response = $this->gateway()->fetchTransaction($data)->send();
2017-07-17 10:07:53 +02:00
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());
}
2017-07-06 22:12:09 +02:00
return false;
}
return RESULT_SUCCESS;
2017-07-06 12:10:54 +02:00
}
2016-06-20 16:14:43 +02:00
}