pin_payment 0.5.1 → 0.5.2

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: 6f9e83c1491377893364052ac15ebcaa486c7f39
4
- data.tar.gz: ff071fcb3b6f47b30045d4cf6de3b641d5976a3c
3
+ metadata.gz: 1dfb1ab658537697e3c6f11264745662ee3e35dd
4
+ data.tar.gz: 20fc251cc598cda75a17a8c0a5eff56c4d2c9643
5
5
  SHA512:
6
- metadata.gz: 181688cdd45686b3d457ba9923b7b14e01e71111f7077fb80fed714501c0d6181036c03faa203dd74f4ed801b88d1e32239030a8b0e4d32026acfb88dce7887a
7
- data.tar.gz: 2477f7e5f8b3c790318272184a425e57fbf95412f3493d347277d426db88b38b5294d3fa8ba508da2efac7999ec5ac2b51955fd2256547ef38c16d8b2a6e3e3c
6
+ metadata.gz: ee665c32242d24ebd7d57803f733c434e12af65236de28da4d0b8f05fd58499c63798ecc02ca2701778a2b6c76f38d80e8c0950b47ed094165ad96ac56cfce35
7
+ data.tar.gz: b6951a24fda40f460075767ae4fddb3970020268cc9c7baa23f2692a738204fb3efcc8bbec49283ba16deffb59458d41c6652c3b395c440d622d04815cce9d3d
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
1
  source 'https://rubygems.org'
2
+
2
3
  gemspec
@@ -1,20 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pin_payment (0.5.1)
4
+ pin_payment (0.5.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  fakeweb (1.3.0)
10
+ minitest (5.11.3)
10
11
  rake (10.0.4)
11
- yard (0.8.6.1)
12
12
 
13
13
  PLATFORMS
14
14
  ruby
15
15
 
16
16
  DEPENDENCIES
17
17
  fakeweb
18
+ minitest
18
19
  pin_payment!
19
20
  rake
20
- yard
21
+
22
+ BUNDLED WITH
23
+ 1.17.2
@@ -20,6 +20,7 @@ module PinPayment
20
20
  end
21
21
 
22
22
  def self.api_url=(url)
23
+ url = 'https://' + url unless url.include?('https://')
23
24
  @@api_url = url
24
25
  end
25
26
 
@@ -23,6 +23,10 @@ module PinPayment
23
23
  def self.get uri, options = {}
24
24
  fetch Net::HTTP::Get, uri, options
25
25
  end
26
+
27
+ def self.delete uri, options = {}
28
+ fetch Net::HTTP::Delete, uri, options
29
+ end
26
30
 
27
31
  def self.fetch klass, uri, options
28
32
  client = Net::HTTP.new(uri.host, uri.port)
@@ -47,6 +47,15 @@ module PinPayment
47
47
  Refund.create self
48
48
  end
49
49
 
50
+ # Fetches all refunds of your charge using the pin API.
51
+ #
52
+ # @return [Array<PinPayment::Refund>]
53
+ # TODO: pagination
54
+ def refunds
55
+ response = Charge.get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/charges/#{token}/refunds" })
56
+ response.map{|x| Refund.new(x.delete('token'), x) }
57
+ end
58
+
50
59
  # @return [Boolean]
51
60
  def success?
52
61
  success == true
@@ -14,6 +14,10 @@ module PinPayment
14
14
  response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/customers' }, options)
15
15
  new(response.delete('token'), response)
16
16
  end
17
+
18
+ def self.delete_customer(token)
19
+ delete(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/customers/#{token}" })
20
+ end
17
21
 
18
22
  # Update a customer using the pin API.
19
23
  #
@@ -7,9 +7,20 @@ module PinPayment
7
7
  #
8
8
  # @param [String, PinPayment::Charge] charge_or_token the charge (or token of the charge) to refund
9
9
  # @return [PinPayment::Refund]
10
- def self.create charge_or_token
10
+ def self.create refund_data
11
+ charge_or_token = refund_data.is_a?(Hash) ? refund_data[:charge] : refund_data
11
12
  token = charge_or_token.is_a?(Charge) ? charge_or_token.token : charge_or_token
12
- response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/charges/#{token}/refunds" })
13
+ options = refund_data.is_a?(Hash) && refund_data[:amount] ? { amount: refund_data[:amount] } : {}
14
+ response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/charges/#{token}/refunds" }, options)
15
+ new(response.delete('token'), response)
16
+ end
17
+
18
+ # Fetches a refund using the Pin API.
19
+ #
20
+ # @param [String] token the charge token
21
+ # @return [PinPayment::Refund]
22
+ def self.find token
23
+ response = get(URI.parse(PinPayment.api_url).tap{ |uri| uri.path = "/1/refunds/#{token}" })
13
24
  new(response.delete('token'), response)
14
25
  end
15
26
 
@@ -1,8 +1,8 @@
1
1
  module PinPayment
2
2
  class Transfer < Base
3
3
 
4
- attr_accessor :description, :amount, :currency, :recipient, :token
5
- protected :description=, :amount=, :currency=, :recipient=, :token=
4
+ attr_accessor :description, :amount, :currency, :recipient, :token, :status, :paid_at, :total_debits, :total_credits
5
+ protected :description=, :amount=, :currency=, :recipient=, :token=, :status=, :paid_at=, :total_debits=, :total_credits=
6
6
 
7
7
  # Uses the pin API to create a transfer.
8
8
  #
@@ -45,7 +45,7 @@ module PinPayment
45
45
  protected
46
46
 
47
47
  def self.attributes
48
- [:token, :description, :amount, :currency, :recipient]
48
+ [:token, :description, :amount, :currency, :recipient, :status, :paid_at, :total_debits, :total_credits]
49
49
  end
50
50
 
51
51
  class LineItem < Base
@@ -2,7 +2,7 @@ module PinPayment
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
- PATCH = 1
5
+ PATCH = 2
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -14,9 +14,9 @@ spec = Gem::Specification.new do |s|
14
14
 
15
15
  s.add_development_dependency('fakeweb')
16
16
  s.add_development_dependency('rake')
17
- s.add_development_dependency('yard')
17
+ s.add_development_dependency('minitest')
18
18
 
19
- s.required_ruby_version = '>= 1.9.2'
19
+ s.required_ruby_version = '>= 2.3.0'
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
22
22
  s.test_files = `git ls-files -- test/*`.split("\n")
@@ -12,6 +12,8 @@ customer:
12
12
  created: '{"response":{"token":"cus__03Cn1lSk3offZ0IGkwpCg","email":"foo@example.com","created_at":"2013-06-12T10:08:30Z","card":{"token":"card_qMwnMfpG-olOhfJeyxmrcg","display_number":"XXXX-XXXX-XXXX-0000","scheme":"master","address_line1":"123 Main St","address_line2":"","address_city":"Melbourne","address_postcode":"3000","address_state":"Victoria","address_country":"Australia"}}}'
13
13
  all: '{"response":[{"token":"cus_OEHdj9KE_OiC9eig0h3IEA","email":"user1@example.com","created_at":"2013-06-25T04:14:35Z","card":{"token":"card_7rviJ2IZM__WC9Dnj0RHJA","display_number":"XXXX-XXXX-XXXX-0000","scheme":"visa","address_line1":"123 Main St","address_line2":"","address_city":"Melbourne","address_postcode":"3000","address_state":"Victoria","address_country":"Australia"}},{"token":"cus_cO2VtF4YzK6i1QBcLsdzOA","email":"user2@example.com","created_at":"2013-06-24T05:53:42Z","card":{"token":"card_bVou2J4hzbDIwe-sQ3ZqdQ","display_number":"XXXX-XXXX-XXXX-0000","scheme":"visa","address_line1":"123 Main St","address_line2":"","address_city":"Melbourne","address_postcode":"3000","address_state":"Victoria","address_country":"Australia"}}],"count":2,"pagination":{"current":1,"previous":null,"next":null,"per_page":25,"pages":1,"count":2}}'
14
14
  create_with_card: '{"response":{"token":"cus_XZg1ULpWaROQCOT5PdwLkQ","email":"roland@pin.net.au","created_at":"2013-06-27T00:24:43Z","card":{"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"}}}'
15
+ deleted: '{"response":{}}'
16
+ delete_not_found: '{"error":"resource_not_found","error_description":"No resource was found at this URL."}'
15
17
  refund:
16
18
  success: '{"response":{"token":"rf_wMYx5YHKaZAwQgj5rtNuTg","success":null,"amount":1000,"currency":"USD","charge":"ch_BjGW-S6WUisI6mOgpDRimg","created_at":"2013-06-25T03:16:33Z","error_message":null,"status_message":"Pending"}}'
17
19
  duplicate: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid.","messages":{"charge":["You have tried to refund more than the original charge"]}}'
@@ -16,6 +16,21 @@ class TestPinCustomer < MiniTest::Unit::TestCase
16
16
  customer = created_customer
17
17
  assert_kind_of PinPayment::Customer, customer
18
18
  end
19
+
20
+ def test_delete_success
21
+ customer = created_customer
22
+ FakeWeb.register_uri(:delete, "https://test-api.pin.net.au/1/customers/#{customer.token}", body: fixtures['responses']['customer']['deleted'])
23
+ response = PinPayment::Customer.delete_customer(customer.token)
24
+ assert_empty response
25
+ end
26
+
27
+ def test_delete_not_found
28
+ token = 'none-existing-token'
29
+ FakeWeb.register_uri(:delete, "https://test-api.pin.net.au/1/customers/#{token}", body: fixtures['responses']['customer']['delete_not_found'])
30
+ assert_raises PinPayment::Error::ResourceNotFound do
31
+ PinPayment::Customer.delete_customer(token)
32
+ end
33
+ end
19
34
 
20
35
  def test_direct_update
21
36
  customer = created_customer
@@ -21,7 +21,7 @@ class TestPinSetup < MiniTest::Unit::TestCase
21
21
  oldurl = PinPayment.api_url
22
22
  assert_equal 'https://test-api.pin.net.au', PinPayment.api_url
23
23
  PinPayment.api_url = 'foo'
24
- assert_equal 'foo', PinPayment.api_url
24
+ assert_equal 'https://foo', PinPayment.api_url
25
25
  PinPayment.api_url = oldurl
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pin_payment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danial Pearce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-20 00:00:00.000000000 Z
11
+ date: 2019-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fakeweb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: yard
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Pin is the easiest way to accept payments online. See https://pin.net.au/
@@ -60,7 +60,7 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
63
+ - ".gitignore"
64
64
  - Gemfile
65
65
  - Gemfile.lock
66
66
  - LICENSE
@@ -100,17 +100,17 @@ require_paths:
100
100
  - lib
101
101
  required_ruby_version: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - '>='
103
+ - - ">="
104
104
  - !ruby/object:Gem::Version
105
- version: 1.9.2
105
+ version: 2.3.0
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.0.14
113
+ rubygems_version: 2.5.1
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Ruby bindings for the Pin API
@@ -126,4 +126,3 @@ test_files:
126
126
  - test/test_pin_refund.rb
127
127
  - test/test_pin_setup.rb
128
128
  - test/test_pin_transfer.rb
129
- has_rdoc: