caboose-cms 0.5.60 → 0.5.61

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/authorize.net.js +187 -0
  3. data/app/assets/javascripts/caboose/cart.js +13 -8
  4. data/app/assets/javascripts/caboose/checkout_step4.js +7 -9
  5. data/app/controllers/caboose/#Untitled-1# +7 -0
  6. data/app/controllers/caboose/application_controller.rb +12 -10
  7. data/app/controllers/caboose/cart_controller.rb +3 -3
  8. data/app/controllers/caboose/checkout_controller.rb +51 -61
  9. data/app/controllers/caboose/orders_controller.rb +1 -0
  10. data/app/mailers/caboose/orders_mailer.rb +4 -2
  11. data/app/models/caboose/authnet.rb +140 -0
  12. data/app/models/caboose/order.rb +6 -0
  13. data/app/models/caboose/payment_processors/authorizenet.rb +18 -23
  14. data/app/models/caboose/schema.rb +3 -1
  15. data/app/models/caboose/site.rb +4 -0
  16. data/app/views/caboose/checkout/#Untitled-2# +41 -0
  17. data/app/views/caboose/checkout/_confirm.html.erb +10 -10
  18. data/app/views/caboose/checkout/authnet_profile_form.html.erb +14 -0
  19. data/app/views/caboose/checkout/authnet_relay.html.erb +16 -0
  20. data/app/views/caboose/checkout/authnet_response.html.erb +12 -0
  21. data/app/views/caboose/checkout/{relay.html.erb → payscape_relay.html.erb} +0 -0
  22. data/app/views/caboose/checkout/step_four.html.erb +36 -35
  23. data/app/views/caboose/checkout/step_four_old.html.erb +63 -0
  24. data/app/views/caboose/checkout/step_two.html.erb +8 -0
  25. data/app/views/caboose/orders/admin_edit.html.erb +14 -6
  26. data/app/views/caboose/orders/admin_index.html.erb +3 -3
  27. data/config/routes.rb +13 -8
  28. data/lib/caboose/version.rb +1 -1
  29. metadata +11 -3
@@ -6,6 +6,7 @@ module Caboose
6
6
  return if !user_is_allowed('orders', 'view')
7
7
 
8
8
  @pager = Caboose::PageBarGenerator.new(params, {
9
+ 'site_id' => @site.id,
9
10
  'customer_id' => '',
10
11
  'status' => 'pending',
11
12
  'shipping_method_code' => '',
@@ -11,13 +11,15 @@ module Caboose
11
11
  # Sends a notification email to the fulfillment dept about a new order
12
12
  def fulfillment_new_order(order)
13
13
  @order = order
14
- mail(:to => Caboose::fulfillment_email, :subject => 'New Order')
14
+ sc = order.site.store_config
15
+ mail(:to => sc.fulfillment_email, :subject => 'New Order')
15
16
  end
16
17
 
17
18
  # Sends a notification email to the shipping dept that an order is ready to be shipped
18
19
  def shipping_order_ready(order)
19
20
  @order = order
20
- mail(:to => Caboose::shipping_email, :subject => 'Order ready for shipping')
21
+ sc = order.site.store_config
22
+ mail(:to => sc.shipping_email, :subject => 'Order ready for shipping')
21
23
  end
22
24
 
23
25
  # Sends a notification email to the customer that the status of the order has been changed
@@ -0,0 +1,140 @@
1
+
2
+ module Caboose
3
+ class Authnet
4
+
5
+ # Sandbox URL: https://apitest.authorize.net/xml/v1/request.api
6
+ # Production URL: https://api.authorize.net/xml/v1/request.api
7
+
8
+ # Locker room
9
+ # 47G9Y5vvQt
10
+ # 4U6zLSj9u5V4Cq8B
11
+
12
+ # williambarry007
13
+ # API Login ID: 9qR2qa4ZWn
14
+ # Transaction Key: 386TLme2j8yp4BQy
15
+ # Secret Question: Simon
16
+
17
+ # Repconnex
18
+ # api_login_id: 3a79FjaHV
19
+ # api_transaction_key: 3K4v7n423KvA5R9P
20
+
21
+ def self.create_customer_profile(store_config, user)
22
+ params = {
23
+ "createCustomerProfileRequest" => {
24
+ "merchantAuthentication" => {
25
+ "name" => '9qR2qa4ZWn', #store_config.pp_username,
26
+ "transactionKey" => '386TLme2j8yp4BQy', #store_config.pp_password
27
+ },
28
+ "profile" => {
29
+ "merchantCustomerId" => user.id,
30
+ "description" => "#{user.first_name} #{user.last_name}",
31
+ "email" => user.email
32
+ }
33
+ }
34
+ }
35
+ resp = nil
36
+ resp = HTTParty.post('https://apitest.authorize.net/xml/v1/request.api',
37
+ :headers => { 'Content-Type' => 'application/json' },
38
+ :body => params.to_json,
39
+ :debug_output => $stdout
40
+ )
41
+ resp = JSON.parse(resp.body.to_s[1..-1])
42
+ Caboose.log(resp)
43
+ # See if we have a duplicate
44
+ if resp['messages'] &&
45
+ resp['messages']['resultCode'] &&
46
+ resp['messages']['resultCode'] == 'Error' &&
47
+ resp['messages']['message'][0]['code'] == 'E00039'
48
+
49
+ Caboose.log("Error: duplicate customer profile.")
50
+ str = resp['messages']['message'][0]['text']
51
+ str.gsub!('A duplicate record with ID ', '')
52
+ str.gsub!(' already exists.', '')
53
+ user.customer_profile_id = str
54
+ user.save
55
+ end
56
+ return user.customer_profile_id
57
+ end
58
+
59
+ def self.hosted_profile_page_token(store_config, user)
60
+ params = {
61
+ "getHostedProfilePageRequest" => {
62
+ "merchantAuthentication" => {
63
+ "name" => '9qR2qa4ZWn', #store_config.pp_username,
64
+ "transactionKey" => '386TLme2j8yp4BQy', #store_config.pp_password
65
+ },
66
+ "customerProfileId" => user.customer_profile_id,
67
+ "hostedProfileSettings" => {
68
+ "setting" => [
69
+ { "settingName" => "hostedProfileReturnUrl" , "settingValue" => "https://google.com" },
70
+ { "settingName" => "hostedProfileReturnUrlText" , "settingValue" => "Continue to confirmation page." },
71
+ { "settingName" => "hostedProfilePageBorderVisible" , "settingValue" => "true" }
72
+ ]
73
+ }
74
+ }
75
+ }
76
+ resp = nil
77
+ resp = HTTParty.get('https://apitest.authorize.net/xml/v1/request.api',
78
+ :headers => { 'Content-Type' => 'application/json' },
79
+ :body => params.to_json,
80
+ :debug_output => $stdout
81
+ )
82
+ resp = JSON.parse(resp.body.to_s[1..-1])
83
+ Caboose.log(resp)
84
+ if resp['messages'] && resp['messages']['resultCode'] && resp['messages']['resultCode'] == 'Ok'
85
+ return resp['token']
86
+ end
87
+ return nil
88
+ end
89
+
90
+ #def self.form_url(order=nil)
91
+ # #if Rails.env == 'development'
92
+ # 'https://test.authorize.net/gateway/transact.dll'
93
+ # #else
94
+ # # 'https://secure.authorize.net/gateway/transact.dll'
95
+ # #end
96
+ #end
97
+ #
98
+ #def self.authorize(order, params)
99
+ # order.update_attribute(:transaction_id, params[:x_trans_id]) if params[:x_trans_id]
100
+ # return params[:x_response_code] == '1'
101
+ #end
102
+ #
103
+ #def self.void(order)
104
+ # response = AuthorizeNet::SIM::Transaction.new(
105
+ # CabooseStore::authorize_net_login_id,
106
+ # CabooseStore::authorize_net_transaction_key,
107
+ # order.total,
108
+ # :transaction_type => 'VOID',
109
+ # :transaction_id => order.transaction_id
110
+ # )
111
+ #
112
+ # ap response
113
+ #end
114
+ #
115
+ #def self.capture(order)
116
+ # response = AuthorizeNet::SIM::Transaction.new(
117
+ # CabooseStore::authorize_net_login_id,
118
+ # CabooseStore::authorize_net_transaction_key,
119
+ # order.total,
120
+ # :transaction_type => 'CAPTURE_ONLY',
121
+ # :transaction_id => order.transaction_id
122
+ # )
123
+ #
124
+ # ap response
125
+ #end
126
+ #
127
+ #def self.refund(order)
128
+ # response = AuthorizeNet::SIM::Transaction.new(
129
+ # CabooseStore::authorize_net_login_id,
130
+ # CabooseStore::authorize_net_transaction_key,
131
+ # order.total,
132
+ # :transaction_type => 'CREDIT',
133
+ # :transaction_id => order.transaction_id
134
+ # )
135
+ #
136
+ # ap response
137
+ #end
138
+
139
+ end
140
+ end
@@ -196,6 +196,12 @@ module Caboose
196
196
  def shipping_and_handling
197
197
  (self.shipping ? self.shipping : 0.0) + (self.handling ? self.handling : 0.0)
198
198
  end
199
+
200
+ def item_count
201
+ count = 0
202
+ self.line_items.each{ |li| count = count + li.quantity } if self.line_items
203
+ return count
204
+ end
199
205
  end
200
206
  end
201
207
 
@@ -1,13 +1,14 @@
1
1
  class Caboose::PaymentProcessors::Authorizenet < Caboose::PaymentProcessors::Base
2
+
2
3
  def self.api(root, body, test=false)
3
4
  end
4
5
 
5
6
  def self.form_url(order=nil)
6
- #if Rails.env == 'development'
7
- 'https://test.authorize.net/gateway/transact.dll'
8
- #else
9
- # 'https://secure.authorize.net/gateway/transact.dll'
10
- #end
7
+ if Rails.env == 'development'
8
+ 'https://test.authorize.net/gateway/transact.dll'
9
+ else
10
+ 'https://secure.authorize.net/gateway/transact.dll'
11
+ end
11
12
  end
12
13
 
13
14
  def self.authorize(order, params)
@@ -16,38 +17,32 @@ class Caboose::PaymentProcessors::Authorizenet < Caboose::PaymentProcessors::Bas
16
17
  end
17
18
 
18
19
  def self.void(order)
20
+ sc = order.site.store_config
19
21
  response = AuthorizeNet::SIM::Transaction.new(
20
- Caboose::authorize_net_login_id,
21
- Caboose::authorize_net_transaction_key,
22
- order.total,
22
+ sc.pp_username, sc.pp_password, order.total,
23
23
  :transaction_type => 'VOID',
24
24
  :transaction_id => order.transaction_id
25
- )
26
-
27
- ap response
25
+ )
26
+ #ap response
28
27
  end
29
28
 
30
29
  def self.capture(order)
30
+ sc = order.site.store_config
31
31
  response = AuthorizeNet::SIM::Transaction.new(
32
- Caboose::authorize_net_login_id,
33
- Caboose::authorize_net_transaction_key,
34
- order.total,
32
+ sc.pp_username, sc.pp_password, order.total,
35
33
  :transaction_type => 'CAPTURE_ONLY',
36
34
  :transaction_id => order.transaction_id
37
- )
38
-
39
- ap response
35
+ )
36
+ #ap response
40
37
  end
