Apple Pay domain validation

This commit is contained in:
Benjamin Beganović 2021-10-31 15:12:02 +01:00
parent 6502ca0bf4
commit 6bfd4d34a6

View File

@ -15,10 +15,25 @@ namespace App\PaymentDrivers\Stripe;
use Illuminate\Http\Request;
use App\PaymentDrivers\Common\MethodInterface;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\PaymentDrivers\StripePaymentDriver;
use App\Utils\Ninja;
use Illuminate\Http\RedirectResponse;
use Stripe\ApplePayDomain;
use Stripe\Exception\ApiErrorException;
class BrowserPay implements MethodInterface
{
protected StripePaymentDriver $stripe;
public function __construct(StripePaymentDriver $stripe)
{
$this->stripe = $stripe;
$this->stripe->init();
$this->ensureApplePayDomainIsValidated();
}
/**
* Authorization page for browser pay.
*
@ -41,7 +56,40 @@ class BrowserPay implements MethodInterface
return redirect()->route('client.payment_methods.index');
}
public function paymentView(array $data) { }
public function paymentView(array $data) {}
public function paymentResponse(PaymentResponseRequest $request) { }
/**
* 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();
}
}