mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Refactor payment with credit card
This commit is contained in:
parent
2501654fec
commit
548405c4d8
@ -4,12 +4,14 @@ namespace App\PaymentDrivers\Mollie;
|
|||||||
|
|
||||||
use App\Exceptions\PaymentFailed;
|
use App\Exceptions\PaymentFailed;
|
||||||
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
||||||
|
use App\Jobs\Mail\PaymentFailureMailer;
|
||||||
use App\Jobs\Util\SystemLogger;
|
use App\Jobs\Util\SystemLogger;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaymentType;
|
use App\Models\PaymentType;
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
use App\PaymentDrivers\MolliePaymentDriver;
|
use App\PaymentDrivers\MolliePaymentDriver;
|
||||||
|
use App\Utils\Number;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
|
|
||||||
@ -48,17 +50,21 @@ class CreditCard
|
|||||||
*/
|
*/
|
||||||
public function paymentResponse(PaymentResponseRequest $request)
|
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 {
|
try {
|
||||||
$payment = $this->mollie->gateway->payments->create([
|
$payment = $this->mollie->gateway->payments->create([
|
||||||
'amount' => [
|
'amount' => [
|
||||||
'currency' => $this->mollie->client->currency()->code,
|
'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),
|
'description' => \sprintf('Hash: %s', $this->mollie->payment_hash->hash),
|
||||||
'redirectUrl' => 'https://webshop.example.org/order/12345/',
|
'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,
|
'cardToken' => $request->token,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -72,12 +78,11 @@ class CreditCard
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($payment->status === 'open') {
|
if ($payment->status === 'open') {
|
||||||
// Handle redirect payment
|
return redirect($payment->getCheckoutUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
dd($payment);
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$this->processUnsuccessfulPayment($e);
|
||||||
|
|
||||||
throw new PaymentFailed($e->getMessage(), $e->getCode());
|
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)]);
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,3 +42,4 @@ Route::get('stripe/signup/{token}', 'StripeConnectController@initialize')->name(
|
|||||||
Route::get('stripe/completed', 'StripeConnectController@completed')->name('stripe_connect.return');
|
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('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');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user