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.

Add the DeliveryRateProvider interface; narrow 6.0 fulfillment types to shipping/pickup/digital

Damian Legawiecebb05f1fcb90
diff --git a/docs/api-reference/store.yaml b/docs/api-reference/store.yaml
index 0186dfb184..85818b604c 100644
--- a/docs/api-reference/store.yaml
+++ b/docs/api-reference/store.yaml
@@ -87,16 +87,16 @@ paths:
content:
application/json:
example:
- token: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJjdXN0b21lciIsImp0aSI6IjFmNDgxZjc4LTVkMDAtNDc5Yy05ZTAwLWMwMjMxOTUxNDE4NSIsImlzcyI6InNwcmVlIiwiYXVkIjoic3RvcmVfYXBpIiwiZXhwIjoxNzg2MTM5MzY5fQ.jKLlQNyWPaA2UgqZj6li3jjM8nRVnrnWNh__KE-9fk4
- refresh_token: qjAnvpPQjuz7UrwsxJYNGewB
+ token: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJjdXN0b21lciIsImp0aSI6ImExMTAwMTQ2LWIyN2ItNDBiNi04NTFhLWNmYjE4YTRhYjczZSIsImlzcyI6InNwcmVlIiwiYXVkIjoic3RvcmVfYXBpIiwiZXhwIjoxNzg2MDM0MjY5fQ.sky_6S65j-6RTgawukhtPK8LtIUbgGcM2CyUzo45mM0
+ refresh_token: qMk9xke4yiYLD8jQUzaVEtfs
user:
id: cust_UkLWZg9DAJ
- first_name: Tanesha
- last_name: Shields
+ first_name: Mitzie
+ last_name: Wehner
phone:
accepts_email_marketing: false
- full_name: Tanesha Shields
+ full_name: Mitzie Wehner
available_store_credit_total: '0'
display_available_store_credit_total: "$0.00"
addresses: []
@@ -194,16 +194,16 @@ paths:
content:
application/json:
example:
- token: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJjdXN0b21lciIsImp0aSI6IjQxZTk0YjJlLTFjMjAtNDg2My1hYzhiLTlmYTFkZGVkYTJkYyIsImlzcyI6InNwcmVlIiwiYXVkIjoic3RvcmVfYXBpIiwiZXhwIjoxNzg2MTM5MzY5fQ.Pq5lymxSNudXHZJfj7XX8vhaHhUEwe1n2qNENJS7lMM
- refresh_token: AtCKZc6PqsRqykRq7DWkJ3Lg
+ token: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJjdXN0b21lciIsImp0aSI6Ijg5MDVhYzFjLTdlMGYtNGRiZC04YTRjLTdmOGUzNjFmM2E5YSIsImlzcyI6InNwcmVlIiwiYXVkIjoic3RvcmVfYXBpIiwiZXhwIjoxNzg2MDM0MjY5fQ.-E5AbyOtdcsFXhOckxA0YvBSHlg4_2FnfZRenA9E1DY
+ refresh_token: sw24UDLbihwRYcd5WHNqAFrR
user:
id: cust_UkLWZg9DAJ
- first_name: Kirk
- last_name: Beer
+ first_name: Dominick
+ last_name: Douglas
phone:
accepts_email_marketing: false
- full_name: Kirk Beer
+ full_name: Dominick Douglas
available_store_credit_total: '0'
display_available_store_credit_total: "$0.00"
addresses: []
@@ -393,16 +393,16 @@ paths:
content:
application/json:
example:
- token: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJjdXN0b21lciIsImp0aSI6ImZiZDU5MDJkLTYxZDktNDVmYi1iZjJkLWVmOWVkZTM0YzQzMyIsImlzcyI6InNwcmVlIiwiYXVkIjoic3RvcmVfYXBpIiwiZXhwIjoxNzg2MTM5MzcyfQ.hOpEfn34eDzhNsE1tVV6LHYtugyzkf6AVR_3dSvT2RM
- refresh_token: EUv7LL2a8fwFjeA8nzTw56oL
+ token: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJjdXN0b21lciIsImp0aSI6IjUyYTMzZTIxLTEzMDMtNGVhNy05MTExLTVjZWQ0NjQ1YTIwOCIsImlzcyI6InNwcmVlIiwiYXVkIjoic3RvcmVfYXBpIiwiZXhwIjoxNzg2MDM0MjczfQ.CRJH3LZeWrxaep6x1klcQdzhyKAc31UJIJfysHW9_mw
+ refresh_token: VHMn9YkqHnpLqNwTMWXMP2LA
user:
id: cust_UkLWZg9DAJ
- first_name: Edwardo
- last_name: Hermann
+ first_name: Anton
+ last_name: Frami
phone:
accepts_email_marketing: false
- full_name: Edwardo Hermann
+ full_name: Anton Frami
available_store_credit_total: '0'
display_available_store_credit_total: "$0.00"
addresses: []
@@ -879,8 +879,8 @@ paths:
example:
data:
- id: prod_UkLWZg9DAJ
- name: Product 1291343
- slug: product-1291343
+ name: Product 129495
+ slug: product-129495
meta_title:
meta_description:
meta_keywords:
@@ -892,20 +892,27 @@ paths:
in_stock: false
backorderable: true
available: true
- description: Nisi minima quis deleniti quam blanditiis possimus.
- At nihil quis deleniti ratione illum molestiae. Repudiandae quibusdam
- reprehenderit magnam odit. Praesentium commodi unde incidunt porro.
- Cupiditate nam sit architecto error natus. Ex enim tempore quibusdam
- praesentium adipisci est recusandae. Inventore excepturi eveniet
- assumenda aliquid. Reiciendis quos ipsam nesciunt quas eaque accusantium.
- Optio recusandae porro saepe id repellat dicta officiis. Quam
- qui ex sit rerum quasi placeat vitae veritatis. Blanditiis ratione
- excepturi recusandae culpa eum consectetur impedit. Magni odit
- nobis cum ipsum cumque voluptates.
+ description: Reiciendis expedita eveniet nihil doloremque dolor
+ amet officia laudantium. Sed nisi itaque nobis id exercitationem
+ repellat. Reiciendis voluptatem iste corrupti eius impedit consequatur
+ sapiente accusamus. Similique quasi magnam libero iure. Quidem
+ labore officia veritatis reiciendis corrupti mollitia ad. Repudiandae
+ nobis ad adipisci nulla totam. Quis inventore quidem velit earum
+ aperiam ipsum doloribus. Recusandae ad adipisci corrupti dolorem
+ quia tempora. Dicta aut iusto ratione tempora provident magnam
+ eaque. Eveniet eius sequi nobis ipsam. Saepe voluptatum repellat
+ cum aliquid nulla et ab non. Provident officia ex repellat dolores
+ id. Rerum error nulla nobis quas. Labore explicabo molestiae sit
+ nobis earum. Totam similique aperiam fugit nesciunt ipsam possimus.
+ Eligendi officiis asperiores minima nostrum autem repellendus
+ iste. Necessitatibus labore inventore esse quos quasi temporibus
+ quibusdam tempore. Earum cum quo nulla quidem vel soluta ex.
description_html: |-
- Nisi minima quis deleniti quam blanditiis possimus. At nihil quis deleniti ratione illum molestiae. Repudiandae quibusdam reprehenderit magnam odit.
- Praesentium commodi unde incidunt porro. Cupiditate nam sit architecto error natus. Ex enim tempore quibusdam praesentium adipisci est recusandae. Inventore excepturi eveniet assumenda aliquid. Reiciendis quos ipsam nesciunt quas eaque accusantium.
- Optio recusandae porro saepe id repellat dicta officiis. Quam qui ex sit rerum quasi placeat vitae veritatis. Blanditiis ratione excepturi recusandae culpa eum consectetur impedit. Magni odit nobis cum ipsum cumque voluptates.
+ Reiciendis expedita eveniet nihil doloremque dolor amet officia laudantium. Sed nisi itaque nobis id exercitationem repellat. Reiciendis voluptatem iste corrupti eius impedit consequatur sapiente accusamus. Similique quasi magnam libero iure.
+ Quidem labore officia veritatis reiciendis corrupti mollitia ad. Repudiandae nobis ad adipisci nulla totam. Quis inventore quidem velit earum aperiam ipsum doloribus.
+ Recusandae ad adipisci corrupti dolorem quia tempora. Dicta aut iusto ratione tempora provident magnam eaque. Eveniet eius sequi nobis ipsam.
+ Saepe voluptatum repellat cum aliquid nulla et ab non. Provident officia ex repellat dolores id. Rerum error nulla nobis quas.
+ Labore explicabo molestiae sit nobis earum. Totam similique aperiam fugit nesciunt ipsam possimus. Eligendi officiis asperiores minima nostrum autem repellendus iste. Necessitatibus labore inventore esse quos quasi temporibus quibusdam tempore. Earum cum quo nulla quidem vel soluta ex.
default_variant_id: variant_UkLWZg9DAJ
thumbnail_url:
tags: []
@@ -1060,8 +1067,8 @@ paths:
example:
data:
- id: prod_UkLWZg9DAJ
- name: Product 1717378
- slug: product-1717378
+ name: Product 1716739
+ slug: product-1716739
meta_title:
meta_description:
meta_keywords:
@@ -1090,8 +1097,8 @@ paths:
price_list_id:
original_price:
- id: prod_gbHJdmfrXB
- name: Product 1723546
- slug: product-1723546
+ name: Product 1721196
+ slug: product-1721196
meta_title:
meta_description:
meta_keywords:
@@ -1103,31 +1110,29 @@ paths:
in_stock: false
backorderable: true
available: true
- description: Iure velit nisi consequatur inventore vel esse commodi.
- Aut cupiditate maxime debitis nesciunt. Ipsa ipsam nihil asperiores
- repellat voluptatibus. Voluptas eos fuga iste accusantium fugit
- dolore. Facilis nobis saepe sunt sed recusandae et rerum. Quidem
- sint perferendis nemo dolorum magni aut similique. Consequatur
- praesentium est cum recusandae quibusdam quod ea. Dolore quaerat
- vero saepe placeat nobis assumenda totam neque. Aperiam sequi
- saepe maxime ea blanditiis quas. Numquam autem neque fugiat libero
- dolore. Cum soluta mollitia quam possimus. Quae a aliquid excepturi
- accusantium maiores. Distinctio at dolores voluptates iste consequuntur
- molestiae fugit aliquid. Quisquam autem officiis possimus provident.
- Ab consequuntur magnam et placeat ducimus dolor aut. Nemo modi
- quidem incidunt accusamus aut exercitationem. At deleniti doloremque
- tempora sunt culpa qui nesciunt. Unde culpa dolorem ducimus autem
- quaerat id. Aliquid cupiditate vero doloribus at quidem quisquam.
- Corporis optio iste nesciunt qui velit nemo corrupti. Dolores
- maiores voluptatem rem nemo ullam esse. Beatae minus in libero
- doloribus quasi quia provident nisi. Nesciunt corrupti voluptatem
- commodi aliquam amet id.
+ description: Nihil error quasi dignissimos in consectetur possimus.
+ Voluptate occaecati consequatur maiores dolorum magni beatae perferendis.
+ Veniam error rerum mollitia hic omnis sit repudiandae. Non reprehenderit
+ repellendus nulla eveniet. Itaque dolorum explicabo perspiciatis
+ exercitationem reprehenderit maiores ab. Voluptatem ex saepe maxime
+ ipsum perferendis veniam voluptates. Suscipit nam quos magni doloribus.
+ Dignissimos mollitia placeat eum blanditiis numquam iusto beatae.
+ Omnis quidem deserunt accusantium molestiae praesentium. Odit
+ odio reiciendis magni ducimus. Iste explicabo aperiam inventore
+ officia magnam quidem earum. Odio reiciendis aperiam suscipit
+ possimus eaque animi quasi. Nemo libero dolores at ducimus. Neque
+ eveniet quo laboriosam cumque necessitatibus adipisci repudiandae.
+ Ratione quas excepturi iusto ducimus accusamus corporis. Alias
+ at fugit id dolor. Hic quibusdam expedita blanditiis voluptatibus
+ sapiente itaque consectetur. Nisi et non labore enim fugiat ut
+ similique. Id tempora quos rerum sint. Est sit optio soluta laudantium
+ temporibus.
description_html: |-
- Iure velit nisi consequatur inventore vel esse commodi. Aut cupiditate maxime debitis nesciunt. Ipsa ipsam nihil asperiores repellat voluptatibus. Voluptas eos fuga iste accusantium fugit dolore. Facilis nobis saepe sunt sed recusandae et rerum.
- Quidem sint perferendis nemo dolorum magni aut similique. Consequatur praesentium est cum recusandae quibusdam quod ea. Dolore quaerat vero saepe placeat nobis assumenda totam neque. Aperiam sequi saepe maxime ea blanditiis quas. Numquam autem neque fugiat libero dolore.
- Cum soluta mollitia quam possimus. Quae a aliquid excepturi accusantium maiores. Distinctio at dolores voluptates iste consequuntur molestiae fugit aliquid. Quisquam autem officiis possimus provident.
- Ab consequuntur magnam et placeat ducimus dolor aut. Nemo modi quidem incidunt accusamus aut exercitationem. At deleniti doloremque tempora sunt culpa qui nesciunt. Unde culpa dolorem ducimus autem quaerat id.
- Aliquid cupiditate vero doloribus at quidem quisquam. Corporis optio iste nesciunt qui velit nemo corrupti. Dolores maiores voluptatem rem nemo ullam esse. Beatae minus in libero doloribus quasi quia provident nisi. Nesciunt corrupti voluptatem commodi aliquam amet id.
+ Nihil error quasi dignissimos in consectetur possimus. Voluptate occaecati consequatur maiores dolorum magni beatae perferendis. Veniam error rerum mollitia hic omnis sit repudiandae.
+ Non reprehenderit repellendus nulla eveniet. Itaque dolorum explicabo perspiciatis exercitationem reprehenderit maiores ab. Voluptatem ex saepe maxime ipsum perferendis veniam voluptates. Suscipit nam quos magni doloribus. Dignissimos mollitia placeat eum blanditiis numquam iusto beatae.
+ Omnis quidem deserunt accusantium molestiae praesentium. Odit odio reiciendis magni ducimus. Iste explicabo aperiam inventore officia magnam quidem earum. Odio reiciendis aperiam suscipit possimus eaque animi quasi.
+ Nemo libero dolores at ducimus. Neque eveniet quo laboriosam cumque necessitatibus adipisci repudiandae. Ratione quas excepturi iusto ducimus accusamus corporis. Alias at fugit id dolor.
+ Hic quibusdam expedita blanditiis voluptatibus sapiente itaque consectetur. Nisi et non labore enim fugiat ut similique. Id tempora quos rerum sint. Est sit optio soluta laudantium temporibus.
default_variant_id: variant_EfhxLZ9ck8
thumbnail_url:
tags: []
@@ -1229,8 +1234,8 @@ paths:
application/json:
example:
id: prod_UkLWZg9DAJ
- name: Product 1996315
- slug: product-1996315
+ name: Product 1993830
+ slug: product-1993830
meta_title:
meta_description:
meta_keywords:
@@ -1264,7 +1269,7 @@ paths:
amount_in_cents: 999
currency: USD
display_amount: "$9.99"
- recorded_at: '2026-07-23T20:49:39Z'
+ recorded_at: '2026-07-22T15:38:02Z'
schema:
"$ref": "#/components/schemas/Product"
'404':
@@ -1514,7 +1519,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_gbHJdmfrXB
- token: ZGwRfzzwTM1QZDmG1fCs2aJ5
+ token: aeiQHcVzXoyteuvQhwwFPsyK
email:
customer_note:
currency: USD
@@ -1573,8 +1578,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1048908
- slug: product-1048908
+ name: Product 1041231
+ slug: product-1041231
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -1619,7 +1624,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: rDJKdfw23YF2LXwEZjM8f7wJ
+ token: hjBaxRS1bmwVd4TTyfAnLPEj
email:
customer_note:
currency: USD
@@ -1678,8 +1683,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1034202
- slug: product-1034202
+ name: Product 1032154
+ slug: product-1032154
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -1797,7 +1802,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: JTsY1USfmyF6pnH4EdMwN7DC
+ token: NTqeY5zAmK5WV35U1m18wEzR
email:
customer_note:
currency: USD
@@ -1962,7 +1967,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: JJytHbVGaseU1BVd1DEAKpFz
+ token: g7x4spVBsFWo74JNTyMN1sAD
email:
customer_note:
currency: USD
@@ -1970,7 +1975,7 @@ paths:
total_quantity: 0
warnings:
- code: line_item_removed
- message: Product 1086790 was removed because it was sold out
+ message: Product 1088421 was removed because it was sold out
line_item_id: li_UkLWZg9DAJ
variant_id: variant_UkLWZg9DAJ
coupon_code:
@@ -2112,7 +2117,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: ssiwdnYqtCKnFAHqAX7ZoeSU
+ token: vCwg1hw7VWk8ZxH4QiHCgaev
email:
customer_note: Leave at door
currency: USD
@@ -2167,8 +2172,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1095813
- slug: product-1095813
+ name: Product 1096256
+ slug: product-1096256
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -2387,8 +2392,8 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: 5vrdx2ikeKAv3d7fJfhwbjat
+ token: iNjmDJX3orT2tSJQ1D7oK41Q
customer_note:
currency: USD
locale: en
@@ -2439,8 +2444,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1115530
- slug: product-1115530
+ name: Product 1112306
+ slug: product-1112306
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -2594,8 +2599,8 @@ paths:
market_id: mkt_UkLWZg9DAJ
cart_id: cart_UkLWZg9DAJ
channel_id: ch_UkLWZg9DAJ
- number: R690497072
+ number: R036840634
customer_note:
currency: USD
locale: en
@@ -2603,7 +2608,7 @@ paths:
coupon_code:
fulfillment_status: backorder
payment_status: paid
- completed_at: '2026-08-07T20:49:30.670Z'
+ completed_at: '2026-08-06T15:37:50.566Z'
item_total: '10.0'
display_item_total: "$10.00"
adjustment_total: '0.0'
@@ -2635,8 +2640,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1144047
- slug: product-1144047
+ name: Product 1144709
+ slug: product-1144709
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -2661,7 +2666,7 @@ paths:
digital_links: []
fulfillments:
- id: ful_gbHJdmfrXB
- number: F39480379632
+ number: F50041337161
tracking:
tracking_url:
pickup_point_data:
@@ -2695,7 +2700,7 @@ paths:
stock_location:
id: sloc_UkLWZg9DAJ
state_abbr: NY
- name: Trinidad Weissnat
+ name: Demetrius Lehner
address1: 1600 Pennsylvania Ave NW
city: Washington
zipcode: '20500'
@@ -2712,6 +2717,9 @@ paths:
additional_tax_total: '0.0'
included_tax_total: '0.0'
tax_total: '0.0'
+ carrier:
+ service_level:
+ estimated_delivery_date:
display_cost: "$10.00"
display_total: "$10.00"
display_additional_tax_total: "$0.00"
@@ -2727,8 +2735,8 @@ paths:
payments:
- id: py_UkLWZg9DAJ
payment_method_id: pm_UkLWZg9DAJ
- response_code: BGS-ea4603e066c1
- number: PUOJEYV0
+ response_code: BGS-06d790f7e2c9
+ number: PTT7VYAB
amount: '20.0'
display_amount: "$20.00"
status: completed
@@ -2884,7 +2892,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: FQDbauG8aEgScLYUcXpMkPpM
+ token: wkrmzeDNZHZN8vMks7qbdNW6
email:
customer_note:
currency: USD
@@ -2942,8 +2950,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1405795
- slug: product-1405795
+ name: Product 1405593
+ slug: product-1405593
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -3072,7 +3080,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: tAv724h9v1PwxK1V9ieHCqMH
+ token: uK4QfijyC5JQsCdSSBr9yZDu
email:
customer_note:
currency: USD
@@ -3127,8 +3135,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1426794
- slug: product-1426794
+ name: Product 1427000
+ slug: product-1427000
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -3246,8 +3254,8 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: tfZdN3Upa8rmmMr4rUQ5SBSC
+ token: SnvAtZ2Q9M7iMotQTR7HGpCi
customer_note:
currency: USD
locale: en
@@ -3295,8 +3303,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1446727
- slug: product-1446727
+ name: Product 1445363
+ slug: product-1445363
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -3321,7 +3329,7 @@ paths:
digital_links: []
fulfillments:
- id: ful_UkLWZg9DAJ
- number: F54133936901
+ number: F32745298512
tracking:
tracking_url:
pickup_point_data:
@@ -3355,7 +3363,7 @@ paths:
stock_location:
id: sloc_UkLWZg9DAJ
state_abbr: NY
- name: Oren Carroll
+ name: Georgianna Labadie
address1: 1600 Pennsylvania Ave NW
city: Washington
zipcode: '20500'
@@ -3372,6 +3380,9 @@ paths:
additional_tax_total: '0.0'
included_tax_total: '0.0'
tax_total: '0.0'
+ carrier:
+ service_level:
+ estimated_delivery_date:
display_cost: "$10.00"
display_total: "$10.00"
display_additional_tax_total: "$0.00"
@@ -3510,7 +3521,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: TMvtwbyRwVToyVreqaaQV8Zt
+ token: 4r8pw4TqFzo4TxJ6ZxhgcaiD
email:
customer_note:
currency: USD
@@ -3561,8 +3572,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1469145
- slug: product-1469145
+ name: Product 1463892
+ slug: product-1463892
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -3589,8 +3600,8 @@ paths:
payments:
- id: py_UkLWZg9DAJ
payment_method_id: pm_UkLWZg9DAJ
- response_code: 1-SC-20260807204934590829
- number: P9BMZ97Y
+ response_code: 1-SC-20260806153756658034
+ number: PWJ7HI47
amount: '10.0'
display_amount: "$10.00"
status: checkout
@@ -3746,7 +3757,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: MXpyX5n3idPNTt2vofWnZdyE
+ token: tMML3fVMTUwuri3urCRJsc4L
email:
customer_note:
currency: USD
@@ -3801,8 +3812,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1505234
- slug: product-1505234
+ name: Product 1502547
+ slug: product-1502547
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -3829,8 +3840,8 @@ paths:
payments:
- id: py_UkLWZg9DAJ
payment_method_id: pm_UkLWZg9DAJ
- response_code: 1-SC-20260807204934865762
- number: PIED5HX1
+ response_code: 1-SC-20260806153757024261
+ number: PI0U5EJH
amount: '10.0'
display_amount: "$10.00"
status: invalid
@@ -3937,7 +3948,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: jvadFhxXvhEg16NhkUmoibCq
+ token: nYRg85x7ikBJVvrJf6rgZkAf
email:
customer_note:
currency: USD
@@ -3945,10 +3956,10 @@ paths:
total_quantity: 2
warnings:
- code: delivery_unavailable
- message: Product 1533090 cannot be delivered to the selected address
+ message: Product 1537997 cannot be delivered to the selected address
line_item_id: li_UkLWZg9DAJ
- code: delivery_unavailable
- message: Product 1545235 cannot be delivered to the selected address
+ message: Product 1543664 cannot be delivered to the selected address
line_item_id: li_gbHJdmfrXB
coupon_code:
item_total: '29.99'
@@ -3998,8 +4009,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1533090
- slug: product-1533090
+ name: Product 1537997
+ slug: product-1537997
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -4028,8 +4039,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1545235
- slug: product-1545235
+ name: Product 1543664
+ slug: product-1543664
options_text: ''
price: '19.99'
display_price: "$19.99"
@@ -4167,7 +4178,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: uUckmDmEqhr6E3DnFTEvFzzy
+ token: eoCDdS3CkHyfrmzXfiEbE12S
email:
customer_note:
currency: USD
@@ -4218,8 +4229,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 157324
- slug: product-157324
+ name: Product 1578535
+ slug: product-1578535
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -4337,7 +4348,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: Q8cbePWDHEjRhPzo6S4byoyR
+ token: w7VsKkfiUWmXRBbUUSMhhTAM
email:
customer_note:
currency: USD
@@ -4477,9 +4488,9 @@ paths:
id: ps_gbHJdmfrXB
status: pending
currency: USD
- external_id: bogus_da5aecdce2f1f7c90d576255
+ external_id: bogus_b7e547c7ab6ae43404d38eb1
external_data:
- client_secret: bogus_secret_806b4e9099a5c035
+ client_secret: bogus_secret_17ddb40ee172eb36
customer_external_id:
expires_at:
amount: '10.0'
@@ -4578,7 +4589,7 @@ paths:
id: ps_UkLWZg9DAJ
status: pending
currency: USD
- external_id: bogus_77cff91ae222d5fad98b608d
+ external_id: bogus_17e72cd004b6d32144a7151f
external_data:
client_secret: secret_123
customer_external_id:
@@ -4641,7 +4652,7 @@ paths:
id: ps_UkLWZg9DAJ
status: pending
currency: USD
- external_id: bogus_191a50d17dc7ebcc9bb4fd1a
+ external_id: bogus_b2bbebc3cda93d365b9b853b
external_data:
client_secret: secret_123
customer_external_id:
@@ -4744,7 +4755,7 @@ paths:
id: ps_UkLWZg9DAJ
status: completed
currency: USD
- external_id: bogus_25cb72f4dc3b5f94c8a8e7a8
+ external_id: bogus_7e8a10787c27cac96434678e
external_data:
client_secret: secret_123
customer_external_id:
@@ -4843,7 +4854,7 @@ paths:
id: py_UkLWZg9DAJ
payment_method_id: pm_UkLWZg9DAJ
response_code:
- number: PGHI0N2F
+ number: PUPDBW9T
amount: '10.0'
display_amount: "$10.00"
status: checkout
@@ -4952,7 +4963,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: MGL861esQxkfKMERy5R6Hu9o
+ token: WhhYif9Zyai7mrWjgDuBboJ5
email:
customer_note:
currency: USD
@@ -5003,8 +5014,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 2199602
- slug: product-2199602
+ name: Product 2191130
+ slug: product-2191130
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -5031,8 +5042,8 @@ paths:
payments:
- id: py_UkLWZg9DAJ
payment_method_id: pm_UkLWZg9DAJ
- response_code: 1-SC-20260807204940420175
- number: PTUTDCC0
+ response_code: 1-SC-20260806153804524287
+ number: PBKZUKZ3
amount: '10.0'
display_amount: "$10.00"
status: checkout
@@ -5152,7 +5163,7 @@ paths:
channel_id: ch_UkLWZg9DAJ
preferred_stock_location_id:
number: cart_UkLWZg9DAJ
- token: DKVofW1AeXvnPu4zmnbpPBYj
+ token: DQRUJw9LTNCqTA13T43mJTyC
email:
customer_note:
currency: USD
@@ -5207,8 +5218,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 2217255
- slug: product-2217255
+ name: Product 2219169
+ slug: product-2219169
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -5323,7 +5334,7 @@ paths:
market_id: mkt_UkLWZg9DAJ
cart_id:
channel_id: ch_UkLWZg9DAJ
- number: R998302679
+ number: R675776516
customer_note:
currency: USD
@@ -5332,7 +5343,7 @@ paths:
coupon_code:
fulfillment_status:
payment_status:
- completed_at: '2026-08-07T20:49:36.532Z'
+ completed_at: '2026-08-06T15:37:59.415Z'
item_total: '10.0'
display_item_total: "$10.00"
adjustment_total: '0.0'
@@ -5364,8 +5375,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1619033
- slug: product-1619033
+ name: Product 1616138
+ slug: product-1616138
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -5390,7 +5401,7 @@ paths:
digital_links: []
fulfillments:
- id: ful_UkLWZg9DAJ
- number: F63949833773
+ number: F53961012863
tracking: U10000
tracking_url:
pickup_point_data:
@@ -5424,7 +5435,7 @@ paths:
stock_location:
id: sloc_UkLWZg9DAJ
state_abbr: NY
- name: Melodi Franecki
+ name: Viva Rutherford
address1: 1600 Pennsylvania Ave NW
city: Washington
zipcode: '20500'
@@ -5441,6 +5452,9 @@ paths:
additional_tax_total: '0.0'
included_tax_total: '0.0'
tax_total: '0.0'
+ carrier:
+ service_level:
+ estimated_delivery_date:
display_cost: "$10.00"
display_total: "$10.00"
display_additional_tax_total: "$0.00"
@@ -6376,8 +6390,8 @@ paths:
market_id: mkt_UkLWZg9DAJ
cart_id:
channel_id: ch_UkLWZg9DAJ
- number: R074347320
+ number: R145162621
customer_note:
currency: USD
locale: en
@@ -6385,7 +6399,7 @@ paths:
coupon_code:
fulfillment_status:
payment_status:
- completed_at: '2026-08-07T20:49:33.026Z'
+ completed_at: '2026-08-06T15:37:54.115Z'
item_total: '10.0'
display_item_total: "$10.00"
adjustment_total: '0.0'
@@ -6417,8 +6431,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1308646
- slug: product-1308646
+ name: Product 1305583
+ slug: product-1305583
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -6443,7 +6457,7 @@ paths:
digital_links: []
fulfillments:
- id: ful_UkLWZg9DAJ
- number: F19402681403
+ number: F48124210255
tracking: U10000
tracking_url:
pickup_point_data:
@@ -6477,7 +6491,7 @@ paths:
stock_location:
id: sloc_UkLWZg9DAJ
state_abbr: NY
- name: Sharen Becker
+ name: Leta Watsica
address1: 1600 Pennsylvania Ave NW
city: Washington
zipcode: '20500'
@@ -6494,6 +6508,9 @@ paths:
additional_tax_total: '0.0'
included_tax_total: '0.0'
tax_total: '0.0'
+ carrier:
+ service_level:
+ estimated_delivery_date:
display_cost: "$10.00"
display_total: "$10.00"
display_additional_tax_total: "$0.00"
@@ -6654,8 +6671,8 @@ paths:
market_id: mkt_UkLWZg9DAJ
cart_id:
channel_id: ch_UkLWZg9DAJ
- number: R660891710
+ number: R842026446
customer_note:
currency: USD
locale: en
@@ -6663,7 +6680,7 @@ paths:
coupon_code:
fulfillment_status:
payment_status:
- completed_at: '2026-08-07T20:49:33.255Z'
+ completed_at: '2026-08-06T15:37:54.387Z'
item_total: '10.0'
display_item_total: "$10.00"
adjustment_total: '0.0'
@@ -6695,8 +6712,8 @@ paths:
preorder_ships_at:
quantity: 1
currency: USD
- name: Product 1325941
- slug: product-1325941
+ name: Product 1324728
+ slug: product-1324728
options_text: ''
price: '10.0'
display_price: "$10.00"
@@ -6721,7 +6738,7 @@ paths:
digital_links: []
fulfillments:
- id: ful_UkLWZg9DAJ
- number: F42518993200
+ number: F68143195377
tracking: U10000
tracking_url:
pickup_point_data:
@@ -6755,7 +6772,7 @@ paths:
stock_location:
id: sloc_UkLWZg9DAJ
state_abbr: NY
- name: Larraine Hahn
+ name: Eura Ziemann
address1: 1600 Pennsylvania Ave NW
city: Washington
zipcode: '20500'
@@ -6772,6 +6789,9 @@ paths:
additional_tax_total: '0.0'
included_tax_total: '0.0'
tax_total: '0.0'
+ carrier:
+ service_level:
+ estimated_delivery_date:
display_cost: "$10.00"
display_total: "$10.00"
display_additional_tax_total: "$0.00"
@@ -6888,8 +6908,8 @@ paths:
content:
application/json:
example:
- token: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJjdXN0b21lciIsImp0aSI6IjAwOWJjZjAzLTAyNzAtNDA1NS05OTYzLTdlNDYzZTJkMzg0ZSIsImlzcyI6InNwcmVlIiwiYXVkIjoic3RvcmVfYXBpIiwiZXhwIjoxNzg2MTM5MzczfQ.YWm3T24sBmwnQpIgElqnyc2iBeU6W5ny4xHUuXEF5wY
- refresh_token: caQWisav2V1qfuqpfvn3qPyh
+ token: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX3R5cGUiOiJjdXN0b21lciIsImp0aSI6IjNjN2Y4YTVhLWUwOGEtNDFjMi04ZGVlLTdkNzg5ODE5YzUzZSIsImlzcyI6InNwcmVlIiwiYXVkIjoic3RvcmVfYXBpIiwiZXhwIjoxNzg2MDM0Mjc0fQ.n49vf8yRDGbdcLJxY_i8KKdrXCdI2-U8uVE5QB0KbMM
+ refresh_token: EQ2f8JrgcKHtfMA5573eG2MT
user:
id: cust_UkLWZg9DAJ
@@ -6906,10 +6926,10 @@ paths:
newsletter_subscriber:
id: sub_UkLWZg9DAJ
- created_at: '2026-08-07T20:49:33.404Z'
- updated_at: '2026-08-07T20:49:33.406Z'
+ created_at: '2026-08-06T15:37:54.588Z'
+ updated_at: '2026-08-06T15:37:54.590Z'
verified: true
- verified_at: '2026-08-07T20:49:33Z'
+ verified_at: '2026-08-06T15:37:54Z'
customer_id: cust_UkLWZg9DAJ
customer_groups: []
schema:
@@ -7012,12 +7032,12 @@ paths:
application/json:
example:
id: cust_UkLWZg9DAJ
- first_name: Rochelle
- last_name: Champlin
+ first_name: Latisha
+ last_name: Lindgren
phone: 555-555-0199
accepts_email_marketing: false
- full_name: Rochelle Champlin
+ full_name: Latisha Lindgren
available_store_credit_total: '0'
display_available_store_credit_total: "$0.00"
addresses:
@@ -7153,7 +7173,7 @@ paths:
application/json:
example:
id: cust_UkLWZg9DAJ
first_name: Updated
last_name: Name
phone: 555-555-0199
@@ -7344,7 +7364,7 @@ paths:
example:
data:
- id: gc_UkLWZg9DAJ
- code: AF6F27B34CA326B8
+ code: BE3A4822E918E550
status: active
currency: USD
amount: '10.0'
@@ -7440,7 +7460,7 @@ paths:
application/json:
example:
id: gc_UkLWZg9DAJ
- code: 0006045EDC4130B7
+ code: 270022DB988FFC86
status: active
currency: USD
amount: '10.0'
@@ -7512,8 +7532,8 @@ paths:
example:
id: pss_gbHJdmfrXB
status: pending
- external_id: bogus_seti_06e37be8d870c452be8085da
- external_client_secret: bogus_seti_secret_b234c3ea512af9cc
+ external_id: bogus_seti_18b6ae7b142d985094c9acbc
+ external_client_secret: bogus_seti_secret_b67565e5f9b8f29c
external_data: {}
payment_method_id: pm_UkLWZg9DAJ
payment_source_id:
@@ -7612,8 +7632,8 @@ paths:
example:
id: pss_UkLWZg9DAJ
status: pending
- external_id: seti_test_42391fd9fa4a73438ae05dea
- external_client_secret: seti_secret_0bea7b367249088c1152c923
+ external_id: seti_test_975701777e1ea1e78de21a09
+ external_client_secret: seti_secret_1150d72c731d8f4a49c44a9f
external_data:
client_secret: secret_123
payment_method_id: pm_UkLWZg9DAJ
@@ -7689,8 +7709,8 @@ paths:
example:
id: pss_UkLWZg9DAJ
status: completed
- external_id: seti_test_e8ee2d846b185a5d8e969db6
- external_client_secret: seti_secret_fb416451aae79dd1d04b6558
+ external_id: seti_test_7c3fd4c6975f94fdea7c3e53
+ external_client_secret: seti_secret_5ac8997d0a7993b638444308
external_data:
client_secret: secret_123
payment_method_id: pm_UkLWZg9DAJ
@@ -8634,7 +8654,7 @@ paths:
data:
- id: wl_UkLWZg9DAJ
name: My Wishlist
- token: cCfcGuXqgQmyvAthWzsaQb8R
+ token: LNb8DPjVcE7JzLGqrKg1pyWG
is_default: false
is_private: true
meta:
@@ -8710,7 +8730,7 @@ paths:
example:
id: wl_gbHJdmfrXB
name: Birthday Ideas
- token: LFUSYaoFAnedbWDoC28moiU3
+ token: MaFKeYRASyGtpXs6XgpPUFf7
is_default: false
is_private: true
schema:
@@ -8811,7 +8831,7 @@ paths:
example:
id: wl_UkLWZg9DAJ
name: My Wishlist
- token: K8VuQB6TFgLUiV5MYMmTZfVK
+ token: 6MK5M9136VthSuyRyfdWJo9i
is_default: false
is_private: true
schema:
@@ -8873,7 +8893,7 @@ paths:
example:
id: wl_UkLWZg9DAJ
name: Updated Name
- token: 5EDZVQqMcUZ5mdbtxJAm4qYV
+ token: Kdb4MMsTNaRXGy1vfCgvmPBC
is_default: false
is_private: true
schema:
@@ -9155,11 +9175,11 @@ paths:
application/json:
example:
id: sub_UkLWZg9DAJ
- created_at: '2026-08-07T20:49:35.983Z'
- updated_at: '2026-08-07T20:49:35.984Z'
+ created_at: '2026-08-06T15:37:58.582Z'
+ updated_at: '2026-08-06T15:37:58.583Z'
verified: true
- verified_at: '2026-08-07T20:49:35Z'
+ verified_at: '2026-08-06T15:37:58Z'
customer_id: cust_UkLWZg9DAJ
schema:
"$ref": "#/components/schemas/NewsletterSubscriber"
@@ -9238,10 +9258,10 @@ paths:
example:
id: sub_UkLWZg9DAJ
- created_at: '2026-08-07T20:49:36.006Z'
- updated_at: '2026-08-07T20:49:36.011Z'
+ created_at: '2026-08-06T15:37:58.658Z'
+ updated_at: '2026-08-06T15:37:58.674Z'
verified: true
- verified_at: '2026-08-07T20:49:36Z'
+ verified_at: '2026-08-06T15:37:58Z'
customer_id:
schema:
"$ref": "#/components/schemas/NewsletterSubscriber"
@@ -9411,7 +9431,7 @@ paths:
body_html: ''
- id: pol_OIJLhNcSbf
name: Privacy Policy
- slug: privacy-policy-e6543f47-bbab-41e2-a91c-cf4d4e4ba168
+ slug: privacy-policy-a14591fa-add7-41a3-b3b6-402cae3f789f
body: We respect your privacy.
body_html: |
<div class="trix-content">
@@ -9678,7 +9698,7 @@ paths:
- name: fulfillment_type
in: query
required: false
- description: 'Filter: shipping, digital, pickup, pickup_point'
+ description: 'Filter: shipping, digital, pickup'
schema:
type: string
responses:
@@ -9801,6 +9821,20 @@ components:
bearerFormat: JWT
description: JWT token for authenticated customers
schemas:
+ ClaimReason:
+ type: object
+ properties:
+ id:
+ type: string
+ name:
+ type: string
+ active:
+ type: boolean
+ required:
+ - id
+ - name
+ - active
+ x-typelizer: true
PaginationMeta:
type: object
properties:
@@ -10573,20 +10607,6 @@ components:
- replacement_variant_id
- line_item_id
x-typelizer: true
- ClaimReason:
- type: object
- properties:
- id:
- type: string
- name:
- type: string
- active:
- type: boolean
- required:
- - id
- - name
- - active
- x-typelizer: true
Claim:
type: object
properties:
@@ -10916,6 +10936,15 @@ components:
type: string
tax_total:
type: string
+ carrier:
+ type: string
+ nullable: true
+ service_level:
+ type: string
+ nullable: true
+ estimated_delivery_date:
+ type: string
+ nullable: true
display_cost:
type: string
display_total:
@@ -10938,6 +10967,9 @@ components:
- additional_tax_total
- included_tax_total
- tax_total
+ - carrier
+ - service_level
+ - estimated_delivery_date
- display_cost
- display_total
- display_additional_tax_total
@@ -12555,20 +12587,6 @@ components:
- line_item_id
- fulfillment_item_id
x-typelizer: true
- ReturnReason:
- type: object
- properties:
- id:
- type: string
- name:
- type: string
- active:
- type: boolean
- required:
- - id
- - name
- - active
- x-typelizer: true
Return:
type: object
properties:
@@ -12619,6 +12637,20 @@ components:
- refunded_at
- canceled_at
x-typelizer: true
+ ReturnReason:
+ type: object
+ properties:
+ id:
+ type: string
+ name:
+ type: string
+ active:
+ type: boolean
+ required:
+ - id
+ - name
+ - active
+ x-typelizer: true
State:
type: object
properties:
diff --git a/docs/docs.json b/docs/docs.json
index 4af72430f0..48e608fb09 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -1136,6 +1136,13 @@
"v6/developer/how-to/custom-promotion"
]
},
+ {
+ "group": "Delivery",
+ "icon": "truck",
+ "pages": [
+ "v6/developer/how-to/custom-delivery-rate-provider"
+ ]
+ },
{
"group": "Reports",
"icon": "chart-bar",
diff --git a/docs/v6/developer/how-to/custom-delivery-rate-provider.mdx b/docs/v6/developer/how-to/custom-delivery-rate-provider.mdx
new file mode 100644
index 0000000000..f26c991d6c
--- /dev/null
+++ b/docs/v6/developer/how-to/custom-delivery-rate-provider.mdx
@@ -0,0 +1,156 @@
+---
+title: Build a Custom Delivery Rate Provider
+description: Connect a carrier or rate aggregator to Spree so checkout quotes live delivery rates instead of calculator-based prices.
+---
+
+## Overview
+
+A delivery rate provider decides **where a delivery method's price comes from**. Spree ships with one built-in provider, `Spree::DeliveryRateProvider::Internal`, which prices through the method's calculator — flat rates, per-item rates, and the rest. That is the default, and stores that never install a carrier integration keep using it.
+
+A custom provider replaces that arithmetic with a live quote: you call a carrier or an aggregator, and the rate that reaches checkout carries the carrier name, the service level, and an estimated delivery date.
+
+Use a provider when the price comes from outside Spree. If you only need different arithmetic on values Spree already has, write a calculator instead — it is far less work. See [Fulfillments](/v6/developer/core-concepts/fulfillments) for how delivery methods, rates and fulfillments fit together.
+
+## What you will build
+
+Three pieces, each with one job:
+
+| Piece | Responsibility |
+|---|---|
+| `Spree::Integration` subclass | Holds the store's credentials, managed from the admin dashboard |
+| `Spree::DeliveryRateProvider::Base` subclass | Turns a package into a rate quote |
+| An initializer | Registers both so admins can select them |
+
+Providers are stateless strategy objects. They never store credentials themselves — that is the integration's job, which is what gives merchants one place to see everything connected to their store.
+
+## 1. Store credentials in an integration
+
+```ruby
+module SpreeAcmeCarrier
+ class Integration < Spree::Integration
+ preference :api_key, :password
+ preference :account_number, :string
+ preference :test_mode, :boolean, default: true
+
+ def self.integration_group = 'shipping'
+
+ # Called when an admin activates the integration. Returning false blocks
+ # activation and shows your message in the dashboard.
+ def can_connect?
+ client.ping
+ true
+ rescue StandardError => e
+ self.connection_error_message = e.message
+ false
+ end
+
+ def client
+ @client ||= AcmeCarrier::Client.new(api_key: preferred_api_key, test: preferred_test_mode)
+ end
+ end
+end
+```
+
+Declare secrets as `:password` preferences. Spree masks them on read and guards the round-trip on write, so an API key never leaves the server in plain text.
+
+## 2. Implement the provider
+
+Only `#estimate` is required. It receives a `Spree::Stock::Package` and returns an `Estimate` — or `nil`.
+
+```ruby
+module SpreeAcmeCarrier
+ class DeliveryRateProvider < Spree::DeliveryRateProvider::Base
+ def self.integration_class = 'SpreeAcmeCarrier::Integration'
+
+ def estimate(package)
+ quote = quotes_for(package).find { |q| q.service_code == delivery_method.metadata['service_code'] }
+ return if quote.nil?
+
+ Spree::DeliveryRateProvider::Estimate.new(
+ cost: quote.amount,
+ carrier: quote.carrier_name,
+ service_level: quote.service_name,
+ estimated_delivery_date: quote.delivery_date,
+ metadata: { quote_id: quote.id }
+ )
+ end
+
+ private
+
+ # One API call serves every delivery method sharing this provider within
+ # a request — carriers return all services in one response, so quoting
+ # five methods should not mean five round-trips.
+ def quotes_for(package)
+ key = [:acme_quotes, store.id, package.stock_location.id, package.order.id]
+ Spree::Current.provider_cache[key] ||= integration.client.rates(
+ from: package.stock_location,
+ to: package.order.ship_address,
+ parcel: { weight: package.weight }
+ )
+ end
+ end
+end
+```
+
+**Returning `nil` hides the delivery method** for that package. This is the same contract calculators follow, and it is how you express "this carrier does not serve this destination" — the method simply does not appear at checkout rather than appearing at a wrong price.
+
+`cost` is pre-tax and pre-VAT. Spree applies the gross-up and resolves the tax rate afterwards, exactly as it does for calculator output, so you never handle tax yourself.
+
+Declaring `integration_class` is all the availability wiring you need: Spree derives `available_for_store?` from it, so your provider is hidden from the admin picker — and rejected on save — until the merchant connects the integration.
+
+### Optional lifecycle hooks
+
+`book` and `release` are part of the provider contract but Spree does not invoke them yet — they are reserved for the rate booking flow. Until then, call `book` yourself from your gem's fulfillment provider when the label is purchased:
+
+```ruby
+# Reserve the quote once your fulfillment provider dispatches.
+def book(delivery_rate)
+ integration.client.book(delivery_rate.metadata['quote_id'])
+end
+
+# Release a quote that is no longer wanted.
+def release(delivery_rate)
+ integration.client.release(delivery_rate.metadata['quote_id'])
+end
+```
+
+## 3. Register both classes
+
+```ruby
+# config/initializers/spree.rb
+Spree.delivery_rate_providers << 'SpreeAcmeCarrier::DeliveryRateProvider'.constantize
+Spree.integrations << 'SpreeAcmeCarrier::Integration'
+```
+
+Registration is what makes a provider selectable: Spree validates `rate_provider` against this list, so a typo fails when the method is saved rather than deep inside checkout.
+
+## 4. Use it
+
+A merchant connects the integration under **Settings → Integrations**, then picks the provider on a delivery method under **Settings → Delivery methods**. The provider field only appears once more than one provider is available, so stores without a carrier integration never see it.
+
+One delivery method means one rate, so model each sellable service as its own method — "Acme Ground" and "Acme Express" are two methods sharing one provider, distinguished by the `service_code` metadata the example reads. Methods stay regional: a carrier serving two continents is two methods, each with its own delivery zones.
+
+Providers and calculators coexist freely. A store can price "Free shipping" with a flat-rate calculator, "Express" through your carrier, and "Local pickup" with neither.
+
+## Testing
+
+Your provider is a plain object, so test it directly:
+
+```ruby
+RSpec.describe SpreeAcmeCarrier::DeliveryRateProvider do
+ let(:delivery_method) { create(:delivery_method, rate_provider: described_class.to_s) }
+
+ it 'quotes the configured service' do
+ estimate = described_class.new(delivery_method).estimate(package)
+
+ expect(estimate.cost).to eq(BigDecimal('12.40'))
+ expect(estimate.carrier).to eq('Acme')
+ end
+
+ it 'hides the method when the carrier does not serve the destination' do
+ expect(described_class.new(delivery_method).estimate(unservable_package)).to be_nil
+ end
+end
+```
+
+Stub the carrier client rather than calling the real API — quoting runs on every checkout, so a slow or flaky test here is a slow or flaky suite everywhere.
diff --git a/packages/admin-sdk/src/admin-client.ts b/packages/admin-sdk/src/admin-client.ts
index db9ecd1374..dfe54df911 100644
--- a/packages/admin-sdk/src/admin-client.ts
+++ b/packages/admin-sdk/src/admin-client.ts
@@ -226,6 +226,7 @@ import type {
CustomFieldDefinition,
DeliveryMethod,
DeliveryMethodRule,
+ DeliveryRateProviderOption,
DeliveryZone,
Discount,
Exchange,
@@ -1604,6 +1605,16 @@ export class AdminClient {
options,
),
+ /** Rate providers available to this store, plus the default when none is chosen. */
+ rateProviders: (
+ options?: RequestOptions,
+ ): Promise<{ data: DeliveryRateProviderOption[]; default: string }> =>
+ this.request<{ data: DeliveryRateProviderOption[]; default: string }>(
+ 'GET',
+ '/delivery_methods/rate_providers',
+ options,
+ ),
+
/** Eligibility rules on a delivery method (item total / weight bounds, …). */
rules: {
list: (
diff --git a/packages/admin-sdk/src/params.ts b/packages/admin-sdk/src/params.ts
index 86f8f765b6..77fca012e1 100644
--- a/packages/admin-sdk/src/params.ts
+++ b/packages/admin-sdk/src/params.ts
@@ -1674,10 +1674,16 @@ export interface DeliveryMethodParams {
name?: string
admin_name?: string | null
code?: string | null
- /** One of `shipping`, `digital`, `pickup`, `pickup_point`. */
+ /** One of `shipping`, `digital`, `pickup` (see `deliveryMethods.fulfillmentProviders()`). */
fulfillment_type?: string
fulfillment_provider?: string
pickup_point_provider?: string | null
+ /**
+ * Quoting strategy class name (see `deliveryMethods.rateProviders()`).
+ * Omit or send null for the built-in Internal provider, which prices
+ * through the method's calculator.
+ */
+ rate_provider?: string | null
storefront_visible?: boolean
tracking_url?: string | null
estimated_transit_business_days_min?: number | null
diff --git a/packages/admin-sdk/src/types/fulfillment-providers.ts b/packages/admin-sdk/src/types/fulfillment-providers.ts
index be1c8d1755..ac8f276336 100644
--- a/packages/admin-sdk/src/types/fulfillment-providers.ts
+++ b/packages/admin-sdk/src/types/fulfillment-providers.ts
@@ -16,3 +16,20 @@ export interface FulfillmentProviderOption {
/** Whether fulfillments handled by this provider ship to a customer address. */
requires_address: boolean
}
+
+/**
+ * A registered `Spree::DeliveryRateProvider` strategy, as returned by
+ * `GET /delivery_methods/rate_providers`. Rate providers decide where a
+ * method's price comes from — the built-in Internal provider prices through
+ * the method's calculator, while carrier providers quote live rates. Only
+ * providers usable by the current store are listed, so a carrier whose
+ * integration is not connected never appears.
+ */
+export interface DeliveryRateProviderOption {
+ /** Ruby class name, e.g. `Spree::DeliveryRateProvider::Internal`. */
+ type: string
+ /** Human-readable name for display. */
+ name: string
+ /** `Spree::Integration` subclass holding this provider's credentials, if any. */
+ integration_class: string | null
+}
diff --git a/packages/admin-sdk/src/types/generated/DeliveryMethod.ts b/packages/admin-sdk/src/types/generated/DeliveryMethod.ts
index e89dfd556b..5168d0a172 100644
--- a/packages/admin-sdk/src/types/generated/DeliveryMethod.ts
+++ b/packages/admin-sdk/src/types/generated/DeliveryMethod.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 4ffece4ffd69fb4a834a12fdc8f38429
+// Typelizer digest 70f65d500b5e28ada3c5823303fbc509
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -12,6 +12,7 @@ interface DeliveryMethod {
admin_name: string | null;
fulfillment_provider: string;
pickup_point_provider: string | null;
+ rate_provider: string | null;
storefront_visible: boolean;
tracking_url: string | null;
created_at: string;
diff --git a/packages/admin-sdk/src/types/generated/DeliveryRate.ts b/packages/admin-sdk/src/types/generated/DeliveryRate.ts
index 3f32e90530..5e4fd9e704 100644
--- a/packages/admin-sdk/src/types/generated/DeliveryRate.ts
+++ b/packages/admin-sdk/src/types/generated/DeliveryRate.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 2b2043ba0981e8d0de5c21dac459064e
+// Typelizer digest 874a711b64affb7549836316fe027ea6
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {DeliveryMethod} from '@/types'
@@ -13,12 +13,16 @@ interface DeliveryRate {
additional_tax_total: string;
included_tax_total: string;
tax_total: string;
+ carrier: string | null;
+ service_level: string | null;
+ estimated_delivery_date: string | null;
display_cost: string;
display_total: string;
display_additional_tax_total: string;
display_included_tax_total: string;
display_tax_total: string;
delivery_method?: DeliveryMethod;
+ metadata: Record<string, unknown> | null;
created_at: string;
updated_at: string;
}
diff --git a/packages/admin-sdk/src/types/index.ts b/packages/admin-sdk/src/types/index.ts
index 3fea0d8695..c875bbe587 100644
--- a/packages/admin-sdk/src/types/index.ts
+++ b/packages/admin-sdk/src/types/index.ts
@@ -8,7 +8,7 @@ export type {
PaginationMeta,
} from '@spree/sdk-core'
// Hand-written discovery-endpoint types (controller-shaped, not generated)
-export type { FulfillmentProviderOption } from './fulfillment-providers'
+export type { DeliveryRateProviderOption, FulfillmentProviderOption } from './fulfillment-providers'
// Admin-specific generated types
export type { default as Address } from './generated/Address'
export type { default as AdminUser } from './generated/AdminUser'
diff --git a/packages/dashboard/src/hooks/use-delivery-methods.ts b/packages/dashboard/src/hooks/use-delivery-methods.ts
index c688f5ce39..6e8f8eb195 100644
--- a/packages/dashboard/src/hooks/use-delivery-methods.ts
+++ b/packages/dashboard/src/hooks/use-delivery-methods.ts
@@ -32,6 +32,14 @@ export function useFulfillmentProviders() {
})
}
+export function useDeliveryRateProviders() {
+ return useQuery({
+ queryKey: useResourceKey('delivery-methods', 'rate-providers'),
+ queryFn: () => adminClient.deliveryMethods.rateProviders(),
+ staleTime: 1000 * 60 * 30,
+ })
+}
+
export function useCreateDeliveryMethod() {
return useResourceMutation<DeliveryMethod, Error, DeliveryMethodParams>({
mutationFn: (params) => adminClient.deliveryMethods.create(params),
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 298bb52ba6..1bb184c6e1 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -709,6 +709,10 @@
"fulfillment_type": {
"label": "نوع التنفيذ"
},
+ "rate_provider": {
+ "label": "مزوّد الأسعار",
+ "help": "مصدر أسعار طريقة التوصيل هذه. المزوّد المدمج يحسب عبر الآلة الحاسبة أدناه؛ ومزوّدو شركات الشحن يوفّرون أسعارًا فورية."
+ },
"pickup_locations": {
"label": "مواقع الاستلام"
},
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index bc74e0b296..4ed98cfaa7 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -709,6 +709,10 @@
"fulfillment_type": {
"label": "Fulfillment-Typ"
},
+ "rate_provider": {
+ "label": "Tarifanbieter",
+ "help": "Woher die Preise dieser Methode stammen. Der integrierte Anbieter rechnet mit dem Kalkulator unten; Carrier-Anbieter liefern Echtzeit-Tarife."
+ },
"pickup_locations": {
"label": "Abholorte"
},
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index a0a34e804d..76d2b361e1 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -709,6 +709,10 @@
"fulfillment_type": {
"label": "Fulfillment type"
},
+ "rate_provider": {
+ "label": "Rate provider",
+ "help": "Where this method's prices come from. The built-in provider prices with the calculator below; carrier providers quote live rates."
+ },
"pickup_locations": {
"label": "Pickup locations"
},
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 766d348656..09608b7ee9 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -709,6 +709,10 @@
"fulfillment_type": {
"label": "Type de traitement"
},
+ "rate_provider": {
+ "label": "Fournisseur de tarifs",
+ "help": "D'où proviennent les prix de cette méthode. Le fournisseur intégré calcule avec le calculateur ci-dessous ; les transporteurs fournissent des tarifs en temps réel."
+ },
"pickup_locations": {
"label": "Points de retrait"
},
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 81214897dc..e74c3fb7fe 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -717,6 +717,10 @@
"fulfillment_type": {
"label": "Typ realizacji"
},
+ "rate_provider": {
+ "label": "Dostawca stawek",
+ "help": "Skąd pochodzą ceny tej metody. Wbudowany dostawca liczy według kalkulatora poniżej; dostawcy przewoźników podają stawki na żywo."
+ },
"pickup_locations": {
"label": "Punkty odbioru"
},
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 9115acd534..89df19b6bf 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -709,6 +709,10 @@
"fulfillment_type": {
"label": "履约类型"
},
+ "rate_provider": {
+ "label": "费率提供方",
+ "help": "此方式的价格来源。内置提供方使用下方的计算器;承运商提供方提供实时费率。"
+ },
"pickup_locations": {
"label": "自提地点"
},
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-methods.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-methods.tsx
index c76a10cda4..aeb8596045 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-methods.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-methods.tsx
@@ -52,6 +52,7 @@ import {
useDeliveryMethod,
useDeliveryMethodRules,
useDeliveryMethodRuleTypes,
+ useDeliveryRateProviders,
useFulfillmentProviders,
useUpdateDeliveryMethod,
} from '../../../../hooks/use-delivery-methods'
@@ -275,6 +276,7 @@ function EditDeliveryMethodSheet({
'shipping',
fulfillment_provider:
deliveryMethod.fulfillment_provider ?? DELIVERY_METHOD_DEFAULTS.fulfillment_provider,
+ rate_provider: deliveryMethod.rate_provider ?? DELIVERY_METHOD_DEFAULTS.rate_provider,
storefront_visible: deliveryMethod.storefront_visible,
tracking_url: deliveryMethod.tracking_url ?? '',
estimated_transit_business_days_min:
@@ -479,11 +481,57 @@ function ConditionRuleRow({
)
}
+function ProviderSelectField({
+ form,
+ name,
+ label,
+ help,
+ options,
+ fallbackValue,
+}: {
+ form: UseFormReturn<DeliveryMethodFormValues>
+ name: 'fulfillment_provider' | 'rate_provider'
+ label: string
+ help: string
+ options: { value: string; label: string }[]
+ fallbackValue?: string
+}) {
+ return (
+ <Field>
+ <FieldLabel>{label}</FieldLabel>
+ <Controller
+ name={name}
+ control={form.control}
+ render={({ field }) => (
+ <Select
+ items={options}
+ value={field.value || fallbackValue || ''}
+ onValueChange={field.onChange}
+ >
+ <SelectTrigger>
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {options.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ )}
+ />
+ <span className="text-muted-foreground text-xs">{help}</span>
+ </Field>
+ )
+}
+
function DeliveryMethodFormFields({ form }: { form: UseFormReturn<DeliveryMethodFormValues> }) {
const { t } = useTranslation()
const { errors } = form.formState
const { data: calculators } = useDeliveryCalculators()
const { data: fulfillmentProviders } = useFulfillmentProviders()
+ const { data: rateProviders } = useDeliveryRateProviders()
const { data: zones } = useDeliveryZones()
const { data: stockLocations } = useStockLocations()
const { data: taxCategories } = useTaxCategories()
@@ -519,6 +567,12 @@ function DeliveryMethodFormFields({ form }: { form: UseFormReturn<DeliveryMethod
label: provider.name,
}))
+ const defaultRateProvider = rateProviders?.default ?? ''
+ const rateProviderOptions = (rateProviders?.data ?? []).map((provider) => ({
+ value: provider.type,
+ label: provider.name,
+ }))
+
// Suggest a provider whenever the admin picks a fulfillment type: prefer one
// that declares that type (Pickup for pickup), since the generic Manual
// fallback would otherwise keep dispatch and address rules wrong. Only the
@@ -603,31 +657,29 @@ function DeliveryMethodFormFields({ form }: { form: UseFormReturn<DeliveryMethod
/>
</Field>
+ {/* Both provider fields render only when there is a real choice: with a
+ single registered provider the default applies and the field stays
+ hidden (for rate providers, until a carrier integration is
+ installed pricing is simply the calculator below). */}
{providerOptions.length > 1 && (
- <Field>
- <FieldLabel>{t('admin.fields.delivery_method.fulfillment_provider.label')}</FieldLabel>
- <Controller
- name="fulfillment_provider"
- control={form.control}
- render={({ field }) => (
- <Select items={providerOptions} value={field.value} onValueChange={field.onChange}>
- <SelectTrigger>
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- {providerOptions.map((option) => (
- <SelectItem key={option.value} value={option.value}>
- {option.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- )}
- />
- <span className="text-muted-foreground text-xs">
- {t('admin.fields.delivery_method.fulfillment_provider.help')}
- </span>
- </Field>
+ <ProviderSelectField
+ form={form}
+ name="fulfillment_provider"
+ label={t('admin.fields.delivery_method.fulfillment_provider.label')}
+ help={t('admin.fields.delivery_method.fulfillment_provider.help')}
+ options={providerOptions}
+ />
+ )}
+
+ {rateProviderOptions.length > 1 && (
+ <ProviderSelectField
+ form={form}
+ name="rate_provider"
+ label={t('admin.fields.delivery_method.rate_provider.label')}
+ help={t('admin.fields.delivery_method.rate_provider.help')}
+ options={rateProviderOptions}
+ fallbackValue={defaultRateProvider}
+ />
)}
{fulfillmentType === 'pickup' && (
diff --git a/packages/dashboard/src/schemas/delivery-method.ts b/packages/dashboard/src/schemas/delivery-method.ts
index 1a0750a97d..544cb841e5 100644
--- a/packages/dashboard/src/schemas/delivery-method.ts
+++ b/packages/dashboard/src/schemas/delivery-method.ts
@@ -24,6 +24,8 @@ export const deliveryMethodFormSchema = z.object({
code: z.string().optional(),
fulfillment_type: z.enum(FULFILLMENT_TYPES),
fulfillment_provider: z.string(),
+ // Empty string means the built-in Internal provider (calculator-priced).
+ rate_provider: z.string(),
storefront_visible: z.boolean(),
tracking_url: z.string().optional(),
estimated_transit_business_days_min: z.string().optional(),
@@ -44,6 +46,7 @@ export const DELIVERY_METHOD_DEFAULTS: DeliveryMethodFormValues = {
code: '',
fulfillment_type: 'shipping',
fulfillment_provider: 'Spree::FulfillmentProvider::Manual',
+ rate_provider: '',
storefront_visible: true,
tracking_url: '',
estimated_transit_business_days_min: '',
@@ -63,6 +66,7 @@ export function deliveryMethodValuesToParams(values: DeliveryMethodFormValues) {
code: values.code || null,
fulfillment_type: values.fulfillment_type,
fulfillment_provider: values.fulfillment_provider,
+ rate_provider: values.rate_provider || null,
storefront_visible: values.storefront_visible,
tracking_url: values.tracking_url || null,
estimated_transit_business_days_min: values.estimated_transit_business_days_min
diff --git a/packages/sdk/src/types/generated/DeliveryRate.ts b/packages/sdk/src/types/generated/DeliveryRate.ts
index b4585dcd24..1a35340082 100644
--- a/packages/sdk/src/types/generated/DeliveryRate.ts
+++ b/packages/sdk/src/types/generated/DeliveryRate.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 16148583a8ec70d0c9c6d6b5f2a9e653
+// Typelizer digest 15858627aaf9b0f93fd1630de9e8743a
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {DeliveryMethod} from '@/types'
@@ -13,6 +13,9 @@ interface DeliveryRate {
additional_tax_total: string;
included_tax_total: string;
tax_total: string;
+ carrier: string | null;
+ service_level: string | null;
+ estimated_delivery_date: string | null;
display_cost: string;
display_total: string;
display_additional_tax_total: string;
diff --git a/packages/sdk/src/zod/generated/DeliveryRate.ts b/packages/sdk/src/zod/generated/DeliveryRate.ts
index 7cf109754b..6d538130e4 100644
--- a/packages/sdk/src/zod/generated/DeliveryRate.ts
+++ b/packages/sdk/src/zod/generated/DeliveryRate.ts
@@ -12,6 +12,9 @@ export const DeliveryRateSchema = z.object({
additional_tax_total: z.string(),
included_tax_total: z.string(),
tax_total: z.string(),
+ carrier: z.string().nullable(),
+ service_level: z.string().nullable(),
+ estimated_delivery_date: z.string().nullable(),
display_cost: z.string(),
display_total: z.string(),
display_additional_tax_total: z.string(),
diff --git a/spree/api/app/controllers/spree/api/v3/admin/delivery_methods_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/delivery_methods_controller.rb
index 9b1a8c8efa..4bb809a800 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/delivery_methods_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/delivery_methods_controller.rb
@@ -42,6 +42,27 @@ module Spree
render json: { data: data, fulfillment_types: Spree.fulfillment_types }
end
+ # GET /api/v3/admin/delivery_methods/rate_providers
+ # Registered DeliveryRateProvider strategies, filtered to those the
+ # current store can actually use — a carrier provider whose
+ # integration isn't connected must not be offered, since choosing it
+ # would break quoting at checkout.
+ def rate_providers
+ authorize! :create, model_class
+
+ data = Spree.delivery_rate_providers.
+ select { |provider_class| provider_class.available_for_store?(current_store) }.
+ map do |provider_class|
+ {
+ type: provider_class.to_s,
+ name: provider_class.provider_name,
+ integration_class: provider_class.integration_class
+ }
+ end
+
+ render json: { data: data, default: Spree::DeliveryMethod::DEFAULT_RATE_PROVIDER }
+ end
+
def create
@resource = model_class.new(assignable_params)
authorize_resource!(@resource, :create)
@@ -81,7 +102,7 @@ module Spree
def permitted_params
params.permit(
:name, :admin_name, :code, :fulfillment_type, :fulfillment_provider,
- :pickup_point_provider, :storefront_visible, :tracking_url,
+ :pickup_point_provider, :rate_provider, :storefront_visible, :tracking_url,
:estimated_transit_business_days_min, :estimated_transit_business_days_max,
:tax_category_id, :calculator_type,
delivery_zone_ids: [], stock_location_ids: [], calculator_preferences: {},
diff --git a/spree/api/app/serializers/spree/api/v3/admin/delivery_method_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/delivery_method_serializer.rb
index ad3cc389a9..2e0178e0c6 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/delivery_method_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/delivery_method_serializer.rb
@@ -5,6 +5,7 @@ module Spree
class DeliveryMethodSerializer < V3::DeliveryMethodSerializer
typelize admin_name: [:string, nullable: true], fulfillment_type: :string,
fulfillment_provider: :string, pickup_point_provider: [:string, nullable: true],
+ rate_provider: [:string, nullable: true],
storefront_visible: :boolean, tracking_url: [:string, nullable: true],
tax_category_id: [:string, nullable: true],
delivery_zone_ids: [:string, multi: true],
@@ -13,7 +14,7 @@ module Spree
calculator_preferences: ['Record<string, unknown>', nullable: true]
attributes :admin_name, :fulfillment_type, :fulfillment_provider, :pickup_point_provider,
- :storefront_visible, :tracking_url,
+ :rate_provider, :storefront_visible, :tracking_url,
created_at: :iso8601, updated_at: :iso8601, deleted_at: :iso8601
attribute :tax_category_id do |record|
diff --git a/spree/api/app/serializers/spree/api/v3/admin/delivery_rate_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/delivery_rate_serializer.rb
index 04e0bcc56d..031638c0f5 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/delivery_rate_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/delivery_rate_serializer.rb
@@ -3,6 +3,11 @@ module Spree
module V3
module Admin
class DeliveryRateSerializer < V3::DeliveryRateSerializer
+ typelize metadata: ['Record<string, unknown>', nullable: true]
+
+ # Raw carrier payload (quote ids, service codes) — operational
+ # detail a customer must never see.
+ attributes :metadata
attributes created_at: :iso8601, updated_at: :iso8601
one :delivery_method, resource: proc { Spree.api.admin_delivery_method_serializer }, if: proc { expand?('delivery_method') }
diff --git a/spree/api/app/serializers/spree/api/v3/delivery_rate_serializer.rb b/spree/api/app/serializers/spree/api/v3/delivery_rate_serializer.rb
index 808851fe0b..12e12f7c0c 100644
--- a/spree/api/app/serializers/spree/api/v3/delivery_rate_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/delivery_rate_serializer.rb
@@ -7,16 +7,23 @@ module Spree
total: :string, display_total: :string,
additional_tax_total: :string, display_additional_tax_total: :string,
included_tax_total: :string, display_included_tax_total: :string,
- tax_total: :string, display_tax_total: :string
+ tax_total: :string, display_tax_total: :string,
+ carrier: [:string, nullable: true],
+ service_level: [:string, nullable: true],
+ estimated_delivery_date: [:string, nullable: true]
attribute :delivery_method_id do |deliver_rate|
deliver_rate.delivery_method&.prefixed_id
end
+ # Carrier, service level and delivery date come from the rate provider
+ # and are what the customer chooses between; nil on calculator-priced
+ # methods. Provider metadata stays admin-only.
attributes :name, :selected,
:cost, :total,
:additional_tax_total, :included_tax_total,
- :tax_total
+ :tax_total,
+ :carrier, :service_level, :estimated_delivery_date
attribute :display_cost do |deliver_rate|
deliver_rate.display_cost.to_s
diff --git a/spree/api/config/routes.rb b/spree/api/config/routes.rb
index 916993a913..d8ed87c29a 100644
--- a/spree/api/config/routes.rb
+++ b/spree/api/config/routes.rb
@@ -325,6 +325,7 @@ Spree::Core::Engine.add_routes do
collection do
get :calculators
get :fulfillment_providers
+ get :rate_providers
end
resources :rules, controller: 'delivery_methods/rules', only: [:index, :show, :create, :update, :destroy]
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/delivery_methods_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/delivery_methods_controller_spec.rb
index 873e1c9a6d..8d321680b0 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/delivery_methods_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/delivery_methods_controller_spec.rb
@@ -51,6 +51,35 @@ RSpec.describe Spree::Api::V3::Admin::DeliveryMethodsController, type: :controll
end
end
+ describe 'GET #rate_providers' do
+ it 'lists the registered providers and the default' do
+ get :rate_providers, params: {}, as: :json
+
+ expect(response).to have_http_status(:ok)
+ internal = json_response['data'].find { |row| row['type'] == 'Spree::DeliveryRateProvider::Internal' }
+ expect(internal['name']).to eq('Internal')
+ expect(internal['integration_class']).to be_nil
+ expect(json_response['default']).to eq('Spree::DeliveryRateProvider::Internal')
+ end
+
+ # Offering a provider whose integration isn't connected would let an
+ # admin pick one that then fails to quote at checkout.
+ it 'hides providers unavailable to the current store' do
+ provider_class = Class.new(Spree::DeliveryRateProvider::Base) do
+ def self.integration_class = 'Spree::Integrations::Unconnected'
+ def self.available_for_store?(_store) = false
+ end
+ stub_const('UnavailableRateProvider', provider_class)
+ Spree.delivery_rate_providers << provider_class
+
+ get :rate_providers, params: {}, as: :json
+
+ expect(json_response['data'].map { |row| row['type'] }).not_to include('UnavailableRateProvider')
+ ensure
+ Spree.delivery_rate_providers.delete(provider_class)
+ end
+ end
+
describe 'POST #create' do
let!(:zone) { create(:delivery_zone) }
diff --git a/spree/api/spec/serializers/spree/api/v3/delivery_rate_serializer_spec.rb b/spree/api/spec/serializers/spree/api/v3/delivery_rate_serializer_spec.rb
index b9e0b698f8..d0c1ced781 100644
--- a/spree/api/spec/serializers/spree/api/v3/delivery_rate_serializer_spec.rb
+++ b/spree/api/spec/serializers/spree/api/v3/delivery_rate_serializer_spec.rb
@@ -17,10 +17,32 @@ RSpec.describe Spree::Api::V3::DeliveryRateSerializer do
additional_tax_total display_additional_tax_total
included_tax_total display_included_tax_total
tax_total display_tax_total
+ carrier service_level estimated_delivery_date
delivery_method
])
end
+ # Carrier fields are populated by rate providers; calculator-priced
+ # methods leave them nil rather than omitting the keys.
+ it 'exposes carrier fields as null when the rate has none' do
+ expect(subject['carrier']).to be_nil
+ expect(subject['service_level']).to be_nil
+ expect(subject['estimated_delivery_date']).to be_nil
+ end
+
+ it 'exposes carrier fields set by a provider' do
+ shipping_rate.update!(carrier: 'UPS', service_level: 'Ground', estimated_delivery_date: Date.new(2026, 8, 20))
+
+ expect(subject['carrier']).to eq('UPS')
+ expect(subject['service_level']).to eq('Ground')
+ expect(subject['estimated_delivery_date']).to eq(Date.new(2026, 8, 20))
+ end
+
+ # Provider payload is operational detail; customers must never see it.
+ it 'does not expose provider metadata' do
+ expect(subject.keys).not_to include('metadata')
+ end
+
it 'returns cost and total' do
expect(subject['cost']).to eq(shipping_rate.cost)
expect(subject['total']).to eq(shipping_rate.total)
diff --git a/spree/core/app/models/spree/current.rb b/spree/core/app/models/spree/current.rb
index 844358b775..3f164d5fff 100644
--- a/spree/core/app/models/spree/current.rb
+++ b/spree/core/app/models/spree/current.rb
@@ -4,10 +4,21 @@ module Spree
# All attributes are automatically reset between requests by Rails.
# Fallback chains ensure sensible defaults when attributes are not explicitly set.
class Current < ::ActiveSupport::CurrentAttributes
- attribute :store, :channel, :market, :currency, :locale, :content_locale, :zone, :default_tax_zone, :price_lists, :global_pricing_context
+ attribute :store, :channel, :market, :currency, :locale, :content_locale, :zone, :default_tax_zone, :price_lists, :global_pricing_context, :provider_cache
resets { @default_tax_zone_loaded = false }
+ # Scratch space for provider strategies to memoize a call across the
+ # request — part of the delivery rate provider contract (nothing in core
+ # writes to it): a carrier gem keys its quote here so several delivery
+ # methods sharing one carrier cost a single API round-trip rather than
+ # one each. Keys must be namespaced by the provider (see the custom
+ # delivery rate provider guide).
+ # @return [Hash]
+ def provider_cache
+ super || (self.provider_cache = {})
+ end
+
# Returns the current store, falling back to the default store.
# @return [Spree::Store]
def store
diff --git a/spree/core/app/models/spree/delivery_method.rb b/spree/core/app/models/spree/delivery_method.rb
index f6d67a4d72..4df7529990 100644
--- a/spree/core/app/models/spree/delivery_method.rb
+++ b/spree/core/app/models/spree/delivery_method.rb
@@ -22,6 +22,9 @@ module Spree
STOREFRONT = :storefront
BACKOFFICE = :backoffice
+ # Quoting strategy used when +rate_provider+ is blank.
+ DEFAULT_RATE_PROVIDER = 'Spree::DeliveryRateProvider::Internal'.freeze
+
# @deprecated Use {STOREFRONT}/{BACKOFFICE}; removed in 6.1.
DISPLAY_ON_FRONT_END = 1
# @deprecated Use {STOREFRONT}/{BACKOFFICE}; removed in 6.1.
@@ -85,6 +88,17 @@ module Spree
if: :fulfillment_type_changed?
validates :estimated_transit_business_days_min, numericality: { greater_than_or_equal_to: 1 }, allow_nil: true
validates :estimated_transit_business_days_max, numericality: { greater_than_or_equal_to: 1 }, allow_nil: true
+ # Same reasoning as fulfillment_type: an unregistered provider is a typo
+ # that would raise at quote time, deep inside checkout. Blank is valid —
+ # it means the Internal provider.
+ validates :rate_provider,
+ inclusion: { in: -> (_record) { Spree.delivery_rate_providers.map(&:to_s) } },
+ allow_blank: true,
+ if: :rate_provider_changed?
+ # The admin picker filters on availability, but a direct API write must
+ # not save a provider whose integration isn't connected — that breaks
+ # quoting at checkout, not at save time where the admin can see it.
+ validate :rate_provider_must_be_available, if: :rate_provider_changed?
scope :digital, -> { by_fulfillment_type('digital') }
@@ -160,6 +174,21 @@ module Spree
@provider ||= (fulfillment_provider.presence || 'Spree::FulfillmentProvider::Manual').constantize.new
end
+ # The DeliveryRateProvider strategy quoting this method. Blank means the
+ # Internal (calculator-backed) provider, so untouched rows keep their
+ # existing pricing.
+ #
+ # @return [Spree::DeliveryRateProvider::Base]
+ def rate_provider_instance
+ @rate_provider_instance ||= rate_provider_class.new(self)
+ end
+
+ # @return [Class]
+ def rate_provider_class
+ (rate_provider.presence || DEFAULT_RATE_PROVIDER).constantize
+ end
+
+
# Flat-payload writer for `rules`, so one PATCH saves the method and its
# conditions together. See
# {Spree::TypedAssociations#assign_typed_association}.
@@ -299,5 +328,16 @@ module Spree
def apply_pending_rules
flush_pending_typed_association(:delivery_method_rules)
end
+
+ # Only meaningful for registered providers — the inclusion validation
+ # already rejects anything else, so an unresolvable name must not raise
+ # here as well.
+ def rate_provider_must_be_available
+ return if rate_provider.blank?
+ return unless Spree.delivery_rate_providers.map(&:to_s).include?(rate_provider)
+ return if rate_provider_class.available_for_store?(store)
+
+ errors.add(:rate_provider, Spree.t('errors.messages.rate_provider_unavailable'))
+ end
end
end
diff --git a/spree/core/app/models/spree/delivery_rate.rb b/spree/core/app/models/spree/delivery_rate.rb
index bf00394786..6602656308 100644
--- a/spree/core/app/models/spree/delivery_rate.rb
+++ b/spree/core/app/models/spree/delivery_rate.rb
@@ -2,6 +2,11 @@ module Spree
class DeliveryRate < Spree.base_class
has_prefix_id :dr
+ # Carrier payload from the rate provider (quote ids, service codes) —
+ # a plain single column per the house rule for new columns, not the
+ # legacy public/private Metadata pair.
+ serialize :metadata, coder: Spree::Metadata::HashSerializer
+
belongs_to :fulfillment, class_name: 'Spree::Fulfillment'
belongs_to :tax_rate, -> { with_deleted }, class_name: 'Spree::TaxRate'
belongs_to :delivery_method, -> { with_deleted }, class_name: 'Spree::DeliveryMethod', inverse_of: :delivery_rates
diff --git a/spree/core/app/models/spree/delivery_rate_provider/base.rb b/spree/core/app/models/spree/delivery_rate_provider/base.rb
new file mode 100644
index 0000000000..536fa69771
--- /dev/null
+++ b/spree/core/app/models/spree/delivery_rate_provider/base.rb
@@ -0,0 +1,90 @@
+module Spree
+ module DeliveryRateProvider
+ # Strategy that answers "what does this delivery method cost for this
+ # package, and what metadata comes with the quote?".
+ #
+ # Stored as a string class name on DeliveryMethod and constantized at call
+ # time; registered via Spree.delivery_rate_providers. The Estimator
+ # dispatches here in place of calling the calculator directly, so
+ # filtering, VAT gross-up, tax resolution and sorting stay in one place
+ # for every provider.
+ #
+ # External providers resolve credentials through the delivery method's
+ # store integration — they never store credentials themselves.
+ class Base
+ attr_reader :delivery_method
+
+ class << self
+ # @return [String] human-readable name for admin UIs
+ def provider_name
+ name.demodulize.titleize
+ end
+
+ # The Spree::Integration subclass holding this provider's credentials,
+ # as a class name string. Internal providers need none.
+ #
+ # @return [String, nil]
+ def integration_class
+ nil
+ end
+
+ # Whether the store can use this provider at all — admin UIs hide
+ # providers whose integration isn't connected, and DeliveryMethod
+ # validates the choice on save. Derived from +integration_class+ so
+ # carrier providers get the right answer by declaring only that.
+ #
+ # @param store [Spree::Store, nil]
+ # @return [Boolean]
+ def available_for_store?(store)
+ return true if integration_class.blank?
+
+ store.present? && store.integrations.active.exists?(type: integration_class)
+ end
+ end
+
+ # @param delivery_method [Spree::DeliveryMethod]
+ def initialize(delivery_method)
+ @delivery_method = delivery_method
+ end
+
+ # Quotes this delivery method for a package.
+ #
+ # Returning nil suppresses the method, matching the calculator contract
+ # where a nil cost hides it — that equivalence is what lets FlatRate's
+ # thresholds keep working through the Internal provider.
+ #
+ # @param _package [Spree::Stock::Package]
+ # @return [Spree::DeliveryRateProvider::Estimate, nil]
+ def estimate(_package)
+ raise NotImplementedError, "Please implement 'estimate' in your delivery rate provider: #{self.class.name}"
+ end
+
+ # Reserves the quote with the carrier once a customer selects it.
+ # Spree does not invoke this yet — it is reserved for the rate booking
+ # flow; until then a provider gem calls it from its own fulfillment
+ # provider.
+ def book(_delivery_rate); end
+
+ # Releases a previously booked quote. Same status as {#book}.
+ def release(_delivery_rate); end
+
+ private
+
+ def store
+ delivery_method.store
+ end
+
+ # The connected, active integration carrying this provider's credentials.
+ # Memoizes the missing case too — an unconnected integration must not
+ # cost a query per estimate.
+ #
+ # @return [Spree::Integration, nil]
+ def integration
+ return if self.class.integration_class.blank?
+ return @integration if defined?(@integration)
+
+ @integration = store&.integrations&.active&.find_by(type: self.class.integration_class)
+ end
+ end
+ end
+end
diff --git a/spree/core/app/models/spree/delivery_rate_provider/estimate.rb b/spree/core/app/models/spree/delivery_rate_provider/estimate.rb
new file mode 100644
index 0000000000..c2223b5d7d
--- /dev/null
+++ b/spree/core/app/models/spree/delivery_rate_provider/estimate.rb
@@ -0,0 +1,20 @@
+module Spree
+ module DeliveryRateProvider
+ # A single quote returned by a delivery rate provider.
+ #
+ # +cost+ is pre-tax and pre-VAT-gross-up: the Estimator applies
+ # +gross_amount+ and resolves the tax rate afterwards, exactly as it does
+ # for calculator output. Everything else is carrier metadata that flows
+ # onto the persisted DeliveryRate.
+ class Estimate
+ include ActiveModel::Model
+ include ActiveModel::Attributes
+
+ attribute :cost, :decimal
+ attribute :carrier, :string
+ attribute :service_level, :string
+ attribute :estimated_delivery_date, :date
+ attribute :metadata, default: -> { {} }
+ end
+ end
+end
diff --git a/spree/core/app/models/spree/delivery_rate_provider/internal.rb b/spree/core/app/models/spree/delivery_rate_provider/internal.rb
new file mode 100644
index 0000000000..28a22fd6b4
--- /dev/null
+++ b/spree/core/app/models/spree/delivery_rate_provider/internal.rb
@@ -0,0 +1,23 @@
+module Spree
+ module DeliveryRateProvider
+ # Default provider: prices through the delivery method's calculator, so
+ # every store that doesn't opt into an external provider behaves exactly
+ # as before. Custom merchant calculators keep working unchanged, including
+ # the ones that suppress a method by returning nil.
+ #
+ # Carries no carrier metadata and no delivery date: turning the method's
+ # configured business days into a date needs a per-market holiday calendar
+ # core doesn't have, and guessing one would put a wrong date in front of
+ # customers. Carrier-backed providers return the real date.
+ class Internal < Base
+ # @param package [Spree::Stock::Package]
+ # @return [Spree::DeliveryRateProvider::Estimate, nil]
+ def estimate(package)
+ cost = delivery_method.calculator.compute(package)
+ return if cost.nil?
+
+ Estimate.new(cost: cost)
+ end
+ end
+ end
+end
diff --git a/spree/core/app/models/spree/stock/estimator.rb b/spree/core/app/models/spree/stock/estimator.rb
index 07dce36a62..ce09618dca 100644
--- a/spree/core/app/models/spree/stock/estimator.rb
+++ b/spree/core/app/models/spree/stock/estimator.rb
@@ -38,15 +38,26 @@ module Spree
delivery_rates.sort_by!(&:cost)
end
+ # Quoting runs through the method's rate provider — Internal prices
+ # through the calculator, carrier providers call their API. A nil
+ # estimate suppresses the method, matching the calculator contract.
+ # Filtering, VAT gross-up, tax resolution and sorting stay here so
+ # every provider gets them identically.
def calculate_delivery_rates(package, audience)
delivery_methods(package, audience).map do |delivery_method|
- cost = delivery_method.calculator.compute(package)
+ estimate = delivery_method.rate_provider_instance.estimate(package)
- next unless cost
+ next if estimate.nil?
delivery_method.delivery_rates.new(
- cost: gross_amount(cost, taxation_options_for(delivery_method)),
- tax_rate: first_tax_rate_for(delivery_method.tax_category)
+ cost: gross_amount(estimate.cost, taxation_options_for(delivery_method)),
+ tax_rate: first_tax_rate_for(delivery_method.tax_category),
+ carrier: estimate.carrier,
+ service_level: estimate.service_level,
+ estimated_delivery_date: estimate.estimated_delivery_date,
+ # presence: rates are rewritten on every refresh, so calculator-
+ # priced methods store NULL rather than an empty hash each time.
+ metadata: estimate.metadata.presence
)
end.compact
end
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index 6edcbb64c7..78ac5686e8 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -901,6 +901,7 @@ en:
oidc_requires_redirect: This provider requires signing in through its own login page.
pickup_point_not_found: pickup point could not be found with this provider
promotion_discount_not_editable: promotion discounts are managed by recalculation and cannot be edited
+ rate_provider_unavailable: is not available for this store — connect its integration first
store_association_can_not_be_changed: The store association can not be changed
store_is_already_set: Store is already set
services:
diff --git a/spree/core/db/migrate/20260806120001_add_rate_provider_to_delivery_methods.rb b/spree/core/db/migrate/20260806120001_add_rate_provider_to_delivery_methods.rb
new file mode 100644
index 0000000000..b83a3f94f2
--- /dev/null
+++ b/spree/core/db/migrate/20260806120001_add_rate_provider_to_delivery_methods.rb
@@ -0,0 +1,7 @@
+class AddRateProviderToDeliveryMethods < ActiveRecord::Migration[7.2]
+ def change
+ # Blank means the Internal provider (calculator-backed), so existing rows
+ # need no backfill.
+ add_column :spree_delivery_methods, :rate_provider, :string
+ end
+end
diff --git a/spree/core/db/migrate/20260806120002_add_carrier_columns_to_delivery_rates.rb b/spree/core/db/migrate/20260806120002_add_carrier_columns_to_delivery_rates.rb
new file mode 100644
index 0000000000..d749f1af8a
--- /dev/null
+++ b/spree/core/db/migrate/20260806120002_add_carrier_columns_to_delivery_rates.rb
@@ -0,0 +1,13 @@
+class AddCarrierColumnsToDeliveryRates < ActiveRecord::Migration[7.2]
+ def change
+ add_column :spree_delivery_rates, :carrier, :string
+ add_column :spree_delivery_rates, :service_level, :string
+ add_column :spree_delivery_rates, :estimated_delivery_date, :date
+
+ if connection.adapter_name.downcase.include?('postgresql')
+ add_column :spree_delivery_rates, :metadata, :jsonb
+ else
+ add_column :spree_delivery_rates, :metadata, :json
+ end
+ end
+end
diff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rb
index a760f44d03..f82c26b705 100644
--- a/spree/core/lib/spree/core.rb
+++ b/spree/core/lib/spree/core.rb
@@ -337,6 +337,17 @@ module Spree
Rails.application.config.spree.delivery_method_rules = value
end
+ # Quoting strategies selectable on a delivery method.
+ #
+ # @return [Array<Class>]
+ def self.delivery_rate_providers
+ Rails.application.config.spree.delivery_rate_providers
+ end
+
+ def self.delivery_rate_providers=(value)
+ Rails.application.config.spree.delivery_rate_providers = value
+ end
+
def self.order_routing
Rails.application.config.spree.order_routing
end
diff --git a/spree/core/lib/spree/core/engine.rb b/spree/core/lib/spree/core/engine.rb
index dd9eee13f3..0cdbc7160d 100644
--- a/spree/core/lib/spree/core/engine.rb
+++ b/spree/core/lib/spree/core/engine.rb
@@ -16,6 +16,7 @@ module Spree
:fulfillment_types,
:stock_splitters,
:delivery_method_rules,
+ :delivery_rate_providers,
:order_routing,
:promotions,
:pricing,
@@ -120,6 +121,10 @@ module Spree
app.config.spree.delivery_method_rules = []
end
+ initializer 'spree.register.delivery_rate_providers', before: :load_config_initializers do |app|
+ app.config.spree.delivery_rate_providers = []
+ end
+
initializer 'spree.register.custom_fields' do |app|
app.config.spree.custom_fields = CustomFieldsEnvironment.new
app.config.spree.custom_fields.types = []
@@ -186,10 +191,17 @@ module Spree
Spree::FulfillmentProvider::PickupPoint
]
- # Open strings, no inclusion validation — extensions append their own
- # (e.g. 'same_day_courier').
+ # Registered vocabulary — DeliveryMethod and ProductType validate
+ # against it on change. Extensions append their own
+ # (e.g. 'same_day_courier') from an initializer.
Rails.application.config.spree.fulfillment_types = %w[shipping pickup digital]
+ # Quoting strategies selectable on a delivery method. Internal prices
+ # through the method's calculator; carrier gems append theirs.
+ Rails.application.config.spree.delivery_rate_providers.concat [
+ Spree::DeliveryRateProvider::Internal
+ ]
+
# Selectable order routing strategies. The internal Reducer collaborator
# is intentionally NOT listed — it is not a Strategy::Base. Plugins add
# their own via this array.
diff --git a/spree/core/spec/models/spree/current_spec.rb b/spree/core/spec/models/spree/current_spec.rb
index 780a615f3a..7929fbda10 100644
--- a/spree/core/spec/models/spree/current_spec.rb
+++ b/spree/core/spec/models/spree/current_spec.rb
@@ -333,4 +333,22 @@ RSpec.describe Spree::Current do
expect(described_class.instance.instance_variable_get(:@default_tax_zone_loaded)).to be false
end
end
+
+ describe '#provider_cache' do
+ it 'defaults to a hash providers can memoize into' do
+ described_class.provider_cache[:quote] = 'cached'
+
+ expect(described_class.provider_cache[:quote]).to eq('cached')
+ end
+
+ # Carrier quotes are request-scoped; leaking them across requests would
+ # price one customer's checkout with another's destination.
+ it 'is cleared between requests' do
+ described_class.provider_cache[:quote] = 'cached'
+
+ described_class.reset
+
+ expect(described_class.provider_cache).to eq({})
+ end
+ end
end
diff --git a/spree/core/spec/models/spree/delivery_method_spec.rb b/spree/core/spec/models/spree/delivery_method_spec.rb
index 290c066708..c9316cc0e2 100644
--- a/spree/core/spec/models/spree/delivery_method_spec.rb
+++ b/spree/core/spec/models/spree/delivery_method_spec.rb
@@ -174,6 +174,60 @@ describe Spree::DeliveryMethod, type: :model do
end
end
+ describe '#rate_provider_instance' do
+ let(:delivery_method) { create(:delivery_method) }
+
+ it 'defaults to the Internal provider when unset' do
+ expect(delivery_method.rate_provider).to be_blank
+ expect(delivery_method.rate_provider_instance).to be_a(Spree::DeliveryRateProvider::Internal)
+ end
+
+ it 'constantizes the configured provider and passes itself to it' do
+ provider_class = Class.new(Spree::DeliveryRateProvider::Base)
+ stub_const('ConfiguredRateProvider', provider_class)
+ Spree.delivery_rate_providers << provider_class
+
+ delivery_method.update!(rate_provider: 'ConfiguredRateProvider')
+
+ expect(delivery_method.rate_provider_instance).to be_a(provider_class)
+ expect(delivery_method.rate_provider_instance.delivery_method).to eq(delivery_method)
+ ensure
+ Spree.delivery_rate_providers.delete(provider_class)
+ end
+
+ # An unregistered provider would otherwise raise at quote time, deep
+ # inside checkout.
+ it 'rejects a provider that is not registered' do
+ delivery_method.rate_provider = 'NotARegisteredProvider'
+
+ expect(delivery_method).not_to be_valid
+ expect(delivery_method.errors[:rate_provider]).to be_present
+ end
+
+ it 'keeps rows loadable when a registered provider is later removed' do
+ delivery_method.update_columns(rate_provider: 'GoneAwayProvider')
+
+ expect(delivery_method.reload).to be_valid
+ end
+
+ # The admin picker filters on availability, but a direct API write must
+ # not save a provider whose integration isn't connected.
+ it 'rejects a registered provider that is unavailable for the store' do
+ provider_class = Class.new(Spree::DeliveryRateProvider::Base) do
+ def self.integration_class = 'Spree::Integrations::Unconnected'
+ end
+ stub_const('UnconnectedRateProvider', provider_class)
+ Spree.delivery_rate_providers << provider_class
+
+ delivery_method.rate_provider = 'UnconnectedRateProvider'
+
+ expect(delivery_method).not_to be_valid
+ expect(delivery_method.errors[:rate_provider]).to be_present
+ ensure
+ Spree.delivery_rate_providers.delete(provider_class)
+ end
+ end
+
# Regression test for #4320
context 'soft deletion' do
let(:delivery_method) { create(:delivery_method) }
diff --git a/spree/core/spec/models/spree/delivery_rate_provider/base_spec.rb b/spree/core/spec/models/spree/delivery_rate_provider/base_spec.rb
new file mode 100644
index 0000000000..ff8987d7ee
--- /dev/null
+++ b/spree/core/spec/models/spree/delivery_rate_provider/base_spec.rb
@@ -0,0 +1,74 @@
+require 'spec_helper'
+
+RSpec.describe Spree::DeliveryRateProvider::Base do
+ let(:store) { @default_store }
+ let(:delivery_method) { create(:delivery_method, store: store) }
+
+ describe 'the contract' do
+ it 'requires subclasses to implement estimate' do
+ expect { described_class.new(delivery_method).estimate(nil) }.to raise_error(NotImplementedError)
+ end
+
+ it 'no-ops the optional lifecycle hooks' do
+ provider = described_class.new(delivery_method)
+
+ expect { provider.book(nil) }.not_to raise_error
+ expect { provider.release(nil) }.not_to raise_error
+ end
+
+ it 'needs no integration by default' do
+ expect(described_class.integration_class).to be_nil
+ expect(described_class.available_for_store?(store)).to be(true)
+ end
+ end
+
+ describe 'credential resolution' do
+ let(:provider_class) do
+ Class.new(described_class) do
+ def self.integration_class = 'Spree::Integration'
+
+ # Exposed so the spec can assert on the resolved record.
+ def resolved_integration = integration
+ end
+ end
+
+ before { stub_const('TestRateProvider', provider_class) }
+
+ it 'resolves the active integration from the method store' do
+ integration = create(:integration, store: store, active: true)
+
+ expect(TestRateProvider.new(delivery_method).resolved_integration).to eq(integration)
+ end
+
+ it 'ignores inactive integrations' do
+ create(:integration, store: store, active: false)
+
+ expect(TestRateProvider.new(delivery_method).resolved_integration).to be_nil
+ end
+
+ # Declaring integration_class is all a carrier provider needs —
+ # availability is derived from it, so forgetting a hand-written override
+ # can't silently offer an unconnected provider.
+ describe '.available_for_store?' do
+ it 'follows the connected integration' do
+ expect(TestRateProvider.available_for_store?(store)).to be(false)
+
+ create(:integration, store: store, active: true)
+
+ expect(TestRateProvider.available_for_store?(store)).to be(true)
+ end
+
+ it 'ignores inactive integrations' do
+ create(:integration, store: store, active: false)
+
+ expect(TestRateProvider.available_for_store?(store)).to be(false)
+ end
+ end
+ end
+
+ describe 'registry' do
+ it 'registers the Internal provider' do
+ expect(Spree.delivery_rate_providers).to include(Spree::DeliveryRateProvider::Internal)
+ end
+ end
+end
diff --git a/spree/core/spec/models/spree/delivery_rate_provider/internal_spec.rb b/spree/core/spec/models/spree/delivery_rate_provider/internal_spec.rb
new file mode 100644
index 0000000000..6974a78121
--- /dev/null
+++ b/spree/core/spec/models/spree/delivery_rate_provider/internal_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+RSpec.describe Spree::DeliveryRateProvider::Internal do
+ let(:store) { @default_store }
+ let(:delivery_method) { create(:delivery_method, store: store) }
+ let(:order) { create(:order_with_line_items, store: store) }
+ let(:package) { order.fulfillments.first.to_package }
+
+ subject(:provider) { described_class.new(delivery_method) }
+
+ describe '#estimate' do
+ it 'prices through the delivery method calculator' do
+ allow(delivery_method.calculator).to receive(:compute).with(package).and_return(BigDecimal('12.5'))
+
+ expect(provider.estimate(package).cost).to eq(BigDecimal('12.5'))
+ end
+
+ # The nil-suppresses-the-method equivalence is what lets calculator
+ # thresholds (FlatRate's min/max bounds) keep hiding methods.
+ it 'returns nil when the calculator suppresses the method' do
+ allow(delivery_method.calculator).to receive(:compute).and_return(nil)
+
+ expect(provider.estimate(package)).to be_nil
+ end
+
+ # Core has no holiday calendar, so it must not invent a delivery date.
+ it 'carries no carrier metadata and no delivery date' do
+ delivery_method.update!(estimated_transit_business_days_min: 3)
+ allow(delivery_method.calculator).to receive(:compute).and_return(BigDecimal('5'))
+
+ estimate = provider.estimate(package)
+ expect(estimate.carrier).to be_nil
+ expect(estimate.estimated_delivery_date).to be_nil
+ end
+ end
+end
diff --git a/spree/core/spec/models/spree/stock/estimator_spec.rb b/spree/core/spec/models/spree/stock/estimator_spec.rb
index 1e1f321709..672d9bafde 100644
--- a/spree/core/spec/models/spree/stock/estimator_spec.rb
+++ b/spree/core/spec/models/spree/stock/estimator_spec.rb
@@ -265,6 +265,74 @@ module Spree
expect(called).to be true
end
end
+
+ # Quoting dispatches through the method's rate provider, so a carrier
+ # provider replaces calculator pricing while the surrounding filtering,
+ # tax and sorting behavior stays identical.
+ describe 'rate provider dispatch' do
+ let(:delivery_method) { create(:delivery_method) }
+ let(:package) { build(:stock_package, contents: inventory_units.map { |_i| ContentItem.new(inventory_unit) }) }
+
+ before do
+ allow(package).to receive_messages(eligible_delivery_methods: [delivery_method])
+ end
+
+ it 'defaults to the Internal provider, pricing through the calculator' do
+ expect(delivery_method.rate_provider_instance).to be_a(Spree::DeliveryRateProvider::Internal)
+
+ allow(delivery_method.calculator).to receive(:compute).and_return(7.00)
+
+ expect(subject.delivery_rates(package).first.cost).to eq(7.00)
+ end
+
+ it 'prices through a configured external provider instead of the calculator' do
+ provider_class = Class.new(Spree::DeliveryRateProvider::Base) do
+ def estimate(_package)
+ Spree::DeliveryRateProvider::Estimate.new(cost: BigDecimal('9.99'), carrier: 'UPS')
+ end
+ end
+ stub_const('CarrierRateProvider', provider_class)
+
+ allow(delivery_method).to receive(:rate_provider_instance).and_return(provider_class.new(delivery_method))
+ expect(delivery_method.calculator).not_to receive(:compute)
+
+ expect(subject.delivery_rates(package).first.cost).to eq(BigDecimal('9.99'))
+ end
+
+ it 'carries the carrier metadata from the estimate onto the rate' do
+ provider_class = Class.new(Spree::DeliveryRateProvider::Base) do
+ def estimate(_package)
+ Spree::DeliveryRateProvider::Estimate.new(
+ cost: BigDecimal('9.99'),
+ carrier: 'UPS',
+ service_level: 'Ground',
+ estimated_delivery_date: Date.new(2026, 8, 20),
+ metadata: { 'quote_id' => 'rate_123' }
+ )
+ end
+ end
+ stub_const('EnrichedRateProvider', provider_class)
+
+ allow(delivery_method).to receive(:rate_provider_instance).and_return(provider_class.new(delivery_method))
+
+ rate = subject.delivery_rates(package).first
+ expect(rate.carrier).to eq('UPS')
+ expect(rate.service_level).to eq('Ground')
+ expect(rate.estimated_delivery_date).to eq(Date.new(2026, 8, 20))
+ expect(rate.metadata['quote_id']).to eq('rate_123')
+ end
+
+ it 'suppresses the method when the provider returns no estimate' do
+ provider_class = Class.new(Spree::DeliveryRateProvider::Base) do
+ def estimate(_package) = nil
+ end
+ stub_const('EmptyRateProvider', provider_class)
+
+ allow(delivery_method).to receive(:rate_provider_instance).and_return(provider_class.new(delivery_method))
+
+ expect(subject.delivery_rates(package)).to be_empty
+ end
+ end
end
end
end