paddle 2.1.4 → 2.2.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +67 -2
  5. data/README.md +67 -4
  6. data/lib/paddle/classic/client.rb +0 -1
  7. data/lib/paddle/classic/resource.rb +1 -1
  8. data/lib/paddle/classic/resources/charges.rb +1 -3
  9. data/lib/paddle/classic/resources/coupons.rb +6 -8
  10. data/lib/paddle/classic/resources/licenses.rb +1 -3
  11. data/lib/paddle/classic/resources/modifiers.rb +4 -6
  12. data/lib/paddle/classic/resources/pay_links.rb +0 -2
  13. data/lib/paddle/classic/resources/payments.rb +3 -5
  14. data/lib/paddle/classic/resources/plans.rb +2 -4
  15. data/lib/paddle/classic/resources/products.rb +0 -2
  16. data/lib/paddle/classic/resources/transactions.rb +0 -2
  17. data/lib/paddle/classic/resources/users.rb +7 -9
  18. data/lib/paddle/classic/resources/webhooks.rb +0 -2
  19. data/lib/paddle/client.rb +1 -6
  20. data/lib/paddle/collection.rb +12 -0
  21. data/lib/paddle/configuration.rb +1 -3
  22. data/lib/paddle/models/address.rb +1 -5
  23. data/lib/paddle/models/adjustment.rb +1 -5
  24. data/lib/paddle/models/business.rb +1 -5
  25. data/lib/paddle/models/customer.rb +1 -5
  26. data/lib/paddle/models/discount.rb +1 -5
  27. data/lib/paddle/models/event.rb +0 -4
  28. data/lib/paddle/models/event_type.rb +0 -4
  29. data/lib/paddle/models/notification.rb +0 -4
  30. data/lib/paddle/models/notification_setting.rb +1 -5
  31. data/lib/paddle/models/price.rb +1 -5
  32. data/lib/paddle/models/pricing_preview.rb +1 -5
  33. data/lib/paddle/models/product.rb +1 -5
  34. data/lib/paddle/models/report.rb +28 -0
  35. data/lib/paddle/models/subscription.rb +3 -7
  36. data/lib/paddle/models/transaction.rb +4 -8
  37. data/lib/paddle/object.rb +1 -1
  38. data/lib/paddle/version.rb +1 -1
  39. data/lib/paddle.rb +1 -2
  40. data/paddle.gemspec +3 -3
  41. metadata +9 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18ca722e2dfa03afa07ccc605919184d6f13ebb594c163c5f4ea0ff2bb4ab242
4
- data.tar.gz: d4d42ff9ab6370b90ecc965a26a936fcabffd455f98d88a1bc43ed39779e6f91
3
+ metadata.gz: 6224fc2a3ec9423990985241a118780185a090617407f95e97bb542120eb9323
4
+ data.tar.gz: 03403341d8dce73c881ed3fc2c722cf738b625803c6352dd2cca15e5d4cd65a7
5
5
  SHA512:
6
- metadata.gz: 9a33e4d7f8462e8c4a987d6bc621b920e29b6aada8cc1076f204e38f9cac69fa733dfed1f12e5447ec4dd148db25b0a0fd01ef39641534dc2ba7466b95416451
7
- data.tar.gz: 697890a2b7465aa1b563fef5e4a388792dbe4325e22582fa16d8b727b5dab2d49702fd90859bbdd056709cba7ad16977706ef463965b1d51ebf35c7a1216c46b
6
+ metadata.gz: 6453da01350a80adf7f8723817b7d45edfac636d5ae72ebeb92b281ad93d85d59866631eb60a17c3a8225f5a8f51780b857e1aeab940c0264daaa53446a70637
7
+ data.tar.gz: 716ef3061039df26a5cfc0dd0f8931cb1e9edcf964947047acf37ed8b95cc63a3cc36595288f6aaccc45ee2b1e3f8fe0b74ae39969123f2c99eeeeea9da41381
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ # Omakase Ruby styling for Rails
2
+ inherit_gem: { rubocop-rails-omakase: rubocop.yml }
3
+
4
+ # Overwrite or add rules to create your own house style
5
+ #
6
+ # # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
7
+ # Layout/SpaceInsideArrayLiteralBrackets:
8
+ # Enabled: false
data/Gemfile CHANGED
@@ -9,5 +9,5 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "minitest", "~> 5.0"
11
11
  gem "dotenv"
12
-
13
12
  gem "vcr"
