square 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/square/connect.rb +6 -0
- data/lib/square/connect/bank_account.rb +23 -0
- data/lib/square/connect/connections/payments.rb +2 -2
- data/lib/square/connect/connections/refunds.rb +11 -0
- data/lib/square/connect/connections/settlements.rb +11 -0
- data/lib/square/connect/merchant.rb +0 -1
- data/lib/square/connect/node.rb +1 -5
- data/lib/square/connect/payment.rb +8 -2
- data/lib/square/connect/refund.rb +3 -1
- data/lib/square/connect/settlement.rb +25 -0
- data/lib/square/connect/settlement_entry.rb +22 -0
- data/spec/mock_response/refunds/list.json +11 -0
- data/spec/mock_response/settlements/list.json +13 -0
- data/spec/square/connect/connections/refunds_spec.rb +19 -0
- data/spec/square/connect/connections/settlements_spec.rb +19 -0
- data/spec/square/connect/payment_spec.rb +0 -11
- metadata +8 -2
- data/lib/square/connect/connections/bank_accounts.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96deb675316127d8568b8c0788d070f74095a0d6
|
4
|
+
data.tar.gz: 39cfdba4095dae9efa6570390b41834838500332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e3834e7da8769dce73df9146cab2622688680063a55b6950cee39ace4898b74a3bb60ea6dfcf6084538ff24dc4ee68a2af37b39ab9e9c17398b8a604a72de4a
|
7
|
+
data.tar.gz: db5dfacd28eff34a3010ba0468e3231888fd64cc197831acbef286442f0193084cf9fc09c36beed7fdde2f61a7fd2a9b34f2399e8caa5f2a690cb0172836f8f5
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/square/connect.rb
CHANGED
@@ -6,6 +6,12 @@ end
|
|
6
6
|
|
7
7
|
require 'square/connect/error'
|
8
8
|
require 'square/connect/node'
|
9
|
+
require 'square/connect/connections'
|
10
|
+
|
11
|
+
require 'square/connect/bank_account'
|
12
|
+
require 'square/connect/merchant'
|
13
|
+
require 'square/connect/payment'
|
14
|
+
require 'square/connect/settlement'
|
9
15
|
|
10
16
|
require 'square/connect/device'
|
11
17
|
require 'square/connect/itemization'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Square
|
2
|
+
module Connect
|
3
|
+
class BankAccount < Node
|
4
|
+
attr_accessor :merchant, :bank_name, :name, :type, :routing_number, :account_number_suffix, :currency_code
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
super do |attributes|
|
8
|
+
self.merchant = if attributes[:merchant_id]
|
9
|
+
Merchant.new attributes[:merchant_id]
|
10
|
+
else
|
11
|
+
Merchant.new :me
|
12
|
+
end
|
13
|
+
self.bank_name = attributes[:bank_name]
|
14
|
+
self.name = attributes[:name]
|
15
|
+
self.type = attributes[:type]
|
16
|
+
self.routing_number = attributes[:routing_number]
|
17
|
+
self.account_number_suffix = attributes[:account_number_suffix]
|
18
|
+
self.currency_code = attributes[:currency_code]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,10 +2,10 @@ module Square
|
|
2
2
|
module Connect
|
3
3
|
module Connections
|
4
4
|
module Payments
|
5
|
-
def payments
|
5
|
+
def payments(params = nil)
|
6
6
|
access_token_required!
|
7
7
|
payments = handle_response do
|
8
|
-
access_token.get endpoint_for(identifier, :payments)
|
8
|
+
access_token.get endpoint_for(identifier, :payments), params
|
9
9
|
end
|
10
10
|
payments.collect do |payment|
|
11
11
|
Payment.new payment.merge(
|
@@ -2,6 +2,17 @@ module Square
|
|
2
2
|
module Connect
|
3
3
|
module Connections
|
4
4
|
module Refunds
|
5
|
+
def refunds(params = nil)
|
6
|
+
access_token_required!
|
7
|
+
refunds = handle_response do
|
8
|
+
access_token.get endpoint_for(identifier, :refunds), params
|
9
|
+
end
|
10
|
+
refunds.collect do |refund|
|
11
|
+
Refund.new refund.merge(
|
12
|
+
access_token: access_token
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
@@ -2,6 +2,17 @@ module Square
|
|
2
2
|
module Connect
|
3
3
|
module Connections
|
4
4
|
module Settlements
|
5
|
+
def settlements(params = nil)
|
6
|
+
access_token_required!
|
7
|
+
settlements = handle_response do
|
8
|
+
access_token.get endpoint_for(identifier, :settlements), params
|
9
|
+
end
|
10
|
+
settlements.collect do |settlement|
|
11
|
+
Settlement.new settlement.merge(
|
12
|
+
access_token: access_token
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
data/lib/square/connect/node.rb
CHANGED
@@ -25,8 +25,14 @@ module Square
|
|
25
25
|
|
26
26
|
def initialize(*args)
|
27
27
|
super do |attributes|
|
28
|
-
self.merchant =
|
29
|
-
|
28
|
+
self.merchant = if attributes[:merchant_id]
|
29
|
+
Merchant.new attributes[:merchant_id]
|
30
|
+
else
|
31
|
+
Merchant.new :me
|
32
|
+
end
|
33
|
+
self.creator = if attributes[:creator_id]
|
34
|
+
Merchant.new attributes[:creator_id]
|
35
|
+
end
|
30
36
|
self.created_at = if attributes[:created_at]
|
31
37
|
Time.parse attributes[:created_at]
|
32
38
|
end
|
@@ -18,7 +18,9 @@ module Square
|
|
18
18
|
self.send "#{time_key}=", Time.parse(attributes[time_key])
|
19
19
|
end
|
20
20
|
end
|
21
|
-
self.payment =
|
21
|
+
self.payment = if attributes[:payment_id]
|
22
|
+
Payment.new attributes[:payment_id]
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Square
|
2
|
+
module Connect
|
3
|
+
class Settlement < Node
|
4
|
+
attr_accessor :status, :initiated_at, :bank_account, :total_money, :entries
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
super do |attributes|
|
8
|
+
self.status = attributes[:status]
|
9
|
+
self.initiated_at = if attributes[:initiated_at]
|
10
|
+
Time.parse attributes[:initiated_at]
|
11
|
+
end
|
12
|
+
self.bank_account = if attributes[:bank_account_id]
|
13
|
+
BankAccount.new attributes[:bank_account_id]
|
14
|
+
end
|
15
|
+
self.total_money = if attributes[:total_money]
|
16
|
+
Money.new attributes[:total_money]
|
17
|
+
end
|
18
|
+
self.entries = Array(attributes[:entries]).collect do |entry_attributes|
|
19
|
+
SettlementEntry.new entry_attributes
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Square
|
2
|
+
module Connect
|
3
|
+
class SettlementEntry
|
4
|
+
attr_accessor :type, :payment, :amount_money, :fee_money
|
5
|
+
|
6
|
+
def initialize(attributes = {})
|
7
|
+
self.type = attributes[:type]
|
8
|
+
self.payment = if attributes[:payment_id]
|
9
|
+
Payment.new attributes[:payment_id]
|
10
|
+
end
|
11
|
+
[
|
12
|
+
:amount_money,
|
13
|
+
:fee_money
|
14
|
+
].each do |money_key|
|
15
|
+
if attributes[money_key].present?
|
16
|
+
self.send "#{money_key}=", Money.new(attributes[money_key])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Square::Connect::Connections::Refunds do
|
4
|
+
let(:access_token) { 'access_token' }
|
5
|
+
let(:me) { Square::Connect::Merchant.me access_token }
|
6
|
+
|
7
|
+
describe '#payments' do
|
8
|
+
it 'should return an array of Square::Connect::Refund' do
|
9
|
+
refunds = mock_request 'me/refunds', 'refunds/list' do
|
10
|
+
me.refunds
|
11
|
+
end
|
12
|
+
refunds.should be_a Array
|
13
|
+
refunds.should_not be_blank
|
14
|
+
refunds.each do |refund|
|
15
|
+
refund.should be_a Square::Connect::Refund
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Square::Connect::Connections::Settlements do
|
4
|
+
let(:access_token) { 'access_token' }
|
5
|
+
let(:me) { Square::Connect::Merchant.me access_token }
|
6
|
+
|
7
|
+
describe '#payments' do
|
8
|
+
it 'should return an array of Square::Connect::Settlement' do
|
9
|
+
settlements = mock_request 'me/settlements', 'settlements/list' do
|
10
|
+
me.settlements
|
11
|
+
end
|
12
|
+
settlements.should be_a Array
|
13
|
+
settlements.should_not be_blank
|
14
|
+
settlements.each do |settlement|
|
15
|
+
settlement.should be_a Square::Connect::Settlement
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -9,12 +9,6 @@ describe Square::Connect::Payment do
|
|
9
9
|
|
10
10
|
describe '#initialize' do
|
11
11
|
describe 'merchant' do
|
12
|
-
context 'when merchant given' do
|
13
|
-
subject { klass.new identifier, merchant: Square::Connect::Merchant.new(merchant_id) }
|
14
|
-
its(:merchant) { should be_a Square::Connect::Merchant }
|
15
|
-
its(:endpoint) { should == File.join(Square::Connect::ROOT_URL, "#{merchant_id}/payments/#{identifier}") }
|
16
|
-
end
|
17
|
-
|
18
12
|
context 'when merchant_id given' do
|
19
13
|
subject { klass.new identifier, merchant_id: merchant_id }
|
20
14
|
its(:merchant) { should be_a Square::Connect::Merchant }
|
@@ -29,11 +23,6 @@ describe Square::Connect::Payment do
|
|
29
23
|
end
|
30
24
|
|
31
25
|
describe 'creator' do
|
32
|
-
context 'when creator given' do
|
33
|
-
subject { klass.new identifier, creator: Square::Connect::Merchant.new(creator_id) }
|
34
|
-
its(:creator) { should be_a Square::Connect::Merchant }
|
35
|
-
end
|
36
|
-
|
37
26
|
context 'when creator_id given' do
|
38
27
|
subject { klass.new identifier, creator_id: creator_id }
|
39
28
|
its(:creator) { should be_a Square::Connect::Merchant }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: square
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov
|
@@ -96,8 +96,8 @@ files:
|
|
96
96
|
- VERSION
|
97
97
|
- lib/square.rb
|
98
98
|
- lib/square/connect.rb
|
99
|
+
- lib/square/connect/bank_account.rb
|
99
100
|
- lib/square/connect/connections.rb
|
100
|
-
- lib/square/connect/connections/bank_accounts.rb
|
101
101
|
- lib/square/connect/connections/payments.rb
|
102
102
|
- lib/square/connect/connections/refunds.rb
|
103
103
|
- lib/square/connect/connections/settlements.rb
|
@@ -109,6 +109,8 @@ files:
|
|
109
109
|
- lib/square/connect/node.rb
|
110
110
|
- lib/square/connect/payment.rb
|
111
111
|
- lib/square/connect/refund.rb
|
112
|
+
- lib/square/connect/settlement.rb
|
113
|
+
- lib/square/connect/settlement_entry.rb
|
112
114
|
- lib/square/connect/tax.rb
|
113
115
|
- lib/square/connect/tender.rb
|
114
116
|
- lib/square/exception.rb
|
@@ -121,9 +123,13 @@ files:
|
|
121
123
|
- spec/mock_response/merchant/me.json
|
122
124
|
- spec/mock_response/payments/list.json
|
123
125
|
- spec/mock_response/payments/single.json
|
126
|
+
- spec/mock_response/refunds/list.json
|
127
|
+
- spec/mock_response/settlements/list.json
|
124
128
|
- spec/mock_response/token.json
|
125
129
|
- spec/spec_helper.rb
|
126
130
|
- spec/square/connect/connections/payments_spec.rb
|
131
|
+
- spec/square/connect/connections/refunds_spec.rb
|
132
|
+
- spec/square/connect/connections/settlements_spec.rb
|
127
133
|
- spec/square/connect/merchant_spec.rb
|
128
134
|
- spec/square/connect/node_spec.rb
|
129
135
|
- spec/square/connect/payment_spec.rb
|