fake_pin 0.0.1 → 0.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: b26c0fbfa19cf74b4521c19774b1e844ec5623b7
4
- data.tar.gz: 65ffac6cf6f96872dd30930e5f8f0681a69ff7cc
3
+ metadata.gz: 84ac3500a8cce674642f7621469a8d3b0427087a
4
+ data.tar.gz: d3f044c2860c7df6663c3dc18a3bb9f0b0db7969
5
5
  SHA512:
6
- metadata.gz: ea5167e1da065cc289fc2160b78427ca65c7ed9779cf0f3242c1efdcd1d0c4fe9ea07d472393c1c4805e8fe14090e8ff3160d072602ed4ed2e30fdefc12343c3
7
- data.tar.gz: ee02b374c8fb12317fc002a2c28a0d478d92e727811faad003bcb012fe0f1e741301d373b234477e0ebc3887053e09488a8d88a65152db202d272c43b0d9ab18
6
+ metadata.gz: 771218e59197d2557e48d0b9e1495058efda8a84c58557848f3fc84700c1698f2222778e79f78ac3d407d6b5cc7d29a9b4cd79b7eea3cd1eec20c011006b31d6
7
+ data.tar.gz: 4e283e7791304ab4a1b4c773ef73b46dc426321a40d192d0470a0fe73e86af6e76a911e4a0ef6ed8d920a871e7e6ec22e88f6a4b28450d2faf4c5dc3185ffc0a
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A basic implmentation of the Pin Payments REST API. This is great for when you want to test your API client or want an offline version of the API for automated testing.
4
4
 
5
+ **Note: The whole API isn't supported yet. Only adding cards, charging cards, and adding customers works currently. If you want one of the other API endpoints supported, Pull Requests are welcome, or just create an issue and I'll do it ASAP**
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -50,6 +52,10 @@ You should then be able to cURL charges like so:
50
52
  curl localhost:9000/1/charges -u your-secret-api-key: -d "amount=400" -d "currency=AUD" -d "description=test charge" -d "email=roland@pin.net.au" -d "ip_address=203.192.1.172" -d "card[number]=5520000000000000" -d "card[expiry_month]=05" -d "card[expiry_year]=2014" -d "card[cvc]=123" -d "card[name]=Roland Robot" -d "card[address_line1]=42 Sevenoaks St" -d "card[address_line2]=" -d "card[address_city]=Lathlain" -d "card[address_postcode]=6454" -d "card[address_state]=WA" -d "card[address_country]=Australia"
51
53
  ```
52
54
 
55
+ ## Should I use this in Production?
56
+
57
+ No.
58
+
53
59
  ## Contributing
54
60
 
55
61
  1. Fork it
@@ -1,9 +1,18 @@
1
1
  module FakePin
2
- autoload :Card, "fake_pin/card"
3
- autoload :Charge, "fake_pin/charge"
4
- autoload :Customer, "fake_pin/customer"
5
- autoload :Params, "fake_pin/params"
6
- autoload :Rack, "fake_pin/rack"
7
- autoload :Token, "fake_pin/token"
8
- autoload :VERSION, "fake_pin/version"
2
+ autoload :Card, "fake_pin/card"
3
+ autoload :Charge, "fake_pin/charge"
4
+ autoload :Customer, "fake_pin/customer"
5
+ autoload :Configuration, "fake_pin/configuration"
6
+ autoload :Params, "fake_pin/params"
7
+ autoload :Rack, "fake_pin/rack"
8
+ autoload :Token, "fake_pin/token"
9
+ autoload :VERSION, "fake_pin/version"
10
+
11
+ def self.configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def self.configure(&block)
16
+ yield(configuration)
17
+ end
9
18
  end
@@ -2,8 +2,8 @@ module FakePin
2
2
  class Card
3
3
  class UnrecognisedCardSchemeError < RuntimeError; end
4
4
 
5
- REQUIRED_PARAMS = :number, :expiry_month, :expiry_year, :name, :address_line1,
6
- :address_city, :address_postcode, :address_state, :address_country
5
+ REQUIRED_PARAMS = :number, :expiry_month, :expiry_year, :name
6
+ REQUIRED_ADDRESS_PARAMS = :address_line1, :address_city, :address_postcode, :address_state, :address_country
7
7
 
8
8
  SCHEMES = {
9
9
  'visa' => /^4\d{12}(\d{3})?$/,
@@ -29,7 +29,13 @@ module FakePin
29
29
  end
30
30
 
31
31
  def create
32
- @params.require(*REQUIRED_PARAMS)
32
+ required_params = if FakePin.configuration.require_address
33
+ [ *REQUIRED_PARAMS, *REQUIRED_ADDRESS_PARAMS ]
34
+ else
35
+ REQUIRED_PARAMS
36
+ end
37
+
38
+ @params.require(*required_params)
33
39
 
34
40
  number = @params['number'].to_s.gsub(/[^0-9]+/, '')
35
41
 
@@ -0,0 +1,9 @@
1
+ module FakePin
2
+ class Configuration
3
+ attr_accessor :require_address
4
+
5
+ def initialize
6
+ @require_address = true
7
+ end
8
+ end
9
+ end
@@ -18,6 +18,9 @@ module FakePin
18
18
  Params.new(request.params)
19
19
  end
20
20
 
21
+ jsonp = (method == "GET" && params['_method'] == "POST")
22
+ jsonp_callback = jsonp ? params['callback'] : nil
23
+
21
24
  if path == "1/customers"
22
25
  if method == "POST"
23
26
  return render_response(201, Customer.create(params))
@@ -27,10 +30,8 @@ module FakePin
27
30
  return render_response(201, Charge.create(params))
28
31
  end
29
32
  elsif path =~ /1\/cards(\.json)?/
30
- is_jsonp = (method == "GET" && params['_method'] == "POST")
31
-
32
- if method == "POST" || is_jsonp
33
- return render_response(201, Card.create(params), :callback => is_jsonp ? params['callback'] : nil)
33
+ if method == "POST" || jsonp
34
+ return render_response(201, Card.create(params), :callback => jsonp_callback)
34
35
  end
35
36
  end
36
37
 
@@ -40,15 +41,22 @@ module FakePin
40
41
  { :code => "#{param}_invalid", :message => "#{param} is required", :param => param }
41
42
  end
42
43
 
43
- render_error 422, 'invalid_resource', 'One or more parameters were missing or invalid.', messages
44
+ render_error 422, 'invalid_resource', 'One or more parameters were missing or invalid.', messages, :callback => jsonp_callback
44
45
  rescue => e
45
- render_error 500, 'fake_pin_exception', "FakePin broke with: #{e.class.name}:#{e.message}"
46
+ render_error 500, 'fake_pin_exception', "FakePin broke with: #{e.class.name}:#{e.message}", nil, :callback => jsonp_callback
46
47
  end
47
48
 
48
49
  private
49
50
 
50
51
  def render_404
51
- render_error(404, "invalid_resource", "The resource you requested could not be found")
52
+ render_error(404, "invalid_resource", "The resource you requested could not be found", nil, :callback => jsonp_callback)
53
+ end
54
+
55
+ def render_error(status, error, description, messages = nil, options = {})
56
+ response = { :error => error, :error_description => description }
57
+ response[:messages] = messages unless messages.nil?
58
+
59
+ render_response(status, response, options)
52
60
  end
53
61
 
54
62
  def render_response(status, response, options = {})
@@ -59,13 +67,6 @@ module FakePin
59
67
  end
60
68
  end
61
69
 
62
- def render_error(status, error, description, messages = nil)
63
- response = { :error => error, :error_description => description }
64
- response[:messages] = messages unless messages.nil?
65
-
66
- render_json(status, response)
67
- end
68
-
69
70
  def render_jsonp(status, json, callback)
70
71
  [
71
72
  status,
@@ -1,3 +1,3 @@
1
1
  module FakePin
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_pin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Pitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-06 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
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: :runtime
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: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
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: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
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
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: A rack-mountable version of the Pin Payments API
@@ -74,8 +74,8 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - .gitignore
78
- - .rspec
77
+ - ".gitignore"
78
+ - ".rspec"
79
79
  - Gemfile
80
80
  - LICENSE.txt
81
81
  - README.md
@@ -85,6 +85,7 @@ files:
85
85
  - lib/fake_pin.rb
86
86
  - lib/fake_pin/card.rb
87
87
  - lib/fake_pin/charge.rb
88
+ - lib/fake_pin/configuration.rb
88
89
  - lib/fake_pin/customer.rb
89
90
  - lib/fake_pin/params.rb
90
91
  - lib/fake_pin/rack.rb
@@ -101,17 +102,17 @@ require_paths:
101
102
  - lib
102
103
  required_ruby_version: !ruby/object:Gem::Requirement
103
104
  requirements:
104
- - - '>='
105
+ - - ">="
105
106
  - !ruby/object:Gem::Version
106
107
  version: '0'
107
108
  required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  requirements:
109
- - - '>='
110
+ - - ">="
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.0.3
115
+ rubygems_version: 2.4.1
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: A rack-mountable version of the Pin Payments API