samurai 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- samurai (0.2.6)
4
+ samurai (0.2.8)
5
5
  activeresource (>= 2.2.2)
6
6
 
7
7
  GEM
@@ -1,15 +1,15 @@
1
1
  <% transaction ||= (@transaction || Samurai::Transaction.new) %>
2
2
  <% payment_method ||= (@payment_method || Samurai::PaymentMethod.new) %>
3
- <% if transaction.errors.any? || payment_method.errors.any? %>
3
+ <% if transaction.has_errors? || payment_method.has_errors? %>
4
4
  <div id="error_explanation">
5
5
  <h4>This transaction could not be processed:</h4>
6
6
  <ul>
7
7
  <% transaction.errors.full_messages.each do |msg| %>
8
8
  <li><%= msg %></li>
9
- <% end %>
9
+ <% end if transaction.has_errors? %>
10
10
  <% payment_method.errors.full_messages.each do |msg| %>
11
11
  <li><%= msg %></li>
12
- <% end %>
12
+ <% end if payment_method.has_errors? %>
13
13
  </ul>
14
14
  </div>
15
15
  <% end %>
@@ -22,27 +22,27 @@
22
22
  <div class="field-group" id="credit_card_address_group">
23
23
  <div>
24
24
  <label for="credit_card_address_1">Address 1</label>
25
- <input class="span-6" id="credit_card_address_1" name="credit_card[address_1]" size="30" type="text" value="<%= payment_method.address_1 %>" />
25
+ <input class="" id="credit_card_address_1" name="credit_card[address_1]" size="30" type="text" value="<%= payment_method.address_1 %>" />
26
26
  </div>
27
27
  <div>
28
28
  <label for="credit_card_address_2">Address 2</label>
29
- <input class="span-6" id="credit_card_address_2" name="credit_card[address_2]" size="30" type="text" value="<%= payment_method.address_2 %>" />
29
+ <input class="" id="credit_card_address_2" name="credit_card[address_2]" size="30" type="text" value="<%= payment_method.address_2 %>" />
30
30
  </div>
31
31
  </div>
32
32
 
33
33
  <div class="field-group" id="location_group">
34
- <div>
34
+ <span>
35
35
  <label for="credit_card_city">City</label>
36
36
  <input id="credit_card_city" name="credit_card[city]" size="30" type="text" value="<%= payment_method.city %>" />
37
- </div>
38
- <div>
37
+ </span>
38
+ <span>
39
39
  <label for="credit_card_state">State</label>
40
- <input class="span-1" id="credit_card_state" name="credit_card[state]" size="30" type="text" value="<%= payment_method.state %>" />
41
- </div>
42
- <div>
40
+ <input class="" id="credit_card_state" name="credit_card[state]" size="30" type="text" value="<%= payment_method.state %>" />
41
+ </span>
42
+ <span>
43
43
  <label for="credit_card_zip">Zip</label>
44
- <input class="span-2" id="credit_card_zip" name="credit_card[zip]" size="30" type="text" value="<%= payment_method.zip %>" />
45
- </div>
44
+ <input class="" id="credit_card_zip" name="credit_card[zip]" size="30" type="text" value="<%= payment_method.zip %>" />
45
+ </span>
46
46
  </div>
47
47
  </fieldset>
48
48
 
@@ -51,40 +51,44 @@
51
51
  <span>
52
52
  <label for="credit_card_card_number">Card Number</label>
53
53
  <input id="credit_card_card_number" name="credit_card[card_number]" size="30" type="text" value="<%= payment_method.card_number %>" />
54
+ <label data-samurai="card_previews">
55
+ <span class='visa'></span>
56
+ <span class='mastercard'></span>
57
+ <span class='amex'></span>
58
+ <span class='discover'></span>
59
+ </label>
54
60
  </span>
55
61
  <span>
56
62
  <label for="credit_card_cvv">CVV</label>
57
- <input class="span-1" id="credit_card_cvv" name="credit_card[cvv]" size="30" type="text" value="<%= payment_method.cvv %>" />
63
+ <input class="" id="credit_card_cvv" name="credit_card[cvv]" size="30" type="text" value="<%= payment_method.cvv %>" />
64
+ </span>
65
+ <span>
66
+ <label for="credit_card_expiry_month">Expires on</label>
67
+ <select id="credit_card_expiry_month" name="credit_card[expiry_month]">
68
+ <option value="1" <%= 'selected' if payment_method.expiry_month.to_s=='1' %>>01</option>
69
+ <option value="2" <%= 'selected' if payment_method.expiry_month.to_s=='2' %>>02</option>
70
+ <option value="3" <%= 'selected' if payment_method.expiry_month.to_s=='3' %>>03</option>
71
+ <option value="4" <%= 'selected' if payment_method.expiry_month.to_s=='4' %>>04</option>
72
+ <option value="5" <%= 'selected' if payment_method.expiry_month.to_s=='5' %>>05</option>
73
+ <option value="6" <%= 'selected' if payment_method.expiry_month.to_s=='6' %>>06</option>
74
+ <option value="7" <%= 'selected' if payment_method.expiry_month.to_s=='7' %>>07</option>
75
+ <option value="8" <%= 'selected' if payment_method.expiry_month.to_s=='8' %>>08</option>
76
+ <option value="9" <%= 'selected' if payment_method.expiry_month.to_s=='9' %>>09</option>
77
+ <option value="10" <%= 'selected' if payment_method.expiry_month.to_s=='10' %>>10</option>
78
+ <option value="11" <%= 'selected' if payment_method.expiry_month.to_s=='11' %>>11</option>
79
+ <option value="12" <%= 'selected' if payment_method.expiry_month.to_s=='12' %>>12</option>
80
+ </select>
81
+ <select id="credit_card_expiry_year" name="credit_card[expiry_year]">
82
+ <option value="2011" <%= 'selected' if payment_method.expiry_year.to_s=='2011' %>>2011</option>
83
+ <option value="2012" <%= 'selected' if payment_method.expiry_year.to_s=='2012' %>>2012</option>
84
+ <option value="2013" <%= 'selected' if payment_method.expiry_year.to_s=='2013' %>>2013</option>
85
+ <option value="2014" <%= 'selected' if payment_method.expiry_year.to_s=='2014' %>>2014</option>
86
+ <option value="2015" <%= 'selected' if payment_method.expiry_year.to_s=='2015' %>>2015</option>
87
+ <option value="2016" <%= 'selected' if payment_method.expiry_year.to_s=='2016' %>>2016</option>
88
+ </select>
58
89
  </span>
59
90
  </div>
60
-
61
- <div>
62
- <label for="credit_card_expiry_month">Expires on</label>
63
- <select id="credit_card_expiry_month" name="credit_card[expiry_month]">
64
- <option value="1" <%= 'selected' if payment_method.expiry_month.to_s=='1' %>>01</option>
65
- <option value="2" <%= 'selected' if payment_method.expiry_month.to_s=='2' %>>02</option>
66
- <option value="3" <%= 'selected' if payment_method.expiry_month.to_s=='3' %>>03</option>
67
- <option value="4" <%= 'selected' if payment_method.expiry_month.to_s=='4' %>>04</option>
68
- <option value="5" <%= 'selected' if payment_method.expiry_month.to_s=='5' %>>05</option>
69
- <option value="6" <%= 'selected' if payment_method.expiry_month.to_s=='6' %>>06</option>
70
- <option value="7" <%= 'selected' if payment_method.expiry_month.to_s=='7' %>>07</option>
71
- <option value="8" <%= 'selected' if payment_method.expiry_month.to_s=='8' %>>08</option>
72
- <option value="9" <%= 'selected' if payment_method.expiry_month.to_s=='9' %>>09</option>
73
- <option value="10" <%= 'selected' if payment_method.expiry_month.to_s=='10' %>>10</option>
74
- <option value="11" <%= 'selected' if payment_method.expiry_month.to_s=='11' %>>11</option>
75
- <option value="12" <%= 'selected' if payment_method.expiry_month.to_s=='12' %>>12</option>
76
- </select>
77
- <select id="credit_card_expiry_year" name="credit_card[expiry_year]">
78
- <option value="2011" <%= 'selected' if payment_method.expiry_year.to_s=='2011' %>>2011</option>
79
- <option value="2012" <%= 'selected' if payment_method.expiry_year.to_s=='2012' %>>2012</option>
80
- <option value="2013" <%= 'selected' if payment_method.expiry_year.to_s=='2013' %>>2013</option>
81
- <option value="2014" <%= 'selected' if payment_method.expiry_year.to_s=='2014' %>>2014</option>
82
- <option value="2015" <%= 'selected' if payment_method.expiry_year.to_s=='2015' %>>2015</option>
83
- <option value="2016" <%= 'selected' if payment_method.expiry_year.to_s=='2016' %>>2016</option>
84
- </select>
85
- </div>
86
-
87
91
  </fieldset>
