samurai 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- samurai (0.2.8)
4
+ samurai (0.2.10)
5
5
  activeresource (>= 2.2.2)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.0.9)
11
- activesupport (= 3.0.9)
12
- builder (~> 2.1.2)
13
- i18n (~> 0.5.0)
14
- activeresource (3.0.9)
15
- activemodel (= 3.0.9)
16
- activesupport (= 3.0.9)
17
- activesupport (3.0.9)
10
+ activemodel (3.1.0)
11
+ activesupport (= 3.1.0)
12
+ bcrypt-ruby (~> 3.0.0)
13
+ builder (~> 3.0.0)
14
+ i18n (~> 0.6)
15
+ activeresource (3.1.0)
16
+ activemodel (= 3.1.0)
17
+ activesupport (= 3.1.0)
18
+ activesupport (3.1.0)
19
+ multi_json (~> 1.0)
18
20
  archive-tar-minitar (0.5.2)
19
- builder (2.1.2)
21
+ bcrypt-ruby (3.0.0)
22
+ builder (3.0.0)
20
23
  columnize (0.3.4)
21
- diff-lcs (1.1.2)
24
+ diff-lcs (1.1.3)
22
25
  fakeweb (1.3.0)
23
- i18n (0.5.0)
26
+ i18n (0.6.0)
24
27
  linecache19 (0.5.12)
25
28
  ruby_core_source (>= 0.1.4)
29
+ multi_json (1.0.3)
26
30
  rspec (2.6.0)
27
31
  rspec-core (~> 2.6.0)
28
32
  rspec-expectations (~> 2.6.0)
@@ -41,4 +41,24 @@ require 'samurai/transaction'
41
41
  require 'samurai/message'
42
42
  require 'samurai/processor_response'
43
43
 
44
- require 'samurai/rails'
44
+ require 'samurai/rails'
45
+
46
+
47
+ # Monkey-patch AR::Base, because chunked encoding isn't handled properly
48
+ # see: https://github.com/jkrall/rails/commit/00920bb374a73626159e0002fe620f3aa4b5cfcf
49
+ # https://github.com/rails/rails/pull/2079
50
+ module ActiveResource
51
+ class Base
52
+ protected
53
+ def load_attributes_from_response(response)
54
+ has_content_length = !response['Content-Length'].blank? && response['Content-Length'] != "0"
55
+ has_body = !response.body.nil? && response.body.strip.size > 0
56
+ is_chunked = response["Transfer-Encoding"] == "chunked"
57
+
58
+ if has_body && (has_content_length || is_chunked)
59
+ load(self.class.format.decode(response.body), true)
60
+ @persisted = true
61
+ end
62
+ end
63
+ end
64
+ end
@@ -19,7 +19,9 @@ class Samurai::Base < ActiveResource::Base
19
19
  protected
20
20
 
21
21
  def load_attributes_from_response(response)
22
- super.tap { |instance| instance.process_response_errors }
22
+ super
23
+ process_response_errors
24
+ self
23
25
  end
24
26
  def self.instantiate_record(record, prefix_options = {})
25
27
  super.tap { |instance| instance.send :process_response_errors }
@@ -38,14 +38,22 @@ class Samurai::PaymentMethod < Samurai::Base
38
38
  end
39
39
  protected :process_response_errors
40
40
 
41
- # Initialize the known attributes from the schema as empty strings, so that they can be accessed via method-missing
42
41
  KNOWN_ATTRIBUTES = [
43
42
  :first_name, :last_name, :address_1, :address_2, :city, :state, :zip,
44
43
  :card_number, :cvv, :expiry_month, :expiry_year
45
44
  ]
46
- EMPTY_ATTRIBUTES = KNOWN_ATTRIBUTES.inject(ActiveSupport::HashWithIndifferentAccess.new) {|h, k| h[k] = ''; h}
47
- def initialize(attrs={})
48
- super(EMPTY_ATTRIBUTES.merge(attrs))
45
+ if ActiveResource::VERSION::MAJOR <= 3 && ActiveResource::VERSION::MINOR < 1
46
+ # If we're using ActiveResource pre-3.1, there's no schema class method, so we resort to some tricks...
47
+ # Initialize the known attributes from the schema as empty strings, so that they can be accessed via method-missing
48
+ EMPTY_ATTRIBUTES = KNOWN_ATTRIBUTES.inject(ActiveSupport::HashWithIndifferentAccess.new) {|h, k| h[k] = ''; h}
49
+ def initialize(attrs={})
50
+ super(EMPTY_ATTRIBUTES.merge(attrs))
51
+ end
52
+ else
53
+ # Post AR 3.1, we can use the schema method to define our attributes
54
+ schema do
55
+ string *KNOWN_ATTRIBUTES
56
+ end
49
57
  end