41
38
 
42
39
  def self.refund(order)
40
+ sc = order.site.store_config
43
41
  response = AuthorizeNet::SIM::Transaction.new(
44
- Caboose::authorize_net_login_id,
45
- Caboose::authorize_net_transaction_key,
46
- order.total,
42
+ sc.pp_username, sc.pp_password, order.total,
47
43
  :transaction_type => 'CREDIT',
48
44
  :transaction_id => order.transaction_id
49
- )
50
-
51
- ap response
45
+ )
46
+ #ap response
52
47
  end
53
48
  end
@@ -556,7 +556,9 @@ class Caboose::Schema < Caboose::Utilities::Schema
556
556
  [ :token , :string ],
557
557
  [ :date_created , :datetime ],
558
558
  [ :image , :attachment ],
559
- [ :is_guest , :boolean , { :default => false }]
559
+ [ :is_guest , :boolean , { :default => false }],
560
+ [ :customer_profile_id , :string ],
561
+ [ :payment_profile_id , :string ]
560
562
  ],
561
563
  Caboose::Variant => [
562
564
  [ :product_id , :integer ],
@@ -24,4 +24,8 @@ class Caboose::Site < ActiveRecord::Base
24
24
  self.name = self.name.downcase.gsub(' ', '_')
25
25
  end
26
26
 
27
+ def primary_domain
28
+ Caboose::Domain.where(:site_id => self.id, :primary => true).first
29
+ end
30
+
27
31
  end
@@ -0,0 +1,41 @@
1
+ "x_response_code"=>"3",
2
+ "x_response_reason_code"=>"8",
3
+ "x_response_reason_text"=>"(TESTMODE) The credit card has expired.",
4
+ "x_avs_code"=>"P",
5
+ "x_auth_code"=>"000000",
6
+ "x_trans_id"=>"0",
7
+ "x_method"=>"CC",
8
+ "x_card_type"=>"Visa",
9
+ "x_account_number"=>"XXXX1111",
10
+ "x_first_name"=>"",
11
+ "x_last_name"=>"",
12
+ "x_company"=>"",
13
+ "x_address"=>"",
14
+ "x_city"=>"",
15
+ "x_state"=>"",
16
+ "x_zip"=>"",
17
+ "x_country"=>"",
18
+ "x_phone"=>"",
19
+ "x_fax"=>"",
20
+ "x_email"=>"",
21
+ "x_invoice_num"=>"",
22
+ "x_description"=>"",
23
+ "x_type"=>"auth_only",
24
+ "x_cust_id"=>"",
25
+ "x_ship_to_first_name"=>"",
26
+ "x_ship_to_last_name"=>"",
27
+ "x_ship_to_company"=>"",
28
+ "x_ship_to_address"=>"",
29
+ "x_ship_to_city"=>"",
30
+ "x_ship_to_state"=>"",
31
+ "x_ship_to_zip"=>"",
32
+ "x_ship_to_country"=>"",
33
+ "x_amount"=>"105.56",
34
+ "x_tax"=>"0.00",
35
+ "x_duty"=>"0.00",
36
+ "x_freight"=>"0.00",
37
+ "x_tax_exempt"=>"FALSE",
38
+ "x_po_num"=>"",
39
+ "x_MD5_Hash"=>"CF7CC5EF1706C38812CF92C2A0EBE276",
40
+ "x_cvv2_resp_code"=>"", "x_cavv_response"=>"", "x_test_request"=>"true", "month"=>"01", "year"=>"14"}
41
+ WARNING: Can't verify CSRF token authenticity
@@ -12,23 +12,23 @@
12
12
  <tr data-id="<%= li.id %>">
13
13
  <td valign='top'>
14
14
  <% if li.variant.product_images.count > 0 %>
15
- <figure style="background-image: url(<%= li.variant.product_images[0].image.url(:thumb) %>)"></figure>
15
+ <img src="<%= li.variant.product_images[0].image.url(:thumb) %>" width="150" />
16
16
  <% end %>
17
17
  <p><%= li.title %></p>
18
18
  </td>
19
- <td valign='top' align='right' class='qty' ><%= li.quantity %></td>
20
- <td valign='top' align='right' class='price' ><%= number_to_currency(li.price, :precision => 2) %></td>
21
- <td valign='top' align='right' class='subtotal'><%= number_to_currency(li.price, :precision => 2) %></td>
19
+ <td valign='top' align='right' class='qty' style='text-align: right;'><%= li.quantity %></td>
20
+ <td valign='top' align='right' class='price' style='text-align: right;'><%= number_to_currency(li.price, :precision => 2) %></td>
21
+ <td valign='top' align='right' class='subtotal' style='text-align: right;'><%= number_to_currency(li.price, :precision => 2) %></td>
22
22
  </tr>
23
23
  <% end %>
24
- <tr><td colspan='3' align='right'>Subtotal: </td><td align='right'><%= number_to_currency(@order.subtotal, :precision => 2) %></td></tr>
25
- <tr><td colspan='3' align='right'>Shipping & Handling: </td><td align='right'><%= number_to_currency(@order.shipping + @order.handling, :precision => 2) %></td></tr>
24
+ <tr><td colspan='3' align='right' style='text-align: right;'>Subtotal: </td><td align='right' style='text-align: right;'><%= number_to_currency(@order.subtotal, :precision => 2) %></td></tr>
25
+ <tr><td colspan='3' align='right' style='text-align: right;'>Shipping & Handling: </td><td align='right' style='text-align: right;'><%= number_to_currency(@order.shipping + @order.handling, :precision => 2) %></td></tr>
26
26
  <% if @order.tax > 0 && @order.billing_address.state == 'AL' %>
27
- <tr><td colspan='3' align='right'>Tax <small>(if in Alabama)</small>: </td><td align='right'><%= number_to_currency(@order.tax, :precision => 2) %></td></tr>
27
+ <tr><td colspan='3' align='right' style='text-align: right;'>Tax <small>(if in Alabama)</small>: </td><td align='right' style='text-align: right;'><%= number_to_currency(@order.tax, :precision => 2) %></td></tr>
28
28
  <% end %>
29
- <tr><td colspan='3' align='right'>Total: </td><td align='right'><%= number_to_currency(@order.total, :precision => 2) %></td></tr>
29
+ <tr><td colspan='3' align='right' style='text-align: right;'>Total: </td><td align='right' style='text-align: right;'><%= number_to_currency(@order.total, :precision => 2) %></td></tr>
30
30
  </table>
31
- </section>
31
+ </section><br />
32
32
  <section id='shipping_address'>
33
33
  <% sa = @order.shipping_address %>
34
34
  <address>
@@ -50,7 +50,7 @@
50
50
  <p><a href="/checkout/step-two">Edit billing address</a></p>
51
51
  </section>
52
52
  <section id='shipping_method'>
53
- <p><%= @order.shipping_service_name %> - <%= number_to_currency(@order.shipping) %></p>
53
+ <p><%= @order.shipping_carrier %> <%= @order.shipping_service_name %> - <%= number_to_currency(@order.shipping) %></p>
54
54
  <p><a href="/checkout/step-three">Edit shipping method</a></p>
55
55
  </section>
56
56
  <section id='payment_method'>
@@ -0,0 +1,14 @@
1
+ <% if @logged_in_user.payment_profile_id %>
2
+ <form method="post" action="https://secure.authorize.net/profile/editPayment" id='authnet_form'>
3
+ <input type="hidden" name="Token" value="<%= raw @token %>" />
4
+ <input type="submit" value="Edit my existing payment method"/>
5
+ </form>
6
+ <% else %>
7
+ <form method="post" action="https://secure.authorize.net/profile/addPayment" id='authnet_form'>
8
+ <input type="hidden" name="Token" value="<%= raw @token %>" />
9
+ <input type="submit" value="Add payment method"/>
10
+ </form>
11
+ <% end %>
12
+ <script type='textjavascript'>
13
+ //document.getElementById('authnet_form').submit();
14
+ </script>
@@ -0,0 +1,16 @@
1
+ <%
2
+ # This relay page is rendered from the authorize.net server in a hidden iframe
3
+ # on the host application's checkout page.
4
+ #
5
+ # Since security rules in browsers disallow javascript access to and from
6
+ # iframes with pages in different domains, we need to send things back to
7
+ # a page on our own domain so we can bubble up the response.
8
+ #
9
+ %><!DOCTYPE>
10
+ <html>
11
+ <body>
12
+ <script type='text/javascript'>
13
+ window.location = <%= raw Caboose.json(@url) %>;
14
+ </script>
15
+ </body>
16
+ </html>
@@ -0,0 +1,12 @@
1
+ <%
2
+ # This page is rendered from the host application's domain, and thus is allowed
3
+ # to access the parent's DOM via javascript.
4
+ #
5
+ %><!DOCTYPE>
6
+ <html>
7
+ <body>
8
+ <script type='text/javascript'>
9
+ parent.relay_handler(<%= raw Caboose.json(@resp) %>);
10
+ </script>
11
+ </body>
12
+ </html>
@@ -6,43 +6,44 @@ store_config = @site.store_config
6
6
  <%= render :partial => 'caboose/checkout/confirm' %>
