apruve 0.11.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +33 -1
- data/README.md +26 -29
- data/lib/apruve.rb +6 -2
- data/lib/apruve/client.rb +2 -2
- data/lib/apruve/error.rb +4 -3
- data/lib/apruve/resources.rb +7 -5
- data/lib/apruve/resources/invoice.rb +69 -0
- data/lib/apruve/resources/invoice_item.rb +7 -0
- data/lib/apruve/resources/merchant.rb +11 -0
- data/lib/apruve/resources/order.rb +81 -0
- data/lib/apruve/resources/{line_item.rb → order_item.rb} +1 -1
- data/lib/apruve/resources/subscription.rb +1 -1
- data/lib/apruve/resources/webhook_endpoint.rb +33 -0
- data/lib/apruve/version.rb +1 -1
- data/spec/apruve/apruve_spec.rb +5 -5
- data/spec/apruve/resources/{payment_item_spec.rb → invoice_item_spec.rb} +5 -4
- data/spec/apruve/resources/invoice_spec.rb +291 -0
- data/spec/apruve/resources/merchant_spec.rb +56 -0
- data/spec/apruve/resources/{line_item_spec.rb → order_item_spec.rb} +2 -2
- data/spec/apruve/resources/order_spec.rb +220 -0
- data/spec/apruve/resources/payment_request_spec.rb +19 -0
- data/spec/apruve/resources/subscription_adjustment_spec.rb +10 -10
- data/spec/apruve/resources/subscription_spec.rb +6 -6
- data/spec/apruve/resources/webhook_endpoint_spec.rb +137 -0
- data/spec/spec_helper.rb +3 -0
- metadata +21 -14
- data/lib/apruve/resources/payment.rb +0 -43
- data/lib/apruve/resources/payment_item.rb +0 -7
- data/lib/apruve/resources/payment_request.rb +0 -59
- data/spec/apruve/resources/payment_spec.rb +0 -129
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apruve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Apruve, Inc.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -109,13 +109,15 @@ files:
|
|
109
109
|
- lib/apruve/faraday_error_handler.rb
|
110
110
|
- lib/apruve/resources.rb
|
111
111
|
- lib/apruve/resources/apruve_object.rb
|
112
|
-
- lib/apruve/resources/
|
113
|
-
- lib/apruve/resources/
|
114
|
-
- lib/apruve/resources/
|
115
|
-
- lib/apruve/resources/
|
112
|
+
- lib/apruve/resources/invoice.rb
|
113
|
+
- lib/apruve/resources/invoice_item.rb
|
114
|
+
- lib/apruve/resources/merchant.rb
|
115
|
+
- lib/apruve/resources/order.rb
|
116
|
+
- lib/apruve/resources/order_item.rb
|
116
117
|
- lib/apruve/resources/subscription.rb
|
117
118
|
- lib/apruve/resources/subscription_adjustment.rb
|
118
119
|
- lib/apruve/resources/validation_error.rb
|
120
|
+
- lib/apruve/resources/webhook_endpoint.rb
|
119
121
|
- lib/apruve/response/apruve_exception_middleware.rb
|
120
122
|
- lib/apruve/response/apruve_parse_json.rb
|
121
123
|
- lib/apruve/utils.rb
|
@@ -123,12 +125,15 @@ files:
|
|
123
125
|
- spec/apruve/apruve_spec.rb
|
124
126
|
- spec/apruve/client_spec.rb
|
125
127
|
- spec/apruve/config_spec.rb
|
126
|
-
- spec/apruve/resources/
|
127
|
-
- spec/apruve/resources/
|
128
|
+
- spec/apruve/resources/invoice_item_spec.rb
|
129
|
+
- spec/apruve/resources/invoice_spec.rb
|
130
|
+
- spec/apruve/resources/merchant_spec.rb
|
131
|
+
- spec/apruve/resources/order_item_spec.rb
|
132
|
+
- spec/apruve/resources/order_spec.rb
|
128
133
|
- spec/apruve/resources/payment_request_spec.rb
|
129
|
-
- spec/apruve/resources/payment_spec.rb
|
130
134
|
- spec/apruve/resources/subscription_adjustment_spec.rb
|
131
135
|
- spec/apruve/resources/subscription_spec.rb
|
136
|
+
- spec/apruve/resources/webhook_endpoint_spec.rb
|
132
137
|
- spec/apruve/response/apruve_exception_middleware_spec.rb
|
133
138
|
- spec/spec_helper.rb
|
134
139
|
homepage: https://www.apruve.com
|
@@ -151,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
156
|
version: '0'
|
152
157
|
requirements: []
|
153
158
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
159
|
+
rubygems_version: 2.4.5.1
|
155
160
|
signing_key:
|
156
161
|
specification_version: 4
|
157
162
|
summary: Helper library for integrating Apruve into a ruby app.
|
@@ -159,12 +164,14 @@ test_files:
|
|
159
164
|
- spec/apruve/apruve_spec.rb
|
160
165
|
- spec/apruve/client_spec.rb
|
161
166
|
- spec/apruve/config_spec.rb
|
162
|
-
- spec/apruve/resources/
|
163
|
-
- spec/apruve/resources/
|
167
|
+
- spec/apruve/resources/invoice_item_spec.rb
|
168
|
+
- spec/apruve/resources/invoice_spec.rb
|
169
|
+
- spec/apruve/resources/merchant_spec.rb
|
170
|
+
- spec/apruve/resources/order_item_spec.rb
|
171
|
+
- spec/apruve/resources/order_spec.rb
|
164
172
|
- spec/apruve/resources/payment_request_spec.rb
|
165
|
-
- spec/apruve/resources/payment_spec.rb
|
166
173
|
- spec/apruve/resources/subscription_adjustment_spec.rb
|
167
174
|
- spec/apruve/resources/subscription_spec.rb
|
175
|
+
- spec/apruve/resources/webhook_endpoint_spec.rb
|
168
176
|
- spec/apruve/response/apruve_exception_middleware_spec.rb
|
169
177
|
- spec/spec_helper.rb
|
170
|
-
has_rdoc:
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Apruve
|
2
|
-
class Payment < Apruve::ApruveObject
|
3
|
-
attr_accessor :id, :payment_request_id, :status, :status, :amount_cents, :currency, :merchant_notes,
|
4
|
-
:payment_items, :api_url, :view_url, :created_at, :updated_at
|
5
|
-
|
6
|
-
def self.find(payment_request_id, id)
|
7
|
-
response = Apruve.get("payment_requests/#{payment_request_id}/payments/#{id}")
|
8
|
-
Payment.new(response.body)
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(params)
|
12
|
-
super
|
13
|
-
# hydrate payment items if appropriate
|
14
|
-
if @payment_items.nil?
|
15
|
-
@payment_items = []
|
16
|
-
elsif @payment_items.is_a?(Array) && @payment_items.first.is_a?(Hash)
|
17
|
-
hydrated_items = []
|
18
|
-
@payment_items.each do |item|
|
19
|
-
hydrated_items << Apruve::LineItem.new(item)
|
20
|
-
end
|
21
|
-
@payment_items = hydrated_items
|
22
|
-
end
|
23
|
-
@currency = Apruve.default_currency if currency.nil?
|
24
|
-
end
|
25
|
-
|
26
|
-
def validate
|
27
|
-
errors = []
|
28
|
-
errors << 'payment_request_id must be set' if payment_request_id.nil?
|
29
|
-
errors << 'amount_cents must be set' if amount_cents.nil?
|
30
|
-
raise Apruve::ValidationError.new(errors) if errors.length > 0
|
31
|
-
end
|
32
|
-
|
33
|
-
def save!
|
34
|
-
validate
|
35
|
-
response = Apruve.post("payment_requests/#{self.payment_request_id}/payments", self.to_json)
|
36
|
-
self.id = response.body['id']
|
37
|
-
self.status = response.body['status']
|
38
|
-
self.api_url = response.body['api_url']
|
39
|
-
self.view_url = response.body['view_url']
|
40
|
-
self.status
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module Apruve
|
2
|
-
class PaymentRequest < Apruve::ApruveObject
|
3
|
-
attr_accessor :id, :merchant_id, :merchant_order_id, :status, :amount_cents, :currency, :tax_cents,
|
4
|
-
:shipping_cents, :line_items, :api_url, :view_url, :created_at, :updated_at, :expire_at
|
5
|
-
|
6
|
-
def self.find(id)
|
7
|
-
response = Apruve.get("payment_requests/#{id}")
|
8
|
-
logger.debug response.body
|
9
|
-
PaymentRequest.new(response.body)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.finalize!(id)
|
13
|
-
response = Apruve.post("payment_requests/#{id}/finalize")
|
14
|
-
logger.debug response.body
|
15
|
-
response.body
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(params)
|
19
|
-
super
|
20
|
-
# hydrate line items if appropriate
|
21
|
-
if @line_items.nil?
|
22
|
-
@line_items = []
|
23
|
-
elsif @line_items.is_a?(Array) && @line_items.first.is_a?(Hash)
|
24
|
-
hydrated_items = []
|
25
|
-
@line_items.each do |item|
|
26
|
-
hydrated_items << Apruve::LineItem.new(item)
|
27
|
-
end
|
28
|
-
@line_items = hydrated_items
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def validate
|
33
|
-
errors = []
|
34
|
-
errors << 'merchant_id must be set' if merchant_id.nil?
|
35
|
-
raise Apruve::ValidationError.new(errors) if errors.length > 0
|
36
|
-
end
|
37
|
-
|
38
|
-
def value_string
|
39
|
-
# add each field in the PR
|
40
|
-
str = "#{self.merchant_id}#{self.merchant_order_id}#{self.amount_cents}#{self.currency}#{self.tax_cents}#{self.shipping_cents}#{self.expire_at}"
|
41
|
-
|
42
|
-
# add the line items
|
43
|
-
self.line_items.each do |item|
|
44
|
-
str += "#{item.title}#{item.plan_code}#{item.amount_cents}#{item.price_ea_cents}"\
|
45
|
-
"#{item.quantity}#{item.merchant_notes}#{item.description}#{item.variant_info}#{item.sku}"\
|
46
|
-
"#{item.vendor}#{item.view_product_url}"
|
47
|
-
end
|
48
|
-
|
49
|
-
str
|
50
|
-
end
|
51
|
-
|
52
|
-
def secure_hash
|
53
|
-
if Apruve.client.api_key.nil?
|
54
|
-
raise 'api_key has not been set. Set it with Apruve.configure(api_key, environment, options)'
|
55
|
-
end
|
56
|
-
Digest::SHA256.hexdigest(Apruve.client.api_key+value_string)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Apruve::Payment do
|
4
|
-
before :each do
|
5
|
-
Apruve.configure('f5fbe71d68772d1f562ed6f598b995b3', 'local')
|
6
|
-
end
|
7
|
-
|
8
|
-
let (:amount_cents) { 12340 }
|
9
|
-
let (:notes) { 'notes from merchant' }
|
10
|
-
let (:payment_request_id) { '9999' }
|
11
|
-
let (:payment) do
|
12
|
-
Apruve::Payment.new(
|
13
|
-
payment_request_id: payment_request_id,
|
14
|
-
amount_cents: amount_cents,
|
15
|
-
)
|
16
|
-
end
|
17
|
-
subject { payment }
|
18
|
-
|
19
|
-
it { should respond_to(:id) }
|
20
|
-
it { should respond_to(:payment_request_id) }
|
21
|
-
it { should respond_to(:status) }
|
22
|
-
it { should respond_to(:amount_cents) }
|
23
|
-
it { should respond_to(:currency) }
|
24
|
-
it { should respond_to(:merchant_notes) }
|
25
|
-
it { should respond_to(:payment_items) }
|
26
|
-
it { should respond_to(:api_url) }
|
27
|
-
it { should respond_to(:view_url) }
|
28
|
-
it { should respond_to(:created_at) }
|
29
|
-
it { should respond_to(:updated_at) }
|
30
|
-
|
31
|
-
describe '#to_json' do
|
32
|
-
let(:expected) do
|
33
|
-
'{"payment_request_id":"9999","amount_cents":12340,"payment_items":[],"currency":"USD"}'
|
34
|
-
end
|
35
|
-
its(:to_json) { should eq expected }
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#validate' do
|
39
|
-
describe 'no errors' do
|
40
|
-
it 'should not raise' do
|
41
|
-
expect { payment.validate }.not_to raise_error
|
42
|
-
end
|
43
|
-
end
|
44
|
-
describe 'errors' do
|
45
|
-
before :each do
|
46
|
-
payment.amount_cents = nil
|
47
|
-
end
|
48
|
-
it 'should raise on no merchant_id' do
|
49
|
-
expect { payment.validate }.to raise_error(Apruve::ValidationError, '["amount_cents must be set"]')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '#find' do
|
55
|
-
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
56
|
-
let (:payment_request_id) { '8fdc91d337a28633deed058dd2d3fc90' }
|
57
|
-
describe 'success' do
|
58
|
-
let! (:stubs) do
|
59
|
-
faraday_stubs do |stub|
|
60
|
-
stub.get("/api/v3/payment_requests/#{payment_request_id}/payments/#{id}") { [200, {}, '{}'] }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
it 'should do a get' do
|
64
|
-
Apruve::Payment.find(payment_request_id, id)
|
65
|
-
stubs.verify_stubbed_calls
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe 'not found' do
|
70
|
-
let! (:stubs) do
|
71
|
-
faraday_stubs do |stub|
|
72
|
-
stub.get("/api/v3/payment_requests/#{payment_request_id}/payments/#{id}") { [404, {}, 'Not Found'] }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
it 'should raise' do
|
76
|
-
expect { Apruve::Payment.find(payment_request_id, id) }.to raise_error(Apruve::NotFound)
|
77
|
-
stubs.verify_stubbed_calls
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe '#save' do
|
83
|
-
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
84
|
-
let (:status) { 'pending' }
|
85
|
-
let (:api_url) { Faker::Internet.url }
|
86
|
-
let (:view_url) { Faker::Internet.url }
|
87
|
-
let (:response) do
|
88
|
-
{
|
89
|
-
id: id,
|
90
|
-
status: status,
|
91
|
-
api_url: api_url,
|
92
|
-
view_url: view_url
|
93
|
-
}
|
94
|
-
end
|
95
|
-
describe 'success' do
|
96
|
-
let! (:stubs) do
|
97
|
-
faraday_stubs do |stub|
|
98
|
-
stub.post(
|
99
|
-
"/api/v3/payment_requests/#{payment_request_id}/payments",
|
100
|
-
payment.to_json,
|
101
|
-
) { [200, {}, response.to_json] }
|
102
|
-
end
|
103
|
-
end
|
104
|
-
it 'should do a post' do
|
105
|
-
payment.save!
|
106
|
-
expect(payment.id).to eq id
|
107
|
-
expect(payment.status).to eq status
|
108
|
-
expect(payment.api_url).to eq api_url
|
109
|
-
expect(payment.view_url).to eq view_url
|
110
|
-
stubs.verify_stubbed_calls
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe 'payment request not found' do
|
115
|
-
let! (:stubs) do
|
116
|
-
faraday_stubs do |stub|
|
117
|
-
stub.post(
|
118
|
-
"/api/v3/payment_requests/#{payment_request_id}/payments",
|
119
|
-
payment.to_json,
|
120
|
-
) { [404, {}, 'Not Found'] }
|
121
|
-
end
|
122
|
-
end
|
123
|
-
it 'should raise' do
|
124
|
-
expect { payment.save! }.to raise_error(Apruve::NotFound)
|
125
|
-
stubs.verify_stubbed_calls
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|