mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 05:14:30 -04:00
Credit card: Pay with new credit card
This commit is contained in:
parent
a29d4f2075
commit
4818ea81bc
@ -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\Util\SystemLogger;
|
||||||
|
use App\Models\GatewayType;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use App\Models\PaymentType;
|
||||||
|
use App\Models\SystemLog;
|
||||||
use App\PaymentDrivers\MolliePaymentDriver;
|
use App\PaymentDrivers\MolliePaymentDriver;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
|
|
||||||
use function Symfony\Component\String\b;
|
|
||||||
|
|
||||||
class CreditCard
|
class CreditCard
|
||||||
{
|
{
|
||||||
@ -38,26 +40,72 @@ class CreditCard
|
|||||||
return render('gateways.mollie.credit_card.pay', $data);
|
return render('gateways.mollie.credit_card.pay', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a payment object.
|
||||||
|
*
|
||||||
|
* @param PaymentResponseRequest $request
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function paymentResponse(PaymentResponseRequest $request)
|
public function paymentResponse(PaymentResponseRequest $request)
|
||||||
{
|
{
|
||||||
|
$amount = number_format((float) $this->mollie->payment_hash->data->amount_with_fee, 2, '.', '');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$payment = $this->mollie->gateway->payments->create([
|
$payment = $this->mollie->gateway->payments->create([
|
||||||
"amount" => [
|
'amount' => [
|
||||||
"currency" => "USD",
|
'currency' => $this->mollie->client->currency()->code,
|
||||||
"value" => "10.00"
|
'value' => $amount,
|
||||||
],
|
],
|
||||||
"description" => "Order #12345",
|
'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' => 'https://webshop.example.org/mollie-webhook/',
|
||||||
|
'cardToken' => $request->token,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($payment->status === 'open') {
|
if ($payment->status === 'paid') {
|
||||||
return redirect($payment->getCheckoutUrl());
|
$this->mollie->logSuccessfulGatewayResponse(
|
||||||
|
['response' => $payment, 'data' => $this->mollie->payment_hash],
|
||||||
|
SystemLog::TYPE_MOLLIE
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->processSuccessfulPayment($payment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($payment->status === 'open') {
|
||||||
|
// Handle redirect payment
|
||||||
|
}
|
||||||
|
|
||||||
|
dd($payment);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new PaymentFailed($e->getMessage(), $e->getCode());
|
throw new PaymentFailed($e->getMessage(), $e->getCode());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dd($payment);
|
protected function processSuccessfulPayment(\Mollie\Api\Resources\Payment $payment)
|
||||||
|
{
|
||||||
|
// Check if storing credit card is enabled
|
||||||
|
|
||||||
|
$payment_hash = $this->mollie->payment_hash;
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'gateway_type_id' => GatewayType::CREDIT_CARD,
|
||||||
|
'amount' => array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total,
|
||||||
|
'payment_type' => PaymentType::CREDIT_CARD_OTHER,
|
||||||
|
'transaction_reference' => $payment->id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$payment_record = $this->mollie->createPayment($data, Payment::STATUS_COMPLETED);
|
||||||
|
|
||||||
|
SystemLogger::dispatch(
|
||||||
|
['response' => $payment, 'data' => $data],
|
||||||
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||||
|
SystemLog::EVENT_GATEWAY_SUCCESS,
|
||||||
|
SystemLog::TYPE_MOLLIE,
|
||||||
|
$this->mollie->client,
|
||||||
|
$this->mollie->client->company,
|
||||||
|
);
|
||||||
|
|
||||||
|
return redirect()->route('client.payments.show', ['payment' => $this->mollie->encodePrimaryKey($payment_record->id)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user