paddle 1.0.0 → 1.1.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 (72) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +3 -0
  3. data/Gemfile +13 -0
  4. data/Gemfile.lock +31 -0
  5. data/README.md +404 -0
  6. data/Rakefile +8 -10
  7. data/bin/console +25 -0
  8. data/bin/setup +8 -0
  9. data/lib/paddle/classic/client.rb +87 -0
  10. data/lib/paddle/classic/collection.rb +29 -0
  11. data/lib/paddle/classic/objects/charge.rb +6 -0
  12. data/lib/paddle/classic/objects/coupon.rb +6 -0
  13. data/lib/paddle/classic/objects/license.rb +6 -0
  14. data/lib/paddle/classic/objects/modifier.rb +6 -0
  15. data/lib/paddle/classic/objects/pay_link.rb +6 -0
  16. data/lib/paddle/classic/objects/payment.rb +6 -0
  17. data/lib/paddle/classic/objects/payment_refund.rb +6 -0
  18. data/lib/paddle/classic/objects/plan.rb +6 -0
  19. data/lib/paddle/classic/objects/product.rb +6 -0
  20. data/lib/paddle/classic/objects/transaction.rb +6 -0
  21. data/lib/paddle/classic/objects/user.rb +6 -0
  22. data/lib/paddle/classic/objects/webhook.rb +6 -0
  23. data/lib/paddle/classic/resource.rb +63 -0
  24. data/lib/paddle/classic/resources/charges.rb +13 -0
  25. data/lib/paddle/classic/resources/coupons.rb +33 -0
  26. data/lib/paddle/classic/resources/licenses.rb +15 -0
  27. data/lib/paddle/classic/resources/modifiers.rb +26 -0
  28. data/lib/paddle/classic/resources/pay_links.rb +13 -0
  29. data/lib/paddle/classic/resources/payments.rb +24 -0
  30. data/lib/paddle/classic/resources/plans.rb +21 -0
  31. data/lib/paddle/classic/resources/products.rb +12 -0
  32. data/lib/paddle/classic/resources/transactions.rb +12 -0
  33. data/lib/paddle/classic/resources/users.rb +42 -0
  34. data/lib/paddle/classic/resources/webhooks.rb +12 -0
  35. data/lib/paddle/client.rb +71 -0
  36. data/lib/paddle/collection.rb +27 -0
  37. data/lib/paddle/configuration.rb +32 -0
  38. data/lib/paddle/error.rb +4 -0
  39. data/lib/paddle/models/address.rb +30 -0
  40. data/lib/paddle/models/adjustment.rb +20 -0
  41. data/lib/paddle/models/business.rb +30 -0
  42. data/lib/paddle/models/customer.rb +30 -0
  43. data/lib/paddle/models/discount.rb +30 -0
  44. data/lib/paddle/models/event.rb +14 -0
  45. data/lib/paddle/models/event_type.rb +14 -0
  46. data/lib/paddle/models/notification.rb +30 -0
  47. data/lib/paddle/models/notification_log.rb +4 -0
  48. data/lib/paddle/models/notification_setting.rb +34 -0
  49. data/lib/paddle/models/price.rb +30 -0
  50. data/lib/paddle/models/pricing_preview.rb +15 -0
  51. data/lib/paddle/models/product.rb +30 -0
  52. data/lib/paddle/models/subscription.rb +56 -0
  53. data/lib/paddle/models/transaction.rb +43 -0
  54. data/lib/paddle/object.rb +19 -0
  55. data/lib/paddle/version.rb +5 -0
  56. data/lib/paddle.rb +73 -5
  57. data/paddle.gemspec +30 -0
  58. metadata +100 -124
  59. data/.autotest +0 -23
  60. data/CHANGELOG.rdoc +0 -6
  61. data/Manifest.txt +0 -16
  62. data/README.rdoc +0 -62
  63. data/lib/images/ruby.png +0 -0
  64. data/lib/rdoc/discover.rb +0 -1
  65. data/lib/rdoc/generator/paddle.rb +0 -144
  66. data/lib/templates/classfile.html.erb +0 -115
  67. data/lib/templates/container.xml +0 -7
  68. data/lib/templates/content.opf.erb +0 -34
  69. data/lib/templates/cover.html.erb +0 -18
  70. data/lib/templates/title.html.erb +0 -18
  71. data/lib/templates/toc.ncx.erb +0 -36
  72. data/test/test_paddle.rb +0 -13
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1f17be832d6c5c21fb071570a91e66cf9c30116bd4694e23e35bc0199aded923
4
+ data.tar.gz: 47a9ba8faf8b325d857aaff5d32a48176ba3fe95d72591a60cb0d16d224e128a
5
+ SHA512:
6
+ metadata.gz: 116f5798eefa20051a10a8dc290d0a9232e87d7b7d34dc9948669e8a65b789e5d784d4e795f19d9a0f6e39689bb59ca5d5781ecae83ecff880d56c2a2f354b9f
7
+ data.tar.gz: c91e17cca641255461e001d3487ba8459fc355308a49b7b1890dc7a6c7843d8336a4dc46ec651b2b95d8339cc73cbb7f5bd3118300f6d56be377f782b97b9134
data/.env.example ADDED
@@ -0,0 +1,3 @@
1
+ PADDLE_VENDOR_ID=
2
+ PADDLE_VENDOR_AUTH_CODE=
3
+ PADDLE_API_KEY=
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in paddle.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+ gem "dotenv"
12
+
13
+ gem "vcr"
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ paddle (1.1.1)
5
+ faraday (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ dotenv (2.7.6)
11
+ faraday (2.7.10)
12
+ faraday-net_http (>= 2.0, < 3.1)
13
+ ruby2_keywords (>= 0.0.4)
14
+ faraday-net_http (3.0.2)
15
+ minitest (5.19.0)
16
+ rake (13.0.6)
17
+ ruby2_keywords (0.0.5)
18
+ vcr (6.2.0)
19
+
20
+ PLATFORMS
21
+ x86_64-linux
22
+
23
+ DEPENDENCIES
24
+ dotenv
25
+ minitest (~> 5.0)
26
+ paddle!
27
+ rake (~> 13.0)
28
+ vcr
29
+
30
+ BUNDLED WITH
31
+ 2.3.22
data/README.md ADDED
@@ -0,0 +1,404 @@
1
+ # Paddle Ruby Library
2
+
3
+ A Ruby library for the Paddle APIs, both Classic and Billing.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "paddle"
11
+ ```
12
+
13
+ ## Billing API
14
+
15
+ For accessing the new Billing API from Paddle. For more info, view the [Paddle Billing](https://www.paddle.com/billing) page.
16
+
17
+ ### Configuration
18
+
19
+ Firstly you'll need to generate and set your API Key and the environment.
20
+
21
+ You can find and generate an API key [here for production](https://vendors.paddle.com/authentication),
22
+ or [here for sandbox](https://sandbox-vendors.paddle.com/authentication)
23
+
24
+ ```ruby
25
+ Paddle.configure do |config|
26
+ # Use :development or :sandbox for the Sandbox API
27
+ # Or use :production for the Production API
28
+ config.environment = :sandbox
29
+ config.api_key = ENV["PADDLE_API_KEY"]
30
+ end
31
+ ```
32
+
33
+ ### Products
34
+
35
+ ```ruby
36
+ # List all products
37
+ # https://developer.paddle.com/api-reference/products/list-products
38
+ Paddle::Product.list
39
+ Paddle::Product.list(status: "active")
40
+ Paddle::Product.list(status: "archived")
41
+ Paddle::Product.list(tax_category: "saas")
42
+
43
+ # Create a product
44
+ # https://developer.paddle.com/api-reference/products/create-product
45
+ Paddle::Product.create(name: "My SAAS Plan", tax_category: "saas")
46
+ Paddle::Product.create(name: "My Standard Product", tax_category: "standard")
47
+
48
+ # Retrieve a product
49
+ Paddle::Product.retrieve(id: "pro_abc123")
50
+
51
+ # Update a product
52
+ # https://developer.paddle.com/api-reference/products/update-product
53
+ Paddle::Product.update(id: "pro_abc123", description: "This is a plan")
54
+ ```
55
+
56
+ ### Prices
57
+
58
+ ```ruby
59
+ # List all prices
60
+ # https://developer.paddle.com/api-reference/prices/list-prices
61
+ Paddle::Price.list
62
+ Paddle::Price.list(status: "active")
63
+ Paddle::Price.list(status: "archived")
64
+ Paddle::Price.list(product_id: "pro_abc123")
65
+
66
+ # Create a price
67
+ # Note that unit_price amount should be a string
68
+ # https://developer.paddle.com/api-reference/prices/create-price
69
+ Paddle::Price.create(product_id: "pro_abc123", description: "A one off price", amount: "1000", currency: "GBP")
70
+
71
+ # Retrieve a price
72
+ Paddle::Price.retrieve(id: "pri_123abc")
73
+
74
+ # Update a price
75
+ # https://developer.paddle.com/api-reference/prices/update-price
76
+ Paddle::Price.update(id: "pri_123abc", description: "An updated description")
77
+ ```
78
+
79
+ ### Pricing Preview
80
+
81
+ ```ruby
82
+ # Preview calculations for one or more prices
83
+ # This is normally used when building pricing pages
84
+ # https://developer.paddle.com/api-reference/pricing-preview/preview-prices
85
+ Paddle::PricingPreview.generate(items: [ { price_id: "pri_123abc", quantity: 5 } ])
86
+ Paddle::PricingPreview.generate(items: [ { price_id: "pri_123abc", quantity: 5 } ], currency_code: "GBP")
87
+ Paddle::PricingPreview.generate(items: [ { price_id: "pri_123abc", quantity: 5 } ], customer_ip_address: "1.1.1.1")
88
+ ```
89
+
90
+ ### Discounts
91
+
92
+ ```ruby
93
+ # List all discounts
94
+ # https://developer.paddle.com/api-reference/discounts/list-discounts
95
+ Paddle::Discount.list
96
+ Paddle::Discount.list(status: "active")
97
+
98
+ # Create a discount
99
+ # Note that amount should be a string
100
+ # https://developer.paddle.com/api-reference/discounts/create-discount
101
+ Paddle::Discount.create(description: "$5 off", type: "flat", amount: "500", currency_code: "USD")
102
+ Paddle::Discount.create(description: "10% Off", type: "percentage", amount: "10", code: "10OFF")
103
+
104
+ # Retrieve a discount
105
+ Paddle::Discount.retrieve(id: "dsc_abc123")
106
+
107
+ # Update a discount
108
+ # https://developer.paddle.com/api-reference/discounts/update-discount
109
+ Paddle::Discount.update(id: "dsc_abc123", description: "An updated description")
110
+ ```
111
+
112
+ ### Customers
113
+
114
+ ```ruby
115
+ # List all customers
116
+ # https://developer.paddle.com/api-reference/customers/list-customers
117
+ Paddle::Customer.list
118
+ Paddle::Customer.list(status: "active")
119
+
120
+ # Create a customer
121
+ # https://developer.paddle.com/api-reference/customers/create-customer
122
+ Paddle::Customer.create(email: "myemail@mydomain.com", name: "Customer Name")
123
+
124
+ # Retrieve a customer
125
+ Paddle::Customer.retrieve(id: "ctm_abc123")
126
+
127
+ # Update a customer
128
+ # https://developer.paddle.com/api-reference/customers/update-customer
129
+ Paddle::Customer.update(id: "ctm_abc123", status: "archived")
130
+ ```
131
+
132
+ ### Addresses
133
+
134
+ ```ruby
135
+ # List all addresses for a customer
136
+ # https://developer.paddle.com/api-reference/addresses/list-addresses
137
+ Paddle::Address.list(customer: "ctm_abc123")
138
+
139
+ # Create an address
140
+ # https://developer.paddle.com/api-reference/addresses/create-address
141
+ Paddle::Address.create(customer: "ctm_abc123", country_code: "GB", postal_code: "SW1A 2AA")
142
+
143
+ # Retrieve an address
144
+ Paddle::Address.retrieve(customer: "ctm_abc123", id: "add_abc123")
145
+
146
+ # Update an address
147
+ # https://developer.paddle.com/api-reference/addresses/update-address
148
+ Paddle::Address.update(customer: "ctm_abc123", id: "add_abc123", status: "archived")
149
+ ```
150
+
151
+ ### Businesses
152
+
153
+ ```ruby
154
+ # List all businesses for a customer
155
+ # https://developer.paddle.com/api-reference/businesses/list-businesses
156
+ Paddle::Business.list(customer: "ctm_abc123")
157
+
158
+ # Create a business
159
+ # https://developer.paddle.com/api-reference/businesses/create-business
160
+ Paddle::Business.create(customer: "ctm_abc123", name: "My Ltd Company")
161
+
162
+ # Retrieve a business
163
+ Paddle::Business.retrieve(customer: "ctm_abc123", id: "biz_abc123")
164
+
165
+ # Update a business
166
+ # https://developer.paddle.com/api-reference/businesses/update-business
167
+ Paddle::Business.update(customer: "ctm_abc123", id: "biz_abc123", status: "archived")
168
+ ```
169
+
170
+ ### Transactions
171
+
172
+ ```ruby
173
+ # List all transactions
174
+ # https://developer.paddle.com/api-reference/transactions/list-transactions
175
+ Paddle::Transaction.list(customer_id: "ctm_abc123")
176
+ Paddle::Transaction.list(subscription_id: "sub_abc123")
177
+ Paddle::Transaction.list(status: "completed")
178
+
179
+ # Create a transaction
180
+ # https://developer.paddle.com/api-reference/transactions/create-transaction
181
+ Paddle::Transaction.create(items: [ { price_id: "pri_abc123", quantity: 1 } ])
182
+
183
+ # Retrieve a transaction
184
+ Paddle::Transaction.retrieve(id: "txn_abc123")
185
+
186
+ # Update a transaction
187
+ # https://developer.paddle.com/api-reference/transaction/update-transaction
188
+ Paddle::Transaction.update(id: "txn_abc123", items: [ { price_id: "pri_abc123", quantity: 2 } ])
189
+
190
+ # Preview a transaction
191
+ # https://developer.paddle.com/api-reference/transaction/preview-transaction
192
+ Paddle::Transaction.preview(items: [ { price_id: "pri_123abc", quantity: 5 } ])
193
+
194
+ # Get a PDF invoice for a transaction
195
+ # Returns a raw URL. This URL is not permanent and will expire.
196
+ # https://developer.paddle.com/api-reference/transaction/get-invoice-pdf
197
+ Paddle::Transaction.invoice(id: "txn_abc123")
198
+ #=> https://paddle-sandbox-invoice...
199
+ ```
200
+
201
+ ### Subscriptions
202
+
203
+ ```ruby
204
+ # List all subscriptions
205
+ # https://developer.paddle.com/api-reference/subscriptions/list-subscriptions
206
+ Paddle::Subscription.list(customer_id: "ctm_abc123")
207
+ Paddle::Subscription.list(price_id: "pri_abc123")
208
+ Paddle::Subscription.list(status: "active")
209
+ Paddle::Subscription.list(status: "canceled")
210
+
211
+ # Retrieve a subscription
212
+ Paddle::Subscription.retrieve(id: "sub_abc123")
213
+
214
+ # Preview an update to a subscription
215
+ # https://developer.paddle.com/api-reference/subscriptions/preview-subscription
216
+ Paddle::Subscription.preview(id: "sub_abc123", items: [ { price_id: "pri_123abc", quantity: 2 } ])
217
+
218
+ # Update a subscription
219
+ # https://developer.paddle.com/api-reference/subscriptions/update-subscription
220
+ Paddle::Subscription.update(id: "sub_abc123", billing_details: {purchase_order_number: "PO-1234"})
221
+
222
+ # Get a transaction to update payment method
223
+ # https://developer.paddle.com/api-reference/subscriptions/update-payment-method
224
+ Paddle::Subscription.get_transaction(id: "sub_abc123")
225
+
226
+ # Create a one-time charge for a subscription
227
+ # https://developer.paddle.com/api-reference/subscriptions/create-one-time-charge
228
+ Paddle::Subscription.charge(id: "sub_abc123", items: [ { price_id: "pri_123abc", quantity: 2 } ], effective_from: "immediately")
229
+
230
+ # Pause a subscription
231
+ # https://developer.paddle.com/api-reference/subscriptions/pause-subscription
232
+ Paddle::Subscription.pause(id: "sub_abc123")
233
+ Paddle::Subscription.pause(id: "sub_abc123", effective_from: "next_billing_period")
234
+
235
+ # Resume a paused subscription
236
+ # https://developer.paddle.com/api-reference/subscriptions/resume-subscription
237
+ Paddle::Subscription.resume(id: "sub_abc123", effective_from: "next_billing_period")
238
+
239
+ # Cancel a subscription
240
+ # https://developer.paddle.com/api-reference/subscriptions/cancel-subscription
241
+ Paddle::Subscription.cancel(id: "sub_abc123", effective_from: "next_billing_period")
242
+ ```
243
+
244
+ ### Adjustments
245
+
246
+ ```ruby
247
+ # List all adjustments
248
+ # https://developer.paddle.com/api-reference/adjustments/list-adjustments
249
+ Paddle::Adjustment.list(subscription_id: "sub_abc123")
250
+ Paddle::Adjustment.list(transaction_id: "txn_abc123")
251
+ Paddle::Adjustment.list(action: "refund")
252
+
253
+ # Create an adjustment
254
+ # https://developer.paddle.com/api-reference/adjustments/create-adjustment
255
+ Paddle::Adjustment.create(
256
+ action: "refund",
257
+ transaction_id: "txn_abc123",
258
+ reason: "Requested by customer",
259
+ items: [
260
+ {
261
+ type: "full",
262
+ item_id: "txnitm_anc123"
263
+ }
264
+ ]
265
+ )
266
+ ```
267
+
268
+ ### Event Types
269
+
270
+ ```ruby
271
+ # List all event types
272
+ Paddle::EventType.list
273
+ ```
274
+
275
+ ### Events
276
+
277
+ ```ruby
278
+ # List all events
279
+ # https://developer.paddle.com/api-reference/events/list-events
280
+ Paddle::Event.list
281
+ ```
282
+
283
+ ### Notification Settings
284
+
285
+ Used for creating webhook and email notifications
286
+
287
+ ```ruby
288
+ # List all notification settings
289
+ Paddle::NotificationSetting.list
290
+
291
+ # Retrieve a notification setting
292
+ Paddle::NotificationSetting.retrieve(id: "ntfset_abc123")
293
+
294
+ # Create a notification setting
295
+ # https://developer.paddle.com/api-reference/notification-settings/create-notification-setting
296
+ Paddle::NotificationSetting.create(
297
+ description: "Webhook for App",
298
+ destination: "https://myapp.com/webhook",
299
+ type: "webhook",
300
+ subscribed_events: [
301
+ "subscription.activated",
302
+ "transaction.completed"
303
+ ]
304
+ )
305
+
306
+ # Update a notification setting
307
+ # https://developer.paddle.com/api-reference/notification-settings/update-notification-setting
308
+ Paddle::NotificationSetting.update(id: "ntfset_abc123",
309
+ subscribed_events: [
310
+ "subscription.activated",
311
+ "transaction.completed",
312
+ "transaction.billed"
313
+ ]
314
+ )
315
+
316
+ # Delete a notification setting
317
+ Paddle::NotificationSetting.delete(id: "ntfset_abc123")
318
+ ```
319
+
320
+ ### Notifications
321
+
322
+ ```ruby
323
+ # List all notifications
324
+ Paddle::Notification.list
325
+ Paddle::Notification.list(notification_setting_id: "ntfset_abc123")
326
+ Paddle::Notification.list(status: "delivered")
327
+ Paddle::Notification.list(status: "failed")
328
+
329
+ # Retrieve a notification
330
+ Paddle::Notification.retrieve(id: "ntf_abc123")
331
+
332
+ # Replay a notification
333
+ # Attempts to resend a notification
334
+ # (currently not working)
335
+ Paddle::Notification.replay(id: "ntf_abc123")
336
+
337
+ # List all logs for a notification
338
+ # https://developer.paddle.com/api-reference/notifications/list-notification-logs
339
+ Paddle::Notification.logs(id: "ntf_abc123")
340
+ ```
341
+
342
+
343
+ ## Classic API
344
+
345
+ For accessing the Paddle Classic API
346
+
347
+ ### Set Client Details
348
+
349
+ Firstly you'll need to set your Vendor ID, Vendor Auth Code and if you want
350
+ to use the Sandbox API or not.
351
+
352
+ You can find your vendor details [here for production](https://vendors.paddle.com/authentication),
353
+ or [here for sandbox](https://sandbox-vendors.paddle.com/authentication)
354
+
355
+ ```ruby
356
+ @client = Paddle::Classic::Client.new(
357
+ vendor_id: "",
358
+ vendor_auth_code: "",
359
+ # Use the sandbox version of the API
360
+ sandbox: true
361
+ )
362
+ ```
363
+
364
+ ### Plans
365
+
366
+ ```ruby
367
+ # Retrieves a list of Plans
368
+ @client.plans.list
369
+ ```
370
+
371
+ ### Subscription Users
372
+
373
+ ```ruby
374
+ # List all users subscribed to any plan
375
+ @client.users.list
376
+ @client.users.list(subscription_id: "abc123")
377
+ @client.users.list(plan_id: "abc123")
378
+ @client.users.list(state: "active")
379
+ @client.users.list(state: "deleted")
380
+
381
+ # Update a user's subscription
382
+ # https://developer.paddle.com/api-reference/e3872343dfbba-update-user
383
+ @client.users.update(subscription_id: "abc123")
384
+
385
+ # Pause a user's subscription
386
+ @client.users.pause(subscription_id: "abc123")
387
+
388
+ # Unpause a user's subscription
389
+ @client.users.unpause(subscription_id: "abc123")
390
+
391
+ # Update the Postcode/ZIP Code of a user's subscription
392
+ @client.users.update_postcode(subscription_id: "abc123", postcode: "123abc")
393
+
394
+ # Cancel a user's subscription
395
+ @client.users.cancel(subscription_id: "abc123")
396
+ ```
397
+
398
+ ## Contributing
399
+
400
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/paddle.
401
+
402
+ ## License
403
+
404
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,14 +1,12 @@
1
- # -*- ruby -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
4
- require 'hoe'
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
5
 
6
- Hoe.spec 'paddle' do
7
- developer('Aaron Patterson', 'aaron@tenderlovemaking.com')
8
- self.readme_file = 'README.rdoc'
9
- self.history_file = 'CHANGELOG.rdoc'
10
- self.extra_rdoc_files = FileList['*.rdoc']
11
- self.extra_deps << ['rdoc', '>= 2.5.3']
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
12
10
  end
13
11
 
14
- # vim: syntax=ruby
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "paddle"
6
+
7
+ # Load environment variables from .env file
8
+ require 'dotenv/load'
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ # (If you use this, don't forget to add pry to your Gemfile!)
14
+ # require "pry"
15
+ # Pry.start
16
+
17
+ @client_classic = Paddle::Classic::Client.new(vendor_id: ENV["PADDLE_VENDOR_ID"], vendor_auth_code: ENV["PADDLE_VENDOR_AUTH_CODE"], sandbox: true)
18
+
19
+ Paddle.configure do |config|
20
+ config.environment = :sandbox
21
+ config.api_key = ENV["PADDLE_API_KEY"]
22
+ end
23
+
24
+ require "irb"
25
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,87 @@
1
+ module Paddle
2
+ module Classic
3
+ class Client
4
+
5
+ BASE_URL = "https://vendors.paddle.com/api"
6
+ SANDBOX_BASE_URL = "https://sandbox-vendors.paddle.com/api"
7
+
8
+ attr_reader :vendor_id, :vendor_auth_code, :sandbox, :adapter
9
+
10
+ def initialize(vendor_id:, vendor_auth_code:, sandbox: false, adapter: Faraday.default_adapter, stubs: nil)
11
+ @vendor_id = vendor_id
12
+ @vendor_auth_code = vendor_auth_code
13
+ @sandbox = sandbox
14
+ @adapter = adapter
15
+
16
+ # Test stubs for requests
17
+ @stubs = stubs
18
+ end
19
+
20
+ def plans
21
+ PlansResource.new(self)
22
+ end
23
+
24
+ def coupons
25
+ CouponsResource.new(self)
26
+ end
27
+
28
+ def products
29
+ ProductsResource.new(self)
30
+ end
31
+
32
+ def licenses
33
+ LicensesResource.new(self)
34
+ end
35
+
36
+ def pay_links
37
+ PayLinksResource.new(self)
38
+ end
39
+
40
+ def transactions
41
+ TransactionsResource.new(self)
42
+ end
43
+
44
+ def payments
45
+ PaymentsResource.new(self)
46
+ end
47
+
48
+ def users
49
+ UsersResource.new(self)
50
+ end
51
+
52
+ def webhooks
53
+ WebhooksResource.new(self)
54
+ end
55
+
56
+ def modifiers
57
+ ModifiersResource.new(self)
58
+ end
59
+
60
+ def charges
61
+ ChargesResource.new(self)
62
+ end
63
+
64
+ def url
65
+ if sandbox == true
66
+ SANDBOX_BASE_URL
67
+ else
68
+ BASE_URL
69
+ end
70
+ end
71
+
72
+ def connection
73
+ @connection ||= Faraday.new(url) do |conn|
74
+ conn.headers = {
75
+ "User-Agent" => "paddlerb/v#{VERSION} (github.com/deanpcmad/paddlerb)"
76
+ }
77
+
78
+ conn.request :json
79
+
80
+ conn.response :json, content_type: "application/json"
81
+
82
+ conn.adapter adapter, @stubs
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,29 @@
1
+ module Paddle
2
+ module Classic
3
+ class Collection
4
+ attr_reader :data, :total
5
+
6
+ def self.from_response(response, type:, key: nil)
7
+ body = response.body
8
+
9
+ if key.is_a?(String)
10
+ data = body["response"][key].map { |attrs| type.new(attrs) }
11
+ total = body["response"]["total"]
12
+ else
13
+ data = body["response"].map { |attrs| type.new(attrs) }
14
+ total = body["response"].count
15
+ end
16
+
17
+ new(
18
+ data: data,
19
+ total: total
20
+ )
21
+ end
22
+
23
+ def initialize(data:, total:)
24
+ @data = data
25
+ @total = total
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ module Paddle
2
+ module Classic
3
+ class Charge < Object
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Paddle
2
+ module Classic
3
+ class Coupon < Object
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Paddle
2
+ module Classic
3
+ class License < Object
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Paddle
2
+ module Classic
3
+ class Modifier < Object
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Paddle
2
+ module Classic
3
+ class PayLink < Object
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Paddle
2
+ module Classic
3
+ class Payment < Object
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Paddle
2
+ module Classic
3
+ class PaymentRefund < Object
4
+ end
5
+ end
6
+ end