This commit is contained in:
Benjamin Beganović 2021-08-02 16:33:37 +02:00
parent 8217065f6c
commit 804c666f3b

View File

@ -115,7 +115,56 @@ class MolliePaymentDriver extends BaseDriver
public function refund(Payment $payment, $amount, $return_client_response = false) public function refund(Payment $payment, $amount, $return_client_response = false)
{ {
$this->init();
try {
$payment = $this->gateway->payments->get($payment->transaction_reference);
$refund = $this->gateway->payments->refund($payment, [
'amount' => [
'currency' => $this->client->currency()->code,
'value' => $this->convertToMollieAmount((float) $amount),
],
]);
if ($refund->status === 'refunded') {
SystemLogger::dispatch(
['server_response' => $refund, 'data' => request()->all()],
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_SUCCESS,
SystemLog::TYPE_MOLLIE,
$this->client,
$this->client->company
);
return [
'transaction_reference' => $refund->id,
'transaction_response' => json_encode($refund),
'success' => $refund->status === 'refunded' ? true : false,
'description' => $refund->description,
'code' => 200,
];
}
} catch (ApiException $e) {
SystemLogger::dispatch(
['server_response' => $refund, 'data' => request()->all()],
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_MOLLIE,
$this->client,
$this->client->companyk
);
nlog($e->getMessage());
return [
'transaction_reference' => null,
'transaction_response' => $e->getMessage(),
'success' => false,
'description' => $e->getMessage(),
'code' => $e->getCode(),
];
}
} }
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
@ -152,7 +201,7 @@ class MolliePaymentDriver extends BaseDriver
$record->save(); $record->save();
return response()->json([], 200); return response()->json([], 200);
} catch(ApiException $e) { } catch (ApiException $e) {
return response()->json(['message' => $e->getMessage(), 'gatewayStatusCode' => $e->getCode()], 500); return response()->json(['message' => $e->getMessage(), 'gatewayStatusCode' => $e->getCode()], 500);
} }
} }