pin_payment 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 369e911042369c7cd9c343e4bc51ec5f0c48d4fc
4
- data.tar.gz: 281569a5aec0327fc79a00fe5b58aebc0f4a1ae3
3
+ metadata.gz: 0dde24ac9bb62f680bbcf020f685976883757e5d
4
+ data.tar.gz: 7f290424a76c2a4b891706275d75144d9eafa4ec
5
5
  SHA512:
6
- metadata.gz: 23240d1e4d1d32fa85b7e0221f03c5cbce8ab11ad040dd5875ec0eab6c3166e922e2be7980512590008a03d2aa93ee00d56125a7d900c9d6b03aa85325196c4e
7
- data.tar.gz: 0a58b3ed5b0d72eb7f3abdfa3bd274f6bf11b02c4c937a376b1c92bbb84dceaad4f1262a732895a9abf9f289307bcf8c67e9fa0979f536e8c944602ee0ac4f76
6
+ metadata.gz: d47880353262fd739c25cb1dd052ef3c89fc0965b04e7ff6ba0a723d4694cc0ffdd8f56285d6fdd9ec3531b7b1e607eee84ab9d964899aff809127a995c6948a
7
+ data.tar.gz: d0234ee44bfbec66f7beb8dfdb2fb159db69ddf97bfe03d483bc0b17399b4e366c460db092d0ce2d6207a149b5f5ad535a552af2a5ad5b7698a132c4a86f4b16
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pin_payment (0.3.0)
4
+ pin_payment (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,28 @@
1
+ module PinPayment
2
+ class Balance < Base
3
+
4
+ attr_accessor :available, :pending
5
+ protected :available=, :pending=
6
+
7
+ def initialize options = {}
8
+ self.available = options["available"][0]
9
+ self.pending = options["pending"][0]
10
+ end
11
+
12
+ # Uses the pin API to fetch your accounts balance.
13
+ #
14
+ # @return [PinPayment::Balance]
15
+ def self.current_balance
16
+ response = get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/balance' }, {})
17
+ new(response)
18
+ end
19
+
20
+ private
21
+
22
+ def self.attributes
23
+ [:available, :pending]
24
+ end
25
+
26
+
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ module PinPayment
2
+ class BankAccount < Base
3
+
4
+ attr_accessor :token, :name, :bsb, :number, :bank_name
5
+ protected :token=, :name=, :bsb=, :number=, :bank_name=
6
+
7
+ # Uses the pin API to create a bank account.
8
+ #
9
+ # @param [Hash] bank_account_data
10
+ # @option bank_account_data [String] :name *required*
11
+ # @option bank_account_data [String] :bsb *required*
12
+ # @option bank_account_data [String] :number *required*
13
+ # @return [PinPayment::BankAccount]
14
+ def self.create bank_account_data
15
+ attributes = self.attributes - [:token,:bank_name] # fix attributes allowed by POST API
16
+ options = parse_options_for_request(attributes, bank_account_data)
17
+ response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/bank_accounts' }, options)
18
+ new(response.delete('token'), response)
19
+ end
20
+
21
+ # @return [Hash]
22
+ def to_hash
23
+ {}.tap do |hash|
24
+ self.class.attributes {|attribute| value = send(attribute); hash[attribute] = value if value}
25
+ end
26
+ end
27
+
28
+ protected
29
+
30
+ def self.attributes
31
+ [:token, :name, :bsb, :number, :bank_name]
32
+ end
33
+
34
+ end
35
+ end
@@ -51,7 +51,7 @@ module PinPayment
51
51
  card = hash.delete(:card) if hash[:card]
52
52
  token = hash.delete('card_token') if hash['card_token']
53
53
  token = hash.delete(:card_token) if hash[:card_token]
54
- if card.is_a?(Card) and token and !card.token
54
+ if card.is_a?(Card) && token && !card.token
55
55
  card.token = token
56
56
  elsif card.is_a?(Hash)
57
57
  card = Card.new(token || card[:token] || card['token'], card)
@@ -98,8 +98,27 @@ module PinPayment
98
98
  hash
99
99
  end
100
100
 
101
+ def self.parse_bank_account_data hash
102
+ hash = hash.dup
103
+ account = hash.delete('bank_account') if hash['bank_account']
104
+ account = hash.delete(:bank_account) if hash[:bank_account]
105
+ token = hash.delete('bank_account_token') if hash['bank_account_token']
106
+ token = hash.delete(:bank_account_token) if hash[:bank_account_token]
107
+ if account.is_a?(BankAccount) and token and !account.token
108
+ account.token = token
109
+ elsif account.is_a?(String)
110
+ account = BankAccount.new(account)
111
+ elsif account.is_a?(Hash)
112
+ account = BankAccount.new(nil,account)
113
+ elsif token
114
+ account = BankAccount.new(token)
115
+ end
116
+ hash['bank_account'] = account if account
117
+ hash
118
+ end
119
+
101
120
  def self.parse_object_tokens hash
102
- parse_charge_data(parse_customer_data(parse_card_data(hash)))
121
+ parse_charge_data(parse_customer_data(parse_card_data(parse_bank_account_data(hash))))
103
122
  end
104
123
 
105
124
  def self.parse_options_for_request attributes, options
@@ -115,6 +134,15 @@ module PinPayment
115
134
  end
116
135
  end
117
136
 
137
+ if bank_account = options.delete('bank_account')
138
+ if bank_account.token
139
+ options['bank_account_token'] = bank_account.token
140
+ else
141
+ # Ruby's Net::HTTP#set_form_data doesn't deal with nested hashes :(
142
+ bank_account.to_hash.each{|k,v| options["bank_account[#{k}]"] = v }
143
+ end
144
+ end
145
+
118
146
  options['customer_token'] = options.delete('customer').token if options['customer']
119
147
  options['charge_token'] = options.delete('charge').token if options['charge']
120
148
 
@@ -0,0 +1,71 @@
1
+ module PinPayment
2
+ class Recipient < Base
3
+ attr_accessor :token, :email, :name, :bank_account, :bank_account_token
4
+ protected :token=, :email=, :name=, :bank_account=, :bank_account_token=
5
+
6
+
7
+ # Uses the pin API to create a recipient.
8
+ #
9
+ # @param [Hash] recipient_data
10
+ # @option recipient_data [String] :email *required*
11
+ # @option recipient_data [String] :name *required*
12
+ # @option recipient_data [String,PinPayment::BankAccount,Hash] :bank_account can be a token, hash or bank account object
13
+ # @return [PinPayment::Recipient]
14
+ def self.create recipient_data
15
+ attributes = self.attributes - [:token] # fix attributes allowed by POST API
16
+ options = parse_options_for_request(attributes, recipient_data)
17
+ response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/recipients' }, options)
18
+ new(response.delete('token'), response)
19
+ end
20
+
21
+ # Update a recipient using the pin API.
22
+ #
23
+ # @param [String] token *required*
24
+ # @param [String] email *required*
25
+ # @param [String,PinPayment::BankAccount,Hash] bank_account can be a token, hash or bank account object *required*
26
+ # @return [PinPayment::Recipient]
27
+ def self.update token, email, card_or_token = nil
28
+ new(token).tap{|c| c.update(email, card_or_token) }
29
+ end
30
+
31
+ # Fetches all of your recipients using the pin API.
32
+ #
33
+ # @return [Array<PinPayment::Recipient>]
34
+ # TODO: pagination
35
+ def self.all
36
+ response = get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/recipients' })
37
+ response.map{|x| new(x.delete('token'), x) }
38
+ end
39
+
40
+ # Fetches a customer using the pin API.
41
+ #
42
+ # @param [String] token the recipient token
43
+ # @return [PinPayment::Recipient]
44
+ def self.find token
45
+ response = get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/recipients/#{token}" })
46
+ new(response.delete('token'), response)
47
+ end
48
+
49
+ # Update a recipient using the pin API.
50
+ #
51
+ # @param [String] email the recipients's new email address
52
+ # @param [String, PinPayment::BankAccount, Hash] account_or_token the recipient's new bank account details
53
+ # @return [PinPayment::Customer]
54
+ def update email, account_or_token = nil
55
+ attributes = self.class.attributes - [:token, :created_at]
56
+ options = self.class.parse_options_for_request(attributes, email: email, bank_account: account_or_token)
57
+ response = self.class.put(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/recipients/#{token}" }, options)
58
+ self.email = response['email']
59
+ self.bank_account = response['bank_account']
60
+ self
61
+ end
62
+
63
+
64
+ private
65
+
66
+ def self.attributes
67
+ [:token,:email,:name,:bank_account]
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,63 @@
1
+ module PinPayment
2
+ class Transfer < Base
3
+
4
+ attr_accessor :description, :amount, :currency, :recipient, :token
5
+ protected :description=, :amount=, :currency=, :recipient=, :token=
6
+
7
+ # Uses the pin API to create a transfer.
8
+ #
9
+ # @param [Hash] transfer_data
10
+ # @option transfer_data [String] :description *required*
11
+ # @option transfer_data [String] :amount *required*
12
+ # @option transfer_data [String] :currency *required* (Currenly only AUD is supported)
13
+ # @option transfer_data [String] :recipient *required* a token for a stored recipient
14
+ # @return [PinPayment::Transfer]
15
+ def self.create transfer_data
16
+ attributes = self.attributes - [:token] # fix attributes allowed by POST API
17
+ options = parse_options_for_request(attributes, transfer_data)
18
+ response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/transfers' }, options)
19
+ new(response.delete('token'), response)
20
+ end
21
+
22
+ # Fetches all of your transfers using the pin API.
23
+ #
24
+ # @return [Array<PinPayment::Transfer>]
25
+ # TODO: pagination
26
+ def self.all
27
+ response = get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/transfers' })
28
+ response.map{|x| new(x.delete('token'), x) }
29
+ end
30
+
31
+ # Fetches a transfer using the pin API.
32
+ #
33
+ # @param [String] token the recipient token
34
+ # @return [PinPayment::Transfer]
35
+ def self.find token
36
+ response = get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/transfers/#{token}" })
37
+ new(response.delete('token'), response)
38
+ end
39
+
40
+ def line_items
41
+ response = self.class.get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/transfers/#{token}/line_items" })
42
+ response.map{|hash| LineItem.new(hash.delete('token')) }
43
+ end
44
+
45
+ protected
46
+
47
+ def self.attributes
48
+ [:token, :description, :amount, :currency, :recipient]
49
+ end
50
+
51
+ class LineItem < Base
52
+ attr_accessor :type, :object, :amount, :token
53
+ protected :type=, :object=, :amount=, :token=
54
+
55
+ protected
56
+
57
+ def self.attributes
58
+ [:token, :type, :object, :amount, :recipient]
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -1,7 +1,7 @@
1
1
  module PinPayment
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 3
4
+ MINOR = 4
5
5
  PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
data/lib/pin_payment.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  require 'pin_payment/base'
2
+ require 'pin_payment/balance'
3
+ require 'pin_payment/bank_account'
2
4
  require 'pin_payment/card'
3
5
  require 'pin_payment/charge'
4
6
  require 'pin_payment/customer'
5
7
  require 'pin_payment/error'
6
8
  require 'pin_payment/refund'
9
+ require 'pin_payment/recipient'
10
+ require 'pin_payment/transfer'
7
11
  require 'pin_payment/version'
8
12
 
9
13
  module PinPayment
@@ -1,4 +1,4 @@
1
- ---
1
+ ---
2
2
  charge:
3
3
  token_already_used: '{"error":"token_already_used","error_description":"Token already used. Card tokens can only be used once, to create a charge or assign a card to a customer."}'
4
4
  invalid_amount: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid.","messages":[{"param":"amount","code":"amount_invalid","message":"Amount must be an integer"},{"param":"amount","code":"amount_invalid","message":"Amount must be more than 1 USD"}]}'
@@ -18,3 +18,21 @@ refund:
18
18
  card:
19
19
  success: '{"response":{"token":"card_nytGw7koRg23EEp9NTmz9w","display_number":"XXXX-XXXX-XXXX-0000","scheme":"master","address_line1":"42 Sevenoaks St","address_line2":null,"address_city":"Lathlain","address_postcode":"6454","address_state":"WA","address_country":"Australia"}}'
20
20
  invalid: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid.","messages":[{"param":"number","code":"number_invalid","message":"Number is not a valid credit card number"}]}'
21
+ bank_account:
22
+ missing_name: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid","messages":[{"param":"name","code":"name_invalid","message":"Name can''t be blank"}]}'
23
+ missing_bsb: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid","messages":[{"param":"bsb","code":"bsb_invalid","message":"BSB can''t be blank"},{"param":"bsb","code":"bsb_invalid","message":"BSB must be 6 numbers"}]}'
24
+ missing_number: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid","messages":[{"param":"number","code":"number_invalid","message":"Number can''t be blank"}]}'
25
+ success: '{"response":{"token":"ba_zHkOnBEFk2L_AmHfq_PxiQ","name":"Test Account","bsb":"736032","number":"XXX456","bank_name":"Westpac Banking Corporation","branch":"Armadale"},"ip_address":"203.153.240.2"}'
26
+ balance:
27
+ success: '{"response":{"available":[{"amount":50000,"currency":"AUD"}],"pending":[{"amount":50000,"currency":"AUD"}]}}'
28
+ recipient:
29
+ blank_email: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid","messages":[{"param":"email","code":"email_invalid","message":"Email can''t be blank"},{"param":"email","code":"email_invalid","message":"Email is not formatted properly"}]}'
30
+ created: '{"response":{"token":"rp_AnyJmM5z_rhj8_u7xTiq_w","name":"Test Name","email":"foo@example.com","created_at":"2014-12-15T03:46:37Z","bank_account":{"token":"ba_POCetS7Qju539urHxrTvoA","name":"Test Account","bsb":"736032","number":"XXX456","bank_name":"Westpac Banking Corporation","branch":"Armadale"}}}'
31
+ updated: '{"response":{"token":"rp_AnyJmM5z_rhj8_u7xTiq_w","name":"Test Name","email":"changed@example.com","created_at":"2014-12-15T03:46:37Z","bank_account":{"token":"ba_POCetS7Qju539urHxrTvoA","name":"Test Account","bsb":"736032","number":"XXX456","bank_name":"Westpac Banking Corporation","branch":"Armadale"}}}'
32
+ all: '{"response":[{"token":"rp_AnyJmM5z_rhj8_u7xTiq_w","name":"Test Name","email":"foo@example.com","created_at":"2014-12-15T03:46:37Z","bank_account":{"token":"ba_POCetS7Qju539urHxrTvoA","name":"Test Account","bsb":"736032","number":"XXX456","bank_name":"Westpac Banking Corporation","branch":"Armadale"}},{"token":"rp_n0-UOFenz-Z23daxHqHxOg","name":"Test","email":"user@example.com","created_at":"2014-12-15T01:48:33Z","bank_account":{"token":"ba_tCGxQlYWbPQxb8Al9OGQww","name":"Test123","bsb":"736032","number":"XXXXXX321","bank_name":"Westpac Banking Corporation","branch":"Armadale"}},{"token":"rp_4qMmyOurC5jf_7FXLHpWSg","name":"Test","email":"user2@example.com","created_at":"2014-12-15T01:42:24Z","bank_account":{"token":"ba_BWKT0WpyaXu6oH_PmBiuaQ","name":"Test","bsb":"736032","number":"XXXXXXXXX123","bank_name":"Westpac Banking Corporation","branch":"Armadale"}},{"token":"rp_1os2F6siI-xjhU5-5tghfQ","name":"Test","email":"user3@example.com","created_at":"2014-12-15T01:41:59Z","bank_account":{"token":"ba_uYIneVsOhG8cNqIOVNDqEQ","name":"Test","bsb":"123123","number":"XXXXXXXXX123","bank_name":"","branch":""}}],"count":4,"pagination":{"current":1,"previous":null,"next":null,"per_page":25,"pages":1,"count":4}}'
33
+ create_with_bank_account: '{"response":{"token":"rp_p6xyKnjzDt3Caqh-VJrRLw","name":"Test User","email":"foo@example.com","created_at":"2014-12-15T03:57:03Z","bank_account":{"token":"ba_iGM_JeiefwKWnLVd0XtVeA","name":"Test Account","bsb":"736032","number":"XXX456","bank_name":"Westpac Banking Corporation","branch":"Armadale"}}}'
34
+ transfer:
35
+ created: '{"response":{"token":"rp_yXQFJfLI-Et6YfKfEgxoyw","name":"Test Name","email":"foo@example.com","created_at":"2014-12-15T06:00:35Z","bank_account":{"token":"ba_POCetS7Qju539urHxrTvoA","name":"Test Account","bsb":"736032","number":"XXX456","bank_name":"Westpac Banking Corporation","branch":"Armadale"}}}'
36
+ all: '{"response":[{"token":"rp_yXQFJfLI-Et6YfKfEgxoyw","name":"Test Name","email":"foo@example.com","created_at":"2014-12-15T06:00:35Z","bank_account":{"token":"ba_POCetS7Qju539urHxrTvoA","name":"Test Account","bsb":"736032","number":"XXX456","bank_name":"Westpac Banking Corporation","branch":"Armadale"}}],"count":1,"pagination":{"current":1,"previous":null,"next":null,"per_page":25,"pages":1,"count":1}}'
37
+ line_item:
38
+ all: '{"response":[{"type":"transfer","amount":100,"currency":"AUD","created_at":"2014-12-15T06:00:06Z","object":"transfer","token":"rp_yXQFJfLI-Et6YfKfEgxoyw"}],"count":1,"pagination":{"current":1,"previous":null,"next":null,"per_page":25,"pages":1,"count":1}}'
data/test/test_helper.rb CHANGED
@@ -46,12 +46,45 @@ def charge_hash
46
46
  }
47
47
  end
48
48
 
49
+ def bank_account_hash
50
+ {
51
+ name: "Test Account",
52
+ bsb: "736032",
53
+ number: "123456"
54
+ }
55
+ end
56
+
57
+ def transfer_hash(recipient_hash)
58
+ {
59
+ description: "Transfer of Things",
60
+ amount: 100,
61
+ currency: "AUD",
62
+ recipient: recipient_hash
63
+ }
64
+ end
65
+
49
66
  def created_customer
50
67
  FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/customers', body: fixtures['responses']['customer']['created'])
51
68
  customer = PinPayment::Customer.create('foo@example.com', card_hash)
52
69
  end
53
70
 
71
+ def created_bank_account
72
+ FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/bank_accounts', body: fixtures['responses']['bank_account']['success'])
73
+ customer = PinPayment::BankAccount.create(bank_account_hash)
74
+ end
75
+
54
76
  def created_charge
55
77
  FakeWeb.register_uri(:post, "https://test-api.pin.net.au/1/charges", body: fixtures['responses']['charge']['success'])
56
78
  charge = PinPayment::Charge.create(charge_hash)
57
79
  end
80
+
81
+ def created_recipient
82
+ FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/recipients', body: fixtures['responses']['recipient']['created'])
83
+ recipient = PinPayment::Recipient.create({email: 'foo@example.com', name: "Test Name", bank_account: bank_account_hash})
84
+ end
85
+
86
+ def created_transfer
87
+ recipient = created_recipient
88
+ FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/transfers', body: fixtures['responses']['transfer']['created'])
89
+ transfer = PinPayment::Transfer.create(transfer_hash(recipient.token))
90
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class TestPinBalance < MiniTest::Unit::TestCase
4
+ def setup
5
+ common_setup
6
+ end
7
+
8
+ def test_current_balance_success
9
+ FakeWeb.register_uri(:get, 'https://test-api.pin.net.au/1/balance', body: fixtures['responses']['balance']['success'])
10
+ assert_kind_of PinPayment::Balance, PinPayment::Balance.current_balance
11
+ end
12
+
13
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class TestPinBankAccount < MiniTest::Unit::TestCase
4
+ def setup
5
+ common_setup
6
+ end
7
+
8
+ def test_create_with_no_name
9
+ FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/bank_accounts', body: fixtures['responses']['bank_account']['missing_name'])
10
+ assert_raises PinPayment::Error::InvalidResource do
11
+ PinPayment::BankAccount.create({bsb: "123123", number: "123456789"})
12
+ end
13
+ end
14
+
15
+ def test_create_with_no_bsb
16
+ FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/bank_accounts', body: fixtures['responses']['bank_account']['missing_bsb'])
17
+ assert_raises PinPayment::Error::InvalidResource do
18
+ PinPayment::BankAccount.create({name: "Test Account", number: "123456789"})
19
+ end
20
+ end
21
+
22
+ def test_create_with_no_number
23
+ FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/bank_accounts', body: fixtures['responses']['bank_account']['missing_number'])
24
+ assert_raises PinPayment::Error::InvalidResource do
25
+ PinPayment::BankAccount.create({name: "Test Account", number: "123456789"})
26
+ end
27
+ end
28
+
29
+ def test_create_success
30
+ bank_account = created_bank_account
31
+ assert_kind_of PinPayment::BankAccount, bank_account
32
+ end
33
+
34
+ end
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ class TestPinRecipient < MiniTest::Unit::TestCase
4
+ def setup
5
+ common_setup
6
+ end
7
+
8
+ def test_create_with_blank_email
9
+ FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/recipients', body: fixtures['responses']['recipient']['blank_email'])
10
+ assert_raises PinPayment::Error::InvalidResource do
11
+ PinPayment::Recipient.create({email: nil, name: "Test Name", bank_account: bank_account_hash})
12
+ end
13
+ end
14
+
15
+ def test_create_success
16
+ recipient = created_recipient
17
+ assert_kind_of PinPayment::Recipient, recipient
18
+ end
19
+
20
+ def test_direct_update
21
+ recipient = created_recipient
22
+ FakeWeb.register_uri(:put, "https://test-api.pin.net.au/1/recipients/#{recipient.token}", body: fixtures['responses']['recipient']['updated'])
23
+ recipient = PinPayment::Recipient.update(recipient.token, 'changed@example.com')
24
+ assert_equal 'changed@example.com', recipient.email
25
+ end
26
+
27
+ def test_object_update
28
+ recipient = created_recipient
29
+ FakeWeb.register_uri(:put, "https://test-api.pin.net.au/1/recipients/#{recipient.token}", body: fixtures['responses']['recipient']['updated'])
30
+ recipient.update('changed@example.com')
31
+ assert_equal 'changed@example.com', recipient.email
32
+ end
33
+
34
+ def test_find_recipient
35
+ recipient = created_recipient
36
+ FakeWeb.register_uri(:get, "https://test-api.pin.net.au/1/recipients/#{recipient.token}", body: fixtures['responses']['recipient']['created'])
37
+ recipient = PinPayment::Recipient.find(recipient.token)
38
+ assert_kind_of PinPayment::Recipient, recipient
39
+ end
40
+
41
+ def test_fetch_all_recipients
42
+ FakeWeb.register_uri(:get, 'https://test-api.pin.net.au/1/recipients', body: fixtures['responses']['recipient']['all'])
43
+ recipients = PinPayment::Recipient.all
44
+ assert_kind_of Array, recipients
45
+ assert_kind_of PinPayment::Recipient, recipients.first
46
+ end
47
+
48
+ def test_create_recipient_with_bank_account_hash
49
+ FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/recipients', body: fixtures['responses']['recipient']['create_with_bank_account'])
50
+ data = {
51
+ email: 'foo@example.com',
52
+ name: 'Test User',
53
+ bank_account: bank_account_hash
54
+ }
55
+ recipient = PinPayment::Recipient.create(data)
56
+ assert_kind_of PinPayment::BankAccount, recipient.bank_account
57
+ assert_kind_of String, recipient.bank_account.token
58
+ assert recipient.bank_account.token.length > 0
59
+ end
60
+ end
@@ -2,20 +2,26 @@ require 'test_helper'
2
2
 
3
3
  class TestPinSetup < MiniTest::Unit::TestCase
4
4
  def test_setting_public_key
5
+ oldpublic = PinPayment.public_key
5
6
  assert_equal nil, PinPayment.public_key
6
7
  PinPayment.public_key = 'foo'
7
8
  assert_equal 'foo', PinPayment.public_key
9
+ PinPayment.public_key = oldpublic
8
10
  end
9
11
 
10
12
  def test_setting_secret_key
13
+ oldsecret = PinPayment.secret_key
11
14
  assert_equal nil, PinPayment.secret_key
12
15
  PinPayment.secret_key = 'foo'
13
16
  assert_equal 'foo', PinPayment.secret_key
17
+ PinPayment.secret_key = oldsecret
14
18
  end
15
19
 
16
20
  def test_api_url
21
+ oldurl = PinPayment.api_url
17
22
  assert_equal 'https://test-api.pin.net.au', PinPayment.api_url
18
23
  PinPayment.api_url = 'foo'
19
24
  assert_equal 'foo', PinPayment.api_url
25
+ PinPayment.api_url = oldurl
20
26
  end
21
27
  end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class TestPinTransfer < MiniTest::Unit::TestCase
4
+ def test_transfer_create
5
+ transfer = created_transfer
6
+ assert_kind_of PinPayment::Transfer, transfer
7
+ end
8
+
9
+ def test_fetch_all_transfers
10
+ FakeWeb.register_uri(:get, 'https://test-api.pin.net.au/1/transfers', body: fixtures['responses']['transfer']['all'])
11
+ transfers = PinPayment::Transfer.all
12
+ assert_kind_of Array, transfers
13
+ assert_kind_of PinPayment::Transfer, transfers.first
14
+ end
15
+
16
+ def test_find_transfer
17
+ transfer = created_transfer
18
+ FakeWeb.register_uri(:get, "https://test-api.pin.net.au/1/transfers/#{transfer.token}", body: fixtures['responses']['transfer']['created'])
19
+ transfer = PinPayment::Transfer.find(transfer.token)
20
+ assert_kind_of PinPayment::Transfer, transfer
21
+ end
22
+
23
+ def test_line_items
24
+ transfer = created_transfer
25
+ FakeWeb.register_uri(:get, "https://test-api.pin.net.au/1/transfers/#{transfer.token}/line_items", body: fixtures['responses']['line_item']['all'])
26
+ line_items = transfer.line_items
27
+ assert_kind_of Array, line_items
28
+ assert_kind_of PinPayment::Transfer::LineItem, line_items.first
29
+ end
30
+
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pin_payment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danial Pearce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-22 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fakeweb
@@ -67,21 +67,29 @@ files:
67
67
  - README.md
68
68
  - Rakefile
69
69
  - lib/pin_payment.rb
70
+ - lib/pin_payment/balance.rb
71
+ - lib/pin_payment/bank_account.rb
70
72
  - lib/pin_payment/base.rb
71
73
  - lib/pin_payment/card.rb
72
74
  - lib/pin_payment/charge.rb
73
75
  - lib/pin_payment/customer.rb
74
76
  - lib/pin_payment/error.rb
77
+ - lib/pin_payment/recipient.rb
75
78
  - lib/pin_payment/refund.rb
79
+ - lib/pin_payment/transfer.rb
76
80
  - lib/pin_payment/version.rb
77
81
  - pin_payment.gemspec
78
82
  - test/fixtures/responses.yml
79
83
  - test/test_helper.rb
84
+ - test/test_pin_balance.rb
85
+ - test/test_pin_bank_account.rb
80
86
  - test/test_pin_card.rb
81
87
  - test/test_pin_charge.rb
82
88
  - test/test_pin_customer.rb
89
+ - test/test_pin_recipient.rb
83
90
  - test/test_pin_refund.rb
84
91
  - test/test_pin_setup.rb
92
+ - test/test_pin_transfer.rb
85
93
  homepage: https://github.com/tigris/pin_payment
86
94
  licenses:
87
95
  - MIT
@@ -109,9 +117,13 @@ summary: Ruby bindings for the Pin API
109
117
  test_files:
110
118
  - test/fixtures/responses.yml
111
119
  - test/test_helper.rb
120
+ - test/test_pin_balance.rb
121
+ - test/test_pin_bank_account.rb
112
122
  - test/test_pin_card.rb
113
123
  - test/test_pin_charge.rb
114
124
  - test/test_pin_customer.rb
125
+ - test/test_pin_recipient.rb
115
126
  - test/test_pin_refund.rb
116
127
  - test/test_pin_setup.rb
128
+ - test/test_pin_transfer.rb
117
129
  has_rdoc: