diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 6cab926f64c0..04325abec5ff 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -14,6 +14,7 @@ namespace App\Http\Controllers\ClientPortal; use = namespace\Cache; use App\Filters\PaymentFilters; use App\Http\Controllers\Controller; +use App\Models\CompanyGateway; use App\Models\Payment; use App\Utils\Traits\MakesHash; use Illuminate\Http\Request; @@ -101,19 +102,23 @@ class PaymentController extends Controller Cache::put($cache_hash, 'value', now()->addMinutes(10)); //boot the payment gateway - - //build the gateway specific views - + $gateway = CompanyGateway::find($company_gateway_id); + //if there is a gateway fee, now is the time to calculate it + //and add it to the invoice + $data = [ - 'redirect_url' =>, + 'cache_hash' => $cache_hash, 'invoices' => $invoices, 'amount' => $amount, - 'gateway_data' =>, - 'cache_hash' => $cache_hash, + 'fee' => $gateway->calcGatewayFee($amount), + 'amount_with_fee' => ($amount + $gateway->calcGatewayFee($amount)), + 'gateway' => $gateway, + 'payment_method_id' => $payment_method_id, + 'token' => auth()->user()->client->gateway_token($gateway->id), ]; - return view('', $data); + return view($gateway->driver()->viewForType($payment_method_id), $data); } diff --git a/app/Models/Client.php b/app/Models/Client.php index a25068402b51..63849bb82c73 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -100,6 +100,25 @@ class Client extends BaseModel return $this->hasMany(ClientGatewayToken::class); } + /** + * Retrieves the specific payment token per + * gateway - per payment method + * + * Allows the storage of multiple tokens + * per client per gateway per payment_method + * + * @param int $gateway_id The gateway ID + * @param int $payment_method_id The payment method ID + * @return ClientGatewayToken The client token record + */ + public function gateway_token($gateway_id, $payment_method_id) + { + return $this->gateway_tokens + ->whereCompanyGatewayId($gateway_id) + ->wherePaymentMethod_id($payment_method_id) + ->first(); + } + public function contacts() { return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc'); diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 9480115c1cff..26f213e033c9 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -12,6 +12,7 @@ namespace App\PaymentDrivers; use App\Models\GatewayType; +use Stripe\PaymentIntent; use Stripe\Stripe; class StripePaymentDriver extends BasePaymentDriver @@ -80,7 +81,7 @@ class StripePaymentDriver extends BasePaymentDriver return 'gateways.stripe.credit_card'; break; case GatewayType::TOKEN: - return 'gateways.stripe.token'; + return 'gateways.stripe.credit_card'; break; case GatewayType::SOFORT: return 'gateways.stripe.sofort'; @@ -106,6 +107,16 @@ class StripePaymentDriver extends BasePaymentDriver break; } } + + /** + * Creates a new String Payment Intent + * @param array $data The data array to be passed to Stripe + * @return PaymentIntent The Stripe payment intent object + */ + public function createIntent($data) + { + return PaymentIntent::create($data); + } /************************************** Omnipay API methods **********************************************************/ diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index abd6a957a60b..d1c56b11da42 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -908,6 +908,7 @@ class CreateUsersTable extends Migration $table->unsignedInteger('client_id')->nullable(); $table->text('token'); $table->unsignedInteger('company_gateway_id'); + $table->unsignedInteger('payment_method_id'); $table->boolean('is_default'); $table->timestamps(6); $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); diff --git a/resources/views/portal/default/gateways/stripe/credit_card.blade.php b/resources/views/portal/default/gateways/stripe/credit_card.blade.php index 7314a46daf94..5289919886fa 100644 --- a/resources/views/portal/default/gateways/stripe/credit_card.blade.php +++ b/resources/views/portal/default/gateways/stripe/credit_card.blade.php @@ -38,15 +38,30 @@
  • {{ ctrans('texts.total')}}

    {{ $amount }}

  • + @if($fee) +
  • {{ ctrans('texts.gateway_fee')}} +

    {{ $fee }}

    +
  • +
  • {{ ctrans('texts.amount_due')}} +

    {{ $amount_with_fee }}

    +
  • + @endif + + @if($token) + + + + @else
    - + @endif + @@ -56,7 +71,7 @@ @endsection @push('scripts') - + @endpush @section('footer') @endsection