Class: SpreeDoordash::Client
- Inherits:
-
Object
- Object
- SpreeDoordash::Client
- Defined in:
- app/services/spree_doordash/client.rb
Overview
Thin wrapper around the DoorDash Drive API (v2). All Drive API access in this extension goes through here.
Auth is fundamentally different from SpreeSquare::Client: DoorDash Drive has no OAuth/refresh flow. A static access key (developer_id/key_id/ signing_secret), created once in DoorDash's Developer Portal, signs a fresh short-lived (5 min) JWT on every call — there's nothing to cache or refresh, unlike Square's 30-day access token.
Defined Under Namespace
Classes: MissingCredentialsError
Constant Summary collapse
- BASE_URL =
'https://openapi.doordash.com'.freeze
- JWT_TTL =
seconds — matches DoorDash's own documented recipe
300
Class Method Summary collapse
- .for_store(store = Spree::Store.default) ⇒ Object
-
.instance ⇒ Object
Deliberately NOT memoized, same rationale as SpreeSquare::Client: a store's credential can be created/edited by an admin mid-process, and nothing here is expensive enough to cache (a JWT is cheap to sign, and is only valid 5 minutes anyway).
Instance Method Summary collapse
-
#accept_quote(external_delivery_id, tip_cents: nil) ⇒ Object
Formally creates the delivery from a still-open quote.
-
#create_quote(payload) ⇒ Object
Validates coverage/pricing for a delivery before formally creating it — DoorDash's own recommended first call (see docs/how_to/quote_deliveries).
-
#initialize(credential: nil) ⇒ Client
constructor
A new instance of Client.
- #sandbox? ⇒ Boolean
Constructor Details
#initialize(credential: nil) ⇒ Client
Returns a new instance of Client.
31 32 33 34 |
# File 'app/services/spree_doordash/client.rb', line 31 def initialize(credential: nil) @credential = credential raise MissingCredentialsError, 'No DoorDash credential connected for this store' unless @credential end |
Class Method Details
.for_store(store = Spree::Store.default) ⇒ Object
27 28 29 |
# File 'app/services/spree_doordash/client.rb', line 27 def self.for_store(store = Spree::Store.default) new(credential: SpreeDoordash::Credential.find_by(store: store)) end |
.instance ⇒ Object
Deliberately NOT memoized, same rationale as SpreeSquare::Client: a store's credential can be created/edited by an admin mid-process, and nothing here is expensive enough to cache (a JWT is cheap to sign, and is only valid 5 minutes anyway).
23 24 25 |
# File 'app/services/spree_doordash/client.rb', line 23 def self.instance for_store end |
Instance Method Details
#accept_quote(external_delivery_id, tip_cents: nil) ⇒ Object
Formally creates the delivery from a still-open quote. Must be called within 5 minutes of the quote (DoorDash's own documented limit — see SpreeDoordash::QuoteMapping#expired?). external_delivery_id is reused as the delivery's own id for its whole lifecycle; DoorDash issues no separate one (confirmed against developer.doordash.com/en-US/docs/drive/how_to/quote_deliveries/).
54 55 56 57 |
# File 'app/services/spree_doordash/client.rb', line 54 def accept_quote(external_delivery_id, tip_cents: nil) body = tip_cents ? { tip: tip_cents } : {} request(:post, "/drive/v2/quotes/#{external_delivery_id}/accept", body) end |
#create_quote(payload) ⇒ Object
Validates coverage/pricing for a delivery before formally creating it — DoorDash's own recommended first call (see docs/how_to/quote_deliveries). Quotes are valid 5 minutes; accept_quote (M2) formally creates the delivery.
44 45 46 |
# File 'app/services/spree_doordash/client.rb', line 44 def create_quote(payload) request(:post, '/drive/v2/quotes', payload) end |
#sandbox? ⇒ Boolean
36 37 38 |
# File 'app/services/spree_doordash/client.rb', line 36 def sandbox? @credential.sandbox? end |