Skip to content

Commit 77f5ff9

Browse files
authored
Merge pull request #37 from DripEmail/orders
Orders API
2 parents dce59be + 6f9366c commit 77f5ff9

15 files changed

Lines changed: 236 additions & 123 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ as methods on the client object. The following methods are currently available:
120120
| List all forms | `#forms` |
121121
| Fetch a form | `#form(id)` |
122122

123-
#### Purchases
123+
#### Orders
124+
125+
**Note:** The beta purchases endpoint has been deprecated and its methods have been removed from the gem except `create_purchase`, which now sends requests to the Order creation endpoint [here](https://developer.drip.com/#orders)
124126

125127
| Actions | Methods |
126128
| :------------------------- | :--------------------------------------------------- |
127-
| List purchases for a subscriber | `#purchases(email)` |
128-
| Create a purchase         | `#create_purchase(email, amount, options = {})` |
129-
| Fetch a purchase | `#purchase(email, id)` |
129+
| Create or update an order | `#create_or_update_order(email, options = {})` |
130+
| Create or update a batch of orders | `#create_or_update_orders(orders = {})` |
131+
| Create or update a refund | `#create_or_update_refund(options = {})` |
130132

131133
#### Subscribers
132134

lib/drip/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require "drip/client/custom_fields"
88
require "drip/client/events"
99
require "drip/client/forms"
10+
require "drip/client/orders"
1011
require "drip/client/purchases"
1112
require "drip/client/subscribers"
1213
require "drip/client/tags"
@@ -27,6 +28,7 @@ class Client
2728
include CustomFields
2829
include Events
2930
include Forms
31+
include Orders
3032
include Purchases
3133
include Subscribers
3234
include Tags

lib/drip/client/events.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require "cgi"
2-
31
module Drip
42
class Client
53
module Events

lib/drip/client/orders.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module Drip
2+
class Client
3+
module Orders
4+
# Public: Create or update an order.
5+
#
6+
# email - Required. The String email address of the subscriber.
7+
# options - Required. A Hash of additional order options. Refer to the
8+
# Drip API docs for the required schema.
9+
#
10+
# Returns a Drip::Response.
11+
# See https://developer.drip.com/#orders
12+
def create_or_update_order(email, options = {})
13+
data = options.merge(email: email)
14+
post "#{account_id}/orders", generate_resource("orders", data)
15+
end
16+
17+
# Public: Create or update a batch of orders.
18+
#
19+
# orders - Required. An Array with between 1 and 1000 objects containing order data
20+
#
21+
# Returns a Drip::Response.
22+
# See https://developer.drip.com/#create-or-update-a-batch-of-orders
23+
def create_or_update_orders(orders)
24+
post "#{account_id}/orders/batches", generate_resource("batches", { "orders" => orders })
25+
end
26+
27+
# Public: Create or update a refund.
28+
#
29+
# options - Required. A Hash of refund properties
30+
# amount - Required. The amount of the refund.
31+
# provider - Required. The provider for the Order being refunded.
32+
# order_upstream_id - Required. The upstream_id for the Order being refunded.
33+
# upstream_id - The unique id of refund in the order management system.
34+
# note - A note about the refund.
35+
# processed_at - The String time at which the refund was processed in
36+
# ISO-8601 format.
37+
#
38+
# Returns a Drip::Response.
39+
# See https://developer.drip.com/#create-or-update-a-refund
40+
def create_or_update_refund(options)
41+
post "#{account_id}/refunds", generate_resource("refunds", options)
42+
end
43+
end
44+
end
45+
end

lib/drip/client/purchases.rb

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,22 @@
1-
require "cgi"
2-
31
module Drip
42
class Client
53
module Purchases
64
# Public: Create a purchase.
75
#
86
# email - Required. The String email address of the subscriber.
97
# amount - Required. The total amount of the purchase in cents.
10-
# options - A Hash of options.
11-
# - properties - Optional. An Object containing properties about
12-
# the order.
13-
# - items - Optional. An Array of objects containing information
14-
# about specific order items.
15-
# - name - Required. The product name.
16-
# - amount - Required. The line total (in
17-
# cents).
18-
# - quantity - Optional. The quantity of the
19-
# item purchased (if omitted,
20-
# defaults to 1).
21-
# - product_id - Optional. A unique identifier
22-
# for the specific product.
23-
# - sku - Optional. The product SKU number.
24-
# - properties - Optional. An Object containing
25-
# properties about the line item.
26-
# - provider - Optional. The identifier for the provider from
27-
# which the purchase data was received
28-
# - order_id - Optional. A unique identifier for the order
29-
# (generally the primary key generated by the
30-
# order management system).
31-
# - permalink - Optional. A URL for the human-readable
32-
# interface to view the order details.
33-
# - occurred_at - Optional. The String time at which the event
34-
# occurred in ISO-8601 format. Defaults to the
35-
# current time.
36-
#
8+
# options - Required. A Hash of additional order options. Refer to the
9+
# Drip API docs for the required schema.
3710
# Returns a Drip::Response.
38-
# See https://www.getdrip.com/docs/rest-api#create_purchase
39-
def create_purchase(email, amount, options = {})
40-
data = options.merge(amount: amount)
41-
post "#{account_id}/subscribers/#{CGI.escape email}/purchases", generate_resource("purchases", data)
42-
end
43-
44-
# Public: Fetch a list of purchases for a subscriber.
45-
#
46-
# email - The String email address of the subscriber.
11+
# See https://developer.drip.com/#orders
4712
#
48-
# Returns a Drip::Response.
49-
# See https://www.getdrip.com/docs/rest-api#list_purchases
50-
def purchases(email)
51-
get "#{account_id}/subscribers/#{CGI.escape email}/purchases"
52-
end
13+
# DEPRECATED: The beta Purchase endpoint has been deprecated and this method now sends
14+
# requests to the Order creation endpoint. Please use `create_or_update_order` instead
15+
def create_purchase(email, amount, options = {})
16+
warn "[DEPRECATED] `create_purchase` is deprecated. Please use `create_or_update_order` instead."
5317

54-
# Public: Fetch a purchase.
55-
#
56-
# email - The String email address of the subscriber.
57-
# id - The String ID of the purchase
58-
#
59-
# Returns a Drip::Response.
60-
# See https://www.getdrip.com/docs/rest-api#list_purchases
61-
def purchase(email, id)
62-
get "#{account_id}/subscribers/#{CGI.escape email}/purchases/#{id}"
18+
data = options.merge({ amount: amount, email: email })
19+
post "#{account_id}/orders", generate_resource("orders", data)
6320
end
6421
end
6522
end

lib/drip/collections.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "drip/collections/campaigns"
44
require "drip/collections/campaign_subscriptions"
55
require "drip/collections/errors"
6+
require "drip/collections/orders"
67
require "drip/collections/purchases"
78
require "drip/collections/subscribers"
89
require "drip/collections/tags"
@@ -19,6 +20,7 @@ def self.classes
1920
Drip::Campaigns,
2021
Drip::CampaignSubscriptions,
2122
Drip::Errors,
23+
Drip::Orders,
2224
Drip::Purchases,
2325
Drip::Subscribers,
2426
Drip::Tags,

lib/drip/collections/orders.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require "drip/collection"
2+
3+
module Drip
4+
class Orders < Collection
5+
def self.collection_name
6+
"orders"
7+
end
8+
9+
def self.resource_name
10+
"order"
11+
end
12+
end
13+
end

lib/drip/resources.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "drip/resources/campaign"
44
require "drip/resources/campaign_subscription"
55
require "drip/resources/error"
6+
require "drip/resources/order"
67
require "drip/resources/purchase"
78
require "drip/resources/subscriber"
89
require "drip/resources/tag"
@@ -19,6 +20,7 @@ def self.classes
1920
Drip::Campaign,
2021
Drip::CampaignSubscription,
2122
Drip::Error,
23+
Drip::Order,
2224
Drip::Purchase,
2325
Drip::Subscriber,
2426
Drip::Tag,

lib/drip/resources/order.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "drip/resource"
2+
3+
module Drip
4+
class Order < Resource
5+
def self.resource_name
6+
"order"
7+
end
8+
end
9+
end

lib/drip/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Drip
2-
VERSION = "1.0.0".freeze
2+
VERSION = "2.0.0".freeze
33
end

0 commit comments

Comments
 (0)