From 6bfd4d34a625c81a21caa6b5f30bdfbca28d2f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Sun, 31 Oct 2021 15:12:02 +0100 Subject: [PATCH] Apple Pay domain validation --- app/PaymentDrivers/Stripe/BrowserPay.php | 50 +++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BrowserPay.php b/app/PaymentDrivers/Stripe/BrowserPay.php index 582b856dd783..f14e87321341 100644 --- a/app/PaymentDrivers/Stripe/BrowserPay.php +++ b/app/PaymentDrivers/Stripe/BrowserPay.php @@ -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(); + } } \ No newline at end of file