nimbleshop_authorizedotnet 0.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. data/README.md +13 -0
  2. data/app/assets/images/nimbleshop_authorizedotnet/american_express.png +0 -0
  3. data/app/assets/images/nimbleshop_authorizedotnet/authorize_net_big.png +0 -0
  4. data/app/assets/images/nimbleshop_authorizedotnet/authorizedotnet_big.png +0 -0
  5. data/app/assets/images/nimbleshop_authorizedotnet/discover.png +0 -0
  6. data/app/assets/images/nimbleshop_authorizedotnet/mastercard.png +0 -0
  7. data/app/assets/images/nimbleshop_authorizedotnet/visa.png +0 -0
  8. data/app/controllers/nimbleshop_authorizedotnet/authorizedotnets_controller.rb +47 -0
  9. data/app/controllers/nimbleshop_authorizedotnet/payments_controller.rb +31 -0
  10. data/app/helpers/nimbleshop_authorizedotnet/exposed_helper.rb +50 -0
  11. data/app/models/nimbleshop_authorizedotnet/authorizedotnet.rb +29 -0
  12. data/app/views/nimbleshop_authorizedotnet/authorizedotnets/_edit.html.erb +32 -0
  13. data/app/views/nimbleshop_authorizedotnet/authorizedotnets/_form.html.erb +55 -0
  14. data/app/views/nimbleshop_authorizedotnet/payments/_authorize_net_instructions.html.erb +41 -0
  15. data/app/views/nimbleshop_authorizedotnet/payments/_new.html.erb +91 -0
  16. data/app/views/nimbleshop_authorizedotnet/payments/_order_show_extra_info.html.erb +4 -0
  17. data/app/views/nimbleshop_authorizedotnet/payments/_payment_info_for_buyer.html.erb +6 -0
  18. data/app/views/nimbleshop_authorizedotnet/payments/_what_is_cvv.html.erb +25 -0
  19. data/config/routes.rb +4 -0
  20. data/lib/nimbleshop_authorizedotnet.rb +6 -0
  21. data/lib/nimbleshop_authorizedotnet/engine.rb +17 -0
  22. data/lib/nimbleshop_authorizedotnet/gateway.rb +11 -0
  23. data/lib/nimbleshop_authorizedotnet/processor.rb +140 -0
  24. data/lib/nimbleshop_authorizedotnet/version.rb +3 -0
  25. data/lib/tasks/nimbleshop_authorizedotnet_tasks.rake +31 -0
  26. metadata +86 -0
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # nimbleshop_authorizedotnet extension
2
+
3
+ This is Authorize.net extension for [nimbleShop](http://www.nimbleShop.org) .
4
+
5
+ Please note that it does not support CIM feature of Authorize.net
6
+
7
+ # Documentation
8
+
9
+ Documentation is available at [http://nimbleshop.org/authorizedotnet.html](http://nimbleshop.org/authorizedotnet.html) .
10
+
11
+ # License
12
+
13
+ nimbleshop_authorizedotnet uses [MIT license](http://www.opensource.org/licenses/mit-license.php) .
@@ -0,0 +1,47 @@
1
+ module NimbleshopAuthorizedotnet
2
+
3
+ class AuthorizedotnetsController < ::Admin::PaymentMethodsController
4
+
5
+ before_filter :load_payment_method
6
+
7
+ def update
8
+ respond_to do |format|
9
+ if @payment_method.update_attributes(post_params[:authorizedotnet])
10
+ format.js {
11
+ flash[:notice] = 'Authorize.net record was successfully updated'
12
+ render js: "window.location = '/admin/payment_methods'"
13
+ }
14
+ else
15
+ msg = @payment_method.errors.full_messages.first
16
+ error = %Q[alert("#{msg}")]
17
+ format.js { render js: error }
18
+ end
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ respond_to do |format|
24
+ if @payment_method.destroy
25
+ format.js {
26
+ flash[:notice] = 'Authorize.net record was successfully deleted'
27
+ render js: "window.location = '/admin/payment_methods'"
28
+ }
29
+ else
30
+ format.js { render js: 'Authorize.net record could not be deleted. Please try again later.' }
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def post_params
38
+ params.permit(authorizedotnet: [:mode, :ssl, :login_id, :transaction_key, :company_name_on_creditcard_statement])
39
+ end
40
+
41
+ def load_payment_method
42
+ @payment_method = NimbleshopAuthorizedotnet::Authorizedotnet.first
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,31 @@
1
+ module NimbleshopAuthorizedotnet
2
+ class PaymentsController < ::ActionController::Base
3
+
4
+ def create
5
+ order = Order.find_by_id(session[:order_id])
6
+ address_attrs = order.final_billing_address.to_credit_card_attributes
7
+ creditcard_attrs = params[:creditcard].merge(address_attrs)
8
+ creditcard = Creditcard.new(creditcard_attrs)
9
+ processor = NimbleshopAuthorizedotnet::Processor.new(order)
10
+
11
+ default_action = Shop.first.default_creditcard_action
12
+
13
+ if processor.send(default_action, creditcard: creditcard)
14
+ url = nimbleshop_simply.order_path(order)
15
+ @output = "window.location='#{url}'"
16
+ else
17
+ error = processor.errors.first
18
+ Rails.logger.info "Error: #{error}"
19
+ @output = "alert('#{error}')"
20
+ end
21
+
22
+ respond_to do |format|
23
+ format.js do
24
+ render js: @output
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,50 @@
1
+ module NimbleshopAuthorizedotnet
2
+ module ExposedHelper
3
+
4
+ def nimbleshop_authorizedotnet_next_payment_processing_action(order)
5
+ if order.authorized?
6
+ link_to 'Capture payment', capture_payment_admin_order_path(order), method: :put, class: 'btn btn-success'
7
+ end
8
+ end
9
+
10
+ def nimbleshop_authorizedotnet_small_image
11
+ image_tag 'engines/nimbleshop_authorizedotnet/authorizedotnet_small.png', alt: 'authorizedotnet icon'
12
+ end
13
+
14
+ def nimbleshop_authorizedotnet_big_image
15
+ image_tag 'engines/nimbleshop_authorizedotnet/authorizedotnet_big.png', alt: 'authorizedotnet logo'
16
+ end
17
+
18
+ def nimbleshop_authorizedotnet_order_show_extra_info(order)
19
+ return unless NimbleshopAuthorizedotnet::Authorizedotnet.first
20
+ render partial: '/nimbleshop_authorizedotnet/payments/order_show_extra_info', locals: { transaction: order.payment_transactions.last }
21
+ end
22
+
23
+ def nimbleshop_authorizedotnet_available_payment_options_icons
24
+ return unless NimbleshopAuthorizedotnet::Authorizedotnet.first
25
+ %w(visa mastercard discover american_express).map { |i| image_tag("engines/nimbleshop_authorizedotnet/#{i}.png") }
26
+ end
27
+
28
+ def nimbleshop_authorizedotnet_icon_for_order_payment(order)
29
+ if payment_transaction = order.payment_transactions.last
30
+ cardtype = payment_transaction.metadata[:cardtype]
31
+ image_tag("engines/nimbleshop_authorizedotnet/#{cardtype}.png", height: '10px')
32
+ end
33
+ end
34
+
35
+ def nimbleshop_authorizedotnet_payment_info_for_buyer(order)
36
+ render partial: '/nimbleshop_authorizedotnet/payments/payment_info_for_buyer', locals: { order: order }
37
+ end
38
+
39
+ def nimbleshop_authorizedotnet_payment_form(order)
40
+ return unless NimbleshopAuthorizedotnet::Authorizedotnet.first
41
+ render partial: '/nimbleshop_authorizedotnet/payments/new', locals: {order: order}
42
+ end
43
+
44
+ def nimbleshop_authorizedotnet_crud_form
45
+ return unless NimbleshopAuthorizedotnet::Authorizedotnet.first
46
+ render partial: '/nimbleshop_authorizedotnet/authorizedotnets/edit'
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ module NimbleshopAuthorizedotnet
2
+ class Authorizedotnet < PaymentMethod
3
+
4
+ store_accessor :metadata, :login_id, :transaction_key, :company_name_on_creditcard_statement, :mode, :ssl
5
+
6
+ before_save :set_mode, :set_ssl
7
+
8
+ validates_presence_of :login_id, :transaction_key, :company_name_on_creditcard_statement
9
+
10
+ def credentials
11
+ { login: login_id, password: transaction_key }
12
+ end
13
+
14
+ def use_ssl?
15
+ self.ssl == 'enabled'
16
+ end
17
+
18
+ private
19
+
20
+ def set_mode
21
+ self.mode ||= 'test'
22
+ end
23
+
24
+ def set_ssl
25
+ self.ssl ||= 'disabled'
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ <div class='payment-method-engine-well'>
2
+
3
+ <div>
4
+ <h2>Authorize.net</h2>
5
+ <div class="edit_link">
6
+ <%= link_to 'Edit', '#', class: 'nimbleshop-payment-method-edit', id: 'nimbleshop-authorizedotnet-payment-method-edit' %>
7
+ <%= link_to nimbleshop_authorizedotnet.authorizedotnet_path, class: 'nimbleshop-payment-method-delete',
8
+ confirm: 'Do you really want to delete Authorize.net payment method', method: :delete, remote: true do %>
9
+ <i class='icon-remove icon-white'></i>
10
+ <% end %>
11
+ </div>
12
+
13
+ <%= nimbleshop_authorizedotnet_big_image %>
14
+
15
+ <div class='clear'></div>
16
+ </div>
17
+
18
+
19
+ <%= render partial: '/nimbleshop_authorizedotnet/authorizedotnets/form' %>
20
+ </div>
21
+
22
+ <script>
23
+ $(function(){
24
+
25
+ $('#nimbleshop-authorizedotnet-payment-method-edit').toggle(function(){
26
+ $('#nimbleshop-authorizedotnet-form-well').show();
27
+ }, function(){
28
+ $('#nimbleshop-authorizedotnet-form-well').hide();
29
+ });
30
+
31
+ })
32
+ </script>
@@ -0,0 +1,55 @@
1
+ <div class='well nimbleshop-payment-method-form-well' id='nimbleshop-authorizedotnet-form-well' style='display:none;'>
2
+
3
+ <%= form_for NimbleshopAuthorizedotnet::Authorizedotnet.first, url: '/nimbleshop_authorizedotnet/authorizedotnet',
4
+ remote: true,
5
+ html: { method: 'put',
6
+ id: 'nimbleshop-authorizedotnet-form',
7
+ class: 'nimbleshop-payment-method-form form-horizontal'} do |f| %>
8
+
9
+ <fieldset>
10
+ <div class="control-group">
11
+ <%= f.label :login_id, nil, class: 'control-label' %>
12
+ <div class="controls">
13
+ <%= f.text_field :login_id, class: 'span6' %>
14
+ </div>
15
+ </div>
16
+ <div class="control-group">
17
+ <%= f.label :transaction_key, nil, class: 'control-label' %>
18
+ <div class="controls">
19
+ <%= f.text_field :transaction_key, class: 'span6' %>
20
+ </div>
21
+ </div>
22
+
23
+ <div class="control-group">
24
+ <%= f.label :company_name_on_creditcard_statement, nil, class: 'control-label' %>
25
+ <div class="controls">
26
+ <%= f.text_field :company_name_on_creditcard_statement, class: 'span6' %>
27
+ </div>
28
+ </div>
29
+
30
+ <div class="control-group">
31
+ <div class="controls">
32
+ <label class='checkbox'>
33
+ <%= f.check_box :mode, {}, 'test', 'production' %> Enable test mode
34
+ </label>
35
+ </div>
36
+ </div>
37
+
38
+ <div class="control-group">
39
+ <div class="controls">
40
+ <label class='checkbox'>
41
+ <%= f.check_box :ssl, {}, 'enabled', 'disabled' %> Enable SSL requirement
42
+ </label>
43
+ </div>
44
+ </div>
45
+
46
+ </fieldset>
47
+
48
+ <div class="form-actions">
49
+ <%= f.submit('Submit', class: 'btn btn-primary') %>
50
+ &nbsp;
51
+ <%= link_to t(:cancel), nimbleshop_authorizedotnet.authorizedotnet_path, class: 'cancel btn' %>
52
+ </div>
53
+ <% end %>
54
+
55
+ </div>
@@ -0,0 +1,41 @@
1
+ <style>
2
+ #authorizenetsandboxhelp li {
3
+ margin-top: 2px;
4
+ margin-bottom: 2px;
5
+ }
6
+ </style>
7
+
8
+ <% if !Rails.env.production? && NimbleshopAuthorizedotnet::Authorizedotnet.first %>
9
+ <div id='authorizenetsandboxhelp' class='modal hide fade'>
10
+
11
+ <div class='modal-header'>
12
+ <%= link_to 'x', '#', class: 'close', 'data-dismiss' => 'modal' %>
13
+ <h3>Valid credit card numbers in Authorize.net Test mode</h3>
14
+ </div>
15
+ <div class="modal-body">
16
+ <p> The application is running Authorize.net in <strong>Test</strong> mode. You cannot make real payment. Here are the valid credit card numbers in test mode. </p>
17
+
18
+ <ul>
19
+ <li> Visa: 4007000000027 </li>
20
+ <li> Second Visa card: 4012888818888 </li>
21
+ <li> American Express: 370000000000002 </li>
22
+ <li> Discover: 6011000000000012 </li>
23
+ <li> JCB: 3088000000000017 </li>
24
+ <li> Diners Club/ Carte Blanche: 38000000000006 </li>
25
+ </ul>
26
+ <br />
27
+ <ul>
28
+ <li> Expiration date must be set to the present day or later. </li>
29
+ <li> Security code for American express must be any 4 digits. For all others use any 3 digits. </li>
30
+ </ul>
31
+ </div>
32
+ <div class="modal-footer">
33
+ <p>
34
+ <%= link_to 'More information', '' %> .
35
+ <small>
36
+ This message never appears when Authorize.net is running in production mode .
37
+ </small>
38
+ </p>
39
+ </div>
40
+ </div>
41
+ <% end %>
@@ -0,0 +1,91 @@
1
+ <br />
2
+
3
+ <p>
4
+ <label class='radio'>
5
+ <%= radio_button_tag 'payment_choice', 'authorize-net', true %>
6
+ <label for='payment_choice'>
7
+ <%= image_tag('engines/nimbleshop_authorizedotnet/visa.png') %>
8
+ <%= image_tag('engines/nimbleshop_authorizedotnet/mastercard.png') %>
9
+ <%= image_tag('engines/nimbleshop_authorizedotnet/american_express.png') %>
10
+ <%= image_tag('engines/nimbleshop_authorizedotnet/discover.png') %>
11
+ </label>
12
+ </label>
13
+ </p>
14
+
15
+ <%= form_for @creditcard, url: nimbleshop_authorizedotnet.payment_path, remote: true, html: { id: 'authorizedotnet-payment-form', class: 'form-horizontal' } do |f| %>
16
+ <div class='nimbleshop_authorizedotnet_umbrella'>
17
+ <% if @creditcard.errors.any? %>
18
+ <div class="alert alert-error">
19
+ <ul>
20
+ <% @creditcard.errors.full_messages.each do |msg| %>
21
+ <li><%= msg %></li>
22
+ <% end %>
23
+ </ul>
24
+ </div>
25
+ <% end %>
26
+
27
+ <fieldset>
28
+ <div class='control-group'>
29
+ <div class='controls'>
30
+ <%= f.text_field :number, class: 'input-xlarge focus', placeholder: 'Credit card number', autocomplete: 'off' %>
31
+ <% unless (NimbleshopAuthorizedotnet::Authorizedotnet.first.mode == 'production') %>
32
+ &nbsp;
33
+ <%= link_to 'Valid number', '#authorizenetsandboxhelp', 'data-toggle' => "modal" %>
34
+ <% end %>
35
+ </div>
36
+ </div>
37
+
38
+ <div class='control-group'>
39
+ <div class='controls'>
40
+ <%= f.text_field :cvv, placeholder: 'CVV', autocomplete: 'off' %>
41
+ &nbsp;
42
+ <%= link_to 'What is this?', '#cvvhelp', 'data-toggle' => "modal" %>
43
+ </div>
44
+ </div>
45
+
46
+ <div class='control-group'>
47
+ <p style='padding-left:160px;'>
48
+ Expiration date
49
+ </p>
50
+ <div class='controls'>
51
+ <%= f.date_select :expires_on, discard_day: true,
52
+ start_year: Date.today.year,
53
+ end_year: (Date.today.year + 10),
54
+ add_month_numbers: true,
55
+ order: [:day, :month, :year] %>
56
+ </div>
57
+ </div>
58
+ </fieldset>
59
+ </div>
60
+
61
+ <div class="form-actions">
62
+ <%= f.submit 'Submit', class: 'btn btn-primary' %>
63
+ </div>
64
+
65
+ <%= render '/nimbleshop_authorizedotnet/payments/authorize_net_instructions' %>
66
+ <%= render '/nimbleshop_authorizedotnet/payments/what_is_cvv' %>
67
+ <% end %>
68
+
69
+ <style>
70
+ #creditcard_expires_on_2i{
71
+ width: 130px;
72
+ }
73
+ #creditcard_expires_on_1i {
74
+ width: 100px;
75
+ }
76
+ </style>
77
+
78
+ <script>
79
+ $(document).ready(function(){
80
+
81
+ $('#authorizedotnet-payment-form')
82
+ .bind("ajax:beforeSend", function(evt, xhr, settings){
83
+ var $btn = $('#authorizedotnet-payment-form').find('.btn-primary');
84
+ $btn.attr('value', 'processing ...').attr('disabled', 'disabled');
85
+ })
86
+ .bind("ajax:complete", function(evt, data, status, xhr){
87
+ var $btn = $('#authorizedotnet-payment-form').find('.btn-primary');
88
+ $btn.attr('value', 'Submit').removeAttr('disabled');
89
+ })
90
+ });
91
+ </script>
@@ -0,0 +1,4 @@
1
+ <tr>
2
+ <td> <%= transaction.created_at.to_s(:long) %> </td>
3
+ <td> <%= transaction.operation.titleize %> <%= number_to_currency((transaction.amount || 0) / 100) %> </td>
4
+ </tr>
@@ -0,0 +1,6 @@
1
+ <li>
2
+ Your credit card was charged <strong><%= number_to_currency(order.total_amount) %> </strong> .
3
+ </li>
4
+ <li>
5
+ In the credit card statement name of the company would appear as <strong><%= order.payment_method.company_name_on_creditcard_statement %></strong> .
6
+ </li>
@@ -0,0 +1,25 @@
1
+ <div id='cvvhelp' class="modal hide fade" >
2
+ <div class='modal-header'>
3
+ <%= link_to 'x', '#', class: 'close', 'data-dismiss' => 'modal' %>
4
+ <h3>What is CVV ?</h3>
5
+ </div>
6
+ <div class="modal-body">
7
+ <p>
8
+ The <strong>CVV Number</strong>
9
+ stands for "<strong>C</strong>ard <strong>V</strong>erification <strong>V</strong>alue" .
10
+ It is a 3 digit number for VISA, MasterCard and Discover cards.
11
+ It is a 4 digit number for American Express credit cards.
12
+ </p>
13
+
14
+ <div class="modal_images">
15
+ <div class="modal_cvv_image">
16
+ <h4>For Visa, MasterCard and Discover credit cards</h4>
17
+ <%= image_tag 'https://www.paypalobjects.com/en_US/i/demo/cv_card.gif' %>
18
+ </div>
19
+ <div class="modal_cvv_image">
20
+ <h4>For American Express credit cards</h4>
21
+ <%= image_tag 'https://www.paypalobjects.com/en_US/i/demo/cv_amex_card.gif' %>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ NimbleshopAuthorizedotnet::Engine.routes.draw do
2
+ resource :authorizedotnet
3
+ resource :payment
4
+ end
@@ -0,0 +1,6 @@
1
+ require "nimbleshop_authorizedotnet/engine"
2
+
3
+ module NimbleshopAuthorizedotnet
4
+ autoload :Processor, "nimbleshop_authorizedotnet/processor"
5
+ autoload :Gateway, "nimbleshop_authorizedotnet/gateway"
6
+ end
@@ -0,0 +1,17 @@
1
+ module NimbleshopAuthorizedotnet
2
+ class Engine < ::Rails::Engine
3
+
4
+ isolate_namespace NimbleshopAuthorizedotnet
5
+
6
+ config.to_prepare do
7
+ ::NimbleshopAuthorizedotnet::Authorizedotnet
8
+ end
9
+
10
+ initializer 'nimbleshop_authorizedotnet_engine.action_controller' do |app|
11
+ ActiveSupport.on_load :action_controller do
12
+ helper NimbleshopAuthorizedotnet::ExposedHelper
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module NimbleshopAuthorizedotnet
2
+ module Gateway
3
+ def self.instance
4
+ record = NimbleshopAuthorizedotnet::Authorizedotnet.first
5
+
6
+ ActiveMerchant::Billing::Gateway.logger = Rails.logger if record.mode.to_s == 'test'
7
+
8
+ ActiveMerchant::Billing::AuthorizeNetGateway.new( record.credentials )
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,140 @@
1
+ module NimbleshopAuthorizedotnet
2
+ class Processor < Processor::Base
3
+
4
+ attr_reader :order, :payment_method, :errors
5
+
6
+ def gateway
7
+ ::NimbleshopAuthorizedotnet::Gateway.instance
8
+ end
9
+
10
+ def initialize(order)
11
+ @errors = []
12
+ @order = order
13
+ @payment_method = NimbleshopAuthorizedotnet::Authorizedotnet.first
14
+ end
15
+
16
+ private
17
+
18
+ def set_active_merchant_mode
19
+ ActiveMerchant::Billing::Base.mode = payment_method.mode.to_sym
20
+ end
21
+
22
+ def do_authorize(options = {})
23
+ options.symbolize_keys!
24
+ options.assert_valid_keys(:creditcard)
25
+
26
+ creditcard = options[:creditcard]
27
+
28
+ unless valid_card?(creditcard)
29
+ @errors.push(*creditcard.errors.full_messages)
30
+ return false
31
+ end
32
+
33
+ response = gateway.authorize(order.total_amount_in_cents, creditcard)
34
+ record_transaction(response, 'authorized', card_number: creditcard.display_number, cardtype: creditcard.cardtype)
35
+
36
+ if response.success?
37
+ order.update_attributes(payment_method: payment_method)
38
+ order.authorize
39
+ else
40
+ @errors << 'Credit card was declined. Please try again!'
41
+ return false
42
+ end
43
+ end
44
+
45
+ def do_purchase(options = {})
46
+ options.symbolize_keys!
47
+ options.assert_valid_keys(:creditcard)
48
+
49
+ creditcard = options[:creditcard]
50
+
51
+ unless valid_card?(creditcard)
52
+ @errors.push(*creditcard.errors.full_messages)
53
+ return false
54
+ end
55
+
56
+ response = gateway.purchase(order.total_amount_in_cents, creditcard)
57
+ record_transaction(response, 'purchased', card_number: creditcard.display_number, cardtype: creditcard.cardtype)
58
+
59
+ if response.success?
60
+ order.update_attributes(payment_method: payment_method)
61
+ order.purchase
62
+ else
63
+ @errors << 'Credit card was declined. Please try again!'
64
+ return false
65
+ end
66
+ end
67
+
68
+ def do_capture(options = {})
69
+ options.symbolize_keys!
70
+ options.assert_valid_keys(:transaction_gid)
71
+ tsx_id = options[:transaction_gid]
72
+
73
+ response = gateway.capture(order.total_amount_in_cents, tsx_id, {})
74
+ record_transaction(response, 'captured')
75
+
76
+ if response.success?
77
+ order.kapture
78
+ else
79
+ @errors << "Capture failed"
80
+ false
81
+ end
82
+ end
83
+
84
+ def do_void(options = {})
85
+ options.symbolize_keys!
86
+ options.assert_valid_keys(:transaction_gid)
87
+ transaction_gid = options[:transaction_gid]
88
+
89
+ response = gateway.void(transaction_gid, {})
90
+ record_transaction(response, 'voided')
91
+
92
+ response.success?.tap do |success|
93
+ order.void if success
94
+ end
95
+ end
96
+
97
+ def do_refund(options = {})
98
+ options.symbolize_keys!
99
+ options.assert_valid_keys(:transaction_gid, :card_number)
100
+
101
+ transaction_gid = options[:transaction_gid]
102
+ card_number = options[:card_number]
103
+
104
+ response = gateway.refund(order.total_amount_in_cents, transaction_gid, card_number: card_number)
105
+ record_transaction(response, 'refunded')
106
+
107
+ response.success?.tap do |success|
108
+ order.refund if success
109
+ end
110
+
111
+ end
112
+
113
+ def record_transaction(response, operation, additional_options = {})
114
+ #
115
+ # Following code invokes response.authorization to get transaction id. Note that this method can be called
116
+ # after capture or refund. And it feels weird to call +authorization+ when the operation was +capture+.
117
+ # However this is how ActiveMerchant works. It sets transaction id in +authorization+ key.
118
+ #
119
+ # https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net.rb#L283
120
+ #
121
+ transaction_gid = response.authorization
122
+
123
+ options = { operation: operation,
124
+ params: response.params,
125
+ success: response.success?,
126
+ metadata: additional_options,
127
+ transaction_gid: transaction_gid }
128
+
129
+ if response.success?
130
+ options.update(amount: order.total_amount_in_cents)
131
+ end
132
+
133
+ order.payment_transactions.create(options)
134
+ end
135
+
136
+ def valid_card?(creditcard)
137
+ creditcard && creditcard.valid?
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,3 @@
1
+ module NimbleshopAuthorizedotnet
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,31 @@
1
+
2
+ namespace :nimbleshop_authorizedotnet do
3
+
4
+ desc 'copies images from engine to main rails application'
5
+ task :copy_images do
6
+ engine_name = 'nimbleshop_authorizedotnet'
7
+ origin = File.expand_path('../../app/assets/images', File.dirname(__FILE__))
8
+ destination = Rails.root.join('app', 'assets', 'images', 'engines', engine_name)
9
+ FileUtils.mkdir_p(destination) if !File.exist?(destination)
10
+ Dir[File.join(origin, '**/*')].each { |file| FileUtils.cp(file, File.join(destination) ) unless File.directory?(file) }
11
+ end
12
+
13
+ desc 'load Authorize.net record'
14
+ task :load_record => :environment do
15
+
16
+ if NimbleshopAuthorizedotnet::Authorizedotnet.find_by_permalink('authorizedotnet')
17
+ puts "Authorize.net record already exists"
18
+ else
19
+ NimbleshopAuthorizedotnet::Authorizedotnet.create!(
20
+ {
21
+ login_id: Nimbleshop.config.authorizedotnet.login_id,
22
+ transaction_key: Nimbleshop.config.authorizedotnet.transaction_key,
23
+ company_name_on_creditcard_statement: 'Nimbleshop LLC',
24
+ name: 'Authorize.net',
25
+ permalink: 'authorizedotnet',
26
+ description: %Q[<p> Authorize.Net is a payment gateway service provider allowing merchants to accept credit card and electronic checks paymentsn. Authorize.Net claims a user base of over 305,000 merchants, which would make them the Internet's largest payment gateway service provider. </p> <p> It also provides an instant test account which you can use while your application is being processed. </p>]
27
+ })
28
+ puts "Authorize.net record was successfuly created"
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nimbleshop_authorizedotnet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.rc1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Neeraj Singh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activemerchant
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Provides Authorize.net feature to nimbleshop
31
+ email:
32
+ - neeraj@BigBinary.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - app/assets/images/nimbleshop_authorizedotnet/american_express.png
38
+ - app/assets/images/nimbleshop_authorizedotnet/authorize_net_big.png
39
+ - app/assets/images/nimbleshop_authorizedotnet/authorizedotnet_big.png
40
+ - app/assets/images/nimbleshop_authorizedotnet/discover.png
41
+ - app/assets/images/nimbleshop_authorizedotnet/mastercard.png
42
+ - app/assets/images/nimbleshop_authorizedotnet/visa.png
43
+ - app/controllers/nimbleshop_authorizedotnet/authorizedotnets_controller.rb
44
+ - app/controllers/nimbleshop_authorizedotnet/payments_controller.rb
45
+ - app/helpers/nimbleshop_authorizedotnet/exposed_helper.rb
46
+ - app/models/nimbleshop_authorizedotnet/authorizedotnet.rb
47
+ - app/views/nimbleshop_authorizedotnet/authorizedotnets/_edit.html.erb
48
+ - app/views/nimbleshop_authorizedotnet/authorizedotnets/_form.html.erb
49
+ - app/views/nimbleshop_authorizedotnet/payments/_authorize_net_instructions.html.erb
50
+ - app/views/nimbleshop_authorizedotnet/payments/_new.html.erb
51
+ - app/views/nimbleshop_authorizedotnet/payments/_order_show_extra_info.html.erb
52
+ - app/views/nimbleshop_authorizedotnet/payments/_payment_info_for_buyer.html.erb
53
+ - app/views/nimbleshop_authorizedotnet/payments/_what_is_cvv.html.erb
54
+ - config/routes.rb
55
+ - lib/nimbleshop_authorizedotnet/engine.rb
56
+ - lib/nimbleshop_authorizedotnet/gateway.rb
57
+ - lib/nimbleshop_authorizedotnet/processor.rb
58
+ - lib/nimbleshop_authorizedotnet/version.rb
59
+ - lib/nimbleshop_authorizedotnet.rb
60
+ - lib/tasks/nimbleshop_authorizedotnet_tasks.rake
61
+ - README.md
62
+ homepage: http://nimbleShop.org
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>'
78
+ - !ruby/object:Gem::Version
79
+ version: 1.3.1
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Authorize.net extension for nimbleshop
86
+ test_files: []