atech-billy 1.0.16 → 1.0.18
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.
- checksums.yaml +7 -0
- data/lib/billy.rb +10 -6
- data/lib/billy/addon.rb +10 -0
- data/lib/billy/card.rb +24 -0
- data/lib/billy/country.rb +8 -0
- data/lib/billy/coupon.rb +10 -0
- data/lib/billy/invoice.rb +20 -8
- data/lib/billy/product.rb +6 -2
- data/lib/billy/request.rb +15 -16
- data/lib/billy/service.rb +120 -14
- data/lib/billy/version.rb +1 -1
- metadata +13 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d1380ec90fdc320c57ae8d837e38900aa168cfc
|
4
|
+
data.tar.gz: 2a9f3d043758c9a0b93f7bc90fe2c2125bdd8ada
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d42af1d0b809a1351829040ba62da7e0f75953e1c33ae2b0b0e93e1f062411d5548416e04bbe526c75c4504872c4b5993a3c00d21abe771521be171e5394716
|
7
|
+
data.tar.gz: 1f063a4c6a50dca553716874fad25abf7d57127406294e4600d20ddf64703e465bc24d87c1a889dda5e3bc4dd61659b474f5e38a5ea01b0d03dccde5c9b30390
|
data/lib/billy.rb
CHANGED
@@ -10,24 +10,28 @@ require 'billy/service'
|
|
10
10
|
require 'billy/signup_token'
|
11
11
|
require 'billy/invoice'
|
12
12
|
require 'billy/product'
|
13
|
+
require 'billy/addon'
|
13
14
|
require 'billy/package'
|
14
15
|
require 'billy/version'
|
16
|
+
require 'billy/card'
|
17
|
+
require 'billy/coupon'
|
18
|
+
require 'billy/country'
|
15
19
|
|
16
20
|
module Billy
|
17
|
-
|
21
|
+
|
18
22
|
class << self
|
19
|
-
|
23
|
+
|
20
24
|
## Application name & key
|
21
25
|
attr_accessor :product, :product_key
|
22
|
-
|
26
|
+
|
23
27
|
## Endpoint to send domains to
|
24
28
|
attr_writer :host
|
25
|
-
|
29
|
+
|
26
30
|
def host
|
27
31
|
@host ||= 'https://billing.atechmedia.com'
|
28
32
|
end
|
29
33
|
end
|
30
|
-
|
34
|
+
|
31
35
|
class Error < StandardError; end
|
32
36
|
module Errors
|
33
37
|
class ServiceUnavailable < Error; end
|
@@ -36,5 +40,5 @@ module Billy
|
|
36
40
|
class CommunicationError < Error; end
|
37
41
|
class ValidationError < Error; end
|
38
42
|
end
|
39
|
-
|
43
|
+
|
40
44
|
end
|
data/lib/billy/addon.rb
ADDED
data/lib/billy/card.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Billy
|
2
|
+
class Card < BaseModel
|
3
|
+
|
4
|
+
## Get a paginated list of all cards for a Billy service
|
5
|
+
def list
|
6
|
+
Billy::Request.request('cards/list', :service => @attributes['id'])
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.add_stripe_card(service, stripe_token, ip_address, options = {})
|
10
|
+
params = {}
|
11
|
+
params[:service] = service
|
12
|
+
params[:token] = stripe_token
|
13
|
+
params[:ip_address] = ip_address
|
14
|
+
params[:invoice] = options[:invoice_to_pay] if options[:invoice_to_pay]
|
15
|
+
Billy::Request.request('cards/add_stripe_card', params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find(code)
|
19
|
+
attributes = Billy::Request.request('coupons/info', :code => code)
|
20
|
+
attributes.is_a?(Hash) ? self.new(attributes) : nil
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/billy/coupon.rb
ADDED
data/lib/billy/invoice.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
module Billy
|
2
2
|
class Invoice < BaseModel
|
3
|
-
|
3
|
+
|
4
4
|
def self.find_for_identity(ati_key)
|
5
5
|
Billy::Request.request('invoices/list_for_identity', :identity => ati_key).map { |p| self.new(p) }
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def add_line(params)
|
9
9
|
attributes = Billy::Request.request('invoices/add_line', :service => @attributes['service_id'], :invoice => @attributes['number'], :line => params)
|
10
10
|
attributes.is_a?(Hash) ? @attributes = attributes : false
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def delete_line(id)
|
14
14
|
attributes = Billy::Request.request('invoices/delete_line', :service => @attributes['service_id'], :invoice => @attributes['number'], :line => id)
|
15
15
|
attributes.is_a?(Hash) ? @attributes = attributes : false
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def finalise!
|
19
19
|
attributes = Billy::Request.request('invoices/finalise', :service => @attributes['service_id'], :invoice => @attributes['number'])
|
20
20
|
@attributes = attributes
|
21
21
|
true
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def mark_as_paid(method, reference, verifier = nil)
|
25
25
|
options = {:service => @attributes['service_id'], :invoice => @attributes['number'], :payment_method => method, :payment_reference => reference}
|
26
26
|
options[:payment_verifier] = verifier if verifier
|
@@ -28,15 +28,27 @@ module Billy
|
|
28
28
|
@attributes = attributes
|
29
29
|
true
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def delete
|
33
33
|
Billy::Request.request('invoices/delete', :service => @attributes['service_id'], :invoice => @attributes['number'])
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def update(properties)
|
37
37
|
@attributes = Billy::Request.request('invoices/update', :service => @attributes['service_id'], :invoice => @attributes['number'], :properties => properties)
|
38
38
|
true
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
|
+
def pay_with_card(card_id)
|
42
|
+
if Billy::Request.request('cards/pay_invoice', :service => @attributes['service_id'], :invoice => @attributes['number'], :card => card_id)
|
43
|
+
true
|
44
|
+
else
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def pdf
|
50
|
+
Billy::Request.request('invoices/pdf', :service => @attributes['service_id'], :invoice => @attributes['number'])
|
51
|
+
end
|
52
|
+
|
41
53
|
end
|
42
54
|
end
|
data/lib/billy/product.rb
CHANGED
@@ -7,8 +7,12 @@ module Billy
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def packages
|
10
|
-
@packages ||= Billy::Request.request('product/packages').map {|package| Billy::Package.new(package) }
|
10
|
+
@packages ||= Billy::Request.request('product/packages').map { |package| Billy::Package.new(package) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def addons
|
14
|
+
@addons ||= Billy::Request.request('product/addons').map { |addon| Billy::Addon.new(addon) }
|
11
15
|
end
|
12
16
|
|
13
17
|
end
|
14
|
-
end
|
18
|
+
end
|
data/lib/billy/request.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
module Billy
|
2
2
|
class Request
|
3
|
-
|
3
|
+
|
4
4
|
def self.request(path, data = {})
|
5
5
|
req = self.new(path, :post)
|
6
6
|
req.data = data
|
7
7
|
req.make && req.success? ? req.output : false
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
attr_reader :path, :method, :client
|
11
11
|
attr_accessor :data
|
12
|
-
|
12
|
+
|
13
13
|
def initialize(path, method = :get)
|
14
14
|
@path = path
|
15
15
|
@method = method
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def success?
|
19
19
|
@success || false
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def output
|
23
23
|
@output || nil
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def make
|
27
27
|
uri = URI.parse([Billy.host, "api/v1", @path].join('/'))
|
28
28
|
http_request = http_class.new(uri.request_uri)
|
@@ -30,14 +30,13 @@ module Billy
|
|
30
30
|
http_request.add_field("X-Billy-Product", Billy.product)
|
31
31
|
http_request.add_field("X-Billy-Key", Billy.product_key)
|
32
32
|
http_request.content_type = 'application/json'
|
33
|
-
|
33
|
+
|
34
34
|
http = Net::HTTP.new(uri.host, uri.port)
|
35
|
-
|
35
|
+
|
36
36
|
if uri.scheme == 'https'
|
37
37
|
http.use_ssl = true
|
38
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
39
38
|
end
|
40
|
-
|
39
|
+
|
41
40
|
http_result = http.request(http_request, @data.to_json)
|
42
41
|
if http_result.body == 'true'
|
43
42
|
@output = true
|
@@ -58,16 +57,16 @@ module Billy
|
|
58
57
|
raise Billy::Errors::NotFound, json['error']
|
59
58
|
when Net::HTTPClientError
|
60
59
|
json = JSON.parse(http_result.body)
|
61
|
-
raise Billy::Errors::ValidationError, json
|
60
|
+
raise Billy::Errors::ValidationError, JSON.dump(json)
|
62
61
|
else
|
63
62
|
raise Billy::Errors::CommunicationError, http_result.body
|
64
63
|
end
|
65
64
|
self
|
66
65
|
end
|
67
|
-
|
66
|
+
|
68
67
|
private
|
69
|
-
|
70
|
-
def http_class
|
68
|
+
|
69
|
+
def http_class
|
71
70
|
case @method
|
72
71
|
when :post then Net::HTTP::Post
|
73
72
|
when :put then Net::HTTP::Put
|
@@ -76,6 +75,6 @@ module Billy
|
|
76
75
|
Net::HTTP::Get
|
77
76
|
end
|
78
77
|
end
|
79
|
-
|
78
|
+
|
80
79
|
end
|
81
|
-
end
|
80
|
+
end
|
data/lib/billy/service.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Billy
|
2
2
|
class Service < BaseModel
|
3
|
-
|
3
|
+
|
4
4
|
## Get a paginated list of all Billy services
|
5
|
-
def list
|
5
|
+
def self.list
|
6
6
|
Billy::Request.request('services/list')
|
7
7
|
end
|
8
8
|
|
@@ -11,21 +11,21 @@ module Billy
|
|
11
11
|
@attributes = Billy::Request.request('services/update', :service => @attributes['id'],:properties => properties)
|
12
12
|
true
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
## Create a new login session and return a URL which can be used to log the user
|
16
16
|
## into the billing application
|
17
17
|
def create_session(start_path = nil, return_url = nil, auto_return_after_payment = false)
|
18
18
|
session = Billy::Request.request('services/create_session', :id => @attributes['id'], :start_path => start_path, :return_url => return_url, :auto_return_after_payment => auto_return_after_payment)
|
19
19
|
session ? [Billy.host, 'start', session['token']].join('/') : false
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
## Create a new signup token for another application
|
23
23
|
def create_signup_token(product, package)
|
24
24
|
return false if product.nil? || package.nil?
|
25
25
|
token = Billy::Request.request('services/create_signup_token', :id => @attributes['id'], :product => product, :package => package)
|
26
26
|
token ? token['url'] : false
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
## Change the user associated with this service to the given aTech identity key
|
30
30
|
def change_user(atech_identity_key)
|
31
31
|
request = Billy::Request.request('services/change_user', :id => @attributes['id'], :atech_identity_key => atech_identity_key)
|
@@ -36,7 +36,7 @@ module Billy
|
|
36
36
|
return false
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
## Change the label associated with a service
|
41
41
|
def change_label(new_label)
|
42
42
|
request = Billy::Request.request('services/change_label', :id => @attributes['id'], :label => new_label)
|
@@ -47,38 +47,141 @@ module Billy
|
|
47
47
|
return false
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
|
+
def change_package(new_package)
|
52
|
+
request = Billy::Request.request('services/change_package', :id => @attributes['id'], :package => new_package)
|
53
|
+
if request
|
54
|
+
@attributes = request['service']
|
55
|
+
|
56
|
+
return Billy::Invoice.new(request['invoice']) if request['invoice']
|
57
|
+
true
|
58
|
+
else
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def change_addon(addon_permalink, quantity)
|
64
|
+
request = Billy::Request.request('services/change_addon', :id => @attributes['id'], :addon => addon_permalink, :quantity => quantity)
|
65
|
+
|
66
|
+
if request
|
67
|
+
@attributes = request['service']
|
68
|
+
true
|
69
|
+
else
|
70
|
+
false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def apply_coupon(code)
|
75
|
+
if Billy::Request.request('services/apply_coupon', :id => @attributes['id'], :code => code)
|
76
|
+
return true
|
77
|
+
else
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def cancel(cancellation_properties = {})
|
83
|
+
if Billy::Request.request('services/cancel', cancellation_properties.merge(:id => @attributes['id']))
|
84
|
+
true
|
85
|
+
else
|
86
|
+
false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def uncancel
|
91
|
+
if Billy::Request.request('services/uncancel', :id => @attributes['id'])
|
92
|
+
true
|
93
|
+
else
|
94
|
+
false
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def auto_cancel(reason)
|
99
|
+
request = Billy::Request.request('services/auto_cancel', :id => @attributes['id'], :cancellation_reason => reason)
|
100
|
+
if request
|
101
|
+
@attributes = request['service']
|
102
|
+
true
|
103
|
+
else
|
104
|
+
false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
51
108
|
## Create a new invoice for the service and return the new invoice object
|
52
109
|
def create_invoice(options = {})
|
53
110
|
attributes = Billy::Request.request('invoices/create', :service => @attributes['id'], :invoice => options)
|
54
111
|
attributes.is_a?(Hash) ? Billy::Invoice.new(attributes) : nil
|
55
112
|
end
|
56
|
-
|
113
|
+
|
114
|
+
## Return all the invoices for this service
|
115
|
+
def invoices
|
116
|
+
list = Billy::Request.request('invoices/list', :service => @attributes['id'])
|
117
|
+
list.is_a?(Array) ? list.map { |i| Billy::Invoice.new(i) } : []
|
118
|
+
end
|
119
|
+
|
57
120
|
## Return the invoice for this service
|
58
121
|
def invoice(number)
|
59
122
|
attributes = Billy::Request.request('invoices/info', :invoice => number, :service => @attributes['id'])
|
60
123
|
attributes.is_a?(Hash) ? Billy::Invoice.new(attributes) : nil
|
61
124
|
end
|
62
|
-
|
125
|
+
|
126
|
+
def pay_invoice(invoice, card)
|
127
|
+
if Billy::Request.request('cards/pay_invoice', :service => @attributes['id'], :invoice => invoice, :card => card)
|
128
|
+
return true
|
129
|
+
else
|
130
|
+
return false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def cards
|
135
|
+
@cards ||= Billy::Request.request('cards/list', :service => @attributes['id'])
|
136
|
+
end
|
137
|
+
|
138
|
+
def default_card
|
139
|
+
cards.select { |c| c['default'] == true }.first
|
140
|
+
end
|
141
|
+
|
142
|
+
def add_stripe_card(*args)
|
143
|
+
Billy::Card.add_stripe_card(@attributes['id'], *args)
|
144
|
+
end
|
145
|
+
|
146
|
+
def begin_subscription
|
147
|
+
req = Billy::Request.request('services/begin_subscription', :id => @attributes['id'])
|
148
|
+
req.is_a?(Hash) ? Billy::Invoice.new(req) : nil
|
149
|
+
end
|
150
|
+
|
151
|
+
def reactivate_subscription
|
152
|
+
req = Billy::Request.request('services/reactivate_subscription', :id => @attributes['id'])
|
153
|
+
req.is_a?(Hash) ? Billy::Invoice.new(req) : nil
|
154
|
+
end
|
155
|
+
|
156
|
+
def immediate_payment(quantity)
|
157
|
+
req = Billy::Request.request('services/immediate_payment', :id => @attributes['id'], :quantity => quantity)
|
158
|
+
req.is_a?(Hash) ? Billy::Invoice.new(req) : nil
|
159
|
+
end
|
160
|
+
|
63
161
|
def address?
|
64
162
|
return false if self.address.first.nil? || self.address.last.nil?
|
65
163
|
return true
|
66
164
|
end
|
67
|
-
|
165
|
+
|
166
|
+
def add_newsletter_subscriber(email_address, first_name, consent_type)
|
167
|
+
req = Billy::Request.request('services/add_newsletter_subscriber', :id => @attributes['id'], :email_address => email_address, :first_name => first_name, :consent_type => consent_type)
|
168
|
+
req ? true : false
|
169
|
+
end
|
170
|
+
|
68
171
|
def self.find(field, data)
|
69
172
|
attributes = Billy::Request.request('services/info', :field => field, :data => data)
|
70
173
|
attributes.is_a?(Hash) ? self.new(attributes) : nil
|
71
174
|
end
|
72
|
-
|
175
|
+
|
73
176
|
def self.find_for_identity(ati_key)
|
74
177
|
Billy::Request.request('services/list_for_identity', :atech_identity_key => ati_key).map { |p| self.new(p) }
|
75
178
|
end
|
76
|
-
|
179
|
+
|
77
180
|
def self.create(atech_identity, service)
|
78
181
|
attributes = Billy::Request.request('services/create', :service => service, :atech_identity_key => atech_identity)
|
79
182
|
attributes.is_a?(Hash) ? self.new(attributes) : nil
|
80
183
|
end
|
81
|
-
|
184
|
+
|
82
185
|
def self.validate_label(label)
|
83
186
|
result = Billy::Request.request('services/validate_label', :label => label)
|
84
187
|
if result.is_a?(Hash)
|
@@ -87,6 +190,9 @@ module Billy
|
|
87
190
|
false
|
88
191
|
end
|
89
192
|
end
|
90
|
-
|
193
|
+
|
194
|
+
def add_log_entry(message)
|
195
|
+
Billy::Request.request('services/add_log_entry', :id => @attributes['id'], :message => message)
|
196
|
+
end
|
91
197
|
end
|
92
198
|
end
|
data/lib/billy/version.rb
CHANGED
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atech-billy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.18
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Adam Cooke
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-05-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: basic_ssl
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description:
|
@@ -34,7 +31,11 @@ extensions: []
|
|
34
31
|
extra_rdoc_files: []
|
35
32
|
files:
|
36
33
|
- lib/billy.rb
|
34
|
+
- lib/billy/addon.rb
|
37
35
|
- lib/billy/base_model.rb
|
36
|
+
- lib/billy/card.rb
|
37
|
+
- lib/billy/country.rb
|
38
|
+
- lib/billy/coupon.rb
|
38
39
|
- lib/billy/invoice.rb
|
39
40
|
- lib/billy/package.rb
|
40
41
|
- lib/billy/product.rb
|
@@ -44,27 +45,25 @@ files:
|
|
44
45
|
- lib/billy/version.rb
|
45
46
|
homepage: http://atechmedia.com
|
46
47
|
licenses: []
|
48
|
+
metadata: {}
|
47
49
|
post_install_message:
|
48
50
|
rdoc_options: []
|
49
51
|
require_paths:
|
50
52
|
- lib
|
51
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
54
|
requirements:
|
54
|
-
- -
|
55
|
+
- - ">="
|
55
56
|
- !ruby/object:Gem::Version
|
56
57
|
version: '0'
|
57
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
64
|
rubyforge_project:
|
65
|
-
rubygems_version:
|
65
|
+
rubygems_version: 2.5.2.1
|
66
66
|
signing_key:
|
67
|
-
specification_version:
|
67
|
+
specification_version: 4
|
68
68
|
summary: Easy to use client library for Billy
|
69
69
|
test_files: []
|
70
|
-
has_rdoc: false
|