13
+ gem "rubocop-rails-omakase", require: false
data/Gemfile.lock CHANGED
@@ -1,22 +1,86 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paddle (2.1.4)
4
+ paddle (2.2.1)
5
5
  faraday (~> 2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ activesupport (7.1.3.4)
11
+ base64
12
+ bigdecimal
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ connection_pool (>= 2.2.5)
15
+ drb
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ mutex_m
19
+ tzinfo (~> 2.0)
20
+ ast (2.4.2)
10
21
  base64 (0.1.1)
22
+ bigdecimal (3.1.8)
23
+ concurrent-ruby (1.3.3)
24
+ connection_pool (2.4.1)
11
25
  dotenv (2.7.6)
26
+ drb (2.2.1)
12
27
  faraday (2.7.11)
13
28
  base64
14
29
  faraday-net_http (>= 2.0, < 3.1)
15
30
  ruby2_keywords (>= 0.0.4)
16
31
  faraday-net_http (3.0.2)
32
+ i18n (1.14.5)
33
+ concurrent-ruby (~> 1.0)
34
+ json (2.7.2)
35
+ language_server-protocol (3.17.0.3)
17
36
  minitest (5.19.0)
37
+ mutex_m (0.2.0)
38
+ parallel (1.25.1)
39
+ parser (3.3.3.0)
40
+ ast (~> 2.4.1)
41
+ racc
42
+ racc (1.8.0)
43
+ rack (3.1.3)
44
+ rainbow (3.1.1)
18
45
  rake (13.0.6)
46
+ regexp_parser (2.9.2)
47
+ rexml (3.3.0)
48
+ strscan
49
+ rubocop (1.64.1)
50
+ json (~> 2.3)
51
+ language_server-protocol (>= 3.17.0)
52
+ parallel (~> 1.10)
53
+ parser (>= 3.3.0.2)
54
+ rainbow (>= 2.2.2, < 4.0)
55
+ regexp_parser (>= 1.8, < 3.0)
56
+ rexml (>= 3.2.5, < 4.0)
57
+ rubocop-ast (>= 1.31.1, < 2.0)
58
+ ruby-progressbar (~> 1.7)
59
+ unicode-display_width (>= 2.4.0, < 3.0)
60
+ rubocop-ast (1.31.3)
61
+ parser (>= 3.3.1.0)
62
+ rubocop-minitest (0.35.0)
63
+ rubocop (>= 1.61, < 2.0)
64
+ rubocop-ast (>= 1.31.1, < 2.0)
65
+ rubocop-performance (1.21.0)
66
+ rubocop (>= 1.48.1, < 2.0)
67
+ rubocop-ast (>= 1.31.1, < 2.0)
68
+ rubocop-rails (2.25.0)
69
+ activesupport (>= 4.2.0)
70
+ rack (>= 1.1)
71
+ rubocop (>= 1.33.0, < 2.0)
72
+ rubocop-ast (>= 1.31.1, < 2.0)
73
+ rubocop-rails-omakase (1.0.0)
74
+ rubocop
75
+ rubocop-minitest
76
+ rubocop-performance
77
+ rubocop-rails
78
+ ruby-progressbar (1.13.0)
19
79
  ruby2_keywords (0.0.5)
80
+ strscan (3.1.0)
81
+ tzinfo (2.0.6)
82
+ concurrent-ruby (~> 1.0)
83
+ unicode-display_width (2.5.0)
20
84
  vcr (6.2.0)
21
85
 
22
86
  PLATFORMS
@@ -27,7 +91,8 @@ DEPENDENCIES
27
91
  minitest (~> 5.0)
28
92
  paddle!
29
93
  rake (~> 13.0)
94
+ rubocop-rails-omakase
30
95
  vcr
31
96
 
32
97
  BUNDLED WITH
33
- 2.4.21
98
+ 2.5.9
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Paddle Ruby Library
2
2
 
3
- A Ruby library for the Paddle APIs, both Classic and Billing.
3
+ The easiest and most complete Ruby library for the Paddle APIs, both Classic and Billing.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem "paddle", "~> 2.1"
10
+ gem "paddle", "~> 2.2"
11
11
  ```
12
12
 
13
13
  ## Billing API
@@ -33,10 +33,49 @@ Paddle.configure do |config|
33
33
  end
34
34
  ```
35
35
 
36
+ ### Resources
37
+
38
+ The gem maps as closely as we can to the Paddle API so you can easily convert API examples to gem code.
39
+
40
+ Responses are created as objects like `Paddle::Product`. Having types like `Paddle::Product` is handy for understanding what
41
+ type of object you're working with. They're built using OpenStruct so you can easily access data in a Ruby-ish way.
42
+
43
+ ### Pagination
44
+
45
+ Some of the endpoints return pages of results. The result object will have a `data` key to access the results.
46
+
47
+ An example of using collections, including pagination:
48
+
49
+ ```ruby
50
+ results = Paddle::Product.list(per_page: 10)
51
+ #=> Paddle::Collection
52
+
53
+ results.total
54
+ #=> 10
55
+
56
+ results.data
57
+ #=> [#<Paddle::Product>, #<Paddle::Product>]
58
+
59
+ results.each do |result|
60
+ puts result.id
61
+ end
62
+
63
+ results.first
64
+ #=> #<Paddle::Product>
65
+
66
+ results.last
67
+ #=> #<Paddle::Product>
68
+
69
+ # Retrieve the next page
70
+ Paddle::Product.list(per_page: 10, after: "abc123")
71
+ #=> Paddle::Collection
72
+ ```
73
+
36
74
  ### Caveats
37
75
 
38
- The Paddle API doesn't take `nil` values for optional parameters. If you want to
39
- remove a value, you'll need to pass `"null"` instead.
76
+ >[!NOTE]
77
+ >
78
+ > The Paddle API doesn't take `nil` values for optional parameters. If you want to remove a value, you'll need to pass `"null"` instead.
40
79
 
41
80
  ### Products
42
81
 
@@ -369,6 +408,30 @@ Paddle::Notification.replay(id: "ntf_abc123")
369
408
  Paddle::Notification.logs(id: "ntf_abc123")
370
409
  ```
371
410
 
411
+ ### Reports
412
+
413
+ ```ruby
414
+ # List all reports
415
+ Paddle::Report.list
416
+
417
+ # Retrieve a report
418
+ Paddle::Report.retrieve(id: "rpt_abc123")
419
+
420
+ # Get CSV download link for a report
421
+ # Returns a raw URL. This URL is not permanent and will expire.
422
+ # https://developer.paddle.com/api-reference/reports/get-report-csv
423
+ Paddle::Report.csv(id: "rpt_abc123")
424
+
425
+ # Create a Report
426
+ # https://developer.paddle.com/api-reference/reports/create-report
427
+ Paddle::Report.create(
428
+ type: "transactions",
429
+ filters: [
430
+ {name: "updated_at", operator: "lt", value: "2024-04-30"},
431
+ {name: "updated_at", operator: "gte", value: "2024-04-01"}
432
+ ]
433
+ )
434
+ ```
372
435
 
373
436
  ## Classic API
374
437
 
@@ -1,7 +1,6 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class Client
4
-
5
4
  BASE_URL = "https://vendors.paddle.com/api"
6
5
  SANDBOX_BASE_URL = "https://sandbox-vendors.paddle.com/api"
7
6
 
@@ -14,7 +14,7 @@ module Paddle
14
14
  # end
15
15
 
16
16
  def post_request(url, body: {}, headers: {})
17
- attrs = {vendor_id: client.vendor_id, vendor_auth_code: client.vendor_auth_code}
17
+ attrs = { vendor_id: client.vendor_id, vendor_auth_code: client.vendor_auth_code }
18
18
  handle_response client.connection.post(url, attrs.merge(body), headers)
19
19
  end
20
20
 
@@ -1,13 +1,11 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class ChargesResource < Resource
4
-
5
4
  def create(subscription_id:, amount:, charge_name:)
6
- attrs = {amount: amount, charge_name: charge_name}
5
+ attrs = { amount: amount, charge_name: charge_name }
7
6
  response = post_request("2.0/subscription/#{subscription_id}/charge", body: attrs)
8
7
  Charge.new(response.body["response"])
9
8
  end
10
-
11
9
  end
12
10
  end
13
11
  end
@@ -1,33 +1,31 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class CouponsResource < Resource
4
-
5
4
  def list(product_id:)
6
- response = post_request("2.0/product/list_coupons", body: {product_id: product_id})
5
+ response = post_request("2.0/product/list_coupons", body: { product_id: product_id })
7
6
  Collection.from_response(response, type: Coupon)
8
7
  end
9
8
 
10
9
  def create(coupon_type:, discount_type:, discount_amount:, **params)
11
- attrs = {coupon_type: coupon_type, discount_type: discount_type, discount_amount: discount_amount}
10
+ attrs = { coupon_type: coupon_type, discount_type: discount_type, discount_amount: discount_amount }
12
11
 
13
12
  response = post_request("2.1/product/create_coupon", body: attrs.merge(params))
14
13
 
15
14
  coupons = response.body["response"]["coupon_codes"]
16
15
 
17
- coupons.map {|c| Paddle::Coupon.new(code: c)}
16
+ coupons.map { |c| Paddle::Coupon.new(code: c) }
18
17
  end
19
18
 
20
19
  def delete(coupon_code:, product_id:)
21
- attrs = {coupon_code: coupon_code, product_id: product_id}
20
+ attrs = { coupon_code: coupon_code, product_id: product_id }
22
21
  response = post_request("2.0/product/delete_coupon", body: attrs)
23
- return true if response.success?
22
+ true if response.success?
24
23
  end
25
24
 
26
25
  def update(**params)
27
26
  response = post_request("2.1/product/update_coupon", body: params)
28
- return true if response.success?
27
+ true if response.success?
29
28
  end
30
-
31
29
  end
32
30
  end
33
31
  end
@@ -1,15 +1,13 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class LicensesResource < Resource
4
-
5
4
  def generate(product_id:, allowed_uses:, **params)
6
- attrs = {product_id: product_id, allowed_uses: allowed_uses}
5
+ attrs = { product_id: product_id, allowed_uses: allowed_uses }
7
6
 
8
7
  response = post_request("2.0/product/generate_license", body: attrs.merge(params))
9
8
 
10
9
  License.new(response.body["response"]) if response.success?
11
10
  end
12
-
13
11
  end
14
12
  end
15
13
  end
@@ -1,26 +1,24 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class ModifiersResource < Resource
4
-
5
4
  def list(**params)
6
5
  response = post_request("2.0/subscription/modifiers", body: params)
7
6
  Collection.from_response(response, type: Modifier)
8
7
  end
9
8
 
10
9
  def create(subscription_id:, modifier_amount:, **params)
11
- attrs = {subscription_id: subscription_id, modifier_amount: modifier_amount}
10
+ attrs = { subscription_id: subscription_id, modifier_amount: modifier_amount }
12
11
  create_response = post_request("2.0/subscription/modifiers/create", body: attrs.merge(params))
13
12
 
14
- response = post_request("2.0/subscription/modifiers", body: {subscription_id: subscription_id} )
13
+ response = post_request("2.0/subscription/modifiers", body: { subscription_id: subscription_id })
15
14
  Collection.from_response(response, type: Modifier)
16
15
  end
17
16
 
18
17
  def delete(modifier_id:)
19
- attrs = {modifier_id: modifier_id}
18
+ attrs = { modifier_id: modifier_id }
20
19
  response = post_request("2.0/subscription/modifiers/delete", body: attrs)
21
- return true if response.success?
20
+ true if response.success?
22
21
  end
23
-
24
22
  end
25
23
  end
26
24
  end
@@ -1,13 +1,11 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class PayLinksResource < Resource
4
-
5
4
  def generate(**params)
6
5
  response = post_request("2.0/product/generate_pay_link", body: params)
7
6
 
8
7
  PayLink.new(response.body["response"]) if response.success?
9
8
  end
10
-
11
9
  end
12
10
  end
13
11
  end
@@ -1,24 +1,22 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class PaymentsResource < Resource
4
-
5
4
  def list(**params)
6
5
  response = post_request("2.0/subscription/payments", body: params)
7
6
  Collection.from_response(response, type: Payment)
8
7
  end
9
8
 
10
9
  def reschedule(payment_id:, date:)
11
- attrs = {payment_id: payment_id, date: date}
10
+ attrs = { payment_id: payment_id, date: date }
12
11
  response = post_request("2.0/subscription/payments_reschedule", body: attrs)
13
- return true if response.success?
12
+ true if response.success?
14
13
  end
15
14
 
16
15
  def refund(order_id:, **params)
17
- attrs = {order_id: order_id}
16
+ attrs = { order_id: order_id }
18
17
  response = post_request("2.0/payment/refund", body: attrs.merge(params))
19
18
  PaymentRefund.new(response.body["response"])
20
19
  end
21
-
22
20
  end
23
21
  end
24
22
  end
@@ -1,21 +1,19 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class PlansResource < Resource
4
-
5
4
  def list
6
5
  response = post_request("2.0/subscription/plans")
7
6
  Collection.from_response(response, type: Plan)
8
7
  end
9
8
 
10
9
  def create(name:, type:, **params)
11
- attrs = {plan_name: name, plan_type: type}
10
+ attrs = { plan_name: name, plan_type: type }
12
11
  create_response = post_request("2.0/subscription/plans_create", body: attrs.merge(params))
13
12
 
14
13
  # After creating the Plan, because it doesn't return the whole record, grab it from the API and return that
15
- response = post_request("2.0/subscription/plans", body: {plan: create_response.body["response"]["product_id"]} )
14
+ response = post_request("2.0/subscription/plans", body: { plan: create_response.body["response"]["product_id"] })
16
15
  Plan.new(response.body.dig("response")[0]) if response.success?
17
16
  end
18
-
19
17
  end
20
18
  end
21
19
  end
@@ -1,12 +1,10 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class ProductsResource < Resource
4
-
5
4
  def list
6
5
  response = post_request("2.0/product/get_products")
7
6
  Collection.from_response(response, type: Product, key: "products")
8
7
  end
9
-
10
8
  end
11
9
  end
12
10
  end
@@ -1,12 +1,10 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class TransactionsResource < Resource
4
-
5
4
  def list(entity:, id:)
6
5
  response = post_request("2.0/#{entity}/#{id}/transactions")
7
6
  Collection.from_response(response, type: Transaction)
8
7
  end
9
-
10
8
  end
11
9
  end
12
10
  end
@@ -1,42 +1,40 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class UsersResource < Resource
4
-
5
4
  def list(**params)
6
5
  response = post_request("2.0/subscription/users", body: params)
7
6
  Collection.from_response(response, type: User)
8
7
  end
9
8
 
10
9
  def update(subscription_id:, **params)
11
- attrs = {subscription_id: subscription_id}
10
+ attrs = { subscription_id: subscription_id }
12
11
  response = post_request("2.0/subscription/users/update", body: attrs.merge(params))
13
12
  User.new(response.body["response"]) if response.success?
14
13
  end
15
14
 
16
15
  def pause(subscription_id:, **params)
17
- attrs = {subscription_id: subscription_id, pause: true}
16
+ attrs = { subscription_id: subscription_id, pause: true }
18
17
  response = post_request("2.0/subscription/users/update", body: attrs.merge(params))
19
18
  User.new(response.body["response"]) if response.success?
20
19
  end
21
20
 
22
21
  def unpause(subscription_id:, **params)
23
- attrs = {subscription_id: subscription_id, pause: false}
22
+ attrs = { subscription_id: subscription_id, pause: false }
24
23
  response = post_request("2.0/subscription/users/update", body: attrs.merge(params))
25
24
  User.new(response.body["response"]) if response.success?
26
25
  end
27
26
 
28
27
  def update_postcode(subscription_id:, postcode:)
29
- attrs = {subscription_id: subscription_id, postcode: postcode}
28
+ attrs = { subscription_id: subscription_id, postcode: postcode }
30
29
  response = post_request("2.0/subscription/users/postcode", body: attrs)
31
- return true if response.success?
30
+ true if response.success?
32
31
  end
33
32
 
34
33
  def cancel(subscription_id:)
35
- attrs = {subscription_id: subscription_id}
34
+ attrs = { subscription_id: subscription_id }
36
35
  response = post_request("2.0/subscription/users_cancel", body: attrs)
37
- return true if response.success?
36
+ true if response.success?
38
37
  end
39
-
40
38
  end
41
39
  end
42
40
  end
@@ -1,12 +1,10 @@
1
1
  module Paddle
2
2
  module Classic
3
3
  class WebhooksResource < Resource
4
-
5
4
  def list(**params)
6
5
  response = post_request("2.0/alert/webhooks", body: params)
7
6
  Collection.from_response(response, type: Webhook, key: "data")
8
7
  end
9
-
10
8
  end
11
9
  end
12
10
  end
data/lib/paddle/client.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Paddle
2
2
  class Client
3
-
4
3
  class << self
5
-
6
4
  def connection
7
5
  @connection ||= Faraday.new(Paddle.config.url) do |conn|
8
6
  conn.request :authorization, :Bearer, Paddle.config.api_key
@@ -13,8 +11,7 @@ module Paddle
13
11
  }
14
12
 
15
13
  conn.request :json
16
-
17
- conn.response :json, content_type: "application/json"
14
+ conn.response :json
18
15
  end
19
16
  end
20
17
 
@@ -65,8 +62,6 @@ module Paddle
65
62
 
66
63
  response
67
64
  end
68
-
69
65
  end
70
-
71
66
  end
72
67
  end
@@ -23,5 +23,17 @@ module Paddle
23
23
  @data = data
24
24
  @total = total
25
25
  end
26
+
27
+ def each(&block)
28
+ data.each(&block)
29
+ end
30
+
31
+ def first
32
+ data.first
33
+ end
34
+
35
+ def last
36
+ data.last
37
+ end
26
38
  end
27
39
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Paddle
4
4
  class Configuration
5
-
6
5
  attr_reader :environment
7
6
 
8
7
  attr_accessor :version
@@ -15,7 +14,7 @@ module Paddle
15
14
 
16
15
  def environment=(env)
17
16
  env = env.nil? ? :production : env.to_sym
18
- unless [:development, :sandbox, :production].include?(env)
17
+ unless [ :development, :sandbox, :production ].include?(env)
19
18
  raise ArgumentError, "#{env.inspect} is not a valid environment"
20
19
  end
21
20
  @environment = env
@@ -29,6 +28,5 @@ module Paddle
29
28
  "https://sandbox-api.paddle.com"
30
29
  end
31
30
  end
32
-
33
31
  end
34
32
  end
@@ -1,15 +1,13 @@
1
1
  module Paddle
2
2
  class Address < Object
3
-
4
3
  class << self
5
-
6
4
  def list(customer:, **params)
7
5
  response = Client.get_request("customers/#{customer}/addresses", params: params)
8
6
  Collection.from_response(response, type: Address)
9
7
  end
10
8
 
11
9
  def create(customer:, country_code:, postal_code:, **params)
12
- attrs = {country_code: country_code, postal_code: postal_code}
10
+ attrs = { country_code: country_code, postal_code: postal_code }
13
11
  response = Client.post_request("customers/#{customer}/addresses", body: attrs.merge(params))
14
12
  Address.new(response.body["data"])
15
13
  end
@@ -23,8 +21,6 @@ module Paddle
23
21
  response = Client.patch_request("customers/#{customer}/addresses/#{id}", body: params)
24
22
  Address.new(response.body["data"])
25
23
  end
26
-
27
24
  end
28
-
29
25
  end
30
26
  end
@@ -1,20 +1,16 @@
1
1
  module Paddle
2
2
  class Adjustment < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("adjustments", params: params)
8
6
  Collection.from_response(response, type: Adjustment)
9
7
  end
10
8
 
11
9
  def create(transaction_id:, action:, reason:, items:, **params)
12
- attrs = {transaction_id: transaction_id, action: action, reason: reason, items: items}
10
+ attrs = { transaction_id: transaction_id, action: action, reason: reason, items: items }
13
11
  response = Client.post_request("adjustments", body: attrs.merge(params))
14
12
  Adjustment.new(response.body["data"])
15
13
  end
16
-
17
14
  end
18
-
19
15
  end
20
16
  end
@@ -1,15 +1,13 @@
1
1
  module Paddle
2
2
  class Business < Object
3
-
4
3
  class << self
5
-
6
4
  def list(customer:, **params)
7
5
  response = Client.get_request("customers/#{customer}/businesses", params: params)
8
6
  Collection.from_response(response, type: Business)
9
7
  end
10
8
 
11
9
  def create(customer:, name:, **params)
12
- attrs = {name: name}
10
+ attrs = { name: name }
13
11
  response = Client.post_request("customers/#{customer}/businesses", body: attrs.merge(params))
14
12
  Business.new(response.body["data"])
15
13
  end
@@ -23,8 +21,6 @@ module Paddle
23
21
  response = Client.patch_request("customers/#{customer}/businesses/#{id}", body: params)
24
22
  Business.new(response.body["data"])
25
23
  end
26
-
27
24
  end
28
-
29
25
  end
30
26
  end
@@ -1,15 +1,13 @@
1
1
  module Paddle
2
2
  class Customer < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("customers", params: params)
8
6
  Collection.from_response(response, type: Customer)
9
7
  end
10
8
 
11
9
  def create(email:, **params)
12
- attrs = {email: email.gsub(/\s+/, "")}
10
+ attrs = { email: email.gsub(/\s+/, "") }
13
11
  response = Client.post_request("customers", body: attrs.merge(params))
14
12
  Customer.new(response.body["data"])
15
13
  end
@@ -28,8 +26,6 @@ module Paddle
28
26
  response = Client.get_request("customers/#{id}/credit-balances")
29
27
  CreditBalance.new(response.body["data"][0])
30
28
  end
31
-
32
29
  end
33
-
34
30
  end
35
31
  end
@@ -1,15 +1,13 @@
1
1
  module Paddle
2
2
  class Discount < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("discounts", params: params)
8
6
  Collection.from_response(response, type: Discount)
9
7
  end
10
8
 
11
9
  def create(amount:, description:, type:, **params)
12
- attrs = {amount: amount, description: description, type: type}
10
+ attrs = { amount: amount, description: description, type: type }
13
11
  response = Client.post_request("discounts", body: attrs.merge(params))
14
12
  Discount.new(response.body["data"])
15
13
  end
@@ -23,8 +21,6 @@ module Paddle
23
21
  response = Client.patch_request("discounts/#{id}", body: params)
24
22
  Discount.new(response.body["data"])
25
23
  end
26
-
27
24
  end
28
-
29
25
  end
30
26
  end
@@ -1,14 +1,10 @@
1
1
  module Paddle
2
2
  class Event < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("events", params: params)
8
6
  Collection.from_response(response, type: Event)
9
7
  end
10
-
11
8
  end
12
-
13
9
  end
14
10
  end
@@ -1,14 +1,10 @@
1
1
  module Paddle
2
2
  class EventType < Object
3
-
4
3
  class << self
5
-
6
4
  def list
7
5
  response = Client.get_request("event-types")
8
6
  Collection.from_response(response, type: EventType)
9
7
  end
10
-
11
8
  end
12
-
13
9
  end
14
10
  end
@@ -1,8 +1,6 @@
1
1
  module Paddle
2
2
  class Notification < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("notifications", params: params)
8
6
  Collection.from_response(response, type: Notification)
@@ -23,8 +21,6 @@ module Paddle
23
21
  response = Client.get_request("notifications/#{id}/logs", params: params)
24
22
  Collection.from_response(response, type: NotificationLog)
25
23
  end
26
-
27
24
  end
28
-
29
25
  end
30
26
  end
@@ -1,15 +1,13 @@
1
1
  module Paddle
2
2
  class NotificationSetting < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("notification-settings", params: params)
8
6
  Collection.from_response(response, type: NotificationSetting)
9
7
  end
10
8
 
11
9
  def create(description:, destination:, type:, subscribed_events:, **params)
12
- attrs = {description: description, destination: destination, type: type, subscribed_events: subscribed_events}
10
+ attrs = { description: description, destination: destination, type: type, subscribed_events: subscribed_events }
13
11
  response = Client.post_request("notification-settings", body: attrs.merge(params))
14
12
  NotificationSetting.new(response.body["data"])
15
13
  end
@@ -27,8 +25,6 @@ module Paddle
27
25
  def delete(id:)
28
26
  Client.delete_request("notification-settings/#{id}")
29
27
  end
30
-
31
28
  end
32
-
33
29
  end
34
30
  end
@@ -1,15 +1,13 @@
1
1
  module Paddle
2
2
  class Price < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("prices", params: params)
8
6
  Collection.from_response(response, type: Price)
9
7
  end
10
8
 
11
9
  def create(product_id:, description:, amount:, currency:, **params)
12
- attrs = {product_id: product_id, description: description, unit_price: {amount: amount, currency_code: currency}}
10
+ attrs = { product_id: product_id, description: description, unit_price: { amount: amount, currency_code: currency } }
13
11
  response = Client.post_request("prices", body: attrs.merge(params))
14
12
  Price.new(response.body["data"])
15
13
  end
@@ -23,8 +21,6 @@ module Paddle
23
21
  response = Client.patch_request("prices/#{id}", body: params)
24
22
  Price.new(response.body["data"])
25
23
  end
26
-
27
24
  end
28
-
29
25
  end
30
26
  end
@@ -1,15 +1,11 @@
1
1
  module Paddle
2
2
  class PricingPreview < Object
3
-
4
3
  class << self
5
-
6
4
  def generate(items:, **params)
7
- attrs = {items: items}
5
+ attrs = { items: items }
8
6
  response = Client.post_request("pricing-preview", body: attrs.merge(params))
9
7
  PricingPreview.new(response.body["data"])
10
8
  end
11
-
12
9
  end
13
-
14
10
  end
15
11
  end
@@ -1,15 +1,13 @@
1
1
  module Paddle
2
2
  class Product < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("products", params: params)
8
6
  Collection.from_response(response, type: Product)
9
7
  end
10
8
 
11
9
  def create(name:, tax_category:, **params)
12
- attrs = {name: name, tax_category: tax_category}
10
+ attrs = { name: name, tax_category: tax_category }
13
11
  response = Client.post_request("products", body: attrs.merge(params))
14
12
  Product.new(response.body["data"])
15
13
  end
@@ -23,8 +21,6 @@ module Paddle
23
21
  response = Client.patch_request("products/#{id}", body: params)
24
22
  Product.new(response.body["data"])
25
23
  end
26
-
27
24
  end
28
-
29
25
  end
30
26
  end
@@ -0,0 +1,28 @@
1
+ module Paddle
2
+ class Report < Object
3
+ class << self
4
+ def list(**params)
5
+ response = Client.get_request("reports", params: params)
6
+ Collection.from_response(response, type: Report)
7
+ end
8
+
9
+ def create(type:, filters:, **params)
10
+ attrs = { type: type, filters: filters }
11
+ response = Client.post_request("reports", body: attrs.merge(params))
12
+ Report.new(response.body["data"])
13
+ end
14
+
15
+ def retrieve(id:)
16
+ response = Client.get_request("reports/#{id}")
17
+ Report.new(response.body["data"])
18
+ end
19
+
20
+ def csv(id:)
21
+ response = Client.get_request("reports/#{id}/download-url")
22
+ if response.success?
23
+ response.body["data"]["url"]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,15 +1,13 @@
1
1
  module Paddle
2
2
  class Subscription < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("subscriptions", params: params)
8
6
  Collection.from_response(response, type: Subscription)
9
7
  end
10
8
 
11
9
  def retrieve(id:, extra: nil)
12
- params = extra ? {include: extra} : {}
10
+ params = extra ? { include: extra } : {}
13
11
  response = Client.get_request("subscriptions/#{id}", params: params)
14
12
  Subscription.new(response.body["data"])
15
13
  end
@@ -30,7 +28,7 @@ module Paddle
30
28
  end
31
29
 
32
30
  def charge(id:, items:, effective_from:, **params)
33
- attrs = {items: items, effective_from: effective_from}
31
+ attrs = { items: items, effective_from: effective_from }
34
32
  response = Client.post_request("subscriptions/#{id}/charge", body: attrs.merge(params))
35
33
  Subscription.new(response.body["data"])
36
34
  end
@@ -41,7 +39,7 @@ module Paddle
41
39
  end
42
40
 
43
41
  def resume(id:, effective_from:, **params)
44
- attrs = {effective_from: effective_from}
42
+ attrs = { effective_from: effective_from }
45
43
  response = Client.post_request("subscriptions/#{id}/resume", body: attrs.merge(params))
46
44
  Subscription.new(response.body["data"])
47
45
  end
@@ -55,8 +53,6 @@ module Paddle
55
53
  response = Client.post_request("subscriptions/#{id}/activate")
56
54
  Subscription.new(response.body["data"])
57
55
  end
58
-
59
56
  end
60
-
61
57
  end
62
58
  end
@@ -1,21 +1,19 @@
1
1
  module Paddle
2
2
  class Transaction < Object
3
-
4
3
  class << self
5
-
6
4
  def list(**params)
7
5
  response = Client.get_request("transactions", params: params)
8
6
  Collection.from_response(response, type: Transaction)
9
7
  end
10
8
 
11
9
  def create(items:, **params)
12
- attrs = {items: items}
10
+ attrs = { items: items }
13
11
  response = Client.post_request("transactions", body: attrs.merge(params))
14
12
  Transaction.new(response.body["data"])
15
13
  end
16
14
 
17
15
  def retrieve(id:, extra: nil)
18
- params = extra ? {include: extra} : {}
16
+ params = extra ? { include: extra } : {}
19
17
  response = Client.get_request("transactions/#{id}", params: params)
20
18
  Transaction.new(response.body["data"])
21
19
  end
@@ -28,17 +26,15 @@ module Paddle
28
26
  def invoice(id:)
29
27
  response = Client.get_request("transactions/#{id}/invoice")
30
28
  if response.success?
31
- return response.body["data"]["url"]
29
+ response.body["data"]["url"]
32
30
  end
33
31
  end
34
32
 
35
33
  def preview(items:, **params)
36
- attrs = {items: items}
34
+ attrs = { items: items }
37
35
  response = Client.post_request("transactions/preview", body: attrs.merge(params))
38
36
  Transaction.new(response.body["data"])
39
37
  end
40
-
41
38
  end
42
-
43
39
  end
44
40
  end
data/lib/paddle/object.rb CHANGED
@@ -8,7 +8,7 @@ module Paddle
8
8
 
9
9
  def to_ostruct(obj)
10
10
  if obj.is_a?(Hash)
11
- OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
11
+ OpenStruct.new(obj.map { |key, val| [ key, to_ostruct(val) ] }.to_h)
12
12
  elsif obj.is_a?(Array)
13
13
  obj.map { |o| to_ostruct(o) }
14
14
  else # Assumed to be a primitive value
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paddle
4
- VERSION = "2.1.4"
4
+ VERSION = "2.2.1"
5
5
  end
data/lib/paddle.rb CHANGED
@@ -5,7 +5,6 @@ require "faraday"
5
5
  require_relative "paddle/version"
6
6
 
7
7
  module Paddle
8
-
9
8
  autoload :Configuration, "paddle/configuration"
10
9
  autoload :Client, "paddle/client"
11
10
  autoload :Collection, "paddle/collection"
@@ -39,6 +38,7 @@ module Paddle
39
38
  autoload :Event, "paddle/models/event"
40
39
  autoload :NotificationSetting, "paddle/models/notification_setting"
41
40
  autoload :Notification, "paddle/models/notification"
41
+ autoload :Report, "paddle/models/report"
42
42
 
43
43
  autoload :NotificationLog, "paddle/models/notification_log"
44
44
  autoload :CreditBalance, "paddle/models/credit_balance"
@@ -74,5 +74,4 @@ module Paddle
74
74
  autoload :Modifier, "paddle/classic/objects/modifier"
75
75
  autoload :Charge, "paddle/classic/objects/charge"
76
76
  end
77
-
78
77
  end
data/paddle.gemspec CHANGED
@@ -5,8 +5,8 @@ require_relative "lib/paddle/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "paddle"
7
7
  spec.version = Paddle::VERSION
8
- spec.authors = ["Dean Perry"]
9
- spec.email = ["dean@deanpcmad.com"]
8
+ spec.authors = [ "Dean Perry" ]
9
+ spec.email = [ "dean@deanpcmad.com" ]
10
10
 
11
11
  spec.summary = "Ruby library for the Paddle Billing & Classic APIs"
12
12
  spec.homepage = "https://github.com/deanpcmad/paddle"
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  end
25
25
  spec.bindir = "exe"
26
26
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
27
+ spec.require_paths = [ "lib" ]
28
28
 
29
29
  spec.add_dependency "faraday", "~> 2.0"
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paddle
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-24 00:00:00.000000000 Z
11
+ date: 2024-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- description:
27
+ description:
28
28
  email:
29
29
  - dean@deanpcmad.com
30
30
  executables: []
@@ -32,6 +32,7 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".env.example"
35
+ - ".rubocop.yml"
35
36
  - Gemfile
36
37
  - Gemfile.lock
37
38
  - README.md
@@ -83,6 +84,7 @@ files:
83
84
  - lib/paddle/models/price.rb
84
85
  - lib/paddle/models/pricing_preview.rb
85
86
  - lib/paddle/models/product.rb
87
+ - lib/paddle/models/report.rb
86
88
  - lib/paddle/models/subscription.rb
87
89
  - lib/paddle/models/transaction.rb
88
90
  - lib/paddle/object.rb
@@ -93,7 +95,7 @@ licenses: []
93
95
  metadata:
94
96
  homepage_uri: https://github.com/deanpcmad/paddle
95
97
  source_code_uri: https://github.com/deanpcmad/paddle
96
- post_install_message:
98
+ post_install_message:
97
99
  rdoc_options: []
98
100
  require_paths:
99
101
  - lib
@@ -108,8 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  - !ruby/object:Gem::Version
109
111
  version: '0'
110
112
  requirements: []
111
- rubygems_version: 3.4.22
112
- signing_key:
113
+ rubygems_version: 3.5.9
114
+ signing_key:
113
115
  specification_version: 4
114
116
  summary: Ruby library for the Paddle Billing & Classic APIs
115
117
  test_files: []