1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/PaymentDrivers/Stripe/BrowserPay.php

95 lines
2.5 KiB
PHP
Raw Normal View History

2021-10-31 14:45:01 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\PaymentDrivers\Stripe;
use Illuminate\Http\Request;
use App\PaymentDrivers\Common\MethodInterface;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
2021-10-31 15:12:02 +01:00
use App\PaymentDrivers\StripePaymentDriver;
use App\Utils\Ninja;
2021-10-31 14:52:15 +01:00
use Illuminate\Http\RedirectResponse;
2021-10-31 15:12:02 +01:00
use Stripe\ApplePayDomain;
use Stripe\Exception\ApiErrorException;
2021-10-31 14:45:01 +01:00
class BrowserPay implements MethodInterface
{
2021-10-31 15:12:02 +01:00
protected StripePaymentDriver $stripe;
public function __construct(StripePaymentDriver $stripe)
{
$this->stripe = $stripe;
$this->stripe->init();
$this->ensureApplePayDomainIsValidated();
}
2021-10-31 14:52:15 +01:00
/**
* Authorization page for browser pay.
*
* @param array $data
* @return RedirectResponse
*/
public function authorizeView(array $data): RedirectResponse
{
return redirect()->route('client.payment_methods.index');
}
2021-10-31 14:45:01 +01:00
2021-10-31 14:52:15 +01:00
/**
* Handle the authorization for browser pay.
*
* @param Request $request
* @return RedirectResponse
*/
public function authorizeResponse(Request $request): RedirectResponse
{
return redirect()->route('client.payment_methods.index');
}
2021-10-31 14:45:01 +01:00
2021-10-31 15:12:02 +01:00
public function paymentView(array $data) {}
2021-10-31 14:45:01 +01:00
public function paymentResponse(PaymentResponseRequest $request) { }
2021-10-31 15:12:02 +01:00
/**
* Ensure Apple Pay domain is verified.
*
* @return void
* @throws ApiErrorException
*/
protected function ensureApplePayDomainIsValidated()
{
$config = $this->stripe->company_gateway->getConfig();
if (property_exists($config, 'apple_pay_domain_id')) {
return;
}
$domain = config('ninja.app_url');
if (Ninja::isHosted()) {
$domain = isset($this->stripe_driver->company_gateway->company->portal_domain)
? $this->stripe_driver->company_gateway->company->portal_domain
: $this->stripe_driver->company_gateway->company->domain();
}
$response = ApplePayDomain::create([
'domain_name' => $domain,
]);
$config->apple_pay_domain_id = $response->id;
$this->stripe->company_gateway->setConfig($config);
$this->stripe->company_gateway->save();
}
2021-10-31 14:45:01 +01:00
}