Working on Mollie webhooks

This commit is contained in:
Hillel Coren 2017-07-17 11:07:53 +03:00
parent 19d2e6aa61
commit 14e4b5121e

View File

@ -4,6 +4,7 @@ namespace App\Ninja\PaymentDrivers;
use Exception; use Exception;
use App\Models\Invitation; use App\Models\Invitation;
use App\Models\Payment;
class MolliePaymentDriver extends BasePaymentDriver class MolliePaymentDriver extends BasePaymentDriver
{ {
@ -19,42 +20,38 @@ class MolliePaymentDriver extends BasePaymentDriver
public function completeOffsitePurchase($input) public function completeOffsitePurchase($input)
{ {
$details = $this->paymentDetails(); // payment is created by the webhook
$details['transactionReference'] = $this->invitation->transaction_reference; return false;
$response = $this->gateway()->fetchTransaction($details)->send();
if ($response->isCancelled() || ! $response->isSuccessful()) {
return false;
}
return $this->createPayment($response->getTransactionReference());
} }
public function handleWebHook($input) public function handleWebHook($input)
{ {
$ref = array_get($input, 'id'); $ref = array_get($input, 'id');
$invitation = Invitation::whereAccountId($this->accountGateway->account_id)
->whereTransactionReference($ref)
->first();
if ($invitation) {
$this->invitation = $invitation;
} else {
return false;
}
$data = [ $data = [
'transactionReference' => $ref 'transactionReference' => $ref
]; ];
$response = $this->gateway()->fetchTransaction($data)->send(); $response = $this->gateway()->fetchTransaction($data)->send();
if ($response->isCancelled() || ! $response->isSuccessful()) { 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 false;
} }
$this->createPayment($ref);
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }