pin_up 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/.ruby-version +1 -0
- data/Guardfile +2 -2
- data/VERSION +1 -1
- data/lib/pin_up/base.rb +20 -19
- data/lib/pin_up/card.rb +1 -2
- data/lib/pin_up/charge.rb +8 -9
- data/lib/pin_up/customer.rb +12 -9
- data/lib/pin_up/pin_errors.rb +26 -22
- data/lib/pin_up/refund.rb +2 -3
- data/lib/pin_up.rb +1 -1
- data/pin_up.gemspec +4 -2
- data/spec/base_spec.rb +13 -13
- data/spec/cards_spec.rb +5 -5
- data/spec/charges_spec.rb +23 -23
- data/spec/customers_spec.rb +28 -28
- data/spec/errors_spec.rb +58 -59
- data/spec/refund_spec.rb +11 -12
- data/spec/spec_helper.rb +9 -7
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 569c2387bbe572f2e680d34ccc7319d663fd2941
|
4
|
+
data.tar.gz: 2e4ff4fc878584bf9938d2d7dd0bdd4b20b248e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 429922018edf82e1cd70f9982961a43f2a335937655463af14640c821bfb6cdad01cb51ffcbe5ec34f0201ce0454e19bc12a48c8ba758f5edbeab86f8be9860a
|
7
|
+
data.tar.gz: 1a65fd45399e990c5730c166b91d5f88155323cd66aa9604c3f1ef1d3d75e95eb340c204d398e5cff4b7c96879ce51e73ad50a3b55c883282ae0bf0fcf9c742b
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0-preview1
|
data/Guardfile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
3
|
guard :rspec do
|
4
4
|
watch(%r{^spec/.+_spec\.rb$})
|
5
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec
|
5
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
6
6
|
watch('spec/spec_helper.rb') { "spec" }
|
7
7
|
|
8
8
|
# Rails example
|
@@ -24,7 +24,7 @@ end
|
|
24
24
|
|
25
25
|
guard :rspec do
|
26
26
|
watch(%r{^spec/.+_spec\.rb$})
|
27
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec
|
27
|
+
watch(%r{^lib/pin_up/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
28
28
|
watch('spec/spec_helper.rb') { "spec" }
|
29
29
|
|
30
30
|
# Rails example
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.5
|
data/lib/pin_up/base.rb
CHANGED
@@ -1,41 +1,38 @@
|
|
1
1
|
module Pin
|
2
2
|
##
|
3
|
-
# This class sets up a few things like the base URL and provides a few
|
3
|
+
# This class sets up a few things like the base URL and provides a few
|
4
|
+
# utility methods to be shared between classes.
|
4
5
|
class Base
|
5
6
|
include HTTParty
|
6
7
|
|
8
|
+
attr_reader :key
|
7
9
|
##
|
8
10
|
# Create a new Pin instance
|
9
11
|
# Args:
|
10
12
|
# key: Your Pin secret key
|
11
|
-
# env: The environment you want to use.
|
13
|
+
# env: The environment you want to use.
|
14
|
+
# Leave blank for live and pass :test for test
|
12
15
|
# An error is raised if an invalid env is passed in.
|
13
|
-
def initialize(key =
|
16
|
+
def initialize(key = '', env = :live)
|
14
17
|
@key = key
|
15
18
|
env = env.to_sym
|
16
|
-
@@auth = {username: key, password: ''}
|
19
|
+
@@auth = { username: @key, password: '' }
|
17
20
|
@@base_url = if env == :live
|
18
|
-
|
21
|
+
'https://api.pin.net.au/1/'
|
19
22
|
elsif env == :test
|
20
|
-
|
23
|
+
'https://test-api.pin.net.au/1/'
|
21
24
|
else
|
22
|
-
|
25
|
+
fail "'env' option must be :live or :test. Leave blank for live payments"
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
26
|
-
##
|
27
|
-
# Provides access to your key if needed
|
28
|
-
def key
|
29
|
-
@key
|
30
|
-
end
|
31
|
-
|
32
29
|
##
|
33
30
|
# Provides access to the base URL if needed
|
34
|
-
def
|
31
|
+
def base_uri
|
35
32
|
@@base_url
|
36
33
|
end
|
37
34
|
|
38
|
-
protected
|
35
|
+
# protected
|
39
36
|
|
40
37
|
##
|
41
38
|
# Sends an authorised GET request to pins server
|
@@ -67,15 +64,19 @@ module Pin
|
|
67
64
|
end
|
68
65
|
|
69
66
|
##
|
70
|
-
# Builds a response of a collection if the response code is 200
|
71
|
-
|
67
|
+
# Builds a response of a collection if the response code is 200
|
68
|
+
# otherwise an empty array is returned
|
69
|
+
def self.build_collection_response(response, pagination = false)
|
72
70
|
models = []
|
73
71
|
if response.code == 200
|
74
72
|
if pagination
|
75
73
|
response.parsed_response['response'].each do |model|
|
76
74
|
models << model
|
77
75
|
end
|
78
|
-
return {
|
76
|
+
return {
|
77
|
+
response: models,
|
78
|
+
pagination: response.parsed_response['pagination']
|
79
|
+
}
|
79
80
|
else
|
80
81
|
response.parsed_response['response'].each do |model|
|
81
82
|
models << model
|
@@ -87,4 +88,4 @@ module Pin
|
|
87
88
|
# models
|
88
89
|
end
|
89
90
|
end
|
90
|
-
end
|
91
|
+
end
|
data/lib/pin_up/card.rb
CHANGED
@@ -2,7 +2,6 @@ module Pin
|
|
2
2
|
##
|
3
3
|
# This class models Pin's Cards API
|
4
4
|
class Card < Base
|
5
|
-
|
6
5
|
##
|
7
6
|
# creates a card given a hash of options
|
8
7
|
# https://pin.net.au/docs/api/cards
|
@@ -15,4 +14,4 @@ module Pin
|
|
15
14
|
build_response(auth_post('cards', options))
|
16
15
|
end
|
17
16
|
end
|
18
|
-
end
|
17
|
+
end
|
data/lib/pin_up/charge.rb
CHANGED
@@ -11,8 +11,8 @@ module Pin
|
|
11
11
|
# and the pagination hash with [:pagination]
|
12
12
|
#
|
13
13
|
# https://pin.net.au/docs/api/charges#get-charges
|
14
|
-
def self.all(page=nil, pagination=false)
|
15
|
-
build_collection_response(auth_get("charges?page=#{page}"),pagination)
|
14
|
+
def self.all(page = nil, pagination = false)
|
15
|
+
build_collection_response(auth_get("charges?page=#{page}"), pagination)
|
16
16
|
end
|
17
17
|
|
18
18
|
##
|
@@ -29,29 +29,28 @@ module Pin
|
|
29
29
|
# returns: a collection of charge objects
|
30
30
|
# https://pin.net.au/docs/api/charges#search-charges
|
31
31
|
def self.search(options = {})
|
32
|
-
term =
|
32
|
+
term = ''
|
33
33
|
options.each do |key, option|
|
34
|
-
term += "#{key.to_s}=#{URI
|
34
|
+
term += "#{key.to_s}=#{URI.encode(option)}&"
|
35
35
|
end
|
36
36
|
build_response(auth_get("charges/search?#{term}"))
|
37
37
|
end
|
38
38
|
|
39
|
-
# Create a charge given charge details and a card,
|
39
|
+
# Create a charge given charge details and a card,
|
40
|
+
# a card_token or a customer_token
|
40
41
|
# args: options (Hash)
|
41
42
|
# returns: a charge object
|
42
43
|
# https://pin.net.au/docs/api/charges#post-charges
|
43
44
|
def self.create(options = {})
|
44
|
-
build_response(auth_post(
|
45
|
+
build_response(auth_post('charges', options))
|
45
46
|
end
|
46
47
|
|
47
48
|
# Captures a previously authorised charge and returns its details.
|
48
49
|
# args: charge-token (String)
|
49
50
|
# returns: charge object
|
50
51
|
# https://pin.net.au/docs/api/charges#put-charges
|
51
|
-
|
52
52
|
def self.capture(token)
|
53
53
|
build_response(auth_put("/charges/#{token}/capture"))
|
54
54
|
end
|
55
|
-
|
56
55
|
end
|
57
|
-
end
|
56
|
+
end
|
data/lib/pin_up/customer.rb
CHANGED
@@ -2,7 +2,6 @@ module Pin
|
|
2
2
|
##
|
3
3
|
# This class models Pins Customers API
|
4
4
|
class Customer < Base
|
5
|
-
|
6
5
|
##
|
7
6
|
# Lists all customers for your account
|
8
7
|
# args: page (Fixnum), pagination (Boolean)
|
@@ -12,7 +11,7 @@ module Pin
|
|
12
11
|
# and the pagination hash with [:pagination]
|
13
12
|
#
|
14
13
|
# https://pin.net.au/docs/api/customers#get-customers
|
15
|
-
def self.all(page=nil, pagination=false)
|
14
|
+
def self.all(page = nil, pagination = false)
|
16
15
|
build_collection_response(auth_get("customers?page=#{page}"), pagination)
|
17
16
|
end
|
18
17
|
|
@@ -23,9 +22,9 @@ module Pin
|
|
23
22
|
# https://pin.net.au/docs/api/customers#post-customers
|
24
23
|
def self.create(email, card)
|
25
24
|
options = if card.respond_to?(:to_hash)
|
26
|
-
{card: card.to_hash}
|
25
|
+
{ card: card.to_hash }
|
27
26
|
else
|
28
|
-
{card_token: card}
|
27
|
+
{ card_token: card }
|
29
28
|
end.merge(email: email)
|
30
29
|
|
31
30
|
build_response(auth_post('customers', options))
|
@@ -41,11 +40,13 @@ module Pin
|
|
41
40
|
end
|
42
41
|
|
43
42
|
##
|
44
|
-
# Update a customer for your account given a token
|
43
|
+
# Update a customer for your account given a token
|
44
|
+
# and any of: email, card (hash),card_token
|
45
45
|
# args: token (String), options (Hash)
|
46
46
|
# returns: a customer object
|
47
47
|
# https://pin.net.au/docs/api/customers#put-customer
|
48
|
-
# NB: When providing a card (hash), you need to specify
|
48
|
+
# NB: When providing a card (hash), you need to specify
|
49
|
+
# the full list of details.
|
49
50
|
def self.update(token, options = {})
|
50
51
|
build_response(auth_put("customers/#{token}", options))
|
51
52
|
end
|
@@ -59,8 +60,10 @@ module Pin
|
|
59
60
|
# and the pagination hash with [:pagination]
|
60
61
|
#
|
61
62
|
# https://pin.net.au/docs/api/customers#get-customers-charges
|
62
|
-
def self.charges(token, page=nil, pagination=false)
|
63
|
-
build_collection_response(
|
63
|
+
def self.charges(token, page = nil, pagination = false)
|
64
|
+
build_collection_response(
|
65
|
+
auth_get("customers/#{token}/charges?page=#{page}"), pagination
|
66
|
+
)
|
64
67
|
end
|
65
68
|
end
|
66
|
-
end
|
69
|
+
end
|
data/lib/pin_up/pin_errors.rb
CHANGED
@@ -1,40 +1,45 @@
|
|
1
1
|
module Pin
|
2
|
+
##
|
3
|
+
# Base Pin Eror class
|
2
4
|
class PinError < Exception
|
3
|
-
|
4
|
-
def initialize(message=nil, http_status=nil)
|
5
|
+
def initialize(message = nil, http_status = nil)
|
5
6
|
@message = message
|
6
7
|
@http_status = http_status
|
7
8
|
end
|
8
9
|
|
9
10
|
def to_s
|
10
|
-
status_string = @http_status.nil? ?
|
11
|
+
status_string = @http_status.nil? ? '' : "(Status #{@http_status}) "
|
11
12
|
"#{status_string}#{@message}"
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.handle_error(http_status, response)
|
15
16
|
case http_status
|
16
17
|
when 400
|
17
|
-
|
18
|
+
fail(Pin::ChargeError, "#{response['error']}: #{response['error_description']}. Charge token: #{response['charge_token']}")
|
18
19
|
when 402
|
19
|
-
|
20
|
+
fail(Pin::InsufficientPinBalance, "#{response['error_description']}")
|
20
21
|
when 404
|
21
|
-
|
22
|
+
fail(Pin::ResourceNotFound, "#{response['error_description']}")
|
22
23
|
when 422
|
23
|
-
message =
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
rescue
|
29
|
-
begin response['messages']['amount'][0]
|
30
|
-
message = "#{response['error']}: #{response['error_description']}. Amount: #{response['messages']['amount'][0]}"
|
31
|
-
rescue
|
32
|
-
message = "#{response['error']}: #{response['error_description']}"
|
33
|
-
end
|
24
|
+
message = handle_bad_response(response)
|
25
|
+
fail(Pin::InvalidResource, message)
|
26
|
+
end
|
27
|
+
end
|
34
28
|
|
35
|
-
|
36
|
-
|
29
|
+
def self.handle_bad_response(response)
|
30
|
+
message = ''
|
31
|
+
begin
|
32
|
+
response['messages'].each do |m|
|
33
|
+
message += "#{m['code']}: #{m['message']}"
|
34
|
+
end
|
35
|
+
rescue
|
36
|
+
begin response['messages']['amount'][0]
|
37
|
+
message = "#{response['error']}: #{response['error_description']}. Amount: #{response['messages']['amount'][0]}"
|
38
|
+
rescue
|
39
|
+
message = "#{response['error']}: #{response['error_description']}"
|
40
|
+
end
|
37
41
|
end
|
42
|
+
message
|
38
43
|
end
|
39
44
|
end
|
40
45
|
|
@@ -47,7 +52,6 @@ module Pin
|
|
47
52
|
class ChargeError < PinError
|
48
53
|
end
|
49
54
|
|
50
|
-
class InsufficientPinBalance <PinError
|
55
|
+
class InsufficientPinBalance < PinError
|
51
56
|
end
|
52
|
-
|
53
|
-
end
|
57
|
+
end
|
data/lib/pin_up/refund.rb
CHANGED
@@ -2,7 +2,6 @@ module Pin
|
|
2
2
|
##
|
3
3
|
# This class models Pin's Charges API
|
4
4
|
class Refund < Base
|
5
|
-
|
6
5
|
##
|
7
6
|
# Find a refund by charge token
|
8
7
|
# returns: a collection of refund objects
|
@@ -23,8 +22,8 @@ module Pin
|
|
23
22
|
# if no amount is passed in, the full amount of the charge will be refunded
|
24
23
|
# https://pin.net.au/docs/api/refunds#post-refunds
|
25
24
|
def self.create(token, amount = nil)
|
26
|
-
options = {amount: amount}
|
25
|
+
options = { amount: amount }
|
27
26
|
build_response(auth_post("charges/#{token}/refunds", options))
|
28
27
|
end
|
29
28
|
end
|
30
|
-
end
|
29
|
+
end
|
data/lib/pin_up.rb
CHANGED
data/pin_up.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
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 0.9.
|
5
|
+
# stub: pin_up 0.9.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "pin_up"
|
9
|
-
s.version = "0.9.
|
9
|
+
s.version = "0.9.5"
|
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"]
|
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
|
|
29
29
|
".idea/scopes/scope_settings.xml",
|
30
30
|
".idea/vcs.xml",
|
31
31
|
".idea/workspace.xml",
|
32
|
+
".rubocop.yml",
|
33
|
+
".ruby-version",
|
32
34
|
".travis.yml",
|
33
35
|
"Gemfile",
|
34
36
|
"Gemfile.lock",
|
data/spec/base_spec.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Base', :vcr, class: Pin::Base do
|
4
4
|
before(:each) do
|
5
|
-
@test_pin = Pin::Base.new(ENV[
|
5
|
+
@test_pin = Pin::Base.new(ENV['PIN_SECRET'], :test)
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
9
|
-
@pin = Pin::Base.new(
|
10
|
-
expect(@pin.key).to eq
|
8
|
+
it 'should set key correctly' do
|
9
|
+
@pin = Pin::Base.new('KEY', :live)
|
10
|
+
expect(@pin.key).to eq 'KEY'
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
@pin = Pin::Base.new(
|
15
|
-
expect(@pin.
|
13
|
+
it 'should set environment to live if no env set' do
|
14
|
+
@pin = Pin::Base.new('KEY', :live)
|
15
|
+
expect(@pin.base_uri).to eq 'https://api.pin.net.au/1/'
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
expect(@test_pin.
|
18
|
+
it 'should set environment to test when set' do
|
19
|
+
expect(@test_pin.base_uri).to eq 'https://test-api.pin.net.au/1/'
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
expect{Pin::Base.new(
|
22
|
+
it 'should raise an error if anything other than '' :live or :test is passed to a new instance' do
|
23
|
+
expect { Pin::Base.new('KEY', :foo) }.to raise_error(RuntimeError, "'env' option must be :live or :test. Leave blank for live payments")
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'should list succesfully connect to Pin' do
|
27
27
|
stub_request(:get, "https://#{@test_pin.key}:''@test-api.pin.net.au/1/customers")
|
28
28
|
expect(Pin::Base.auth_get('customers').code).to eq 200
|
29
29
|
end
|
data/spec/cards_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Card', :vcr, class: Pin::Card do
|
4
4
|
before(:each) do
|
5
|
-
Pin::Base.new(ENV[
|
5
|
+
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
9
|
-
options = {number:
|
8
|
+
it 'should create a card and respond with the card detail from pin' do
|
9
|
+
options = { number: '5520000000000000', expiry_month: '12', expiry_year: '2018', cvc: '123', name: 'Roland Robot', address_line1: '123 Fake Road', address_line2: '', address_city: 'Melbourne', address_postcode: '1223', address_state: 'Vic', address_country: 'AU' }
|
10
10
|
Pin::Card.create(options)['token'].should match(/^[a-z]{4}[_]/)
|
11
11
|
end
|
12
|
-
end
|
12
|
+
end
|
data/spec/charges_spec.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Charge', :vcr, class: Pin::Charges do
|
4
4
|
before(:each) do
|
5
|
-
Pin::Base.new(ENV[
|
5
|
+
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should list charges in Pin' do
|
9
9
|
Pin::Charges.all.should_not == []
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
13
|
-
Pin::Charges.find(
|
12
|
+
it 'should show a charge given a token' do
|
13
|
+
Pin::Charges.find('ch_0kdOMXP7gG0_W_Vh8qAWdA')['token'].should match(/^[a-z]{2}[_]/)
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
17
|
-
Pin::Charges.search(
|
16
|
+
it 'should show a charge given a search term' do
|
17
|
+
Pin::Charges.search(query: 'mid Plan - My Focusbook', end_date: 'Mar 25, 2013').should_not == []
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
Pin::Charges.search(
|
20
|
+
it 'should not show a charge if end_date is out of range' do
|
21
|
+
Pin::Charges.search(end_date: 'Mar 25, 2011').should == []
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
options = {email:
|
26
|
-
Pin::Charges.create(options)[
|
24
|
+
it 'should create a charge given details' do
|
25
|
+
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_8ImkZdEZ6BXUA6NcJDZg_g' }
|
26
|
+
Pin::Charges.create(options)['success'].should eq true
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
Pin::Charges.all(3,true)[:pagination][
|
29
|
+
it 'should return pagination if "pagination" is true' do
|
30
|
+
Pin::Charges.all(3, true)[:pagination]['current'] == 3
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it 'should list charges on a page given a page' do
|
34
34
|
Pin::Charges.all(1).should_not == []
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
options = {email:
|
39
|
-
Pin::Charges.create(options)[
|
37
|
+
it 'should create a pre-auth (capture a charge)' do
|
38
|
+
options = { email: 'dNitza@gmail.com', description: 'A new captured charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: 'cus_8ImkZdEZ6BXUA6NcJDZg_g', capture: false }
|
39
|
+
Pin::Charges.create(options)['captured'].should eq false
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
43
|
-
options = {email:
|
44
|
-
token = Pin::Charges.create(options)[
|
45
|
-
Pin::Charges.capture(token)[
|
42
|
+
it 'should capture a charge' do
|
43
|
+
options = { email: 'dNitza@gmail.com', description: 'A new captured charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: 'cus_8ImkZdEZ6BXUA6NcJDZg_g', capture: false }
|
44
|
+
token = Pin::Charges.create(options)['token']
|
45
|
+
Pin::Charges.capture(token)['success'].should eq true
|
46
46
|
end
|
47
|
-
end
|
47
|
+
end
|
data/spec/customers_spec.rb
CHANGED
@@ -1,63 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Customer', :vcr, class: Pin::Customer do
|
4
4
|
before(:each) do
|
5
|
-
Pin::Base.new(ENV[
|
5
|
+
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should list customers' do
|
9
9
|
Pin::Customer.all.should_not == []
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
13
|
-
request = Pin::Customer.all(20,true)
|
14
|
-
request[:pagination][
|
12
|
+
it 'should go to a specific page when page paramater is passed' do
|
13
|
+
request = Pin::Customer.all(20, true)
|
14
|
+
request[:pagination]['current'].should == 20
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
request = Pin::Customer.all(1,true)
|
17
|
+
it 'should list customers on a page given a page' do
|
18
|
+
request = Pin::Customer.all(1, true)
|
19
19
|
request[:response].should_not == []
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
request = Pin::Customer.all(1,true)
|
24
|
-
request[:pagination].keys.include?(
|
22
|
+
it 'should return pagination if true is passed for pagination' do
|
23
|
+
request = Pin::Customer.all(1, true)
|
24
|
+
request[:pagination].keys.include?(%W('current previous next per_page pages count))
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
request = Pin::Customer.all(25,true)
|
27
|
+
it 'should not list customers on a page given a page if there are no customers' do
|
28
|
+
request = Pin::Customer.all(25, true)
|
29
29
|
request[:response].should == []
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
Pin::Customer.find('cus_8ImkZdEZ6BXUA6NcJDZg_g')['token'].should ==
|
32
|
+
it 'should show a customer given a token' do
|
33
|
+
Pin::Customer.find('cus_8ImkZdEZ6BXUA6NcJDZg_g')['token'].should == 'cus_8ImkZdEZ6BXUA6NcJDZg_g'
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'should list charges to a customer given a token' do
|
37
37
|
Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g')[0]['token'].should match(/^[a-z]{2}[_]/)
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g',5,true)[:pagination][
|
40
|
+
it 'should show pagination on a page given a token and a page' do
|
41
|
+
Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g', 5, true)[:pagination]['current'] == 5
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
45
|
-
Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g',1,true)[:response][0]['token'].should match(/^[a-z]{2}[_]/)
|
44
|
+
it 'should list charges to a customer on a page given a token and a page' do
|
45
|
+
Pin::Customer.charges('cus_8ImkZdEZ6BXUA6NcJDZg_g', 1, true)[:response][0]['token'].should match(/^[a-z]{2}[_]/)
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
49
|
-
Pin::Customer.create('dNitza@gmail.com',
|
48
|
+
it 'should create a customer given an email and card details' do
|
49
|
+
Pin::Customer.create('dNitza@gmail.com', number: '5520000000000000', expiry_month: '12', expiry_year: '2014', cvc: '123', name: 'Roland Robot', address_line1: '123 fake street', address_city: 'Melbourne', address_postcode: '1234', address_state: 'Vic', address_country: 'Australia')['token'].should match(/^[a-z]{3}[_]/)
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
53
|
-
options = {email:
|
54
|
-
Pin::Customer.update('cus_sRtAD2Am-goZoLg1K-HVpA', options)['card']['address_line1'].should ==
|
52
|
+
it 'should update a customer given a token and details to update' do
|
53
|
+
options = { email: 'dNitza@gmail.com', card: { number: '5520000000000000', address_line1: '12345 Fake Street', expiry_month: '05', expiry_year: '2014', cvc: '123', name: 'Daniel Nitsikopoulos', address_city: 'Melbourne', address_postcode: '1234', address_state: 'VIC', address_country: 'Australia' } }
|
54
|
+
Pin::Customer.update('cus_sRtAD2Am-goZoLg1K-HVpA', options)['card']['address_line1'].should == '12345 Fake Street'
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
58
|
-
options = {number:
|
57
|
+
it 'should create a customer given a card token customer email' do
|
58
|
+
options = { number: '5520000000000000', expiry_month: '12', expiry_year: '2018', cvc: '123', name: 'Roland TestRobot', address_line1: '123 Fake Road', address_line2: '', address_city: 'Melbourne', address_postcode: '1223', address_state: 'Vic', address_country: 'AU' }
|
59
59
|
@card = Pin::Card.create(options)
|
60
60
|
Pin::Customer.create('nitza98@hotmail.com', @card['token'])['token'].should match(/^[a-z]{3}[_]/)
|
61
61
|
end
|
62
62
|
|
63
|
-
end
|
63
|
+
end
|
data/spec/errors_spec.rb
CHANGED
@@ -1,82 +1,81 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Errors', :vcr, class: Pin::PinError do
|
4
4
|
before(:each) do
|
5
|
-
Pin::Base.new(ENV[
|
5
|
+
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
9
|
-
expect{Pin::Customer.find('foo')}.to raise_error(Pin::ResourceNotFound,
|
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(Pin::ResourceNotFound, 'The requested resource could not be found.')
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
13
|
-
options = {email:
|
14
|
-
expect{Pin::Customer.update('cus_sRtAD2Am-goZoLg1K-HVpA', options)}.to raise_error(Pin::InvalidResource,
|
12
|
+
it 'should raise a 422 error when trying to update missing a param' do
|
13
|
+
options = { email: 'dNitza@gmail.com', card: { address_line1: '12345 Fake Street', expiry_month: '05', expiry_year: '2014', cvc: '123', address_city: 'Melbourne', address_postcode: '1234', address_state: 'VIC', address_country: 'Australia' } }
|
14
|
+
expect { Pin::Customer.update('cus_sRtAD2Am-goZoLg1K-HVpA', options) }.to raise_error(Pin::InvalidResource, 'invalid_resource: One or more parameters were missing or invalid')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
options = {email:
|
19
|
-
number:
|
20
|
-
expiry_month:
|
21
|
-
expiry_year:
|
22
|
-
cvc:
|
23
|
-
name:
|
24
|
-
address_line1:
|
25
|
-
address_city:
|
26
|
-
address_postcode:
|
27
|
-
address_state:
|
28
|
-
address_country:
|
29
|
-
}}
|
30
|
-
expect{Pin::Charges.create(options)}.to raise_error(Pin::InvalidResource,
|
17
|
+
it 'should raise a 422 error when trying to make a payment with an expired card' do
|
18
|
+
options = { email: 'dNitza@gmail.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', card: {
|
19
|
+
number: '5520000000000000',
|
20
|
+
expiry_month: '05',
|
21
|
+
expiry_year: '2012',
|
22
|
+
cvc: '123',
|
23
|
+
name: 'Roland Robot',
|
24
|
+
address_line1: '42 Sevenoaks St',
|
25
|
+
address_city: 'Lathlain',
|
26
|
+
address_postcode: '6454',
|
27
|
+
address_state: 'WA',
|
28
|
+
address_country: 'Australia'
|
29
|
+
} }
|
30
|
+
expect { Pin::Charges.create(options) }.to raise_error(Pin::InvalidResource, 'card_expiry_month_invalid: Card expiry month is expiredcard_expiry_year_invalid: Card expiry year is expired')
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
34
|
-
options = {email:
|
35
|
-
number:
|
36
|
-
expiry_month:
|
37
|
-
expiry_year:
|
38
|
-
cvc:
|
39
|
-
name:
|
40
|
-
address_line1:
|
41
|
-
address_city:
|
42
|
-
address_postcode:
|
43
|
-
address_state:
|
44
|
-
address_country:
|
45
|
-
}}
|
46
|
-
expect{Pin::Charges.create(options)}.to raise_error(Pin::ChargeError)
|
33
|
+
it 'should raise a 400 error when trying to make a payment and a valid card gets declined' do
|
34
|
+
options = { email: 'dNitza@gmail.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', card: {
|
35
|
+
number: '5560000000000001',
|
36
|
+
expiry_month: '05',
|
37
|
+
expiry_year: '2018',
|
38
|
+
cvc: '123',
|
39
|
+
name: 'Roland Robot',
|
40
|
+
address_line1: '42 Sevenoaks St',
|
41
|
+
address_city: 'Lathlain',
|
42
|
+
address_postcode: '6454',
|
43
|
+
address_state: 'WA',
|
44
|
+
address_country: 'Australia'
|
45
|
+
} }
|
46
|
+
expect { Pin::Charges.create(options) }.to raise_error(Pin::ChargeError)
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
50
|
-
options = {email:
|
51
|
-
number:
|
52
|
-
expiry_month:
|
53
|
-
expiry_year:
|
54
|
-
cvc:
|
55
|
-
name:
|
56
|
-
address_line1:
|
57
|
-
address_city:
|
58
|
-
address_postcode:
|
59
|
-
address_state:
|
60
|
-
address_country:
|
61
|
-
}}
|
62
|
-
expect{Pin::Charges.create(options)}.to raise_error(Pin::InvalidResource,
|
49
|
+
it 'should raise a 422 error when trying to make a payment with an invalid card' do
|
50
|
+
options = { email: 'dNitza@gmail.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', card: {
|
51
|
+
number: '5520000000000099',
|
52
|
+
expiry_month: '05',
|
53
|
+
expiry_year: '2014',
|
54
|
+
cvc: '123',
|
55
|
+
name: 'Roland Robot',
|
56
|
+
address_line1: '42 Sevenoaks St',
|
57
|
+
address_city: 'Lathlain',
|
58
|
+
address_postcode: '6454',
|
59
|
+
address_state: 'WA',
|
60
|
+
address_country: 'Australia'
|
61
|
+
} }
|
62
|
+
expect { Pin::Charges.create(options) }.to raise_error(Pin::InvalidResource, 'card_number_invalid: Card number is not a valid Visa or Mastercard number')
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
66
|
-
expect{Pin::Customer.charges(
|
65
|
+
it 'Should raise a ResourceNotFound error when can\'t find customer' do
|
66
|
+
expect { Pin::Customer.charges('foo') }.to raise_error(Pin::ResourceNotFound, 'The requested resource could not be found.')
|
67
67
|
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
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_8ImkZdEZ6BXUA6NcJDZg_g" }
|
69
|
+
it 'should raise a 422 error if no 2nd argument is given' do
|
70
|
+
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_8ImkZdEZ6BXUA6NcJDZg_g' }
|
72
71
|
@charge = Pin::Charges.create(options)
|
73
|
-
expect{Pin::Refund.create(@charge['token'])}.to raise_error(Pin::InvalidResource,
|
72
|
+
expect { Pin::Refund.create(@charge['token']) }.to raise_error(Pin::InvalidResource, 'invalid_resource: One or more parameters were missing or invalid. Amount: can\'t be blank')
|
74
73
|
end
|
75
74
|
|
76
|
-
xit
|
77
|
-
options = {email:
|
75
|
+
xit 'should raise a 422 error if a value of < 100 is given' do
|
76
|
+
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_8ImkZdEZ6BXUA6NcJDZg_g' }
|
78
77
|
@charge = Pin::Charges.create(options)
|
79
|
-
expect{Pin::Refund.create(@charge['token'], 90)}.to raise_error(Pin::InvalidResource,
|
78
|
+
expect { Pin::Refund.create(@charge['token'], 90) }.to raise_error(Pin::InvalidResource, 'One or more parameters were missing or invalid')
|
80
79
|
end
|
81
80
|
|
82
|
-
end
|
81
|
+
end
|
data/spec/refund_spec.rb
CHANGED
@@ -1,27 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
describe "Refund", :vcr, class: Pin::Refund do
|
3
|
+
describe 'Refund', :vcr, class: Pin::Refund do
|
5
4
|
before(:each) do
|
6
|
-
Pin::Base.new(ENV[
|
5
|
+
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
7
6
|
end
|
8
7
|
|
9
|
-
it
|
10
|
-
Pin::Refund.find('ch_S_3tP81Q9_sDngSv27gShQ')[0]['token'].should ==
|
8
|
+
it 'should list all refunds made to a charge given a token' do
|
9
|
+
Pin::Refund.find('ch_S_3tP81Q9_sDngSv27gShQ')[0]['token'].should == 'rf_O4lHrNzwXYmMmTbBq0ZLPw'
|
11
10
|
end
|
12
11
|
|
13
|
-
it
|
12
|
+
it 'should return nothing if looking for a charge without a refund' do
|
14
13
|
Pin::Refund.find('ch_rqPIWDK71YU46M4MAQHQKg').should == []
|
15
14
|
end
|
16
15
|
|
17
|
-
it
|
18
|
-
Pin::Refund.find('ch_S_3tP81Q9_sDngSv27gShQ',1,true)[:response].should_not == []
|
16
|
+
it 'should return a page of refunds given a page and token' do
|
17
|
+
Pin::Refund.find('ch_S_3tP81Q9_sDngSv27gShQ', 1, true)[:response].should_not == []
|
19
18
|
end
|
20
19
|
|
21
|
-
it
|
22
|
-
options = {email:
|
20
|
+
it 'should create a refund for a given amount and charge' do
|
21
|
+
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_8ImkZdEZ6BXUA6NcJDZg_g' }
|
23
22
|
@charge = Pin::Charges.create(options)
|
24
|
-
Pin::Refund.create(@charge['token'],
|
23
|
+
Pin::Refund.create(@charge['token'], '400')['amount'].should == 400
|
25
24
|
end
|
26
25
|
|
27
|
-
end
|
26
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,11 +7,11 @@ require 'webmock/rspec'
|
|
7
7
|
require 'capybara/rspec'
|
8
8
|
require 'vcr'
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
10
|
+
require 'net/https'
|
11
|
+
require 'uri'
|
12
12
|
|
13
13
|
## Uncomment to load in a .yml with your pin key
|
14
|
-
# ENV.update YAML.load(File.read(File.expand_path(
|
14
|
+
# ENV.update YAML.load(File.read(File.expand_path('../test_data.yml', __FILE__)))
|
15
15
|
|
16
16
|
# require pin_up gem
|
17
17
|
require 'pin_up'
|
@@ -20,15 +20,17 @@ RSpec.configure do |config|
|
|
20
20
|
config.include WebMock::API
|
21
21
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
22
22
|
config.around(:each, :vcr) do |example|
|
23
|
-
name = example
|
24
|
-
|
23
|
+
name = example
|
24
|
+
.metadata[:full_description]
|
25
|
+
.split(/\s+/, 2).join('/')
|
26
|
+
.gsub(/[^\w\/]+/, '_')
|
25
27
|
VCR.use_cassette(name) { example.call }
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
31
|
VCR.configure do |c|
|
30
|
-
c.cassette_library_dir =
|
32
|
+
c.cassette_library_dir = 'spec/vcr'
|
31
33
|
c.hook_into :webmock
|
32
34
|
c.allow_http_connections_when_no_cassette = true
|
33
|
-
c.filter_sensitive_data('<key>') {ENV[
|
35
|
+
c.filter_sensitive_data('<key>') { ENV['PIN_SECRET'] }
|
34
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pin_up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Nitsikopoulos
|
@@ -182,6 +182,8 @@ files:
|
|
182
182
|
- ".idea/scopes/scope_settings.xml"
|
183
183
|
- ".idea/vcs.xml"
|
184
184
|
- ".idea/workspace.xml"
|
185
|
+
- ".rubocop.yml"
|
186
|
+
- ".ruby-version"
|
185
187
|
- ".travis.yml"
|
186
188
|
- Gemfile
|
187
189
|
- Gemfile.lock
|