Refactor payment with credit card

This commit is contained in:
Benjamin Beganović 2021-07-26 17:03:40 +02:00
parent 2501654fec
commit 548405c4d8
2 changed files with 32 additions and 7 deletions

View File

@ -4,12 +4,14 @@ namespace App\PaymentDrivers\Mollie;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\MolliePaymentDriver;
use App\Utils\Number;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
@ -48,17 +50,21 @@ class CreditCard
*/
public function paymentResponse(PaymentResponseRequest $request)
{
$amount = number_format((float) $this->mollie->payment_hash->data->amount_with_fee, 2, '.', '');
$this->mollie->payment_hash->withData('gateway_type_id', GatewayType::CREDIT_CARD);
try {
$payment = $this->mollie->gateway->payments->create([
'amount' => [
'currency' => $this->mollie->client->currency()->code,
'value' => $amount,
'value' => Number::formatValue($this->mollie->payment_hash->data->amount_with_fee, $this->mollie->client->currency()),
],
'description' => \sprintf('Hash: %s', $this->mollie->payment_hash->hash),
'redirectUrl' => 'https://webshop.example.org/order/12345/',
'webhookUrl' => 'https://webshop.example.org/mollie-webhook/',
'webhookUrl' => route('mollie.3ds_redirect', [
'company_key' => $this->mollie->client->company->company_key,
'company_gateway_id' => $this->mollie->company_gateway->hashed_id,
'hash' => $this->mollie->payment_hash->hash,
]),
'cardToken' => $request->token,
]);
@ -72,12 +78,11 @@ class CreditCard
}
if ($payment->status === 'open') {
// Handle redirect payment
return redirect($payment->getCheckoutUrl());
}
dd($payment);
} catch (\Exception $e) {
$this->processUnsuccessfulPayment($e);
throw new PaymentFailed($e->getMessage(), $e->getCode());
}
}
@ -108,4 +113,23 @@ class CreditCard
return redirect()->route('client.payments.show', ['payment' => $this->mollie->encodePrimaryKey($payment_record->id)]);
}
public function processUnsuccessfulPayment(\Exception $e)
{
PaymentFailureMailer::dispatch(
$this->mollie->client,
$e->getMessage(),
$this->mollie->client->company,
$this->mollie->payment_hash->data->amount_with_fee
);
SystemLogger::dispatch(
$e->getMessage(),
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_MOLLIE,
$this->mollie->client,
$this->mollie->client->company,
);
}
}

View File

@ -42,3 +42,4 @@ Route::get('stripe/signup/{token}', 'StripeConnectController@initialize')->name(
Route::get('stripe/completed', 'StripeConnectController@completed')->name('stripe_connect.return');
Route::get('checkout/3ds_redirect/{company_key}/{company_gateway_id}/{hash}', 'Gateways\Checkout3dsController@index')->name('checkout.3ds_redirect');
Route::get('mollie/3ds_redirect/{company_key}/{company_gateway_id}/{hash}', 'Gateways\Mollie3dsController@index')->name('mollie.3ds_redirect');