paddle_pay 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -2
- data/lib/paddle_pay.rb +23 -23
- data/lib/paddle_pay/configuration.rb +19 -6
- data/lib/paddle_pay/connection.rb +11 -11
- data/lib/paddle_pay/errors/paddle_pay_error.rb +4 -1
- data/lib/paddle_pay/models/alert/webhook.rb +2 -2
- data/lib/paddle_pay/models/product/coupon.rb +12 -12
- data/lib/paddle_pay/models/product/license.rb +2 -2
- data/lib/paddle_pay/models/product/pay_link.rb +2 -2
- data/lib/paddle_pay/models/product/payment.rb +4 -4
- data/lib/paddle_pay/models/product/product.rb +2 -2
- data/lib/paddle_pay/models/subscription/charge.rb +1 -1
- data/lib/paddle_pay/models/subscription/modifier.rb +6 -6
- data/lib/paddle_pay/models/subscription/payment.rb +7 -7
- data/lib/paddle_pay/models/subscription/plan.rb +4 -4
- data/lib/paddle_pay/models/subscription/user.rb +10 -10
- data/lib/paddle_pay/util.rb +6 -6
- data/lib/paddle_pay/version.rb +1 -1
- data/test/spec/paddle_pay/configuration_spec.rb +35 -7
- data/test/spec/paddle_pay/connection_spec.rb +38 -38
- data/test/spec/paddle_pay/models/alert/webhook_spec.rb +9 -13
- data/test/spec/paddle_pay/models/product/coupon_spec.rb +29 -33
- data/test/spec/paddle_pay/models/product/license_spec.rb +8 -8
- data/test/spec/paddle_pay/models/product/pay_link_spec.rb +8 -8
- data/test/spec/paddle_pay/models/product/payment_spec.rb +7 -7
- data/test/spec/paddle_pay/models/product/product_spec.rb +9 -13
- data/test/spec/paddle_pay/models/subscription/charge_spec.rb +8 -8
- data/test/spec/paddle_pay/models/subscription/modifier_spec.rb +17 -21
- data/test/spec/paddle_pay/models/subscription/payment_spec.rb +17 -21
- data/test/spec/paddle_pay/models/subscription/plan_spec.rb +14 -18
- data/test/spec/paddle_pay/models/subscription/user_spec.rb +20 -24
- data/test/spec/paddle_pay/models/transaction/checkout_spec.rb +10 -14
- data/test/spec/paddle_pay/models/transaction/order_spec.rb +10 -14
- data/test/spec/paddle_pay/models/transaction/product_spec.rb +9 -13
- data/test/spec/paddle_pay/models/transaction/subscription_spec.rb +9 -13
- data/test/spec/paddle_pay/models/transaction/user_spec.rb +9 -13
- data/test/spec/paddle_pay/util_spec.rb +19 -19
- data/test/spec/paddle_pay/version_spec.rb +2 -2
- data/test/test_helper.rb +10 -10
- metadata +35 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2c11cc7eda43495df42fa84b9806cca833202178676463725f2b94c9c08f245
|
4
|
+
data.tar.gz: 61061e1fcc1db7c7515bf9a8efd66bd564767843ee82b7ce75568e4d9802269d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc6e6db5f4c96a9731f324c85c5c088013dccd213ccc115eb6ce165d8d9719b929cfd9059dd1222e8b085497091464154c815a13905adc320a114ca94ab7c2c4
|
7
|
+
data.tar.gz: 789a614eeb26dc9ae04420316a9e75e6c396de296aed42b2841f4487d908cea3f72eec5f3c3fc4e5d5fcc2aacc0480be22b47ff1456b6608b253d96fa7275210
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# PaddlePay
|
2
2
|
|
3
|
+
![Tests](https://github.com/devmindo/paddle_pay/workflows/Tests/badge.svg?branch=master)
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/paddle_pay.svg?style=flat)](https://rubygems.org/gems/paddle_pay)
|
5
|
+
|
3
6
|
A Ruby wrapper for the paddle.com API.
|
4
7
|
|
5
8
|
## Installation
|
@@ -18,12 +21,24 @@ And then execute:
|
|
18
21
|
|
19
22
|
Configure the gem with the credentials obtained from the Paddle Dashboard
|
20
23
|
|
24
|
+
### Development
|
21
25
|
```ruby
|
22
26
|
PaddlePay.configure do |config|
|
23
|
-
config.
|
24
|
-
config.
|
27
|
+
config.environment = :development # or :sandbox
|
28
|
+
config.vendor_id = 'YOUR SANDBOX VENDOR ID'
|
29
|
+
config.vendor_auth_code = 'YOUR SANDBOX VENDOR AUTH CODE'
|
25
30
|
end
|
26
31
|
```
|
32
|
+
|
33
|
+
### Production
|
34
|
+
```ruby
|
35
|
+
PaddlePay.configure do |config|
|
36
|
+
config.environment = :production
|
37
|
+
config.vendor_id = 'YOUR PRODUCTION VENDOR ID'
|
38
|
+
config.vendor_auth_code = 'YOUR PRODUCTION VENDOR AUTH CODE'
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
27
42
|
## Usage
|
28
43
|
|
29
44
|
### Product
|
@@ -198,6 +213,10 @@ id = '123456'
|
|
198
213
|
PaddlePay::Transaction::User.list(id, options = {})
|
199
214
|
```
|
200
215
|
|
216
|
+
## Webhooks
|
217
|
+
|
218
|
+
With this gem it is possible to communicate with the Paddle API, but no webhooks are handled. If you want to handle Paddle webhooks in a Ruby on Rails application, please have a look at the [pay gem](https://github.com/pay-rails/pay) where this gem is integrated.
|
219
|
+
|
201
220
|
## Development
|
202
221
|
|
203
222
|
Check out the repository and run `bin/setup` to install dependencies. For configuration run `mv .env.template .env` and set your credentials in the required fields. After that, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt.
|
data/lib/paddle_pay.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "faraday"
|
4
|
+
require "json"
|
5
5
|
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
14
|
-
require_relative
|
15
|
-
require_relative
|
16
|
-
require_relative
|
17
|
-
require_relative
|
18
|
-
require_relative
|
19
|
-
require_relative
|
20
|
-
require_relative
|
21
|
-
require_relative
|
22
|
-
require_relative
|
23
|
-
require_relative
|
24
|
-
require_relative
|
25
|
-
require_relative
|
26
|
-
require_relative
|
6
|
+
require_relative "paddle_pay/configuration"
|
7
|
+
require_relative "paddle_pay/connection"
|
8
|
+
require_relative "paddle_pay/util"
|
9
|
+
require_relative "paddle_pay/version"
|
10
|
+
require_relative "paddle_pay/errors/paddle_pay_error"
|
11
|
+
require_relative "paddle_pay/models/alert/webhook"
|
12
|
+
require_relative "paddle_pay/models/product/coupon"
|
13
|
+
require_relative "paddle_pay/models/product/license"
|
14
|
+
require_relative "paddle_pay/models/product/pay_link"
|
15
|
+
require_relative "paddle_pay/models/product/payment"
|
16
|
+
require_relative "paddle_pay/models/product/product"
|
17
|
+
require_relative "paddle_pay/models/subscription/charge"
|
18
|
+
require_relative "paddle_pay/models/subscription/modifier"
|
19
|
+
require_relative "paddle_pay/models/subscription/payment"
|
20
|
+
require_relative "paddle_pay/models/subscription/plan"
|
21
|
+
require_relative "paddle_pay/models/subscription/user"
|
22
|
+
require_relative "paddle_pay/models/transaction/checkout"
|
23
|
+
require_relative "paddle_pay/models/transaction/order"
|
24
|
+
require_relative "paddle_pay/models/transaction/product"
|
25
|
+
require_relative "paddle_pay/models/transaction/subscription"
|
26
|
+
require_relative "paddle_pay/models/transaction/user"
|
27
27
|
|
28
28
|
module PaddlePay
|
29
29
|
class << self
|
@@ -2,16 +2,29 @@
|
|
2
2
|
|
3
3
|
module PaddlePay
|
4
4
|
class Configuration
|
5
|
-
attr_reader :
|
6
|
-
|
7
|
-
|
5
|
+
attr_reader :environment
|
6
|
+
attr_accessor :vendor_auth_code
|
7
|
+
attr_accessor :vendor_id
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
@
|
10
|
+
@environment ||= :production
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
def environment=(env)
|
14
|
+
env = env.to_sym
|
15
|
+
unless [:development, :sandbox, :production].include?(env)
|
16
|
+
raise ArgumentError, "#{env.inspect} is not a valid environment"
|
17
|
+
end
|
18
|
+
@environment = env
|
19
|
+
end
|
14
20
|
|
15
|
-
|
21
|
+
def vendors_url
|
22
|
+
case @environment
|
23
|
+
when :production
|
24
|
+
"https://vendors.paddle.com/api"
|
25
|
+
when :development, :sandbox
|
26
|
+
"https://sandbox-vendors.paddle.com/api"
|
27
|
+
end
|
28
|
+
end
|
16
29
|
end
|
17
30
|
end
|
@@ -9,23 +9,23 @@ module PaddlePay
|
|
9
9
|
headers = options.delete(:headers) || {}
|
10
10
|
body = options.delete(:body) || {}
|
11
11
|
|
12
|
-
conn = Faraday.new(url: request_url)
|
12
|
+
conn = Faraday.new(url: request_url) { |faraday|
|
13
13
|
faraday.request :url_encoded
|
14
14
|
faraday.response :raise_error
|
15
15
|
faraday.adapter :net_http
|
16
|
-
|
16
|
+
}
|
17
17
|
|
18
18
|
begin
|
19
|
-
response = conn.post(url, config.merge(body))
|
19
|
+
response = conn.post(url, config.merge(body)) { |req|
|
20
20
|
req.params.merge!(params)
|
21
21
|
req.headers.merge!(headers)
|
22
|
-
|
22
|
+
}
|
23
23
|
result = parse(response)
|
24
|
-
unless result[
|
25
|
-
raise PaddlePayError.new(result[
|
24
|
+
unless result["success"]
|
25
|
+
raise PaddlePayError.new(result["error"]["message"], result["error"]["code"])
|
26
26
|
end
|
27
27
|
|
28
|
-
PaddlePay::Util.convert_hash_keys(result[
|
28
|
+
PaddlePay::Util.convert_hash_keys(result["response"])
|
29
29
|
rescue Faraday::BadRequestError => e
|
30
30
|
raise BadRequestError.new(e.response[:body], e.response[:status])
|
31
31
|
rescue Faraday::UnauthorizedError => e
|
@@ -40,10 +40,10 @@ module PaddlePay
|
|
40
40
|
raise ConflictError.new(e.response[:body], e.response[:status])
|
41
41
|
rescue Faraday::UnprocessableEntityError => e
|
42
42
|
raise UnprocessableEntityError.new(e.response[:body], e.response[:status])
|
43
|
-
rescue Faraday::TimeoutError
|
44
|
-
raise TimeoutError,
|
45
|
-
rescue Faraday::ConnectionFailed
|
46
|
-
raise ConnectionError,
|
43
|
+
rescue Faraday::TimeoutError
|
44
|
+
raise TimeoutError, "The connection has timed out"
|
45
|
+
rescue Faraday::ConnectionFailed
|
46
|
+
raise ConnectionError, "The connection failed"
|
47
47
|
rescue Faraday::ServerError => e
|
48
48
|
raise ServerError.new(e.response[:body], e.response[:status])
|
49
49
|
end
|
@@ -7,7 +7,7 @@ module PaddlePay
|
|
7
7
|
attr_reader :message
|
8
8
|
|
9
9
|
def initialize(message, code = nil)
|
10
|
-
super("#{message} #{
|
10
|
+
super("#{message} #{"(Code " + code.to_s + ")" if code}")
|
11
11
|
@code = code
|
12
12
|
@message = message
|
13
13
|
end
|
@@ -37,6 +37,9 @@ module PaddlePay
|
|
37
37
|
class UnprocessableEntityError < ClientError
|
38
38
|
end
|
39
39
|
|
40
|
+
class ArgumentError < ClientError
|
41
|
+
end
|
42
|
+
|
40
43
|
class ServerError < PaddlePayError
|
41
44
|
end
|
42
45
|
|
@@ -5,8 +5,8 @@ module PaddlePay
|
|
5
5
|
module Webhook
|
6
6
|
class << self
|
7
7
|
def history(filters = {}, options = {})
|
8
|
-
options
|
9
|
-
Connection.request(
|
8
|
+
options[:body] = filters if filters.is_a?(::Hash)
|
9
|
+
Connection.request("2.0/alert/webhooks", options)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -5,30 +5,30 @@ module PaddlePay
|
|
5
5
|
module Coupon
|
6
6
|
class << self
|
7
7
|
def list(product_id, options = {})
|
8
|
-
options
|
9
|
-
Connection.request(
|
8
|
+
options[:body] = {product_id: product_id}
|
9
|
+
Connection.request("2.0/product/list_coupons", options)
|
10
10
|
end
|
11
11
|
|
12
12
|
def create(attributes, options = {})
|
13
|
-
options
|
14
|
-
Connection.request(
|
13
|
+
options[:body] = attributes if attributes.is_a?(::Hash)
|
14
|
+
Connection.request("2.1/product/create_coupon", options)
|
15
15
|
end
|
16
16
|
|
17
17
|
def delete(coupon_code, product_id, options = {})
|
18
|
-
options
|
19
|
-
Connection.request(
|
18
|
+
options[:body] = {coupon_code: coupon_code, product_id: product_id}
|
19
|
+
Connection.request("2.0/product/delete_coupon", options)
|
20
20
|
end
|
21
21
|
|
22
22
|
def update_code(coupon_code, attributes = {}, options = {})
|
23
|
-
attributes
|
24
|
-
options
|
25
|
-
Connection.request(
|
23
|
+
attributes[:coupon_code] = coupon_code
|
24
|
+
options[:body] = attributes
|
25
|
+
Connection.request("2.1/product/update_coupon", options)
|
26
26
|
end
|
27
27
|
|
28
28
|
def update_group(group, attributes = {}, options = {})
|
29
|
-
attributes
|
30
|
-
options
|
31
|
-
Connection.request(
|
29
|
+
attributes[:group] = group
|
30
|
+
options[:body] = attributes
|
31
|
+
Connection.request("2.1/product/update_coupon", options)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -5,8 +5,8 @@ module PaddlePay
|
|
5
5
|
module License
|
6
6
|
class << self
|
7
7
|
def generate(attributes, options = {})
|
8
|
-
options
|
9
|
-
Connection.request(
|
8
|
+
options[:body] = attributes if attributes.is_a?(::Hash)
|
9
|
+
Connection.request("2.0/product/generate_license", options)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -5,8 +5,8 @@ module PaddlePay
|
|
5
5
|
module PayLink
|
6
6
|
class << self
|
7
7
|
def generate(attributes, options = {})
|
8
|
-
options
|
9
|
-
Connection.request(
|
8
|
+
options[:body] = attributes if attributes.is_a?(::Hash)
|
9
|
+
Connection.request("2.0/product/generate_pay_link", options)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -5,11 +5,11 @@ module PaddlePay
|
|
5
5
|
module Payment
|
6
6
|
class << self
|
7
7
|
def refund(order_id, attributes = {}, options = {})
|
8
|
-
attributes
|
9
|
-
options
|
10
|
-
Connection.request(
|
8
|
+
attributes[:order_id] = order_id
|
9
|
+
options[:body] = attributes
|
10
|
+
Connection.request("2.0/payment/refund", options)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -4,8 +4,8 @@ module PaddlePay
|
|
4
4
|
module Product
|
5
5
|
class << self
|
6
6
|
def list(filters = {}, options = {})
|
7
|
-
options
|
8
|
-
Connection.request(
|
7
|
+
options[:body] = filters if filters.is_a?(::Hash)
|
8
|
+
Connection.request("2.0/product/get_products", options)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -5,7 +5,7 @@ module PaddlePay
|
|
5
5
|
module Charge
|
6
6
|
class << self
|
7
7
|
def create(subscription_id, amount, charge_name, options = {})
|
8
|
-
options
|
8
|
+
options[:body] = {amount: amount, charge_name: charge_name}
|
9
9
|
Connection.request("2.0/subscription/#{subscription_id}/charge", options)
|
10
10
|
end
|
11
11
|
end
|
@@ -5,18 +5,18 @@ module PaddlePay
|
|
5
5
|
module Modifier
|
6
6
|
class << self
|
7
7
|
def list(filters = {}, options = {})
|
8
|
-
options
|
9
|
-
Connection.request(
|
8
|
+
options[:body] = filters if filters.is_a?(::Hash)
|
9
|
+
Connection.request("2.0/subscription/modifiers", options)
|
10
10
|
end
|
11
11
|
|
12
12
|
def create(attributes, options = {})
|
13
|
-
options
|
14
|
-
Connection.request(
|
13
|
+
options[:body] = attributes if attributes.is_a?(::Hash)
|
14
|
+
Connection.request("2.0/subscription/modifiers/create", options)
|
15
15
|
end
|
16
16
|
|
17
17
|
def delete(modifier_id, options = {})
|
18
|
-
options
|
19
|
-
Connection.request(
|
18
|
+
options[:body] = {modifier_id: modifier_id}
|
19
|
+
Connection.request("2.0/subscription/modifiers/delete", options)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -5,19 +5,19 @@ module PaddlePay
|
|
5
5
|
module Payment
|
6
6
|
class << self
|
7
7
|
def list(filters = {}, options = {})
|
8
|
-
options
|
9
|
-
Connection.request(
|
8
|
+
options[:body] = filters if filters.is_a?(::Hash)
|
9
|
+
Connection.request("2.0/subscription/payments", options)
|
10
10
|
end
|
11
11
|
|
12
12
|
def reschedule(payment_id, date, options = {})
|
13
|
-
options
|
14
|
-
Connection.request(
|
13
|
+
options[:body] = {payment_id: payment_id, date: date}
|
14
|
+
Connection.request("2.0/subscription/payments_reschedule", options)
|
15
15
|
end
|
16
16
|
|
17
17
|
def refund(order_id, attributes = {}, options = {})
|
18
|
-
attributes
|
19
|
-
options
|
20
|
-
Connection.request(
|
18
|
+
attributes[:order_id] = order_id
|
19
|
+
options[:body] = attributes
|
20
|
+
Connection.request("2.0/payment/refund", options)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -5,13 +5,13 @@ module PaddlePay
|
|
5
5
|
module Plan
|
6
6
|
class << self
|
7
7
|
def list(filters = {}, options = {})
|
8
|
-
options
|
9
|
-
Connection.request(
|
8
|
+
options[:body] = filters if filters.is_a?(::Hash)
|
9
|
+
Connection.request("2.0/subscription/plans", options)
|
10
10
|
end
|
11
11
|
|
12
12
|
def create(attributes, options = {})
|
13
|
-
options
|
14
|
-
Connection.request(
|
13
|
+
options[:body] = attributes if attributes.is_a?(::Hash)
|
14
|
+
Connection.request("2.0/subscription/plans_create", options)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -5,25 +5,25 @@ module PaddlePay
|
|
5
5
|
module User
|
6
6
|
class << self
|
7
7
|
def list(filters = {}, options = {})
|
8
|
-
options
|
9
|
-
Connection.request(
|
8
|
+
options[:body] = filters if filters.is_a?(::Hash)
|
9
|
+
Connection.request("2.0/subscription/users", options)
|
10
10
|
end
|
11
11
|
|
12
12
|
def cancel(subscription_id, options = {})
|
13
|
-
options
|
14
|
-
Connection.request(
|
13
|
+
options[:body] = {subscription_id: subscription_id}
|
14
|
+
Connection.request("2.0/subscription/users_cancel", options)
|
15
15
|
end
|
16
16
|
|
17
17
|
def update(subscription_id, attributes = {}, options = {})
|
18
|
-
attributes
|
19
|
-
options
|
20
|
-
Connection.request(
|
18
|
+
attributes[:subscription_id] = subscription_id
|
19
|
+
options[:body] = attributes
|
20
|
+
Connection.request("2.0/subscription/users_update", options)
|
21
21
|
end
|
22
22
|
|
23
23
|
def preview_update(subscription_id, attributes = {}, options = {})
|
24
|
-
attributes
|
25
|
-
options
|
26
|
-
Connection.request(
|
24
|
+
attributes[:subscription_id] = subscription_id
|
25
|
+
options[:body] = attributes
|
26
|
+
Connection.request("2.0/subscription/preview_update", options)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/paddle_pay/util.rb
CHANGED
@@ -15,7 +15,7 @@ module PaddlePay
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def convert_class_to_path(class_name)
|
18
|
-
class_name.split(
|
18
|
+
class_name.split("::").map { |v| to_snake_case(v) }.join("/")
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
@@ -25,11 +25,11 @@ module PaddlePay
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def to_snake_case(string)
|
28
|
-
string.gsub(/::/,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
string.gsub(/::/, "/")
|
29
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
30
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
31
|
+
.tr("-", "_")
|
32
|
+
.downcase
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|