paddle 1.0.0 → 1.1.0

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 (71) 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 +402 -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/product.rb +30 -0
  51. data/lib/paddle/models/subscription.rb +56 -0
  52. data/lib/paddle/models/transaction.rb +49 -0
  53. data/lib/paddle/object.rb +19 -0
  54. data/lib/paddle/version.rb +5 -0
  55. data/lib/paddle.rb +72 -5
  56. data/paddle.gemspec +30 -0
  57. metadata +99 -124
  58. data/.autotest +0 -23
  59. data/CHANGELOG.rdoc +0 -6
  60. data/Manifest.txt +0 -16
  61. data/README.rdoc +0 -62
  62. data/lib/images/ruby.png +0 -0
  63. data/lib/rdoc/discover.rb +0 -1
  64. data/lib/rdoc/generator/paddle.rb +0 -144
  65. data/lib/templates/classfile.html.erb +0 -115
  66. data/lib/templates/container.xml +0 -7
  67. data/lib/templates/content.opf.erb +0 -34
  68. data/lib/templates/cover.html.erb +0 -18
  69. data/lib/templates/title.html.erb +0 -18
  70. data/lib/templates/toc.ncx.erb +0 -36
  71. data/test/test_paddle.rb +0 -13
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca5a8b764dae4b1f902067e833058202619cb5b514fbc104016d2d5e78f01313
4
+ data.tar.gz: 82c63035a66315b0891bd76c49e72d6405866f86139e7538c85e001af1d73563
5
+ SHA512:
6
+ metadata.gz: 193a39db9033fff5e87af49e15fa42ca6945efbb8e8a65779c8e47140c2e6c517547d54d260795f71f0f681a74d32de5047d48c8be97535cee15724f968bfec6
7
+ data.tar.gz: 88414b3354d28ac9924e8e36c644136366aeede634aa779e875f86aa52866aa420cd12967d10ad0f18ff301061496a8c70ff6588bc1de381d28d0c27d5e336ec
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.0)
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,402 @@
1
+ # PaddleRB
2
+
3
+ PaddleRB is a Ruby library for interacting with the Paddle APIs, both Classic and Billing.
4
+
5
+ **This library is currently under development for Paddle's new Billing APIs**
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "paddlerb"
13
+ ```
14
+
15
+ ## Billing API
16
+
17
+ For accessing the new Billing API from Paddle. For more info, view the [Paddle Billing](https://www.paddle.com/billing) page.
18
+
19
+ ### Configuration
20
+
21
+ Firstly you'll need to generate and set your API Key and the environment.
22
+
23
+ You can find and generate an API key [here for production](https://vendors.paddle.com/authentication),
24
+ or [here for sandbox](https://sandbox-vendors.paddle.com/authentication)
25
+
26
+ ```ruby
27
+ Paddle.configure do |config|
28
+ # Use :development or :sandbox for the Sandbox API
29
+ # Or use :production for the Production API
30
+ config.environment = :sandbox
31
+ config.api_key = ENV["PADDLE_API_KEY"]
32
+ end
33
+ ```
34
+
35
+ ### Products
36
+
37
+ ```ruby
38
+ # List all products
39
+ # https://developer.paddle.com/api-reference/products/list-products
40
+ Paddle::Product.list
41
+ Paddle::Product.list(status: "active")
42
+ Paddle::Product.list(status: "archived")
43
+ Paddle::Product.list(tax_category: "saas")
44
+
45
+ # Create a product
46
+ # https://developer.paddle.com/api-reference/products/create-product
47
+ Paddle::Product.create(name: "My SAAS Plan", tax_category: "saas")
48
+ Paddle::Product.create(name: "My Standard Product", tax_category: "standard")
49
+
50
+ # Retrieve a product
51
+ Paddle::Product.retrieve(id: "pro_abc123")
52
+
53
+ # Update a product
54
+ # https://developer.paddle.com/api-reference/products/update-product
55
+ Paddle::Product.update(id: "pro_abc123", description: "This is a plan")
56
+ ```
57
+
58
+ ### Prices
59
+
60
+ ```ruby
61
+ # List all prices
62
+ # https://developer.paddle.com/api-reference/prices/list-prices
63
+ Paddle::Price.list
64
+ Paddle::Price.list(status: "active")
65
+ Paddle::Price.list(status: "archived")
66
+ Paddle::Price.list(product_id: "pro_abc123")
67
+
68
+ # Create a price
69
+ # Note that unit_price amount should be a string
70
+ # https://developer.paddle.com/api-reference/prices/create-price
71
+ Paddle::Price.create(product_id: "pro_abc123", description: "A one off price", amount: "1000", currency: "GBP")
72
+
73
+ # Retrieve a price
74
+ Paddle::Price.retrieve(id: "pri_123abc")
75
+
76
+ # Update a price
77
+ # https://developer.paddle.com/api-reference/prices/update-price
78
+ Paddle::Price.update(id: "pri_123abc", description: "An updated description")
79
+ ```
80
+
81
+ ### Discounts
82
+
83
+ ```ruby
84
+ # List all discounts
85
+ # https://developer.paddle.com/api-reference/discounts/list-discounts
86
+ Paddle::Discount.list
87
+ Paddle::Discount.list(status: "active")
88
+
89
+ # Create a discount
90
+ # Note that amount should be a string
91
+ # https://developer.paddle.com/api-reference/discounts/create-discount
92
+ Paddle::Discount.create(description: "$5 off", type: "flat", amount: "500", currency_code: "USD")
93
+ Paddle::Discount.create(description: "10% Off", type: "percentage", amount: "10", code: "10OFF")
94
+
95
+ # Retrieve a discount
96
+ Paddle::Discount.retrieve(id: "dsc_abc123")
97
+
98
+ # Update a discount
99
+ # https://developer.paddle.com/api-reference/discounts/update-discount
100
+ Paddle::Discount.update(id: "dsc_abc123", description: "An updated description")
101
+ ```
102
+
103
+ ### Customers
104
+
105
+ ```ruby
106
+ # List all customers
107
+ # https://developer.paddle.com/api-reference/customers/list-customers
108
+ Paddle::Customer.list
109
+ Paddle::Customer.list(status: "active")
110
+
111
+ # Create a customer
112
+ # https://developer.paddle.com/api-reference/customers/create-customer
113
+ Paddle::Customer.create(email: "myemail@mydomain.com", name: "Customer Name")
114
+
115
+ # Retrieve a customer
116
+ Paddle::Customer.retrieve(id: "ctm_abc123")
117
+
118
+ # Update a customer
119
+ # https://developer.paddle.com/api-reference/customers/update-customer
120
+ Paddle::Customer.update(id: "ctm_abc123", status: "archived")
121
+ ```
122
+
123
+ ### Addresses
124
+
125
+ ```ruby
126
+ # List all addresses for a customer
127
+ # https://developer.paddle.com/api-reference/addresses/list-addresses
128
+ Paddle::Address.list(customer: "ctm_abc123")
129
+
130
+ # Create an address
131
+ # https://developer.paddle.com/api-reference/addresses/create-address
132
+ Paddle::Address.create(customer: "ctm_abc123", country_code: "GB", postal_code: "SW1A 2AA")
133
+
134
+ # Retrieve an address
135
+ Paddle::Address.retrieve(customer: "ctm_abc123", id: "add_abc123")
136
+
137
+ # Update an address
138
+ # https://developer.paddle.com/api-reference/addresses/update-address
139
+ Paddle::Address.update(customer: "ctm_abc123", id: "add_abc123", status: "archived")
140
+ ```
141
+
142
+ ### Businesses
143
+
144
+ ```ruby
145
+ # List all businesses for a customer
146
+ # https://developer.paddle.com/api-reference/businesses/list-businesses
147
+ Paddle::Business.list(customer: "ctm_abc123")
148
+
149
+ # Create a business
150
+ # https://developer.paddle.com/api-reference/businesses/create-business
151
+ Paddle::Business.create(customer: "ctm_abc123", name: "My Ltd Company")
152
+
153
+ # Retrieve a business
154
+ Paddle::Business.retrieve(customer: "ctm_abc123", id: "biz_abc123")
155
+
156
+ # Update a business
157
+ # https://developer.paddle.com/api-reference/businesses/update-business
158
+ Paddle::Business.update(customer: "ctm_abc123", id: "biz_abc123", status: "archived")
159
+ ```
160
+
161
+ ### Transactions
162
+
163
+ ```ruby
164
+ # List all transactions
165
+ # https://developer.paddle.com/api-reference/transactions/list-transactions
166
+ Paddle::Transaction.list(customer_id: "ctm_abc123")
167
+ Paddle::Transaction.list(subscription_id: "sub_abc123")
168
+ Paddle::Transaction.list(status: "completed")
169
+
170
+ # Create a transaction
171
+ # https://developer.paddle.com/api-reference/transactions/create-transaction
172
+ Paddle::Transaction.create(items: [ { price_id: "pri_abc123", quantity: 1 } ])
173
+
174
+ # Retrieve a transaction
175
+ Paddle::Transaction.retrieve(id: "txn_abc123")
176
+
177
+ # Update a transaction
178
+ # https://developer.paddle.com/api-reference/transaction/update-transaction
179
+ Paddle::Transaction.update(id: "txn_abc123", items: [ { price_id: "pri_abc123", quantity: 2 } ])
180
+
181
+ # Preview a transaction
182
+ # https://developer.paddle.com/api-reference/transaction/preview-transaction
183
+ Paddle::Transaction.preview(items: [ { price_id: "pri_123abc", quantity: 5 } ])
184
+
185
+ # Preview calculations for one or more prices
186
+ # This is normally used when building pricing pages
187
+ # https://developer.paddle.com/api-reference/transaction/preview-prices
188
+ Paddle::Transaction.preview_prices(items: [ { price_id: "pri_123abc", quantity: 5 } ])
189
+ Paddle::Transaction.preview_prices(items: [ { price_id: "pri_123abc", quantity: 5 } ], currency_code: "GBP")
190
+ Paddle::Transaction.preview_prices(items: [ { price_id: "pri_123abc", quantity: 5 } ], customer_ip_address: "1.1.1.1")
191
+
192
+ # Get a PDF invoice for a transaction
193
+ # Returns a raw URL. This URL is not permanent and will expire.
194
+ # https://developer.paddle.com/api-reference/transaction/get-invoice-pdf
195
+ Paddle::Transaction.invoice(id: "txn_abc123")
196
+ #=> https://paddle-sandbox-invoice...
197
+ ```
198
+
199
+ ### Subscriptions
200
+
201
+ ```ruby
202
+ # List all subscriptions
203
+ # https://developer.paddle.com/api-reference/subscriptions/list-subscriptions
204
+ Paddle::Subscription.list(customer_id: "ctm_abc123")
205
+ Paddle::Subscription.list(price_id: "pri_abc123")
206
+ Paddle::Subscription.list(status: "active")
207
+ Paddle::Subscription.list(status: "canceled")
208
+
209
+ # Retrieve a subscription
210
+ Paddle::Subscription.retrieve(id: "sub_abc123")
211
+
212
+ # Preview an update to a subscription
213
+ # https://developer.paddle.com/api-reference/subscriptions/preview-subscription
214
+ Paddle::Subscription.preview(id: "sub_abc123", items: [ { price_id: "pri_123abc", quantity: 2 } ])
215
+
216
+ # Update a subscription
217
+ # https://developer.paddle.com/api-reference/subscriptions/update-subscription
218
+ Paddle::Subscription.update(id: "sub_abc123", billing_details: {purchase_order_number: "PO-1234"})
219
+
220
+ # Get a transaction to update payment method
221
+ # https://developer.paddle.com/api-reference/subscriptions/update-payment-method
222
+ Paddle::Subscription.get_transaction(id: "sub_abc123")
223
+
224
+ # Create a one-time charge for a subscription
225
+ # https://developer.paddle.com/api-reference/subscriptions/create-one-time-charge
226
+ Paddle::Subscription.charge(id: "sub_abc123", items: [ { price_id: "pri_123abc", quantity: 2 } ], effective_from: "immediately")
227
+
228
+ # Pause a subscription
229
+ # https://developer.paddle.com/api-reference/subscriptions/pause-subscription
230
+ Paddle::Subscription.pause(id: "sub_abc123")
231
+ Paddle::Subscription.pause(id: "sub_abc123", effective_from: "next_billing_period")
232
+
233
+ # Resume a paused subscription
234
+ # https://developer.paddle.com/api-reference/subscriptions/resume-subscription
235
+ Paddle::Subscription.resume(id: "sub_abc123", effective_from: "next_billing_period")
236
+
237
+ # Cancel a subscription
238
+ # https://developer.paddle.com/api-reference/subscriptions/cancel-subscription
239
+ Paddle::Subscription.cancel(id: "sub_abc123", effective_from: "next_billing_period")
240
+ ```
241
+
242
+ ### Adjustments
243
+
244
+ ```ruby
245
+ # List all adjustments
246
+ # https://developer.paddle.com/api-reference/adjustments/list-adjustments
247
+ Paddle::Adjustment.list(subscription_id: "sub_abc123")
248
+ Paddle::Adjustment.list(transaction_id: "txn_abc123")
249
+ Paddle::Adjustment.list(action: "refund")
250
+
251
+ # Create an adjustment
252
+ # https://developer.paddle.com/api-reference/adjustments/create-adjustment
253
+ Paddle::Adjustment.create(
254
+ action: "refund",
255
+ transaction_id: "txn_abc123",
256
+ reason: "Requested by customer",
257
+ items: [
258
+ {
259
+ type: "full",
260
+ item_id: "txnitm_anc123"
261
+ }
262
+ ]
263
+ )
264
+ ```
265
+
266
+ ### Event Types
267
+
268
+ ```ruby
269
+ # List all event types
270
+ Paddle::EventType.list
271
+ ```
272
+
273
+ ### Events
274
+
275
+ ```ruby
276
+ # List all events
277
+ # https://developer.paddle.com/api-reference/events/list-events
278
+ Paddle::Event.list
279
+ ```
280
+
281
+ ### Notification Settings
282
+
283
+ Used for creating webhook and email notifications
284
+
285
+ ```ruby
286
+ # List all notification settings
287
+ Paddle::NotificationSetting.list
288
+
289
+ # Retrieve a notification setting
290
+ Paddle::NotificationSetting.retrieve(id: "ntfset_abc123")
291
+
292
+ # Create a notification setting
293
+ # https://developer.paddle.com/api-reference/notification-settings/create-notification-setting
294
+ Paddle::NotificationSetting.create(
295
+ description: "Webhook for App",
296
+ destination: "https://myapp.com/webhook",
297
+ type: "webhook",
298
+ subscribed_events: [
299
+ "subscription.activated",
300
+ "transaction.completed"
301
+ ]
302
+ )
303
+
304
+ # Update a notification setting
305
+ # https://developer.paddle.com/api-reference/notification-settings/update-notification-setting
306
+ Paddle::NotificationSetting.update(id: "ntfset_abc123",
307
+ subscribed_events: [
308
+ "subscription.activated",
309
+ "transaction.completed",
310
+ "transaction.billed"
311
+ ]
312
+ )
313
+
314
+ # Delete a notification setting
315
+ Paddle::NotificationSetting.delete(id: "ntfset_abc123")
316
+ ```
317
+
318
+ ### Notifications
319
+
320
+ ```ruby
321
+ # List all notifications
322
+ Paddle::Notification.list
323
+ Paddle::Notification.list(notification_setting_id: "ntfset_abc123")
324
+ Paddle::Notification.list(status: "delivered")
325
+ Paddle::Notification.list(status: "failed")
326
+
327
+ # Retrieve a notification
328
+ Paddle::Notification.retrieve(id: "ntf_abc123")
329
+
330
+ # Replay a notification
331
+ # Attempts to resend a notification
332
+ # (currently not working)
333
+ Paddle::Notification.replay(id: "ntf_abc123")
334
+
335
+ # List all logs for a notification
336
+ # https://developer.paddle.com/api-reference/notifications/list-notification-logs
337
+ Paddle::Notification.logs(id: "ntf_abc123")
338
+ ```
339
+
340
+
341
+ ## Classic API
342
+
343
+ For accessing the Paddle Classic API
344
+
345
+ ### Set Client Details
346
+
347
+ Firstly you'll need to set your Vendor ID, Vendor Auth Code and if you want
348
+ to use the Sandbox API or not.
349
+
350
+ You can find your vendor details [here for production](https://vendors.paddle.com/authentication),
351
+ or [here for sandbox](https://sandbox-vendors.paddle.com/authentication)
352
+
353
+ ```ruby
354
+ @client = Paddle::Classic::Client.new(
355
+ vendor_id: "",
356
+ vendor_auth_code: "",
357
+ # Use the sandbox version of the API
358
+ sandbox: true
359
+ )
360
+ ```
361
+
362
+ ### Plans
363
+
364
+ ```ruby
365
+ # Retrieves a list of Plans
366
+ @client.plans.list
367
+ ```
368
+
369
+ ### Subscription Users
370
+
371
+ ```ruby
372
+ # List all users subscribed to any plan
373
+ @client.users.list
374
+ @client.users.list(subscription_id: "abc123")
375
+ @client.users.list(plan_id: "abc123")
376
+ @client.users.list(state: "active")
377
+ @client.users.list(state: "deleted")
378
+
379
+ # Update a user's subscription
380
+ # https://developer.paddle.com/api-reference/e3872343dfbba-update-user
381
+ @client.users.update(subscription_id: "abc123")
382
+
383
+ # Pause a user's subscription
384
+ @client.users.pause(subscription_id: "abc123")
385
+
386
+ # Unpause a user's subscription
387
+ @client.users.unpause(subscription_id: "abc123")
388
+
389
+ # Update the Postcode/ZIP Code of a user's subscription
390
+ @client.users.update_postcode(subscription_id: "abc123", postcode: "123abc")
391
+
392
+ # Cancel a user's subscription
393
+ @client.users.cancel(subscription_id: "abc123")
394
+ ```
395
+
396
+ ## Contributing
397
+
398
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/paddlerb.
399
+
400
+ ## License
401
+
402
+ 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