50
58
 
51
59
  # Prepare a new PaymentMethod for use with a transparent redirect form
@@ -48,10 +48,14 @@ class Samurai::Processor < Samurai::Base
48
48
  def execute(action, options = {})
49
49
  transaction = Samurai::Transaction.transaction_payload(options)
50
50
  begin
51
+ @persisted = true # keep AR 3.1 from using the new_ resource path
52
+
51
53
  # send a purchase request
52
54
  resp = post(action, {}, transaction)
55
+
53
56
  # return the response, wrapped in a Samurai::Transaction
54
57
  Samurai::Transaction.new.load_attributes_from_response(resp)
58
+
55
59
  rescue ActiveResource::BadRequest=>e
56
60
  # initialize a fresh transaction with the give options, add a generic error to it, and return it
57
61
  Samurai::Transaction.new(options.merge(:transaction_type=>action.to_s)).tap do |transaction|
@@ -86,14 +86,22 @@ class Samurai::Transaction < Samurai::Base
86
86
  to_xml(:skip_instruct => true, :root => 'transaction', :dasherize => false)
87
87
  end
88
88
 
89
- # Initialize the known attributes from the schema as empty strings, so that they can be accessed via method-missing
90
89
  KNOWN_ATTRIBUTES = [
91
90
  :amount, :type, :payment_method_token, :currency_code,
92
- :descriptor, :custom, :customer_reference, :billing_reference
91
+ :descriptor, :custom, :customer_reference, :billing_reference, :processor_response
93
92
  ]
94
- EMPTY_ATTRIBUTES = KNOWN_ATTRIBUTES.inject(ActiveSupport::HashWithIndifferentAccess.new) {|h, k| h[k] = ''; h}
95
- def initialize(attrs={})
96
- super(EMPTY_ATTRIBUTES.merge(attrs))
93
+ if ActiveResource::VERSION::MAJOR <= 3 && ActiveResource::VERSION::MINOR < 1
94
+ # If we're using ActiveResource pre-3.1, there's no schema class method, so we resort to some tricks...
95
+ # Initialize the known attributes from the schema as empty strings, so that they can be accessed via method-missing
96
+ EMPTY_ATTRIBUTES = KNOWN_ATTRIBUTES.inject(ActiveSupport::HashWithIndifferentAccess.new) {|h, k| h[k] = ''; h}
97
+ def initialize(attrs={})
98
+ super(EMPTY_ATTRIBUTES.merge(attrs))
99
+ end
100
+ else
101
+ # Post AR 3.1, we can use the schema method to define our attributes
102
+ schema do
103
+ string *KNOWN_ATTRIBUTES
104
+ end
97
105
  end
98
106
 
99
107
  end
@@ -1,3 +1,3 @@
1
1
  module Samurai
2
- VERSION = "0.2.9".freeze
2
+ VERSION = "0.2.10".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samurai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2011-09-01 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activeresource
17
- requirement: &70359512757220 !ruby/object:Gem::Requirement
17
+ requirement: &70135382363820 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.2.2
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70359512757220
25
+ version_requirements: *70135382363820
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bundler
28
- requirement: &70359512756760 !ruby/object:Gem::Requirement
28
+ requirement: &70135382363360 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70359512756760
36
+ version_requirements: *70135382363360
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70359512756300 !ruby/object:Gem::Requirement
39
+ requirement: &70135382362900 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.6.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70359512756300
47
+ version_requirements: *70135382362900
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: fakeweb
50
- requirement: &70359512755920 !ruby/object:Gem::Requirement
50
+ requirement: &70135382362520 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70359512755920
58
+ version_requirements: *70135382362520
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: ruby-debug19
61
- requirement: &70359512755420 !ruby/object:Gem::Requirement
61
+ requirement: &70135382362020 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70359512755420
69
+ version_requirements: *70135382362020
70
70
  description: If you are an online merchant and using samurai.feefighters.com, this
71
71
  gem will make your life easy. Integrate with the samurai.feefighters.com portal
72
72
  and process transaction.