Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Show marketplace terms when a seller accepts them (#14636)

Damian Legawiec613f16631c68
diff --git a/docs/api-reference/seller.yaml b/docs/api-reference/seller.yaml
index b466142a54..696ba1592d 100644
--- a/docs/api-reference/seller.yaml
+++ b/docs/api-reference/seller.yaml
@@ -21370,6 +21370,9 @@ components:
required_policy_name:
type: string
nullable: true
+ terms_html:
+ type: string
+ nullable: true
submission:
"$ref": "#/components/schemas/RequirementSubmission"
custom_fields:
@@ -21391,6 +21394,7 @@ components:
- requires_file
- accepted_content_types
- required_policy_name
+ - terms_html
x-typelizer: true
RequirementSubmission:
type: object
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index b0c6cb8e81..b137ec8207 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -4232,6 +4232,12 @@
"percent": "نسبة مئوية",
"preferred_amount": "كمية",
"preferred_percent": "نسبة مئوية",
+ "terms_body": "الشروط",
+ "terms_body_description": "ما يقرأه البائع قبل الموافقة. يظهر في قائمة إعداداته.",
+ "terms_effective_from": "الشروط سارية من",
+ "terms_effective_from_description": "يُطلب من البائعين الذين وافقوا قبل هذا التاريخ الموافقة مرة أخرى.",
+ "terms_url": "رابط الشروط",
+ "terms_url_description": "نسخة منشورة اختيارية من الشروط نفسها، تُفتح في علامة تبويب جديدة.",
"webhook_secret": "مفتاح توقيع الويب هوك",
"webhook_secret_description": "السر الذي ضبطته على ويب هوك EasyPost. بدونه تُرفض تحديثات شركة الشحن."
},
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index acf00bcbe1..5d54f8145d 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -4207,6 +4207,12 @@
"percent": "Prozent",
"preferred_amount": "Betrag",
"preferred_percent": "Prozent",
+ "terms_body": "Bedingungen",
+ "terms_body_description": "Was der Verkäufer vor der Zustimmung liest. Wird in seiner Einrichtungscheckliste angezeigt.",
+ "terms_effective_from": "Bedingungen gültig ab",
+ "terms_effective_from_description": "Verkäufer, die davor zugestimmt haben, werden erneut gefragt.",
+ "terms_url": "URL der Bedingungen",
+ "terms_url_description": "Optionale veröffentlichte Fassung derselben Bedingungen, öffnet in einem neuen Tab.",
"webhook_secret": "Webhook-Signaturschlüssel",
"webhook_secret_description": "Das Geheimnis, das Sie im EasyPost-Webhook festgelegt haben. Ohne es werden Carrier-Updates abgelehnt."
},
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 7b959da4e3..5dab51cf98 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -4207,6 +4207,12 @@
"percent": "Percent",
"preferred_amount": "Amount",
"preferred_percent": "Percent",
+ "terms_body": "Terms",
+ "terms_body_description": "What the seller reads before they accept. Shown in their setup checklist.",
+ "terms_effective_from": "Terms effective from",
+ "terms_effective_from_description": "Sellers who accepted before this date are asked again.",
+ "terms_url": "Terms URL",
+ "terms_url_description": "Optional published copy of the same terms, opened in a new tab.",
"webhook_secret": "Webhook signing secret",
"webhook_secret_description": "The secret you set on the EasyPost webhook. Carrier updates are refused without it."
},
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 31fba22752..419187165c 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -4207,6 +4207,12 @@
"percent": "Pourcentage",
"preferred_amount": "Montant",
"preferred_percent": "Pourcentage",
+ "terms_body": "Conditions",
+ "terms_body_description": "Ce que le vendeur lit avant d’accepter. Affiché dans sa liste de configuration.",
+ "terms_effective_from": "Conditions en vigueur à partir du",
+ "terms_effective_from_description": "Les vendeurs qui ont accepté avant cette date sont invités à accepter à nouveau.",
+ "terms_url": "URL des conditions",
+ "terms_url_description": "Copie publiée facultative des mêmes conditions, ouverte dans un nouvel onglet.",
"webhook_secret": "Clé de signature du webhook",
"webhook_secret_description": "Le secret défini sur le webhook EasyPost. Sans lui, les mises à jour du transporteur sont refusées."
},
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 53ecd31ddc..ef1b266dd2 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -4259,6 +4259,12 @@
"percent": "Procent",
"preferred_amount": "Kwota",
"preferred_percent": "Procent",
+ "terms_body": "Regulamin",
+ "terms_body_description": "Tekst, który sprzedawca czyta przed akceptacją. Widoczny na liście wymagań.",
+ "terms_effective_from": "Regulamin obowiązuje od",
+ "terms_effective_from_description": "Sprzedawcy, którzy zaakceptowali przed tą datą, zostaną poproszeni ponownie.",
+ "terms_url": "Adres URL regulaminu",
+ "terms_url_description": "Opcjonalna opublikowana kopia tego samego regulaminu, otwierana w nowej karcie.",
"webhook_secret": "Sekret podpisu webhooka",
"webhook_secret_description": "Sekret ustawiony na webhooku EasyPost. Bez niego aktualizacje od przewoźnika są odrzucane."
},
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index fa3885891b..1eafe026d9 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -4197,6 +4197,12 @@
"percent": "百分比",
"preferred_amount": "金额",
"preferred_percent": "百分比",
+ "terms_body": "条款",
+ "terms_body_description": "卖家在同意前阅读的内容。显示在其设置清单中。",
+ "terms_effective_from": "条款生效日期",
+ "terms_effective_from_description": "在此日期之前已同意的卖家需要再次同意。",
+ "terms_url": "条款链接",
+ "terms_url_description": "同一条款的可选已发布副本,在新标签页中打开。",
"webhook_secret": "Webhook 签名密钥",
"webhook_secret_description": "您在 EasyPost webhook 上设置的密钥。缺少它,承运商更新将被拒绝。"
},
diff --git a/packages/seller-dashboard/src/pages/onboarding.tsx b/packages/seller-dashboard/src/pages/onboarding.tsx
index c5d35a0eef..9148c599a2 100644
--- a/packages/seller-dashboard/src/pages/onboarding.tsx
+++ b/packages/seller-dashboard/src/pages/onboarding.tsx
@@ -20,6 +20,7 @@ import {
FieldLabel,
Input,
Progress,
+ ScrollArea,
StatusBadge as SharedStatusBadge,
Textarea,
toastManager,
@@ -308,20 +309,32 @@ function RequirementAction({ requirement }: { requirement: RequirementStatus })
{rejection}
{requirement.kind === 'accept_terms' && (
- <div className="flex flex-wrap items-center gap-2">
- {/* The terms themselves, when the marketplace configured a link.
- Accepting something a seller cannot read is not consent. */}
- {requirement.action_url && (
- <Button variant="outline" asChild>
- <a href={requirement.action_url} target="_blank" rel="noopener noreferrer">
- {t('onboarding.read_terms')}
- <ExternalLinkIcon className="size-4" />
- </a>
- </Button>
+ <div className="flex flex-col gap-3">
+ {/* The terms themselves. Accepting something a seller cannot
+ read is not consent — a link away is not enough. */}
+ {requirement.terms_html && (
+ <ScrollArea className="h-72 rounded-md border">
+ <div
+ className="prose prose-sm dark:prose-invert max-w-none p-4"
+ // Sanitized server-side by Spree::RichTextSanitizer.
+ // biome-ignore lint/security/noDangerouslySetInnerHtml: sanitized on write
+ dangerouslySetInnerHTML={{ __html: requirement.terms_html }}
+ />
+ </ScrollArea>
)}
- <Button disabled={acceptTerms.isPending} onClick={() => acceptTerms.mutate()}>
- {t('onboarding.accept_terms')}
- </Button>
+ <div className="flex flex-wrap items-center gap-2">
+ {requirement.action_url && (
+ <Button variant="outline" asChild>
+ <a href={requirement.action_url} target="_blank" rel="noopener noreferrer">
+ {t('onboarding.read_terms')}
+ <ExternalLinkIcon className="size-4" />
+ </a>
+ </Button>
+ )}
+ <Button disabled={acceptTerms.isPending} onClick={() => acceptTerms.mutate()}>
+ {t('onboarding.accept_terms')}
+ </Button>
+ </div>
</div>
)}
diff --git a/packages/seller-sdk/src/types/generated/RequirementStatus.ts b/packages/seller-sdk/src/types/generated/RequirementStatus.ts
index a21391cd71..91503d2001 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 c04d634c20177b58fd6ed309f6572dab
+// Typelizer digest c3e47131f6be0040127cc94287730754
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {RequirementSubmission, RequirementCustomField} from '@/types'
@@ -19,6 +19,7 @@ type RequirementStatus = {
requires_file: boolean;
accepted_content_types: Array<string>;
required_policy_name: string | null;
+ terms_html: string | null;
submission?: RequirementSubmission;
custom_fields?: Array<RequirementCustomField>;
}
diff --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.rb
index 0e0c2392ab..91f2bdff0e 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
@@ -13,7 +13,8 @@ module Spree
blocker: ['{ state: string; message: string | null } | null'],
accepts_submissions: :boolean, requires_file: :boolean,
accepted_content_types: [:string, multi: true],
- required_policy_name: [:string, nullable: true]
+ required_policy_name: [:string, nullable: true],
+ terms_html: [:string, nullable: true]
attributes :id, :kind, :name, :description, :required, :position, :status, :action_url, :blocker
@@ -39,6 +40,12 @@ module Spree
status.required_policy_name
end
+ # The marketplace terms this line asks the seller to accept. Null
+ # for every other kind, and null while nothing has been written.
+ attribute :terms_html do |status|
+ status.terms_html
+ end
+
one :submission,
resource: proc { Spree.api.seller_requirement_submission_serializer },
if: proc { |status| status.submission.present? }
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.rb
index fddf46f105..ac7f62cd6e 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
@@ -47,6 +47,18 @@ RSpec.describe Spree::Api::V3::Seller::OnboardingController, type: :controller d
expect(json_response['requirements']).to eq([])
end
+ # Accepting something they cannot read is not consent — the panel
+ # renders this rather than only offering a link away.
+ it 'includes the terms the seller is asked to accept' do
+ create(:accept_terms_requirement, store: store,
+ preferred_terms_body: '<p>Be excellent to each other.</p>')
+
+ get :show, as: :json
+
+ terms = json_response['requirements'].find { |row| row['kind'] == 'accept_terms' }
+ expect(terms['terms_html']).to include('Be excellent to each other')
+ end
+
it 'returns the checklist with the seller current standing' do
create(:accept_terms_requirement, store: store)
create(:billing_address_requirement, store: store)
diff --git a/spree/core/app/models/spree/seller_requirement_status.rb b/spree/core/app/models/spree/seller_requirement_status.rb
index a42efb6087..951f31060c 100644
--- a/spree/core/app/models/spree/seller_requirement_status.rb
+++ b/spree/core/app/models/spree/seller_requirement_status.rb
@@ -95,6 +95,17 @@ module Spree
requirement.required_policy_name.presence
end
+ # The marketplace terms this line asks the seller to accept, as
+ # sanitized markup. Nil for every other kind, and nil while the
+ # marketplace has not written any.
+ #
+ # @return [String, nil]
+ def terms_html
+ return nil unless requirement.respond_to?(:terms_html)
+
+ requirement.terms_html
+ end
+
# The policy the seller actually published against this line, when they
# have — nil for every other kind, and nil while the document is still
# owed.
diff --git a/spree/core/app/models/spree/seller_requirements/accept_terms.rb b/spree/core/app/models/spree/seller_requirements/accept_terms.rb
index ec7269c236..e8f6292ff2 100644
--- a/spree/core/app/models/spree/seller_requirements/accept_terms.rb
+++ b/spree/core/app/models/spree/seller_requirements/accept_terms.rb
@@ -8,12 +8,16 @@ module Spree
# them: everyone who accepted before that date falls back to unmet, and
# the seller sees the requirement return to their checklist.
class AcceptTerms < Spree::SellerRequirement
+ # What the seller reads in the panel. Optional: a marketplace that
+ # already publishes customer Terms of Service can leave this blank
+ # and the checklist falls back to that policy, so the two cannot
+ # drift. A seller agreement that is not the shopper-facing document
+ # is written here instead.
+ preference :terms_body, :text, default: nil, nullable: true
preference :terms_effective_from, :string, default: nil
- # Where the terms actually are. A URL rather than stored copy: a
- # marketplace already publishes its terms somewhere, and keeping a
- # second copy here would be the one that goes stale. Optional — a
- # marketplace that agrees terms out of band still uses this kind to
- # record that the seller accepted.
+ # A published copy of the same terms, for a marketplace that also
+ # hosts them on a public page. Optional — the panel renders the
+ # body above; this is the "open the full document" link.
preference :terms_url, :string, default: nil
# A date nobody can parse would otherwise read as "no date at all", and
@@ -30,6 +34,27 @@ module Spree
accepted_at >= effective_from
end
+ # The terms themselves, so the seller can read what they are accepting.
+ # `action_url` is the checklist's existing "go here" channel for a
+ # published copy; the body is what the panel renders inline.
+ #
+ # @return [String, nil]
+ def action_url(_seller)
+ preferred_terms_url.presence
+ end
+
+ # Sanitized markup the seller reads before accepting. The requirement's
+ # own body wins; otherwise the store's Terms of Service, so a
+ # marketplace that already wrote that policy does not write it twice.
+ #
+ # @return [String, nil]
+ def terms_html
+ source = preferred_terms_body.presence || store_terms_body
+ return if source.blank?
+
+ Spree::RichTextSanitizer.sanitize(source).presence
+ end
+
# `iso8601`, not `parse`: parse fills in whatever a value leaves out, so
# "09:00" becomes nine o'clock *today* and the threshold would move every
# midnight — sellers who met it yesterday would fall out of compliance
@@ -39,15 +64,6 @@ module Spree
# types means midnight where they trade, and interpreting "2026-01-01"
# in UTC would move the deadline by hours for everyone else.
#
- # The terms themselves, so the seller can read what they are accepting.
- # `action_url` is the checklist's existing "go here" channel, which the
- # panel already renders — no new field for one kind.
- #
- # @return [String, nil]
- def action_url(_seller)
- preferred_terms_url.presence
- end
-
# @return [ActiveSupport::TimeWithZone, nil]
def effective_from
return nil if preferred_terms_effective_from.blank?
@@ -73,6 +89,12 @@ module Spree
message: Spree.t('seller_requirements.invalid_terms_effective_from',
default: 'Terms effective from is not a date'))
end
+
+ def store_terms_body
+ return if store.nil?
+
+ store.policies.with_matching_name(Spree.t(:terms_of_service)).detect(&:with_body?)&.body
+ end
end
end
end
diff --git a/spree/core/spec/models/spree/seller_requirements_spec.rb b/spree/core/spec/models/spree/seller_requirements_spec.rb
index a0abc517e8..6b8ef0764f 100644
--- a/spree/core/spec/models/spree/seller_requirements_spec.rb
+++ b/spree/core/spec/models/spree/seller_requirements_spec.rb
@@ -6,6 +6,10 @@ RSpec.describe 'seller requirement kinds', type: :model do
describe Spree::SellerRequirements::AcceptTerms do
let(:requirement) { create(:accept_terms_requirement, store: store) }
+ let(:terms_policy) do
+ store.policies.with_matching_name(Spree.t(:terms_of_service)).first ||
+ store.policies.create!(name: Spree.t(:terms_of_service))
+ end
it 'is unmet until the seller accepts' do
expect(requirement.satisfied?(seller)).to be false
@@ -23,6 +27,39 @@ RSpec.describe 'seller requirement kinds', type: :model do
expect(requirement.action_url(seller)).to be_nil
end
+ # Accepting something they cannot read is not consent — the panel
+ # renders this markup in the checklist.
+ it 'exposes the terms the marketplace wrote on the requirement' do
+ requirement.update!(preferred_terms_body: '<p>Be excellent to each other.</p>')
+
+ expect(requirement.terms_html).to include('Be excellent to each other')
+ end
+
+ it 'falls back to the store Terms of Service when none were written here' do
+ terms_policy.update!(body: '<p>Shop fairly.</p>')
+
+ expect(requirement.terms_html).to include('Shop fairly')
+ end
+
+ it 'prefers the requirement body over the store policy' do
+ terms_policy.update!(body: '<p>Shop fairly.</p>')
+ requirement.update!(preferred_terms_body: '<p>Seller agreement.</p>')
+
+ expect(requirement.terms_html).to include('Seller agreement')
+ expect(requirement.terms_html).not_to include('Shop fairly')
+ end
+
+ it 'strips markup a seller must not be served' do
+ requirement.update!(preferred_terms_body: '<p>Fine</p><script>alert(1)</script>')
+
+ expect(requirement.terms_html).to include('Fine')
+ expect(requirement.terms_html).not_to include('<script>')
+ end
+
+ it 'has no terms when neither the requirement nor the store wrote any' do
+ expect(requirement.terms_html).to be_nil
+ end
+
it 'is met once they have' do
seller.update!(terms_accepted_at: Time.current)