recharge-api 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +6 -3
- data/README.md +17 -3
- data/lib/recharge.rb +2 -1
- data/lib/recharge/classes.rb +162 -8
- data/lib/recharge/http_request.rb +6 -5
- data/lib/recharge/version.rb +1 -1
- data/recharge-api.gemspec +4 -2
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9f3a7eb0f67af92f82030c6051b89285c6b12a0e6eeb6d959d0b3ce9ca467c62
|
4
|
+
data.tar.gz: 2ee8e765979f5b691ac980e9a4cc691069e6bfe1b672d36ddd0a816ecaaabed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ea64a155cd959427bf2e7cc39c2e657ee9e42915a13639b26fc58146b4a061c489d92dfdca43dd6e8266be6ef6c47a600e67522f9a1a973c9eea73999565024
|
7
|
+
data.tar.gz: ec422be602cb58ac9272bb70bee0a53a4423f94986c9fed5a1626c6e0e6c8db988cf02db64a9eb2563b5857c86c8874b681117a24a840e46bbc21aa0de7a661e
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -17,6 +17,9 @@ Bundler:
|
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
|
+
An API key is required. The key can be set via `ReCharge.api_key` or via the `RECHARGE_API_KEY`
|
21
|
+
environment variable.
|
22
|
+
|
20
23
|
```rb
|
21
24
|
require "recharge"
|
22
25
|
|
@@ -64,16 +67,27 @@ For complete documentation refer to the API docs: http://rdoc.info/gems/recharge
|
|
64
67
|
|
65
68
|
## Rake Tasks for Webhook Management
|
66
69
|
|
67
|
-
|
68
|
-
|
70
|
+
Add the following to your `Rakefile`:
|
71
|
+
|
72
|
+
```rb
|
73
|
+
require "recharge/tasks"
|
74
|
+
```
|
69
75
|
|
70
|
-
|
76
|
+
This will add the following tasks:
|
71
77
|
|
72
78
|
* `recharge:hook:create` - create webhook `HOOK` to be sent to `CALLBACK`
|
73
79
|
* `recharge:hooks:delete` - delete the webhook(s) given by `ID`
|
74
80
|
* `recharge:hooks:delete_all` - delete all webhooks
|
75
81
|
* `recharge:hooks:list` - list webhooks
|
76
82
|
|
83
|
+
All tasks require `RECHARGE_API_KEY` be set.
|
84
|
+
|
85
|
+
For example, to create a hook run the following:
|
86
|
+
|
87
|
+
```
|
88
|
+
rake recharge:hooks:create RECHARGE_API_KEY=YOURKEY HOOK=subscription/created CALLBACK=https://example.com/callback
|
89
|
+
```
|
90
|
+
|
77
91
|
## License
|
78
92
|
|
79
93
|
Released under the MIT License: www.opensource.org/licenses/MIT
|
data/lib/recharge.rb
CHANGED
@@ -11,7 +11,8 @@ module Recharge
|
|
11
11
|
ConnectionError = Class.new(Error)
|
12
12
|
|
13
13
|
#
|
14
|
-
# Raised when a non-2XX HTTP response is returned
|
14
|
+
# Raised when a non-2XX HTTP response is returned or a response with
|
15
|
+
# an error or warning property
|
15
16
|
#
|
16
17
|
class RequestError < Error
|
17
18
|
attr_accessor :errors
|
data/lib/recharge/classes.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "json"
|
2
4
|
require "class2"
|
3
5
|
require "recharge/http_request"
|
@@ -8,28 +10,42 @@ class2 "Recharge", JSON.parse(<<-END) do
|
|
8
10
|
{
|
9
11
|
"id":10101,
|
10
12
|
"address_id":178918,
|
13
|
+
"analytics_data": {},
|
11
14
|
"customer_id":1438,
|
15
|
+
"cancellation_reason": "$$$$",
|
16
|
+
"cancellation_reason_comments": "",
|
17
|
+
"cancelled_at":"2017-02-28T20:31:29",
|
18
|
+
"charge_interval_frequency": "3",
|
12
19
|
"created_at":"2017-02-28T20:31:29",
|
13
20
|
"updated_at":"2017-02-28 20:31:29",
|
14
21
|
"next_charge_scheduled_at":"2017-04-01T00:00:00",
|
15
22
|
"cancelled_at":null,
|
23
|
+
"has_queued_charges": 1,
|
24
|
+
"is_skippable": true,
|
25
|
+
"is_swappable": true,
|
26
|
+
"is_prepaid": false,
|
27
|
+
"max_retries_reached": 0,
|
16
28
|
"product_title":"Sumatra Coffee",
|
17
29
|
"price":12,
|
18
30
|
"quantity":1,
|
31
|
+
"recharge_product_id": 518676,
|
19
32
|
"status":"ACTIVE",
|
20
33
|
"shopify_product_id":1255183683,
|
21
34
|
"shopify_variant_id":3844924611,
|
35
|
+
"sku_override": false,
|
22
36
|
"sku":null,
|
23
37
|
"order_interval_unit":"day",
|
24
38
|
"order_interval_frequency":"30",
|
25
39
|
"charge_interval_frequency":"30",
|
26
40
|
"order_day_of_month":null,
|
27
41
|
"order_day_of_week":null,
|
28
|
-
"properties": []
|
42
|
+
"properties": [],
|
43
|
+
"variant_title": "Milk - a / b"
|
29
44
|
},
|
30
45
|
"charge":
|
31
46
|
{
|
32
47
|
"address_id":178918,
|
48
|
+
"analytics_data": {},
|
33
49
|
"billing_address":{
|
34
50
|
"address1":"3030 Nebraska Avenue",
|
35
51
|
"address2":"",
|
@@ -50,11 +66,13 @@ class2 "Recharge", JSON.parse(<<-END) do
|
|
50
66
|
"customer_hash":null,
|
51
67
|
"customer_id":10101,
|
52
68
|
"first_name":"Mike",
|
69
|
+
"has_uncommited_changes": false,
|
53
70
|
"id":1843,
|
54
71
|
"last_name":"Flynn",
|
55
72
|
"line_items":[
|
56
73
|
{
|
57
74
|
"grams":0,
|
75
|
+
"images": {},
|
58
76
|
"price":100.0,
|
59
77
|
"properties":[],
|
60
78
|
"quantity":1,
|
@@ -67,6 +85,9 @@ class2 "Recharge", JSON.parse(<<-END) do
|
|
67
85
|
"subscription_id":14562
|
68
86
|
}
|
69
87
|
],
|
88
|
+
"note": "blah blah",
|
89
|
+
"note_attributes": [],
|
90
|
+
"processor_name": "foo",
|
70
91
|
"processed_at":"2014-11-20T00:00:00",
|
71
92
|
"scheduled_at":"2014-11-20T00:00:01",
|
72
93
|
"shipments_count":null,
|
@@ -82,10 +103,20 @@ class2 "Recharge", JSON.parse(<<-END) do
|
|
82
103
|
"province":"California",
|
83
104
|
"zip":"90404"
|
84
105
|
},
|
106
|
+
"shipping_lines": [],
|
85
107
|
"shopify_order_id":"281223307",
|
86
108
|
"status":"SUCCESS",
|
87
109
|
"total_price":446.00,
|
88
|
-
"updated_at":"2016-09-05T09:19:29"
|
110
|
+
"updated_at":"2016-09-05T09:19:29",
|
111
|
+
"tax_lines": 0,
|
112
|
+
"total_discounts": "0.0",
|
113
|
+
"total_line_items_price": "12.00",
|
114
|
+
"total_price": "12.00",
|
115
|
+
"total_refunds": null,
|
116
|
+
"total_tax": 0,
|
117
|
+
"total_weight": 4536,
|
118
|
+
"transaction_id": "cch_1Du2QpJ2iqHvZRd18RyqoPvc",
|
119
|
+
"type": "RECURRING"
|
89
120
|
},
|
90
121
|
"customer":
|
91
122
|
{
|
@@ -108,7 +139,10 @@ class2 "Recharge", JSON.parse(<<-END) do
|
|
108
139
|
"billing_country": "United States",
|
109
140
|
"billing_phone": "3103843698",
|
110
141
|
"processor_type": null,
|
111
|
-
"status": "FOO"
|
142
|
+
"status": "FOO",
|
143
|
+
"stripe_customer_token": "123123",
|
144
|
+
"paypal_customer_token": "123123",
|
145
|
+
"braintree_customer_token": "123123"
|
112
146
|
},
|
113
147
|
"order": {
|
114
148
|
"id":7271806,
|
@@ -168,11 +202,49 @@ class2 "Recharge", JSON.parse(<<-END) do
|
|
168
202
|
"country":"United States"
|
169
203
|
}
|
170
204
|
},
|
171
|
-
"
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
205
|
+
"metafield": {
|
206
|
+
"created_at": "2018-11-05T12:59:30",
|
207
|
+
"description": "desc lorem ipsum",
|
208
|
+
"id": 15,
|
209
|
+
"key": "marjan",
|
210
|
+
"namespace": "nmsp2c",
|
211
|
+
"owner_id": 17868054,
|
212
|
+
"owner_resource": "customer",
|
213
|
+
"updated_at": "2018-11-05T15:48:42",
|
214
|
+
"value": "5",
|
215
|
+
"value_type": "integer"
|
216
|
+
},
|
217
|
+
"product": {
|
218
|
+
"collection_id": null,
|
219
|
+
"created_at": "2019-11-07T11:36:19",
|
220
|
+
"discount_amount": 15.0,
|
221
|
+
"discount_type": "percentage",
|
222
|
+
"handle": null,
|
223
|
+
"id": 1327844,
|
224
|
+
"images": {},
|
225
|
+
"product_id": 4354268856408,
|
226
|
+
"shopify_product_id": 4354268856408,
|
227
|
+
"subscription_defaults": {
|
228
|
+
"charge_interval_frequency": 4,
|
229
|
+
"cutoff_day_of_month": null,
|
230
|
+
"cutoff_day_of_week": null,
|
231
|
+
"expire_after_specific_number_of_charges": null,
|
232
|
+
"modifiable_properties": [],
|
233
|
+
"number_charges_until_expiration": null,
|
234
|
+
"order_day_of_month": 0,
|
235
|
+
"order_day_of_week": null,
|
236
|
+
"order_interval_frequency": 4,
|
237
|
+
"order_interval_frequency_options": [],
|
238
|
+
"order_interval_unit": "month",
|
239
|
+
"storefront_purchase_options": "subscription_only"
|
240
|
+
},
|
241
|
+
"title": "T-shirt",
|
242
|
+
"updated_at": "2019-11-07T14:04:52"
|
243
|
+
},
|
244
|
+
"webhook": {
|
245
|
+
"id":6,
|
246
|
+
"address":"https://request.in/foo",
|
247
|
+
"topic":"order/create"
|
176
248
|
},
|
177
249
|
"address":{
|
178
250
|
"id":3411137,
|
@@ -186,6 +258,26 @@ class2 "Recharge", JSON.parse(<<-END) do
|
|
186
258
|
"company":"bootstrap",
|
187
259
|
"phone":"3103103101",
|
188
260
|
"country":"United States"
|
261
|
+
},
|
262
|
+
"discount":{
|
263
|
+
"id": 3748296,
|
264
|
+
"code": "Discount1",
|
265
|
+
"value": 12,
|
266
|
+
"ends_at": "2019-12-15T00:00:00",
|
267
|
+
"starts_at": "2018-05-16T00:00:00",
|
268
|
+
"status": "enabled",
|
269
|
+
"usage_limit": 10,
|
270
|
+
"applies_to_id": null,
|
271
|
+
"discount_type": "percentage",
|
272
|
+
"applies_to": null,
|
273
|
+
"applies_to_resource": null,
|
274
|
+
"times_used": 0,
|
275
|
+
"duration": "usage_limit",
|
276
|
+
"duration_usage_limit": 10,
|
277
|
+
"applies_to_product_type": "ALL",
|
278
|
+
"created_at": "2018-04-25T14:32:39",
|
279
|
+
"updated_at": "2018-05-04T13:33:53",
|
280
|
+
"once_per_customer": false
|
189
281
|
}
|
190
282
|
}
|
191
283
|
END
|
@@ -348,6 +440,58 @@ module Recharge
|
|
348
440
|
end
|
349
441
|
end
|
350
442
|
|
443
|
+
class Discount
|
444
|
+
PATH = "/discounts".freeze
|
445
|
+
SINGLE = "discount".freeze
|
446
|
+
COLLECTION = "discounts"
|
447
|
+
|
448
|
+
extend HTTPRequest::Count
|
449
|
+
extend HTTPRequest::Create
|
450
|
+
extend HTTPRequest::Delete
|
451
|
+
extend HTTPRequest::Get
|
452
|
+
extend HTTPRequest::List
|
453
|
+
extend HTTPRequest::Update
|
454
|
+
|
455
|
+
include Persistable
|
456
|
+
|
457
|
+
def self.count(options = nil)
|
458
|
+
super(convert_date_params(options, :created_at_max, :created_at_min, :date_min, :date_max))
|
459
|
+
end
|
460
|
+
|
461
|
+
def self.list(options = nil)
|
462
|
+
super(convert_date_params(options, :created_at, :created_at_max, :updated_at, :updated_at_max))
|
463
|
+
end
|
464
|
+
|
465
|
+
def delete
|
466
|
+
self.class.delete(id)
|
467
|
+
true
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
class Metafield
|
472
|
+
PATH = "/metafields"
|
473
|
+
SINGLE = "metafield"
|
474
|
+
COLLECTION = "metafields"
|
475
|
+
|
476
|
+
extend HTTPRequest::Count
|
477
|
+
extend HTTPRequest::Create
|
478
|
+
extend HTTPRequest::Delete
|
479
|
+
extend HTTPRequest::Get
|
480
|
+
extend HTTPRequest::List
|
481
|
+
|
482
|
+
include Persistable
|
483
|
+
|
484
|
+
def self.list(owner, options = nil)
|
485
|
+
raise ArgumentError, "owner resource required" if owner.nil? || owner.to_s.strip.empty?
|
486
|
+
super (options||{}).merge(:owner_resource => owner)
|
487
|
+
end
|
488
|
+
|
489
|
+
def delete
|
490
|
+
self.class.delete(id)
|
491
|
+
true
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
351
495
|
class Order
|
352
496
|
PATH = "/orders".freeze
|
353
497
|
SINGLE = "order".freeze
|
@@ -373,6 +517,16 @@ module Recharge
|
|
373
517
|
end
|
374
518
|
end
|
375
519
|
|
520
|
+
class Product
|
521
|
+
PATH = "/products".freeze
|
522
|
+
SINGLE = "product".freeze
|
523
|
+
COLLECTION = "products".freeze
|
524
|
+
|
525
|
+
extend HTTPRequest::Count
|
526
|
+
extend HTTPRequest::Get
|
527
|
+
extend HTTPRequest::List
|
528
|
+
end
|
529
|
+
|
376
530
|
class Subscription
|
377
531
|
PATH = "/subscriptions".freeze
|
378
532
|
SINGLE = "subscription".freeze
|
@@ -3,8 +3,8 @@ require "uri"
|
|
3
3
|
require "json"
|
4
4
|
|
5
5
|
# For iso8601
|
6
|
-
require "date"
|
7
|
-
require "time"
|
6
|
+
#require "date"
|
7
|
+
#require "time"
|
8
8
|
|
9
9
|
module Recharge
|
10
10
|
module HTTPRequest # :nodoc:
|
@@ -56,7 +56,7 @@ module Recharge
|
|
56
56
|
private
|
57
57
|
|
58
58
|
def request(req, data = {})
|
59
|
-
req[TOKEN_HEADER] = ReCharge.api_key || ""
|
59
|
+
req[TOKEN_HEADER] = ReCharge.api_key || ENV["RECHARGE_API_KEY"] || ""
|
60
60
|
req["User-Agent"] = USER_AGENT
|
61
61
|
|
62
62
|
if req.request_body_permitted? && data && data.any?
|
@@ -66,7 +66,8 @@ module Recharge
|
|
66
66
|
|
67
67
|
connection.start do |http|
|
68
68
|
res = http.request(req)
|
69
|
-
|
69
|
+
# API returns 204 but content-type header is set to application/json so check body
|
70
|
+
data = res.body && res["Content-Type"] == "application/json" ? parse_json(res.body) : {}
|
70
71
|
data["meta"] = { "id" => res["X-Request-Id"], "limit" => res["X-Recharge-Limit"] }
|
71
72
|
|
72
73
|
return data if res.code[0] == "2" && !data["warning"] && !data["error"]
|
@@ -185,7 +186,7 @@ module Recharge
|
|
185
186
|
end
|
186
187
|
|
187
188
|
#
|
188
|
-
# Retrieve a page of records for the included/extended class'
|
189
|
+
# Retrieve a page of records for the included/extended class' endpoint
|
189
190
|
#
|
190
191
|
# === Arguments
|
191
192
|
#
|
data/lib/recharge/version.rb
CHANGED
data/recharge-api.gemspec
CHANGED
@@ -20,8 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_dependency "class2", "~> 0.3.0"
|
23
|
+
# Keep this until we can upgrade class2
|
24
|
+
# We don't upgrade yet because versions > 3 default to Symbol keys
|
25
|
+
spec.add_dependency "activesupport", "< 6"
|
23
26
|
spec.add_development_dependency "webmock", "~> 3.0"
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
26
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recharge-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Skye Shaw
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: class2
|
@@ -25,47 +25,47 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
33
|
+
version: '6'
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "<"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: webmock
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 12.3.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 12.3.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.6
|
123
|
+
rubygems_version: 2.7.6
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Client for ReCharge Payments API
|