Enable Mollie webhooks

This commit is contained in:
Hillel Coren 2017-07-06 23:17:17 +03:00
parent 29ba313086
commit d40c222253
2 changed files with 43 additions and 4 deletions

View File

@ -618,6 +618,9 @@ class BasePaymentDriver
$account = $this->account(); $account = $this->account();
$invitation = $this->invitation; $invitation = $this->invitation;
$invoice = $this->invoice(); $invoice = $this->invoice();
if (! $invoice->canBePaid()) {
return false;
}
$invoice->markSentIfUnsent(); $invoice->markSentIfUnsent();
$payment = Payment::createNew($invitation); $payment = Payment::createNew($invitation);

View File

@ -3,23 +3,59 @@
namespace App\Ninja\PaymentDrivers; namespace App\Ninja\PaymentDrivers;
use Exception; use Exception;
use App\Models\Invitation;
class MolliePaymentDriver extends BasePaymentDriver 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) public function completeOffsitePurchase($input)
{ {
$details = $this->paymentDetails(); $details = $this->paymentDetails();
$details['transactionReference'] = $this->invitation->transaction_reference; $details['transactionReference'] = $this->invitation->transaction_reference;
$response = $this->gateway()->fetchTransaction($details)->send(); $response = $this->gateway()->fetchTransaction($details)->send();
if ($response->isCancelled()) { if ($response->isCancelled() || ! $response->isSuccessful()) {
return false; return false;
} elseif (! $response->isSuccessful()) {
throw new Exception($response->getMessage());
} }
return $this->createPayment($response->getTransactionReference()); return $this->createPayment($response->getTransactionReference());
} }
public function handleWebHook($input)
{
$ref = array_get($input, 'id');
$invitation = Invitation::whereAccountId($this->accountGateway->account_id)
->whereTransactionReference($ref)
->first();
if ($invitation) {
$this->invitation = $invitation;
} else {
return false;
}
$data = [
'transactionReference' => $ref
];
$response = $this->gateway()->fetchTransaction($data)->send();
if ($response->isCancelled() || ! $response->isSuccessful()) {
return false;
}
$this->createPayment($ref);
return RESULT_SUCCESS;
}
} }