pin_up 1.1.1 → 1.2.0
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/pin_up/pin_errors.rb +33 -12
- data/pin_up.gemspec +3 -3
- data/spec/errors_spec.rb +35 -13
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c67d8075501e91bd3b435d0e505340c02205a535
|
4
|
+
data.tar.gz: 36267918b46bcc3bbeb595f3e8af798daba499f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5cc15ec66e259f6e3ef21c22b7fb4e936195ba84c22a2f8521b0ff130ba9e42bfa1a399b0986beafcfaab0c299d20b89c466c8e71d6b5dcd4129452da6f3500
|
7
|
+
data.tar.gz: 1e25012796615fa553563200ca24888d915b06d6c55348f3ac7fdbd6d8696226424593d722add3dda0fcba055f8a36f6a04cff6c3d7f851724b44a880f364ebd
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/pin_up/pin_errors.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Pin
|
2
2
|
##
|
3
3
|
# Base Pin Error class
|
4
|
-
class PinError
|
4
|
+
class PinError
|
5
5
|
def initialize(message = nil, http_status = nil)
|
6
6
|
@message = message
|
7
7
|
@http_status = http_status
|
@@ -17,17 +17,17 @@ module Pin
|
|
17
17
|
when 400
|
18
18
|
case response['error']
|
19
19
|
when 'cannot_delete_primary_card'
|
20
|
-
raise
|
20
|
+
raise Pin::InvalidResource.new(response, response['error_description'])
|
21
21
|
else
|
22
|
-
raise
|
22
|
+
raise Pin::ChargeError.new(response)
|
23
23
|
end
|
24
24
|
when 402
|
25
|
-
raise
|
25
|
+
raise Pin::InsufficientPinBalance.new(response)
|
26
26
|
when 404
|
27
|
-
raise
|
27
|
+
raise Pin::ResourceNotFound.new response
|
28
28
|
when 422
|
29
29
|
message = handle_bad_response(response)
|
30
|
-
raise
|
30
|
+
raise Pin::InvalidResource.new(response, message)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -48,22 +48,43 @@ module Pin
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def self.handle_bad_request
|
51
|
-
raise
|
51
|
+
raise Pin::ClientError, 'request :method must be one of get, post, put, patch or delete'
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
class
|
55
|
+
class SimpleError < StandardError
|
56
|
+
attr_accessor :response, :message
|
57
|
+
def initialize(response, message=nil)
|
58
|
+
@response = response
|
59
|
+
@message = message || @response['error_description']
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s
|
63
|
+
@message
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class ResourceNotFound < SimpleError
|
56
68
|
end
|
57
69
|
|
58
|
-
class InvalidResource <
|
70
|
+
class InvalidResource < SimpleError
|
59
71
|
end
|
60
72
|
|
61
|
-
class ChargeError <
|
73
|
+
class ChargeError < StandardError
|
74
|
+
attr_accessor :response, :message
|
75
|
+
def initialize(response)
|
76
|
+
@response = response
|
77
|
+
@message = "#{@response['error']}: #{@response['error_description']}. Charge token: #{@response['charge_token']}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_s
|
81
|
+
@message
|
82
|
+
end
|
62
83
|
end
|
63
84
|
|
64
|
-
class InsufficientPinBalance <
|
85
|
+
class InsufficientPinBalance < SimpleError
|
65
86
|
end
|
66
87
|
|
67
|
-
class ClientError <
|
88
|
+
class ClientError < StandardError
|
68
89
|
end
|
69
90
|
end
|
data/pin_up.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: pin_up 1.
|
5
|
+
# stub: pin_up 1.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "pin_up"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Daniel Nitsikopoulos"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-11-14"
|
15
15
|
s.description = "A Ruby gem wrapper for the pin-payments (pin.net.au) API"
|
16
16
|
s.email = "dnitza@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
data/spec/errors_spec.rb
CHANGED
@@ -6,12 +6,20 @@ describe 'Errors', :vcr, class: Pin::PinError do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'should raise a 404 error when looking for a customer that doesn\'t exist' do
|
9
|
-
expect { Pin::Customer.find('foo') }.to raise_error
|
9
|
+
expect { Pin::Customer.find('foo') }.to raise_error do |error|
|
10
|
+
expect(error).to be_a Pin::ResourceNotFound
|
11
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
12
|
+
expect(error.response).to be_a Hash
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
it 'should raise a 422 error when trying to update missing a param' do
|
13
17
|
options = { email: 'dNitza@gmail.com', card: { address_line1: '12345 Fake Street', expiry_month: '05', expiry_year: '2016', cvc: '123', address_city: 'Melbourne', address_postcode: '1234', address_state: 'VIC', address_country: 'Australia' } }
|
14
|
-
expect { Pin::Customer.update('cus_6XnfOD5bvQ1qkaf3LqmhfQ', options) }.to raise_error
|
18
|
+
expect { Pin::Customer.update('cus_6XnfOD5bvQ1qkaf3LqmhfQ', options) }.to raise_error do |error|
|
19
|
+
expect(error).to be_a Pin::InvalidResource
|
20
|
+
expect(error.message).to eq "card_number_invalid: Card number can't be blank card_name_invalid: Card name can't be blank "
|
21
|
+
expect(error.response).to be_a Hash
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
it 'should raise a 422 error when trying to make a payment with an expired card' do
|
@@ -27,7 +35,11 @@ describe 'Errors', :vcr, class: Pin::PinError do
|
|
27
35
|
address_state: 'WA',
|
28
36
|
address_country: 'Australia'
|
29
37
|
} }
|
30
|
-
expect { Pin::Charges.create(options) }.to raise_error
|
38
|
+
expect { Pin::Charges.create(options) }.to raise_error do |error|
|
39
|
+
expect(error).to be_a Pin::InvalidResource
|
40
|
+
expect(error.message).to eq 'card_expiry_month_invalid: Card expiry month is expired card_expiry_year_invalid: Card expiry year is expired '
|
41
|
+
expect(error.response).to be_a Hash
|
42
|
+
end
|
31
43
|
end
|
32
44
|
|
33
45
|
it 'should raise a 400 error when trying to make a payment and a valid card gets declined' do
|
@@ -59,30 +71,40 @@ describe 'Errors', :vcr, class: Pin::PinError do
|
|
59
71
|
address_state: 'WA',
|
60
72
|
address_country: 'Australia'
|
61
73
|
} }
|
62
|
-
expect { Pin::Charges.create(options) }.to raise_error
|
74
|
+
expect { Pin::Charges.create(options) }.to raise_error do |error|
|
75
|
+
expect(error).to be_a Pin::InvalidResource
|
76
|
+
expect(error.message).to eq 'card_number_invalid: Card number is not valid '
|
77
|
+
expect(error.response).to be_a Hash
|
78
|
+
end
|
63
79
|
end
|
64
80
|
|
65
81
|
it 'Should raise a ResourceNotFound error when can\'t find customer' do
|
66
|
-
expect { Pin::Customer.charges('foo') }.to raise_error
|
82
|
+
expect { Pin::Customer.charges('foo') }.to raise_error do |error|
|
83
|
+
expect(error).to be_a Pin::ResourceNotFound
|
84
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
85
|
+
expect(error.response).to be_a Hash
|
86
|
+
end
|
67
87
|
end
|
68
88
|
|
69
89
|
it 'should raise a 422 error if no 2nd argument is given' do
|
70
90
|
options = { email: 'dNitza@gmail.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: 'cus_6XnfOD5bvQ1qkaf3LqmhfQ' }
|
71
91
|
@charge = Pin::Charges.create(options)
|
72
|
-
expect { Pin::Refund.create(@charge['token']) }.to raise_error
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
@charge = Pin::Charges.create(options)
|
78
|
-
# expect { Pin::Refund.create(@charge['token'], 90) }.to raise_error(Pin::InvalidResource, 'amount_invalid: Amount must be more than 100 ($1.00 AUD)')
|
92
|
+
expect { Pin::Refund.create(@charge['token']) }.to raise_error do |error|
|
93
|
+
expect(error).to be_a Pin::InvalidResource
|
94
|
+
expect(error.message).to eq "amount_invalid: Amount can't be blank amount_invalid: Amount is not a number "
|
95
|
+
expect(error.response).to be_a Hash
|
96
|
+
end
|
79
97
|
end
|
80
98
|
|
81
99
|
it 'should raise a 400 error when attempting to delete customer\'s primary card' do
|
82
100
|
customer_token = 'cus_6XnfOD5bvQ1qkaf3LqmhfQ'
|
83
101
|
cards = Pin::Customer.cards(customer_token)
|
84
102
|
primary_card_token = cards.select{|card| card['primary'] }.first['token']
|
85
|
-
expect { Pin::Customer.delete_card(customer_token, primary_card_token) }.to raise_error
|
103
|
+
expect { Pin::Customer.delete_card(customer_token, primary_card_token) }.to raise_error do |error|
|
104
|
+
expect(error).to be_a Pin::InvalidResource
|
105
|
+
expect(error.message).to eq 'You cannot delete a customer\'s primary card token'
|
106
|
+
expect(error.response).to be_a Hash
|
107
|
+
end
|
86
108
|
end
|
87
109
|
|
88
110
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pin_up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Nitsikopoulos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|