|
1 | | -require "cgi" |
2 | | - |
3 | 1 | module Drip |
4 | 2 | class Client |
5 | 3 | module Purchases |
6 | 4 | # Public: Create a purchase. |
7 | 5 | # |
8 | 6 | # email - Required. The String email address of the subscriber. |
9 | 7 | # 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. |
37 | 10 | # 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 |
47 | 12 | # |
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." |
53 | 17 |
|
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) |
63 | 20 | end |
64 | 21 | end |
65 | 22 | end |
|
0 commit comments