Merge pull request #4778 from beganovich/v5-2701-ach-blank-screen

(v5) ACH: Fix blank screen after payment
This commit is contained in:
Benjamin Beganović 2021-01-28 15:45:14 +01:00 committed by GitHub
commit e2d1c7ac43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -22,6 +22,7 @@ use App\Models\Payment;
use App\Models\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver; use App\PaymentDrivers\StripePaymentDriver;
use App\Utils\Traits\MakesHash;
use Exception; use Exception;
use Stripe\Customer; use Stripe\Customer;
use Stripe\Exception\CardException; use Stripe\Exception\CardException;
@ -29,6 +30,8 @@ use Stripe\Exception\InvalidRequestException;
class ACH class ACH
{ {
use MakesHash;
/** @var StripePaymentDriver */ /** @var StripePaymentDriver */
public $stripe; public $stripe;
@ -109,16 +112,25 @@ class ACH
{ {
$this->stripe->init(); $this->stripe->init();
$source = ClientGatewayToken::query()
->where('id', $this->decodePrimaryKey($request->source))
->where('company_id', auth('contact')->user()->client->company->id)
->first();
if (!$source) {
throw new PaymentFailed(ctrans('texts.payment_token_not_found'), 401);
}
$state = [ $state = [
'payment_method' => $request->payment_method_id, 'payment_method' => $request->payment_method_id,
'gateway_type_id' => $request->company_gateway_id, 'gateway_type_id' => $request->company_gateway_id,
'amount' => $this->stripe->convertToStripeAmount($request->amount, $this->stripe->client->currency()->precision), 'amount' => $this->stripe->convertToStripeAmount($request->amount, $this->stripe->client->currency()->precision),
'currency' => $request->currency, 'currency' => $request->currency,
'source' => $request->source,
'customer' => $request->customer, 'customer' => $request->customer,
]; ];
$state = array_merge($state, $request->all()); $state = array_merge($state, $request->all());
$state['source'] = $source->token;
$this->stripe->payment_hash->data = array_merge((array)$this->stripe->payment_hash->data, $state); $this->stripe->payment_hash->data = array_merge((array)$this->stripe->payment_hash->data, $state);
$this->stripe->payment_hash->save(); $this->stripe->payment_hash->save();
@ -145,6 +157,8 @@ class ACH
if ($e instanceof CardException) { if ($e instanceof CardException) {
return redirect()->route('client.payment_methods.verification', ['id' => ClientGatewayToken::first()->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); return redirect()->route('client.payment_methods.verification', ['id' => ClientGatewayToken::first()->hashed_id, 'method' => GatewayType::BANK_TRANSFER]);
} }
throw new PaymentFailed($e->getMessage(), $e->getCode());
} }
} }

View File

@ -23,7 +23,7 @@
<label class="mr-4"> <label class="mr-4">
<input <input
type="radio" type="radio"
data-token="{{ $token->token }}" data-token="{{ $token->hashed_id }}"
name="payment-type" name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/> class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">{{ ctrans('texts.bank_transfer') }} (*{{ $token->meta->last4 }})</span> <span class="ml-1 cursor-pointer">{{ ctrans('texts.bank_transfer') }} (*{{ $token->meta->last4 }})</span>