7
7
  <section id="checkout-payment">
8
8
  <div class="wrapper">
9
- <% if store_config.pp_name == 'authorize.net' %>
10
- <form id="payment" target="relay" action="https://test.authorize.net/gateway/transact.dll" method="post">
9
+ <% if store_config.pp_name == 'authorize.net' %>
10
+ <form id="payment" target="relay" action="https://secure.authorize.net/gateway/transact.dll" method="post">
11
11
  <%= sim_fields(@sim_transaction) %>
12
+ <input id="x_invoice_num" name="x_invoice_num" type="hidden" value="<%= @order.id %>" />
13
+ <input id="x_description" name="x_after_relay" type="hidden" value="<%= raw "#{@request.protocol}#{@request.host_with_port}/checkout/authnet-response/#{@order.id}" %>" />
14
+ <p>
15
+ <label>Card Number</label>
16
+ <input name="x_card_num" id='billing-cc-number' type="text" maxlength="16" />
17
+ </p>
12
18
 
13
- <label>Card Number</label>
14
- <input name="x_card_num" type="text" maxlength="16" />
15
- <!--<br />
16
- <label>Security Code</label><br />
17
- <input id="x_card_code" name="x_card_code" type="text" />-->
18
- <br />
19
+ <p>
20
+ <label>Expiration</label>
21
+ <input id="expiration" name="x_exp_date" type="hidden" />
22
+ <select id="month" name="month">
23
+ <option value="01">01 - Jan</option>
24
+ <option value="02">02 - Feb</option>
25
+ <option value="03">03 - Mar</option>
26
+ <option value="04">04 - Apr</option>
27
+ <option value="05">05 - May</option>
28
+ <option value="06">06 - Jun</option>
29
+ <option value="07">07 - Jul</option>
30
+ <option value="08">08 - Aug</option>
31
+ <option value="09">09 - Sep</option>
32
+ <option value="10">10 - Oct</option>
33
+ <option value="11">11 - Nov</option>
34
+ <option value="12">12 - Dec</option>
35
+ </select>
36
+ /
37
+ <select id="year" name="year">
38
+ <% (DateTime.now.year...DateTime.now.year + 20).each do |i| %>
39
+ <option value="<%= i-2000 %>"><%= i %></option>
40
+ <% end %>
41
+ </select>
42
+ </p>
43
+
44
+ <!--<input type="submit" value="Submit" />-->
19
45
 
20
- <label>Expiration</label>
21
- <input id="expiration" name="x_exp_date" type="hidden" />
22
- <select id="month" name="month">
23
- <option value="01">01 - Jan</option>
24
- <option value="02">02 - Feb</option>
25
- <option value="03">03 - Mar</option>
26
- <option value="04">04 - Apr</option>
27
- <option value="05">05 - May</option>
28
- <option value="06">06 - Jun</option>
29
- <option value="07">07 - Jul</option>
30
- <option value="08">08 - Aug</option>
31
- <option value="09">09 - Sep</option>
32
- <option value="10">10 - Oct</option>
33
- <option value="11">11 - Nov</option>
34
- <option value="12">12 - Dec</option>
35
- </select>
36
- /
37
- <select id="year" name="year">
38
- <% (DateTime.now.year...DateTime.now.year + 20).each do |i| %>
39
- <option value="<%= i-2000 %>"><%= i %></option>
40
- <% end %>
41
- </select><br />
42
- <br />
43
- <input type="submit" value="Submit" />
44
- </form>
45
- <iframe id="relay" name="relay" style='display: block; width: 800px; height: 400px; border: #000 1px solid;'></iframe>
46
+ </form>
46
47
  <% end %>
47
48
  </div>
48
49
  </section>
@@ -52,7 +53,7 @@ store_config = @site.store_config
52
53
  <em>or</em>
53
54
  <a href="/">return to the store</a>
54
55
  </section>
55
-
56
+ <iframe id="relay" name="relay" style='display: block; width: 800px; height: 400px; border: #000 1px solid;'></iframe>
56
57
  </div>
57
58
 
58
59
  <%= content_for :caboose_js do %>