client()->v2->core->accounts->create([ 'contact_email' => $email, 'display_name' => $store->name, 'dashboard' => 'full', 'identity' => ['country' => 'my'], // FPX cannot be asked for yet: Stripe first needs the business type from the sign-up form. 'configuration' => ['merchant' => ['capabilities' => ['card_payments' => ['requested' => true]]]], 'defaults' => [ 'currency' => 'myr', 'responsibilities' => ['fees_collector' => 'stripe', 'losses_collector' => 'stripe'], ], 'metadata' => ['store_id' => (string) $store->id], ])->id; } catch (ApiErrorException $e) { throw new PaymentException('Stripe could not open an account: '.$e->getMessage(), 0, $e); } } public function setupLink(string $accountId, string $returnUrl, string $refreshUrl): string { try { return $this->client()->v2->core->accountLinks->create([ 'account' => $accountId, 'use_case' => [ 'type' => 'account_onboarding', 'account_onboarding' => [ 'return_url' => $returnUrl, 'refresh_url' => $refreshUrl, ], ], ])->url; } catch (ApiErrorException $e) { throw new PaymentException('Stripe could not open its sign-up form: '.$e->getMessage(), 0, $e); } } public function status(string $accountId): MerchantAccountStatus { try { // The older accounts API still reads v2 accounts, and says plainly what we need. $account = $this->client()->accounts->retrieve($accountId); } catch (ApiErrorException $e) { throw new PaymentException('Stripe could not find the account: '.$e->getMessage(), 0, $e); } return new MerchantAccountStatus( chargesEnabled: (bool) $account->charges_enabled, payoutsEnabled: (bool) $account->payouts_enabled, detailsSubmitted: (bool) $account->details_submitted, ); } public function requestFpx(string $accountId): void { try { // The older capability call. The v2 update refuses Malaysian sole proprietors // ("sole_proprietorship is not supported for entity type company"), found on 2026-11-30. $client = $this->client(); $in = ['stripe_account' => $accountId]; $client->accounts->updateCapability($accountId, 'fpx_payments', ['requested' => true]); // Approved is not enough: FPX also starts switched off in the account's payment method // settings, so shoppers would only see cards. Switch it on there too. foreach ($client->paymentMethodConfigurations->all(['limit' => 10], $in)->data as $configuration) { $client->paymentMethodConfigurations->update($configuration->id, ['fpx' => ['display_preference' => ['preference' => 'on']]], $in); } } catch (ApiErrorException $e) { throw new PaymentException('Stripe could not switch on FPX: '.$e->getMessage(), 0, $e); } } private function client(): StripeClient { $secret = (string) config('services.stripe.secret'); if ($secret === '') { throw new PaymentException('STRIPE_SECRET is missing in the settings file.'); } return new StripeClient($secret); } }