stripeAccount; if ($account === null) { $account = $store->stripeAccount()->create(['account_id' => $this->accounts->create($store, $email)]); $store->setRelation('stripeAccount', $account); } return $this->accounts->setupLink($account->account_id, $returnUrl, $refreshUrl); } /** * Ask Stripe about the store's account and save the answer. * Once the sign-up form is finished, FPX and GrabPay are asked for too, each once. * * @throws PaymentException */ public function refresh(Store $store): ?StripeAccount { $account = $store->stripeAccount; if ($account === null) { return null; } $status = $this->accounts->status($account->account_id); $account->fill([ 'charges_enabled' => $status->chargesEnabled, 'payouts_enabled' => $status->payoutsEnabled, 'details_submitted' => $status->detailsSubmitted, 'checked_at' => now(), ]); if ($status->detailsSubmitted) { foreach ($account->methodsToRequest() as $method) { try { $this->accounts->requestMethod($account->account_id, $method); $account->{StripeAccount::METHODS[$method]} = true; } catch (PaymentException $e) { // Cards still work. We try again next time. report($e); } } } $account->save(); return $account; } /** * The store's account, refreshed from Stripe when it is not fully set up and was not checked in the last minute. * A store that is fully set up is not asked about again here. */ public function current(Store $store): ?StripeAccount { $account = $store->stripeAccount; // A fully set up store is not asked about again, unless a payment method we added later // (such as GrabPay, added 2026-12-01) still has to be switched on for it. if ($account === null || ($account->charges_enabled && $account->payouts_enabled && $account->methodsToRequest() === [])) { return $account; } if ($account->checked_at !== null && $account->checked_at->diffInSeconds(now()) < self::RECHECK_SECONDS) { return $account; } try { return $this->refresh($store); } catch (PaymentException $e) { report($e); return $account; } } /** * Whether shoppers can pay this store now. */ public function canTakePayments(Store $store): bool { return (bool) $this->current($store)?->charges_enabled; } }