paddle 2.3.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +29 -11
- data/lib/paddle/classic/error.rb +6 -0
- data/lib/paddle/error.rb +0 -123
- data/lib/paddle/error_generator.rb +128 -0
- data/lib/paddle/version.rb +1 -1
- data/lib/paddle.rb +4 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27bf08d2edf30371cb338f2e7f266616831fc3509a5b3017330ab8e13edf39d7
|
4
|
+
data.tar.gz: a178eb8b09ca9ac0a911bb666d6857d6248c99e6eb3219e4d4b870a6280ffe88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cad5eb956cf18312af1a4758f52fa9ad7c566312d1c2fc0a911864f06be77542cc04236359a2558a6e7fcdfd9fb0d638a83daf81f8ddff5a71b44205239507b1
|
7
|
+
data.tar.gz: 9dabf150b46d778de8b85dced2cc79a8137e8b36bdc9aa50aef24c060c4d06373145c38c7af88d0b7b43a1322482f6ebeddc9f5792337a7f093b9a1e70144052
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ The easiest and most complete Ruby library for the Paddle APIs, both Classic and
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem "paddle", "~> 2.
|
10
|
+
gem "paddle", "~> 2.3"
|
11
11
|
```
|
12
12
|
|
13
13
|
## Billing API
|
@@ -101,10 +101,12 @@ Paddle::Product.create(name: "My SAAS Plan", tax_category: "saas")
|
|
101
101
|
Paddle::Product.create(name: "My Standard Product", tax_category: "standard")
|
102
102
|
|
103
103
|
# Retrieve a product
|
104
|
-
Paddle::Product.retrieve(id: "pro_abc123")
|
104
|
+
product = Paddle::Product.retrieve(id: "pro_abc123")
|
105
105
|
|
106
106
|
# Update a product
|
107
107
|
# https://developer.paddle.com/api-reference/products/update-product
|
108
|
+
product.update(description: "This is a plan")
|
109
|
+
# or
|
108
110
|
Paddle::Product.update(id: "pro_abc123", description: "This is a plan")
|
109
111
|
```
|
110
112
|
|
@@ -124,10 +126,12 @@ Paddle::Price.list(product_id: "pro_abc123")
|
|
124
126
|
Paddle::Price.create(product_id: "pro_abc123", description: "A one off price", amount: "1000", currency: "GBP")
|
125
127
|
|
126
128
|
# Retrieve a price
|
127
|
-
Paddle::Price.retrieve(id: "pri_123abc")
|
129
|
+
price = Paddle::Price.retrieve(id: "pri_123abc")
|
128
130
|
|
129
131
|
# Update a price
|
130
132
|
# https://developer.paddle.com/api-reference/prices/update-price
|
133
|
+
price.update(description: "An updated description")
|
134
|
+
# or
|
131
135
|
Paddle::Price.update(id: "pri_123abc", description: "An updated description")
|
132
136
|
```
|
133
137
|
|
@@ -157,10 +161,12 @@ Paddle::Discount.create(description: "$5 off", type: "flat", amount: "500", curr
|
|
157
161
|
Paddle::Discount.create(description: "10% Off", type: "percentage", amount: "10", code: "10OFF")
|
158
162
|
|
159
163
|
# Retrieve a discount
|
160
|
-
Paddle::Discount.retrieve(id: "dsc_abc123")
|
164
|
+
discount = Paddle::Discount.retrieve(id: "dsc_abc123")
|
161
165
|
|
162
166
|
# Update a discount
|
163
167
|
# https://developer.paddle.com/api-reference/discounts/update-discount
|
168
|
+
discount.update(description: "An updated description")
|
169
|
+
# or
|
164
170
|
Paddle::Discount.update(id: "dsc_abc123", description: "An updated description")
|
165
171
|
```
|
166
172
|
|
@@ -175,14 +181,16 @@ Paddle::Customer.list(email: "me@mydomain.com")
|
|
175
181
|
|
176
182
|
# Create a customer
|
177
183
|
# https://developer.paddle.com/api-reference/customers/create-customer
|
178
|
-
# Returns a Paddle::ConflictError if the email is already used on Paddle
|
184
|
+
# Returns a Paddle::Errors::ConflictError if the email is already used on Paddle
|
179
185
|
Paddle::Customer.create(email: "myemail@mydomain.com", name: "Customer Name")
|
180
186
|
|
181
187
|
# Retrieve a customer
|
182
|
-
Paddle::Customer.retrieve(id: "ctm_abc123")
|
188
|
+
customer = Paddle::Customer.retrieve(id: "ctm_abc123")
|
183
189
|
|
184
190
|
# Update a customer
|
185
191
|
# https://developer.paddle.com/api-reference/customers/update-customer
|
192
|
+
customer.update(status: "archived")
|
193
|
+
# or
|
186
194
|
Paddle::Customer.update(id: "ctm_abc123", status: "archived")
|
187
195
|
|
188
196
|
# Retrieve credit balance for a customer
|
@@ -202,10 +210,12 @@ Paddle::Address.list(customer: "ctm_abc123")
|
|
202
210
|
Paddle::Address.create(customer: "ctm_abc123", country_code: "GB", postal_code: "SW1A 2AA")
|
203
211
|
|
204
212
|
# Retrieve an address
|
205
|
-
Paddle::Address.retrieve(customer: "ctm_abc123", id: "add_abc123")
|
213
|
+
address = Paddle::Address.retrieve(customer: "ctm_abc123", id: "add_abc123")
|
206
214
|
|
207
215
|
# Update an address
|
208
216
|
# https://developer.paddle.com/api-reference/addresses/update-address
|
217
|
+
address.update(status: "archived")
|
218
|
+
# or
|
209
219
|
Paddle::Address.update(customer: "ctm_abc123", id: "add_abc123", status: "archived")
|
210
220
|
```
|
211
221
|
|
@@ -221,10 +231,12 @@ Paddle::Business.list(customer: "ctm_abc123")
|
|
221
231
|
Paddle::Business.create(customer: "ctm_abc123", name: "My Ltd Company")
|
222
232
|
|
223
233
|
# Retrieve a business
|
224
|
-
Paddle::Business.retrieve(customer: "ctm_abc123", id: "biz_abc123")
|
234
|
+
business = Paddle::Business.retrieve(customer: "ctm_abc123", id: "biz_abc123")
|
225
235
|
|
226
236
|
# Update a business
|
227
237
|
# https://developer.paddle.com/api-reference/businesses/update-business
|
238
|
+
business.update(status: "archived")
|
239
|
+
# or
|
228
240
|
Paddle::Business.update(customer: "ctm_abc123", id: "biz_abc123", status: "archived")
|
229
241
|
```
|
230
242
|
|
@@ -246,10 +258,12 @@ Paddle::Transaction.retrieve(id: "txn_abc123")
|
|
246
258
|
|
247
259
|
# Retrieve a transaction with extra information
|
248
260
|
# extra can be either "address", "adjustment", "adjustments_totals", "business", "customer", "discount"
|
249
|
-
Paddle::Transaction.retrieve(id: "txn_abc123", extra: "customer")
|
261
|
+
transaction = Paddle::Transaction.retrieve(id: "txn_abc123", extra: "customer")
|
250
262
|
|
251
263
|
# Update a transaction
|
252
264
|
# https://developer.paddle.com/api-reference/transaction/update-transaction
|
265
|
+
transaction.update(items: [ { price_id: "pri_abc123", quantity: 2 } ])
|
266
|
+
# or
|
253
267
|
Paddle::Transaction.update(id: "txn_abc123", items: [ { price_id: "pri_abc123", quantity: 2 } ])
|
254
268
|
|
255
269
|
# Preview a transaction
|
@@ -280,7 +294,7 @@ Paddle::Subscription.retrieve(id: "sub_abc123")
|
|
280
294
|
|
281
295
|
# Retrieve a subscription with extra information
|
282
296
|
# extra can be either "next_transaction" or "recurring_transaction_details"
|
283
|
-
Paddle::Subscription.retrieve(id: "sub_abc123", extra: "next_transaction")
|
297
|
+
subscription = Paddle::Subscription.retrieve(id: "sub_abc123", extra: "next_transaction")
|
284
298
|
|
285
299
|
# Preview an update to a subscription
|
286
300
|
# https://developer.paddle.com/api-reference/subscriptions/preview-subscription
|
@@ -288,6 +302,8 @@ Paddle::Subscription.preview(id: "sub_abc123", items: [ { price_id: "pri_123abc"
|
|
288
302
|
|
289
303
|
# Update a subscription
|
290
304
|
# https://developer.paddle.com/api-reference/subscriptions/update-subscription
|
305
|
+
subscription.update(billing_details: {purchase_order_number: "PO-1234"})
|
306
|
+
# or
|
291
307
|
Paddle::Subscription.update(id: "sub_abc123", billing_details: {purchase_order_number: "PO-1234"})
|
292
308
|
|
293
309
|
# Get a transaction to update payment method
|
@@ -367,7 +383,7 @@ Used for creating webhook and email notifications
|
|
367
383
|
Paddle::NotificationSetting.list
|
368
384
|
|
369
385
|
# Retrieve a notification setting
|
370
|
-
Paddle::NotificationSetting.retrieve(id: "ntfset_abc123")
|
386
|
+
setting = Paddle::NotificationSetting.retrieve(id: "ntfset_abc123")
|
371
387
|
|
372
388
|
# Create a notification setting
|
373
389
|
# https://developer.paddle.com/api-reference/notification-settings/create-notification-setting
|
@@ -383,6 +399,8 @@ Paddle::NotificationSetting.create(
|
|
383
399
|
|
384
400
|
# Update a notification setting
|
385
401
|
# https://developer.paddle.com/api-reference/notification-settings/update-notification-setting
|
402
|
+
setting.update(subscribed_events: %w[subscription.activated transaction.completed transaction.billed])
|
403
|
+
# or
|
386
404
|
Paddle::NotificationSetting.update(id: "ntfset_abc123",
|
387
405
|
subscribed_events: [
|
388
406
|
"subscription.activated",
|
data/lib/paddle/error.rb
CHANGED
@@ -1,127 +1,4 @@
|
|
1
1
|
module Paddle
|
2
2
|
class Error < StandardError
|
3
|
-
attr_reader :http_status_code
|
4
|
-
attr_reader :paddle_error_code
|
5
|
-
attr_reader :paddle_error_message
|
6
|
-
|
7
|
-
def initialize(response_body, http_status_code)
|
8
|
-
@response_body = response_body
|
9
|
-
@http_status_code = http_status_code
|
10
|
-
set_paddle_error_values
|
11
|
-
super(build_message)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def set_paddle_error_values
|
17
|
-
@paddle_error_code = @response_body.dig("error", "code")
|
18
|
-
@paddle_error_message = @response_body.dig("error", "detail")
|
19
|
-
end
|
20
|
-
|
21
|
-
def error_message
|
22
|
-
@paddle_error_message || @response_body.dig("error", "code")
|
23
|
-
rescue NoMethodError
|
24
|
-
"An unknown error occurred."
|
25
|
-
end
|
26
|
-
|
27
|
-
def build_message
|
28
|
-
if paddle_error_code.nil?
|
29
|
-
return "Error #{@http_status_code}: #{error_message}"
|
30
|
-
end
|
31
|
-
"Error #{@http_status_code}: #{error_message} '#{paddle_error_code}'"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class BadRequestError < Error
|
36
|
-
private
|
37
|
-
|
38
|
-
def error_message
|
39
|
-
"Your request was malformed."
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class AuthenticationMissingError < Error
|
44
|
-
private
|
45
|
-
|
46
|
-
def error_message
|
47
|
-
"You did not supply valid authentication credentials."
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class ForbiddenError < Error
|
52
|
-
private
|
53
|
-
|
54
|
-
def error_message
|
55
|
-
"You are not allowed to perform that action."
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class EntityNotFoundError < Error
|
60
|
-
private
|
61
|
-
|
62
|
-
def error_message
|
63
|
-
"No results were found for your request."
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class ConflictError < Error
|
68
|
-
private
|
69
|
-
|
70
|
-
def error_message
|
71
|
-
"Your request was a conflict."
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class TooManyRequestsError < Error
|
76
|
-
private
|
77
|
-
|
78
|
-
def error_message
|
79
|
-
"Your request exceeded the API rate limit."
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
class InternalError < Error
|
84
|
-
private
|
85
|
-
|
86
|
-
def error_message
|
87
|
-
"We were unable to perform the request due to server-side problems."
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
class ServiceUnavailableError < Error
|
92
|
-
private
|
93
|
-
|
94
|
-
def error_message
|
95
|
-
"You have been rate limited for sending more than 20 requests per second."
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class NotImplementedError < Error
|
100
|
-
private
|
101
|
-
|
102
|
-
def error_message
|
103
|
-
"This resource has not been implemented."
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
class ErrorFactory
|
109
|
-
HTTP_ERROR_MAP = {
|
110
|
-
400 => BadRequestError,
|
111
|
-
401 => AuthenticationMissingError,
|
112
|
-
403 => ForbiddenError,
|
113
|
-
404 => EntityNotFoundError,
|
114
|
-
409 => ConflictError,
|
115
|
-
429 => TooManyRequestsError,
|
116
|
-
500 => InternalError,
|
117
|
-
503 => ServiceUnavailableError,
|
118
|
-
501 => NotImplementedError
|
119
|
-
}.freeze
|
120
|
-
|
121
|
-
def self.create(response_body, http_status_code)
|
122
|
-
status = http_status_code
|
123
|
-
error_class = HTTP_ERROR_MAP[status] || Error
|
124
|
-
error_class.new(response_body, http_status_code) if error_class
|
125
|
-
end
|
126
3
|
end
|
127
4
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Paddle
|
2
|
+
class ErrorGenerator < StandardError
|
3
|
+
attr_reader :http_status_code
|
4
|
+
attr_reader :paddle_error_code
|
5
|
+
attr_reader :paddle_error_message
|
6
|
+
|
7
|
+
def initialize(response_body, http_status_code)
|
8
|
+
@response_body = response_body
|
9
|
+
@http_status_code = http_status_code
|
10
|
+
set_paddle_error_values
|
11
|
+
super(build_message)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def set_paddle_error_values
|
17
|
+
@paddle_error_code = @response_body.dig("error", "code")
|
18
|
+
@paddle_error_message = @response_body.dig("error", "detail")
|
19
|
+
end
|
20
|
+
|
21
|
+
def error_message
|
22
|
+
@paddle_error_message || @response_body.dig("error", "code")
|
23
|
+
rescue NoMethodError
|
24
|
+
"An unknown error occurred."
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_message
|
28
|
+
if paddle_error_code.nil?
|
29
|
+
return "Error #{@http_status_code}: #{error_message}"
|
30
|
+
end
|
31
|
+
"Error #{@http_status_code}: #{error_message} '#{paddle_error_code}'"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module Errors
|
36
|
+
class BadRequestError < ErrorGenerator
|
37
|
+
private
|
38
|
+
|
39
|
+
def error_message
|
40
|
+
"Your request was malformed."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class AuthenticationMissingError < ErrorGenerator
|
45
|
+
private
|
46
|
+
|
47
|
+
def error_message
|
48
|
+
"You did not supply valid authentication credentials."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class ForbiddenError < ErrorGenerator
|
53
|
+
private
|
54
|
+
|
55
|
+
def error_message
|
56
|
+
"You are not allowed to perform that action."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class EntityNotFoundError < ErrorGenerator
|
61
|
+
private
|
62
|
+
|
63
|
+
def error_message
|
64
|
+
"No results were found for your request."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class ConflictError < ErrorGenerator
|
69
|
+
private
|
70
|
+
|
71
|
+
def error_message
|
72
|
+
"Your request was a conflict."
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class TooManyRequestsError < ErrorGenerator
|
77
|
+
private
|
78
|
+
|
79
|
+
def error_message
|
80
|
+
"Your request exceeded the API rate limit."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class InternalError < ErrorGenerator
|
85
|
+
private
|
86
|
+
|
87
|
+
def error_message
|
88
|
+
"We were unable to perform the request due to server-side problems."
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class ServiceUnavailableError < ErrorGenerator
|
93
|
+
private
|
94
|
+
|
95
|
+
def error_message
|
96
|
+
"You have been rate limited for sending more than 20 requests per second."
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class NotImplementedError < ErrorGenerator
|
101
|
+
private
|
102
|
+
|
103
|
+
def error_message
|
104
|
+
"This resource has not been implemented."
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class ErrorFactory
|
110
|
+
HTTP_ERROR_MAP = {
|
111
|
+
400 => Errors::BadRequestError,
|
112
|
+
401 => Errors::AuthenticationMissingError,
|
113
|
+
403 => Errors::ForbiddenError,
|
114
|
+
404 => Errors::EntityNotFoundError,
|
115
|
+
409 => Errors::ConflictError,
|
116
|
+
429 => Errors::TooManyRequestsError,
|
117
|
+
500 => Errors::InternalError,
|
118
|
+
503 => Errors::ServiceUnavailableError,
|
119
|
+
501 => Errors::NotImplementedError
|
120
|
+
}.freeze
|
121
|
+
|
122
|
+
def self.create(response_body, http_status_code)
|
123
|
+
status = http_status_code
|
124
|
+
error_class = HTTP_ERROR_MAP[status] || ErrorGenerator
|
125
|
+
error_class.new(response_body, http_status_code) if error_class
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/paddle/version.rb
CHANGED
data/lib/paddle.rb
CHANGED
@@ -9,7 +9,9 @@ module Paddle
|
|
9
9
|
autoload :Client, "paddle/client"
|
10
10
|
autoload :Collection, "paddle/collection"
|
11
11
|
autoload :Error, "paddle/error"
|
12
|
-
autoload :
|
12
|
+
autoload :Errors, "paddle/error_generator"
|
13
|
+
autoload :ErrorGenerator, "paddle/error_generator"
|
14
|
+
autoload :ErrorFactory, "paddle/error_generator"
|
13
15
|
|
14
16
|
autoload :Object, "paddle/object"
|
15
17
|
|
@@ -50,6 +52,7 @@ module Paddle
|
|
50
52
|
autoload :Client, "paddle/classic/client"
|
51
53
|
autoload :Collection, "paddle/classic/collection"
|
52
54
|
autoload :Resource, "paddle/classic/resource"
|
55
|
+
autoload :Error, "paddle/classic/error"
|
53
56
|
|
54
57
|
autoload :PlansResource, "paddle/classic/resources/plans"
|
55
58
|
autoload :CouponsResource, "paddle/classic/resources/coupons"
|
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.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Perry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/paddle.rb
|
43
43
|
- lib/paddle/classic/client.rb
|
44
44
|
- lib/paddle/classic/collection.rb
|
45
|
+
- lib/paddle/classic/error.rb
|
45
46
|
- lib/paddle/classic/objects/charge.rb
|
46
47
|
- lib/paddle/classic/objects/coupon.rb
|
47
48
|
- lib/paddle/classic/objects/license.rb
|
@@ -70,6 +71,7 @@ files:
|
|
70
71
|
- lib/paddle/collection.rb
|
71
72
|
- lib/paddle/configuration.rb
|
72
73
|
- lib/paddle/error.rb
|
74
|
+
- lib/paddle/error_generator.rb
|
73
75
|
- lib/paddle/models/address.rb
|
74
76
|
- lib/paddle/models/adjustment.rb
|
75
77
|
- lib/paddle/models/business.rb
|
@@ -110,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
112
|
- !ruby/object:Gem::Version
|
111
113
|
version: '0'
|
112
114
|
requirements: []
|
113
|
-
rubygems_version: 3.5.
|
115
|
+
rubygems_version: 3.5.11
|
114
116
|
signing_key:
|
115
117
|
specification_version: 4
|
116
118
|
summary: Ruby library for the Paddle Billing & Classic APIs
|