Add payment method button added on Cconfirm payment page.

This commit is contained in:
Kishan Patel 2022-04-19 17:47:28 +05:30
parent 7be910ea69
commit c9f900a673
4 changed files with 44 additions and 36 deletions

View File

@ -14,6 +14,7 @@ namespace App\PaymentDrivers\Forte;
use App\Models\Payment; use App\Models\Payment;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\PaymentHash;
use App\Models\PaymentType; use App\Models\PaymentType;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
@ -160,7 +161,7 @@ class ACH
$this->forte->storeGatewayToken($data, ['gateway_customer_reference' => $customer_token]); $this->forte->storeGatewayToken($data, ['gateway_customer_reference' => $customer_token]);
return redirect()->route('client.payment_methods.index'); return redirect()->route('client.payment_methods.index')->withSuccess('Payment Method added.');
} }
public function paymentView(array $data) public function paymentView(array $data)
@ -169,17 +170,12 @@ class ACH
$this->forte->payment_hash->save(); $this->forte->payment_hash->save();
$data['gateway'] = $this; $data['gateway'] = $this;
$data['system_amount_with_fee'] = $data['amount_with_fee'];
$data['fee_percent'] = $this->forte->company_gateway->fees_and_limits->{GatewayType::BANK_TRANSFER}->fee_percent;
$data['total']['fee_total'] = $data['total']['invoice_totals'] * $data['fee_percent'] / 100;
$data['total']['amount_with_fee'] = $data['total']['fee_total'] + $data['total']['invoice_totals'];
$data['amount_with_fee'] = $data['total']['amount_with_fee'];
return render('gateways.forte.ach.pay', $data); return render('gateways.forte.ach.pay', $data);
} }
public function paymentResponse($request) public function paymentResponse($request)
{ {
$data=$request; $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->firstOrFail();
try { try {
$curl = curl_init(); $curl = curl_init();
@ -194,8 +190,8 @@ class ACH
CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{ CURLOPT_POSTFIELDS =>'{
"action":"sale", "action":"sale",
"authorization_amount": '.$data->amount_with_fee.', "authorization_amount": '.$payment_hash->data->total->amount_with_fee.',
"paymethod_token": "'.$data->payment_token.'", "paymethod_token": "'.$request->payment_token.'",
"echeck":{ "echeck":{
"sec_code":"PPD", "sec_code":"PPD",
}, },
@ -228,10 +224,13 @@ class ACH
return redirect('client/invoices')->withErrors($error); return redirect('client/invoices')->withErrors($error);
} }
$data['gateway_type_id']=GatewayType::CREDIT_CARD; $data = [
$data['amount']=$request->system_amount_with_fee; 'payment_method' => $request->payment_method_id,
$data['payment_type']=PaymentType::ACH; 'payment_type' => PaymentType::parseCardType(strtolower($request->card_brand)) ?: PaymentType::CREDIT_CARD_OTHER,
$data['transaction_reference']=$response->transaction_id; 'amount' => $payment_hash->data->amount_with_fee,
'transaction_reference' => $response->transaction_id,
'gateway_type_id' => GatewayType::CREDIT_CARD,
];
$payment=$this->forte->createPayment($data, Payment::STATUS_COMPLETED); $payment=$this->forte->createPayment($data, Payment::STATUS_COMPLETED);
return redirect('client/invoices')->withSuccess('Invoice paid.'); return redirect('client/invoices')->withSuccess('Invoice paid.');

View File

@ -14,6 +14,7 @@ namespace App\PaymentDrivers\Forte;
use App\Models\Payment; use App\Models\Payment;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\PaymentHash;
use App\Models\PaymentType; use App\Models\PaymentType;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Session;
@ -165,7 +166,7 @@ class CreditCard
$this->forte->storeGatewayToken($data, ['gateway_customer_reference' => $customer_token]); $this->forte->storeGatewayToken($data, ['gateway_customer_reference' => $customer_token]);
return redirect()->route('client.payment_methods.index'); return redirect()->route('client.payment_methods.index')->withSuccess('Payment Method added.');
} }
public function paymentView(array $data) public function paymentView(array $data)
@ -174,17 +175,12 @@ class CreditCard
$this->forte->payment_hash->save(); $this->forte->payment_hash->save();
$data['gateway'] = $this; $data['gateway'] = $this;
$data['system_amount_with_fee'] = $data['amount_with_fee'];
$data['fee_percent'] = $this->forte->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->fee_percent;
$data['total']['fee_total'] = $data['total']['invoice_totals'] * $data['fee_percent'] / 100;
$data['total']['amount_with_fee'] = $data['total']['fee_total'] + $data['total']['invoice_totals'];
$data['amount_with_fee'] = $data['total']['amount_with_fee'];
return render('gateways.forte.credit_card.pay', $data); return render('gateways.forte.credit_card.pay', $data);
} }
public function paymentResponse(PaymentResponseRequest $request) public function paymentResponse(PaymentResponseRequest $request)
{ {
$data=$request; $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->firstOrFail();
try { try {
$curl = curl_init(); $curl = curl_init();
@ -199,9 +195,9 @@ class CreditCard
CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{ CURLOPT_POSTFIELDS =>'{
"action":"sale", "action":"sale",
"authorization_amount": '.$data->amount_with_fee.', "authorization_amount": '.$payment_hash->data->total->amount_with_fee.',
"service_fee_amount": '.$data->fee_total.', "service_fee_amount": '.$payment_hash->data->total->fee_total.',
"paymethod_token": "'.$data->payment_token.'", "paymethod_token": "'.$request->payment_token.'",
"billing_address":{ "billing_address":{
"first_name": "'.auth()->user()->client->name.'", "first_name": "'.auth()->user()->client->name.'",
"last_name": "'.auth()->user()->client->name.'" "last_name": "'.auth()->user()->client->name.'"
@ -230,11 +226,13 @@ class CreditCard
return redirect('client/invoices')->withErrors($error); return redirect('client/invoices')->withErrors($error);
} }
$data['gateway_type_id']=GatewayType::CREDIT_CARD; $data = [
$data['amount']=$request->system_amount_with_fee; 'payment_method' => $request->payment_method_id,
$data['payment_type']=PaymentType::parseCardType(strtolower($request->card_brand)) ?: PaymentType::CREDIT_CARD_OTHER; 'payment_type' => PaymentType::parseCardType(strtolower($request->card_brand)) ?: PaymentType::CREDIT_CARD_OTHER,
$data['transaction_reference']=$response->transaction_id; 'amount' => $payment_hash->data->amount_with_fee,
'transaction_reference' => $response->transaction_id,
'gateway_type_id' => GatewayType::CREDIT_CARD,
];
$payment=$this->forte->createPayment($data, Payment::STATUS_COMPLETED); $payment=$this->forte->createPayment($data, Payment::STATUS_COMPLETED);
return redirect('client/invoices')->withSuccess('Invoice paid.'); return redirect('client/invoices')->withSuccess('Invoice paid.');
} }

View File

@ -21,9 +21,6 @@
<input type="hidden" name="dataDescriptor" id="dataDescriptor"/> <input type="hidden" name="dataDescriptor" id="dataDescriptor"/>
<input type="hidden" name="token" id="token"/> <input type="hidden" name="token" id="token"/>
<input type="hidden" name="store_card" id="store_card"/> <input type="hidden" name="store_card" id="store_card"/>
<input type="hidden" name="amount_with_fee" id="amount_with_fee" value="{{ $total['amount_with_fee'] }}"/>
<input type="hidden" name="system_amount_with_fee" id="system_amount_with_fee" value="{{ $system_amount_with_fee }}"/>
<input type="hidden" name="fee_total" id="fee_total" value="{{ $total['fee_total'] }}"/>
<div id="errors"></div> <div id="errors"></div>
@ -47,7 +44,15 @@
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span> <span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
</label> </label>
@endforeach @endforeach
@endisset @else
<div class="relative" x-data="{ open: false }" x-on:click.away="open = false">
@if($client->getBankTransferGateway())
<a data-cy="add-bank-account-link" href="{{ route('client.payment_methods.create', ['method' => $client->getBankTransferMethodType()]) }}" class="button button-primary bg-primary">
{{ ctrans('texts.bank_account') }}
</a>
@endif
</div>
@endif
@endcomponent @endcomponent
<div class="bg-white px-4 py-5 flex justify-end"> <div class="bg-white px-4 py-5 flex justify-end">

View File

@ -21,9 +21,6 @@
<input type="hidden" name="dataDescriptor" id="dataDescriptor"/> <input type="hidden" name="dataDescriptor" id="dataDescriptor"/>
<input type="hidden" name="token" id="token"/> <input type="hidden" name="token" id="token"/>
<input type="hidden" name="store_card" id="store_card"/> <input type="hidden" name="store_card" id="store_card"/>
<input type="hidden" name="amount_with_fee" id="amount_with_fee" value="{{ $total['amount_with_fee'] }}"/>
<input type="hidden" name="system_amount_with_fee" id="system_amount_with_fee" value="{{ $system_amount_with_fee }}"/>
<input type="hidden" name="fee_total" id="fee_total" value="{{ $total['fee_total'] }}"/>
<div id="errors"></div> <div id="errors"></div>
@ -48,7 +45,16 @@
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span> <span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
</label> </label>
@endforeach @endforeach
@endisset @else
<div class="relative" x-data="{ open: false }" x-on:click.away="open = false">
<!-- Add payment method button -->
@if($client->getCreditCardGateway())
<a data-cy="add-credit-card-link" href="{{ route('client.payment_methods.create', ['method' => App\Models\GatewayType::CREDIT_CARD]) }}" class="button button-primary bg-primary">
{{ ctrans('texts.credit_card') }}
</a>
@endif
</div>
@endif
@endcomponent @endcomponent
<div class="bg-white px-4 py-5 flex justify-end"> <div class="bg-white px-4 py-5 flex justify-end">