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. * The first time the sign-up form is finished, FPX is asked for too. * * @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 && ! $account->fpx_requested) { try { $this->accounts->requestFpx($account->account_id); $account->fpx_requested = 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; if ($account === null || ($account->charges_enabled && $account->payouts_enabled)) { 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; } }