1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
This commit is contained in:
Benjamin Beganović 2021-07-29 16:15:27 +02:00
parent d50c629476
commit 202cc9d670
2 changed files with 73 additions and 2 deletions

View File

@ -11,7 +11,7 @@ use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\MolliePaymentDriver;
use App\Utils\Number;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
@ -50,6 +50,8 @@ class CreditCard
*/
public function paymentResponse(PaymentResponseRequest $request)
{
dd($this->mollie->gateway->mandates->listForId('cst_6S77wEkuQT'));
// TODO: Unit tests.
$amount = number_format((float) $this->mollie->payment_hash->data->amount_with_fee, 2, '.', '');
@ -58,7 +60,16 @@ class CreditCard
->withData('client_id', $this->mollie->client->id);
try {
$customer = $this->mollie->gateway->customers->create([
'name' => $this->mollie->client->name,
'metadata' => [
'id' => $this->mollie->client->hashed_id,
],
]);
$payment = $this->mollie->gateway->payments->create([
'customerId' => $customer->id,
'sequenceType' => 'first',
'amount' => [
'currency' => $this->mollie->client->currency()->code,
'value' => $amount,
@ -79,7 +90,7 @@ class CreditCard
SystemLog::TYPE_MOLLIE
);
return $this->processSuccessfulPayment($payment);
return $this->processSuccessfulPayment($payment);
}
if ($payment->status === 'open') {
@ -139,4 +150,27 @@ class CreditCard
throw new PaymentFailed($e->getMessage(), $e->getCode());
}
/**
* Show authorization page.
*
* @param array $data
* @return Factory|View
*/
public function authorizeView(array $data)
{
return render('gateways.mollie.credit_card.authorize', $data);
}
public function authorizeResponse($request)
{
$customer = $this->mollie->gateway->customers->create([
'name' => $this->mollie->client->name,
'metadata' => [
'id' => $this->mollie->client->hashed_id,
],
]);
// Save $customer->id to database..
}
}

View File

@ -0,0 +1,37 @@
@extends('portal.ninja2020.layout.payments', ['gateway_title' => ctrans('texts.credit_card'), 'card_title' =>
ctrans('texts.credit_card')])
@section('gateway_head')
@endsection
@section('gateway_content')
<form action="{{ route('client.payment_methods.store', ['method' => App\Models\GatewayType::CREDIT_CARD]) }}"
method="post" id="server_response">
@csrf
<input type="hidden" name="company_gateway_id" value="{{ $gateway->gateway_id }}">
{{-- <input type="hidden" name="payment_method_id" value="1"> --}}
<input type="hidden" name="gateway_response" id="gateway_response">
</form>
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.method')])
{{ ctrans('texts.credit_card') }}
@endcomponent
@component('portal.ninja2020.components.general.card-element-single')
Click the "Add Payment Method" button to complete test payment.
@endcomponent
@component('portal.ninja2020.gateways.includes.pay_now', ['id' => 'authorize-card'])
{{ ctrans('texts.add_payment_method') }}
@endcomponent
@endsection
@section('gateway_footer')
<script>
document.getElementById('authorize-card')
.addEventListener('click', (e) => {
document.getElementById('server_response').submit();
});
</script>
@endsection