Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Give a seller a way into their payout provider, and a reason when they cannot
Damian Legawiec8029585fa4ae
diff --git a/packages/admin-sdk/src/types/generated/SellerRequirementStatus.ts b/packages/admin-sdk/src/types/generated/SellerRequirementStatus.tsindex 9e20f0b0ad..91c0019cc7 100644--- a/packages/admin-sdk/src/types/generated/SellerRequirementStatus.ts+++ b/packages/admin-sdk/src/types/generated/SellerRequirementStatus.ts@@ -1,4 +1,4 @@-// Typelizer digest 4d0f2420eec1d6bc006dc2e20e6d6b4c+// Typelizer digest 09545124df8c5b19913250147c0be3ac//// DO NOT MODIFY: This file was automatically generated by Typelizer.import type {SellerRequirementSubmission} from '@/types'@@ -12,6 +12,7 @@ interface SellerRequirementStatus {position: number;status: string;action_url: string | null;+ blocker: { state: string; message: string | null } | null;blocking: boolean;submission?: SellerRequirementSubmission;}diff --git a/packages/admin-sdk/src/types/generated/index.ts b/packages/admin-sdk/src/types/generated/index.tsindex d105227c81..622c8e93d3 100644--- a/packages/admin-sdk/src/types/generated/index.ts+++ b/packages/admin-sdk/src/types/generated/index.ts@@ -1,4 +1,4 @@-// Typelizer digest 24592d8acac1d654961214db09a1c086+// Typelizer digest 6b72dd432f9ad836abc3a73207e757f7//// DO NOT MODIFY: This file was automatically generated by Typelizer.export type { default as Address } from './Address'diff --git a/packages/seller-dashboard/src/locales/en.json b/packages/seller-dashboard/src/locales/en.jsonindex 6a69dc64d9..a59d448b3a 100644--- a/packages/seller-dashboard/src/locales/en.json+++ b/packages/seller-dashboard/src/locales/en.json@@ -60,6 +60,9 @@"onboarding": {"accept_terms": "Accept the terms","awaiting_review": "Waiting for the marketplace to review this.",+ "connect_payout_account": "Set up how you get paid",+ "payout_account_rejected": "Contact your payout provider",+ "awaiting_payout_provider": "Waiting for your payout provider to finish checking your details.","confirm": "Confirm","document_help": "PDF or an image of the document.","document_label": "Document",diff --git a/packages/seller-dashboard/src/pages/onboarding.tsx b/packages/seller-dashboard/src/pages/onboarding.tsxindex e9afe0fe15..c881c03ddd 100644--- a/packages/seller-dashboard/src/pages/onboarding.tsx+++ b/packages/seller-dashboard/src/pages/onboarding.tsx@@ -222,6 +222,29 @@ function RequirementAction({ requirement }: { requirement: RequirementStatus })}),})+ // Asked for at the moment the seller clicks, never earlier: a provider's+ // hosted link is short-lived and single-use, so one fetched while drawing+ // this page would often be dead by the time it was used. The seller comes+ // back here — this page is where the checklist says what is outstanding.+ const connectPayoutAccount = useMutation({+ mutationFn: () => {+ const here = window.location.href.split('?')[0]++ return sellerClient().onboarding.payoutAccount({+ refresh_url: here,+ return_url: here,+ })+ },+ onSuccess: ({ url }) => {+ if (url) window.location.href = url+ },+ onError: (err) =>+ toastManager.add({+ type: 'error',+ title: err instanceof Error ? err.message : t('common.error'),+ }),+ })+// One submit for every kind that takes one — an attestation the seller// ticks, a document they upload, a manual check they say is ready. What// differs is which controls render above it, not what posting means.@@ -392,6 +415,38 @@ function RequirementAction({ requirement }: { requirement: RequirementStatus })address form. */}{requirement.kind === 'returns_address' && <SellerReturnsLocationCard headless />}+ {/* The provider hosts the form, so this is a redirect rather than a+ page: the seller gives their bank and identity details to whoever+ is paying them, and the marketplace never handles either.++ Three outcomes, three different things to say. Waiting on the+ provider gets no button at all — offering one would invite the+ seller round a flow that cannot move, and they would click it+ repeatedly wondering why nothing changed. */}+ {requirement.kind === 'payout_account' && (+ <div className="flex flex-col items-start gap-2">+ {requirement.blocker?.message && (+ <p className="text-muted-foreground text-sm">{requirement.blocker.message}</p>+ )}++ {requirement.blocker?.state === 'pending' ? (+ <p className="text-muted-foreground text-sm">+ {t('onboarding.awaiting_payout_provider')}+ </p>+ ) : (+ <Button+ disabled={connectPayoutAccount.isPending}+ onClick={() => connectPayoutAccount.mutate()}+ >+ {requirement.blocker?.state === 'rejected'+ ? t('onboarding.payout_account_rejected')+ : t('onboarding.connect_payout_account')}+ <ExternalLinkIcon className="size-4" />+ </Button>+ )}+ </div>+ )}+{/* Kinds whose work happens on a page this panel already has. Theserver cannot supply these: `action_url` is for somewhere it knowsabout (a provider's hosted flow), and it has no idea how this panel@@ -409,16 +464,18 @@ function RequirementAction({ requirement }: { requirement: RequirementStatus }))}{/* `accept_terms` renders its own link above, with different words. */}- {requirement.action_url && requirement.kind !== 'accept_terms' && (- <div className="flex justify-start">- <Button variant="outline" asChild>- <a href={requirement.action_url} target="_blank" rel="noreferrer">- {t('onboarding.go')}- <ExternalLinkIcon className="size-4" />- </a>- </Button>- </div>- )}+ {requirement.action_url &&+ requirement.kind !== 'accept_terms' &&+ requirement.kind !== 'payout_account' && (+ <div className="flex justify-start">+ <Button variant="outline" asChild>+ <a href={requirement.action_url} target="_blank" rel="noreferrer">+ {t('onboarding.go')}+ <ExternalLinkIcon className="size-4" />+ </a>+ </Button>+ </div>+ )}</>)}diff --git a/packages/seller-sdk/src/seller-client.ts b/packages/seller-sdk/src/seller-client.tsindex 2b8e8aab91..a17184635d 100644--- a/packages/seller-sdk/src/seller-client.ts+++ b/packages/seller-sdk/src/seller-client.ts@@ -151,6 +151,25 @@ export class SellerClient {*/submitForReview: (options?: RequestOptions): Promise<OnboardingResponse> =>this.request<OnboardingResponse>('POST', '/onboarding/submit_for_review', options),++ /**+ * A fresh link to wherever the marketplace's payout provider collects+ * what it needs before it will pay this seller.+ *+ * Asked for at the moment the seller acts, never rendered with the+ * checklist: these links are short-lived and single-use, so one made+ * while drawing a page is often dead before it is clicked. Answers+ * `{ url: null }` when the provider hosts no onboarding — a marketplace+ * paying by hand collects those details itself.+ */+ payoutAccount: (+ data: { refresh_url: string; return_url: string },+ options?: RequestOptions,+ ): Promise<PayoutAccountLink> =>+ this.request<PayoutAccountLink>('POST', '/onboarding/payout_account', {+ ...options,+ body: data,+ }),}/**@@ -378,6 +397,12 @@ export interface SellerCountry {states?: Array<{ abbr: string; name: string }>}+/** Where to send a seller to set up how they get paid. */+export interface PayoutAccountLink {+ /** Null when the provider hosts no onboarding of its own. */+ url: string | null+}+/** What `/seller/onboarding` answers. */export interface OnboardingResponse {/** The seller's lifecycle status, e.g. `onboarding`, `ready_for_review`. */diff --git a/packages/seller-sdk/src/types/generated/RequirementStatus.ts b/packages/seller-sdk/src/types/generated/RequirementStatus.tsindex 9e9279f463..d10419f041 100644--- a/packages/seller-sdk/src/types/generated/RequirementStatus.ts+++ b/packages/seller-sdk/src/types/generated/RequirementStatus.ts@@ -1,4 +1,4 @@-// Typelizer digest 434bfb90137616b68851e9a0fec33b60+// Typelizer digest 10484e01e4987aa4c449c3c379797d7d//// DO NOT MODIFY: This file was automatically generated by Typelizer.import type {RequirementSubmission, RequirementCustomField} from '@/types'@@ -12,6 +12,7 @@ type RequirementStatus = {position: number;status: string;action_url: string | null;+ blocker: { state: string; message: string | null } | null;blocking: boolean;accepts_submissions: boolean;requires_file: boolean;diff --git a/spree/api/app/controllers/spree/api/v3/seller/onboarding_controller.rb b/spree/api/app/controllers/spree/api/v3/seller/onboarding_controller.rbindex d20dc6b206..a1b9cd097e 100644--- a/spree/api/app/controllers/spree/api/v3/seller/onboarding_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/seller/onboarding_controller.rb@@ -51,11 +51,10 @@ module Spreereturn_url: params.require(:return_url))- # No link means there is nowhere to send them — an operator paying- # by hand collects these details themselves.- return head :no_content if url.blank?-- render json: { url: url }+ # A null link rather than an empty response: the panel has to tell+ # "this provider hosts nothing" from "the request failed", and a+ # 204 makes the client infer that from an absence.+ render json: { url: url.presence }rescue Spree::Core::GatewayError => erender_service_error(e.message)enddiff --git a/spree/api/app/serializers/spree/api/v3/admin/seller_requirement_status_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/seller_requirement_status_serializer.rbindex 1b5173d882..eb6f1ad0dd 100644--- a/spree/api/app/serializers/spree/api/v3/admin/seller_requirement_status_serializer.rb+++ b/spree/api/app/serializers/spree/api/v3/admin/seller_requirement_status_serializer.rb@@ -13,9 +13,10 @@ module Spreetypelize id: :string, kind: :string, name: :string,description: [:string, nullable: true],required: :boolean, position: :number, status: :string,- blocking: :boolean, action_url: [:string, nullable: true]+ blocking: :boolean, action_url: [:string, nullable: true],+ blocker: ['{ state: string; message: string | null } | null']- attributes :id, :kind, :name, :description, :required, :position, :status, :action_url+ attributes :id, :kind, :name, :description, :required, :position, :status, :action_url, :blocker# Whether this stands between the seller and approval. Serialized# rather than left to each client to derive, so the dashboard'sdiff --git a/spree/api/app/serializers/spree/api/v3/seller/requirement_status_serializer.rb b/spree/api/app/serializers/spree/api/v3/seller/requirement_status_serializer.rbindex 6d49490dba..aa91830cf1 100644--- a/spree/api/app/serializers/spree/api/v3/seller/requirement_status_serializer.rb+++ b/spree/api/app/serializers/spree/api/v3/seller/requirement_status_serializer.rb@@ -10,10 +10,11 @@ module Spreedescription: [:string, nullable: true],required: :boolean, position: :number, status: :string,blocking: :boolean, action_url: [:string, nullable: true],+ blocker: ['{ state: string; message: string | null } | null'],accepts_submissions: :boolean, requires_file: :boolean,accepted_content_types: [:string, multi: true]- attributes :id, :kind, :name, :description, :required, :position, :status, :action_url+ attributes :id, :kind, :name, :description, :required, :position, :status, :action_url, :blockerattribute :blocking do |status|status.blocking?diff --git a/spree/api/spec/controllers/spree/api/v3/seller/onboarding_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/seller/onboarding_controller_spec.rbindex 1d7d467092..75d53fd9a5 100644--- a/spree/api/spec/controllers/spree/api/v3/seller/onboarding_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/seller/onboarding_controller_spec.rb@@ -98,10 +98,12 @@ RSpec.describe Spree::Api::V3::Seller::OnboardingController, type: :controller d# An operator settling by hand collects bank details themselves, so there# is nowhere to send the seller.- it 'answers with nothing when the provider hosts no onboarding' do+ # The panel has to tell "hosts nothing" from "the request failed".+ it 'answers with no link when the provider hosts no onboarding' dopost :payout_account, params: urls, as: :json- expect(response).to have_http_status(:no_content)+ expect(response).to have_http_status(:ok)+ expect(json_response['url']).to be_nilendcontext 'with a provider that hosts its own onboarding' dodiff --git a/spree/core/app/models/spree/payout_provider/base.rb b/spree/core/app/models/spree/payout_provider/base.rbindex 8563272845..4124697868 100644--- a/spree/core/app/models/spree/payout_provider/base.rb+++ b/spree/core/app/models/spree/payout_provider/base.rb@@ -103,6 +103,45 @@ module Spree!self.class.requires_payout_account? || seller.payouts_enabled?end+ # Why a seller is not payable yet, in terms any provider can answer.+ #+ # Deliberately a state rather than a list of outstanding fields. What+ # each provider is missing is its own vocabulary — field paths, document+ # codes, review case ids — and none of it survives translation into a+ # shared one. The reference provider goes further and asks not to be+ # enumerated at all: its guidance is to send the seller back to the+ # hosted flow, which already knows what it wants, rather than to+ # reimplement its form badly.+ #+ # What a seller actually needs from this is which of three things is+ # true, because each deserves different words and a different button:+ #+ # nil — nothing to say; they are payable, or no provider asks+ # :action — the provider wants something from them+ # :pending — the provider is checking, and nobody can hurry it+ # :rejected — the provider has refused them+ #+ # A provider may add a sentence of its own through {#onboarding_message},+ # which is best-effort and unlocalized.+ #+ # @param _seller [Spree::Seller]+ # @return [Symbol, nil]+ def onboarding_state(_seller)+ nil+ end++ # A provider's own words about what is outstanding, when it has any.+ #+ # Best-effort and **unlocalized** — providers write these in English and+ # say so. Shown as supporting detail beside copy the panel has+ # translated, never as the only explanation a seller gets.+ #+ # @param _seller [Spree::Seller]+ # @return [String, nil]+ def onboarding_message(_seller)+ nil+ end+# Credits a seller for one fulfilled order.## @param seller_transfer [Spree::SellerTransfer]diff --git a/spree/core/app/models/spree/seller_requirement.rb b/spree/core/app/models/spree/seller_requirement.rbindex 6e34b0e5bc..9c7a507fdd 100644--- a/spree/core/app/models/spree/seller_requirement.rb+++ b/spree/core/app/models/spree/seller_requirement.rb@@ -216,6 +216,17 @@ module Spreenilend+ # Why this line is not done, when the answer is somewhere the seller+ # cannot see. Nil for every kind whose own description already says what+ # is wanted, which is nearly all of them — a requirement asking for an+ # address explains itself.+ #+ # @param _seller [Spree::Seller]+ # @return [Hash, nil] `{ state:, message: }`+ def blocker(_seller)+ nil+ end+# The submission that decides this requirement's standing for a seller:# the most recent one. Earlier rows are the audit trail.#diff --git a/spree/core/app/models/spree/seller_requirement_status.rb b/spree/core/app/models/spree/seller_requirement_status.rbindex 5b9223dee1..9b022c78e2 100644--- a/spree/core/app/models/spree/seller_requirement_status.rb+++ b/spree/core/app/models/spree/seller_requirement_status.rb@@ -30,6 +30,18 @@ module Spreeattribute :status, :stringattribute :action_url, :string+ # Why this line is stuck, when the reason lives somewhere the seller+ # cannot see — a payout provider still checking their identity, say.+ #+ # `state` is one of `action` (they must do something), `pending` (the+ # provider is looking, and nobody can hurry it) or `rejected`. `message`+ # is the provider's own sentence when it wrote one: best-effort and+ # unlocalized, so it is shown as detail beside translated copy rather+ # than in place of it.+ #+ # @return [Hash, nil]+ attr_accessor :blocker+# The submission behind the status, when there is one.# @return [Spree::SellerRequirementSubmission, nil]attr_accessor :submissiondiff --git a/spree/core/app/models/spree/seller_requirements/payout_account.rb b/spree/core/app/models/spree/seller_requirements/payout_account.rbindex 03db3eff27..202848fb88 100644--- a/spree/core/app/models/spree/seller_requirements/payout_account.rb+++ b/spree/core/app/models/spree/seller_requirements/payout_account.rb@@ -25,6 +25,16 @@ module Spreeprovider_for(seller).onboarded?(seller)end+ # Asked of the provider, since only it knows — and its three answers+ # want different words: go and finish, wait, or you have been refused.+ def blocker(seller)+ provider = provider_for(seller)+ state = provider.onboarding_state(seller)+ return nil if state.nil?++ { state: state.to_s, message: provider.onboarding_message(seller) }+ end+privatedef provider_for(seller)diff --git a/spree/core/app/services/spree/sellers/requirements.rb b/spree/core/app/services/spree/sellers/requirements.rbindex 5485041635..2c0221e143 100644--- a/spree/core/app/services/spree/sellers/requirements.rb+++ b/spree/core/app/services/spree/sellers/requirements.rb@@ -110,6 +110,7 @@ module Spreeposition: requirement.position,status: requirement.status_for(seller),action_url: requirement.action_url(seller),+ blocker: requirement.blocker(seller),submission: requirement.latest_submission(seller),requirement: requirement,seller: sellerdiff --git a/spree/core/spec/models/spree/seller_requirements/payout_account_spec.rb b/spree/core/spec/models/spree/seller_requirements/payout_account_spec.rbindex 95a7d8bc9f..1a1a6c43d1 100644--- a/spree/core/spec/models/spree/seller_requirements/payout_account_spec.rb+++ b/spree/core/spec/models/spree/seller_requirements/payout_account_spec.rb@@ -42,6 +42,49 @@ RSpec.describe Spree::SellerRequirements::PayoutAccount doendend+ describe '#blocker' do+ # Nothing to explain when the provider has no opinion.+ it 'is silent under the record-only provider' do+ expect(requirement.blocker(seller)).to be_nil+ end++ context 'with a provider that reports on its own onboarding' do+ before do+ allow_any_instance_of(Spree::PayoutProvider::System).to receive(:onboarding_state).and_return(state)+ allow_any_instance_of(Spree::PayoutProvider::System).to receive(:onboarding_message).+ and_return('We could not read the document you uploaded.')+ end++ context 'when the provider wants something from the seller' do+ let(:state) { :action }++ it 'says so, with the provider’s own words' do+ expect(requirement.blocker(seller)).to eq(+ state: 'action', message: 'We could not read the document you uploaded.'+ )+ end+ end++ # Nobody can hurry this, so the panel says wait rather than offering a+ # button that would send the seller round a flow that cannot move.+ context 'when the provider is still checking' do+ let(:state) { :pending }++ it 'reports that it is waiting' do+ expect(requirement.blocker(seller)[:state]).to eq('pending')+ end+ end++ context 'when the provider has refused the seller' do+ let(:state) { :rejected }++ it 'reports the refusal' do+ expect(requirement.blocker(seller)[:state]).to eq('rejected')+ end+ end+ end+ end+# A marketplace settling by hand should not have this forced on it.it 'is registered as a kind an operator may add' doexpect(Spree.seller_requirements).to include(described_class)diff --git a/spree/providers/stripe/app/models/spree_stripe/payout_provider.rb b/spree/providers/stripe/app/models/spree_stripe/payout_provider.rbindex ce5ae3cf74..9e61a4b248 100644--- a/spree/providers/stripe/app/models/spree_stripe/payout_provider.rb+++ b/spree/providers/stripe/app/models/spree_stripe/payout_provider.rb@@ -19,6 +19,11 @@ module SpreeStripe# retry after a timeout finds the movement it already made instead of making# a second.class PayoutProvider < Spree::PayoutProvider::Base+ # Stripe is looking at the account, and there is nothing the seller can do+ # about it — different words and no button, rather than an invitation to+ # go round the same flow again.+ PENDING_REASONS = %w[under_review requirements.pending_verification platform_paused].freeze+def self.display_name'Stripe Connect'end@@ -58,6 +63,35 @@ module SpreeStripe)end+ # Which of the three things is true, read off the account itself.+ #+ # Stripe's `disabled_reason` is the account-level answer, and its values+ # divide cleanly: some mean the seller must do something, some mean Stripe+ # is looking and nobody can hurry it, and some mean Stripe has said no.+ # The per-field requirement list is deliberately not read — Stripe's own+ # guidance for Express is to send the seller back to hosted onboarding+ # rather than enumerate what it wants, since that flow already knows.+ def onboarding_state(seller)+ account = retrieve_account(seller)+ return nil if account.nil? || account.payouts_enabled++ reason = account.requirements&.disabled_reason.to_s+ return :rejected if reason.start_with?('rejected.') || reason == 'listed'+ return :pending if PENDING_REASONS.include?(reason)++ :action+ end++ # Stripe writes these itself, in English, and says so — shown as detail+ # beside translated copy, never instead of it. Only the failures have one:+ # a field simply not provided yet has no error and nothing to say.+ def onboarding_message(seller)+ account = retrieve_account(seller)+ return nil if account.nil?++ Array(account.requirements&.errors).filter_map { |error| error[:reason] }.first+ end+# Moves one seller's earning to their connected account.def transfer!(seller_transfer)seller = seller_transfer.seller@@ -130,6 +164,21 @@ module SpreeStripeprivate+ # Nil rather than raising: a checklist row asking why it is incomplete+ # must not take the page down because Stripe is unreachable.+ def retrieve_account(seller)+ account_id = seller.payout_account_reference(self.class)+ return nil if account_id.blank?++ @retrieved_accounts ||= {}+ @retrieved_accounts[account_id] ||= Stripe::Account.retrieve(+ account_id, gateway_for(seller.store).api_options+ )+ rescue Stripe::StripeError => e+ Rails.error.report(e, handled: true, context: { seller_id: seller.id }, source: 'spree_stripe')+ nil+ end+def gateway_for(store)self.class.gateway_for(store) ||raise(Spree::Core::GatewayError, 'No active Stripe payment method on this store')diff --git a/spree/providers/stripe/spec/models/spree_stripe/payout_provider_spec.rb b/spree/providers/stripe/spec/models/spree_stripe/payout_provider_spec.rbindex 172a817fb9..9db09fb286 100644--- a/spree/providers/stripe/spec/models/spree_stripe/payout_provider_spec.rb+++ b/spree/providers/stripe/spec/models/spree_stripe/payout_provider_spec.rb@@ -128,6 +128,94 @@ RSpec.describe SpreeStripe::PayoutProvider doendend+ describe '#onboarding_state' do+ def account(payouts_enabled:, disabled_reason: nil, errors: [])+ Stripe::StripeObject.construct_from(+ id: 'acct_seller',+ payouts_enabled: payouts_enabled,+ requirements: { disabled_reason: disabled_reason, errors: errors }+ )+ end++ def stub_account(**attrs)+ allow(Stripe::Account).to receive(:retrieve).and_return(account(**attrs))+ end++ it 'has nothing to say about a seller who can be paid' do+ stub_account(payouts_enabled: true)++ expect(described_class.new.onboarding_state(seller)).to be_nil+ end++ it 'asks the seller to finish when Stripe is waiting on them' do+ stub_account(payouts_enabled: false, disabled_reason: 'requirements.past_due')++ expect(described_class.new.onboarding_state(seller)).to eq(:action)+ end++ # Nobody can hurry a review, so this must not read as "go and finish".+ it 'reports a review in progress as pending' do+ stub_account(payouts_enabled: false, disabled_reason: 'requirements.pending_verification')++ expect(described_class.new.onboarding_state(seller)).to eq(:pending)+ end++ it 'reports an account under review as pending' do+ stub_account(payouts_enabled: false, disabled_reason: 'under_review')++ expect(described_class.new.onboarding_state(seller)).to eq(:pending)+ end++ it 'reports a refusal as rejected' do+ stub_account(payouts_enabled: false, disabled_reason: 'rejected.fraud')++ expect(described_class.new.onboarding_state(seller)).to eq(:rejected)+ end++ # A checklist asking why it is stuck must not take the page down because+ # Stripe is unreachable.+ it 'stays quiet when Stripe cannot be reached' do+ allow(Stripe::Account).to receive(:retrieve).and_raise(Stripe::APIError.new('boom'))++ expect(described_class.new.onboarding_state(seller)).to be_nil+ end++ it 'has nothing to say about a seller who holds no account' do+ other = create(:seller, :approved, store: store)++ expect(described_class.new.onboarding_state(other)).to be_nil+ end+ end++ describe '#onboarding_message' do+ it 'passes on what Stripe said, so the seller knows what to fix' do+ allow(Stripe::Account).to receive(:retrieve).and_return(+ Stripe::StripeObject.construct_from(+ id: 'acct_seller',+ payouts_enabled: false,+ requirements: {+ disabled_reason: 'requirements.past_due',+ errors: [{ code: 'verification_document_not_readable', reason: 'The image supplied isn’t readable.' }]+ }+ )+ )++ expect(described_class.new.onboarding_message(seller)).to eq('The image supplied isn’t readable.')+ end++ # A field simply not provided yet has no error and nothing to say.+ it 'says nothing when Stripe reported no failure' do+ allow(Stripe::Account).to receive(:retrieve).and_return(+ Stripe::StripeObject.construct_from(+ id: 'acct_seller', payouts_enabled: false,+ requirements: { disabled_reason: 'requirements.past_due', errors: [] }+ )+ )++ expect(described_class.new.onboarding_message(seller)).to be_nil+ end+ end+describe '.requires_payout_account?' doit 'is true — nothing can be sent to a seller without a connected account' doexpect(described_class.requires_payout_account?).to be(true)