88
92
 
89
- <button type='submit' class='button blue'>Submit Payment</button>
93
+ <p><button type='submit' class='button blue'>Submit Payment</button></p>
90
94
  </form>
@@ -1,28 +1,29 @@
1
1
  <% transaction ||= @transaction %>
2
- <h3><%= transaction.errors.empty? ? 'Successful' : 'Failed' %> <%= transaction.transaction_type.titleize %> Transaction</h3>
3
- <h4>Reference ID: <%= transaction.reference_id %></h4>
2
+ <% if transaction %><h3><%= transaction.has_errors? ? 'Failed' : 'Successful' %> <%= transaction.transaction_type.titleize %></h3><% end %>
4
3
 
5
- <%= render Samurai::Views.errors :transaction=>transaction %>
4
+ <%= @errors || render(Samurai::Rails::Views.errors) %>
6
5
 
7
- <p>
8
- <strong>Amount:</strong>
9
- <%= transaction.amount %> (<%= transaction.currency_code %>)
10
- </p>
6
+ <% if transaction %>
7
+ <p>
8
+ <strong>Amount:</strong>
9
+ <%= transaction.amount %> (<%= transaction.currency_code %>)
10
+ </p>
11
11
 
12
- <p>
13
- <strong>Credit Card:</strong>
14
- <em>XXXX XXXX XXXX</em> <%= transaction.payment_method.last_four_digits %>
15
- (<%= "%02d" % transaction.payment_method.expiry_month %> / <%= "%04d" % transaction.payment_method.expiry_year %>)
16
- </p>
12
+ <p>
13
+ <strong>Credit Card:</strong>
14
+ <em>XXXX XXXX XXXX</em> <%= transaction.payment_method.last_four_digits %>
15
+ (<%= "%02d" % transaction.payment_method.expiry_month %> / <%= "%04d" % transaction.payment_method.expiry_year %>)
16
+ </p>
17
17
 
18
- <p><strong>Date / Time:</strong> <%= transaction.created_at %></p>
19
- <p>
20
- <strong>Descriptor:</strong> <%= transaction.descriptor %><br>
21
- <strong>Billing Reference:</strong> <%= transaction.billing_reference %><br>
22
- <strong>Customer Reference: </strong> <%= transaction.customer_reference %><br>
23
- <strong>Custom Data: </strong> <%= transaction.custom %><br>
24
- </p>
18
+ <p><strong>Date / Time:</strong> <%= transaction.created_at %></p>
19
+ <p>
20
+ <strong>Descriptor:</strong> <%= transaction.descriptor %><br>
21
+ <strong>Billing Reference:</strong> <%= transaction.billing_reference %><br>
22
+ <strong>Customer Reference: </strong> <%= transaction.customer_reference %><br>
23
+ <strong>Custom Data: </strong> <%= transaction.custom %><br>
24
+ </p>
25
25
 
26
- <p>
27
- <strong>AVS Response:</strong> <%= transaction.processor_response.avs_result_code || 'None' %>
28
- </p>
26
+ <p>
27
+ <strong>AVS Response:</strong> <%= transaction.processor_response.try(:avs_result_code) || 'None' %>
28
+ </p>
29
+ <% end %>
@@ -47,10 +47,20 @@ class Samurai::Processor < Samurai::Base
47
47
 
48
48
  def execute(action, options = {})
49
49
  transaction = Samurai::Transaction.transaction_payload(options)
50
- # send a purchase request
51
- resp = post(action, {}, transaction)
52
- # return the response, wrapped in a Samurai::Transaction
53
- Samurai::Transaction.new.load_attributes_from_response(resp)
50
+ begin
51
+ # send a purchase request
52
+ resp = post(action, {}, transaction)
53
+ # return the response, wrapped in a Samurai::Transaction
54
+ Samurai::Transaction.new.load_attributes_from_response(resp)
55
+ rescue ActiveResource::BadRequest=>e
56
+ # initialize a fresh transaction with the give options, add a generic error to it, and return it
57
+ Samurai::Transaction.new(options.merge(:transaction_type=>action.to_s)).tap do |transaction|
58
+ transaction.payment_method = Samurai::PaymentMethod.find options[:payment_method_token]
59
+ transaction.created_at = Time.now
60
+ transaction.processor_response = nil
61
+ transaction.errors[:base] << "Invalid request."
62
+ end
63
+ end
54
64
  end
55
65
 
56
66
  end
@@ -15,7 +15,7 @@ module Samurai::Rails
15
15
  Pathname.new(__FILE__).dirname.join('../../..', 'app', 'views', 'application', "_#{partial}.html.erb").to_s
16
16
  end
17
17
  define_method "#{partial}_html" do
18
- File.read(send partial)
18
+ File.read send("#{partial}_file")
19
19
  end
20
20
  end
21
21
 
@@ -45,9 +45,18 @@ class Samurai::Transaction < Samurai::Base
45
45
  private
46
46
 
47
47
  def execute(action, options = {})
48
- resp = post(action, {}, self.class.transaction_payload(options))
49
- # return the response, wrapped in a Samurai::Transaction
50
- Samurai::Transaction.new.load_attributes_from_response(resp)
48
+ begin
49
+ resp = post(action, {}, self.class.transaction_payload(options))
50
+ # return the response, wrapped in a Samurai::Transaction
51
+ Samurai::Transaction.new.load_attributes_from_response(resp)
52
+ rescue ActiveResource::BadRequest=>e
53
+ # initialize a fresh transaction with the give options, add a generic error to it, and return it
54
+ Samurai::Transaction.new(options.merge(:transaction_type=>action.to_s)).tap do |transaction|
55
+ transaction.created_at = Time.now
56
+ transaction.processor_response = nil
57
+ transaction.errors[:base] << "Invalid request."
58
+ end
59
+ end
51
60
  end
52
61
 
53
62
  def process_response_errors
@@ -87,19 +96,4 @@ class Samurai::Transaction < Samurai::Base
87
96
  super(EMPTY_ATTRIBUTES.merge(attrs))
88
97
  end
89
98
 
90
-
91
- require 'pathname'
92
- def self.form_html
93
- File.read(form_partial_path)
94
- end
95
- def self.form_partial_path
96
- Pathname.new(__FILE__).dirname.join('..', '..', 'app', 'views', 'application', '_transaction_form.html.erb')
97
- end
98
- def self.show_html
99
- File.read(show_partial_path)
100
- end
101
- def self.show_partial_path
102
- Pathname.new(__FILE__).dirname.join('..', '..', 'app', 'views', 'application', '_transaction.html.erb')
103
- end
104
-
105
99
  end
@@ -1,3 +1,3 @@
1
1
  module Samurai
2
- VERSION = "0.2.7".freeze
2
+ VERSION = "0.2.8".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.7
4
+ version: 0.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-08-29 00:00:00.000000000Z
13
+ date: 2011-09-01 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activeresource
17
- requirement: &70212280242520 !ruby/object:Gem::Requirement
17
+ requirement: &70208845185200 !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: *70212280242520
25
+ version_requirements: *70208845185200
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bundler
28
- requirement: &70212280242060 !ruby/object:Gem::Requirement
28
+ requirement: &70208845184740 !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: *70212280242060
36
+ version_requirements: *70208845184740
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70212280241600 !ruby/object:Gem::Requirement
39
+ requirement: &70208845184280 !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: *70212280241600
47
+ version_requirements: *70208845184280
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: fakeweb
50
- requirement: &70212280241220 !ruby/object:Gem::Requirement
50
+ requirement: &70208845183900 !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: *70212280241220
58
+ version_requirements: *70208845183900
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: ruby-debug19
61
- requirement: &70212280240720 !ruby/object:Gem::Requirement
61
+ requirement: &70208845183400 !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: *70212280240720
69
+ version_requirements: *70208845183400
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.