stall-authorize_dot_net 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8be2d495b523c2f2d2dee5bc40398619502c95d6
4
+ data.tar.gz: d7f998272e8d9accec44985e68ce96f3d7e484ce
5
+ SHA512:
6
+ metadata.gz: 27f144c3071853bd5e4df0c1201dfea091c3b10a0b045616834a82a1edd824c71091b66086a8a87d0f199374c45b8a78c15dec4e853102859fd510afe7a856cd
7
+ data.tar.gz: 62e6735d4a8ca749b091bb6f4f38511a5af26bb11fea8e91c5f8abf1bdc6ad34fefd700dc0db82138978211f7f2b07424cbe4c4cf9a63cb8abd88b5ad2c8800f
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stall-authorize_dot_net.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 vala
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ # Stall::AuthorizeDotNet
2
+
3
+ This gem allows integrating your [Stall](https://github.com/stall-rails/stall)
4
+ e-commerce app with the Authorize.net online payment gateway solution.
5
+
6
+ This gem is just the glue between [Stall](https://github.com/stall-rails/stall)
7
+ and the [offsite_payments](https://github.com/activemerchant/offsite_payments/) gem.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile :
12
+
13
+ ```ruby
14
+ gem 'stall-authorize_dot_net'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install stall-authorize_dot_net
24
+
25
+ Then use the install generator to copy the config template file :
26
+
27
+ $ rails generator stall:authorize_dot_net:install
28
+
29
+
30
+ ## Usage
31
+
32
+ You first need to configure the gateway by filling the required variables in
33
+ that were added to the stall config initialize.
34
+
35
+ By default, it is configured to fetch from the variables from the environment,
36
+ so ideally, just create the following env vars :
37
+
38
+ - `AUTHORIZE_NET_ACCOUNT`
39
+ - `AUTHORIZE_NET_TRANSACTION_KEY`
40
+ - `AUTHORIZE_NET_MD5_HASH`
41
+
42
+ Note that you **must** set the `AUTHORIZE_NET_MD5_HASH` value in your
43
+ Authorize.net account security "MD5 Hash" section. This acts as a token
44
+ used to authenticate Authorize.net incoming requests for payment notifications.
45
+ More informations : https://support.authorize.net/authkb/index?page=content&id=A588
46
+
47
+ Restart your server, and you should now be able to use the Authorize.net payment
48
+ gateway in test mode.
49
+
50
+ When you're ready to switch to production, juste set the following environment
51
+ variable :
52
+
53
+ - `AUTHORIZE_NET_PRODUCTION_MODE=true`
54
+
55
+ Just like the other settings, you can change the way it's configured in the
56
+ stall initializer file.
57
+
58
+ ### Sandbox account
59
+
60
+ By default, the Authorize.net gateway is configured to run in test mode.
61
+
62
+ To run your tests, you'll want to create a Sandbox account at :
63
+ https://sandbox.authorize.net and use the provided credentials to run your
64
+ payment tests, before switching to production with your real credentials.
65
+
66
+ ### Automatic response URL
67
+
68
+ You need to provide a payment response URL to your bank which will be :
69
+
70
+ ```text
71
+ <http|https>://<YOUR_DOMAIN>/authorize_dot_net/payment/notify
72
+ ```
73
+
74
+ You can find the route with :
75
+
76
+ ```bash
77
+ rake routes | grep payment/notify
78
+ ```
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/stall-rails/stall-authorize_dot_net.
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
87
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,52 @@
1
+ <% payment_service_for(request.gateway.transaction_id, request.gateway.account, service: :authorize_net_sim, amount: request.cart.total_price) do |service|
2
+ # You must call setup_hash and invoice
3
+ service.setup_hash transaction_key: request.gateway.transaction_key,
4
+ order_timestamp: Time.now.to_i
5
+
6
+ service.customer_id request.cart.customer.id
7
+
8
+ service.customer first_name: request.cart.billing_address.try(:first_name),
9
+ last_name: request.cart.billing_address.try(:last_name),
10
+ email: request.cart.customer.email
11
+
12
+ if request.cart.billing_address
13
+ service.billing_address zip: request.cart.billing_address.zip,
14
+ country: request.cart.billing_address.country_name,
15
+ address1: request.cart.billing_address.address,
16
+ city: request.cart.billing_address.city
17
+ end
18
+
19
+
20
+ if request.cart.shipping_address
21
+ service.ship_to_address first_name: request.cart.shipping_address.first_name,
22
+ last_name: request.cart.shipping_address.last_name,
23
+ city: request.cart.shipping_address.city,
24
+ address1: request.cart.shipping_address.address,
25
+ address2: request.cart.shipping_address.address_details,
26
+ state: request.cart.shipping_address.state,
27
+ country: request.cart.shipping_address.country_name,
28
+ zip: request.cart.shipping_address.zip
29
+ end
30
+
31
+ service.invoice request.cart.reference # your invoice number
32
+
33
+ # The end-user is presented with the HTML produced by the notify_url.
34
+ service.notify_url request.gateway.payment_urls.payment_notification_url
35
+ service.payment_header Stall.config.store_name
36
+
37
+ # service.add_line_item name: 'item name', quantity: 1, unit_price: 0
38
+
39
+ # service.test_request 'true' # only if it's just a test
40
+ # service.shipping '25.0'
41
+
42
+ # Tell it to display a "0" line item for shipping, with the price in
43
+ # the name, otherwise it isn't shown at all, leaving the end user to
44
+ # wonder why the total is different than the sum of the line items.
45
+ # service.add_shipping_as_line_item
46
+ # server.add_tax_as_line_item # same with tax
47
+ # See the helper.rb file for various custom fields
48
+ %>
49
+ <button type="submit" class="btn btn-primary">
50
+ <%= t('stall.payments.gateway.pay') %>
51
+ </button>
52
+ <% end %>
@@ -0,0 +1,2 @@
1
+ :javascript
2
+ window.location.href = '#{ gateway.payment_urls.payment_failure_return_url }'
@@ -0,0 +1,2 @@
1
+ :javascript
2
+ window.location.href = '#{ gateway.payment_urls.payment_success_return_url }'
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "stall/authorize_dot_net"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ en:
2
+ stall:
3
+ authorize_dot_net:
4
+ relay_response:
5
+ success:
6
+ title: "Payment successful"
7
+ help: |
8
+ Your payment has been successfully processed by the Authorize.net
9
+ service.
10
+ action: "Back to the shop"
@@ -0,0 +1,10 @@
1
+ fr:
2
+ stall:
3
+ authorize_dot_net:
4
+ relay_response:
5
+ success:
6
+ title: "Paiement effectué"
7
+ help: |
8
+ Votre paiement a bien été pris en compte par le système
9
+ Authorize.net.
10
+ action: "Retourner à la boutique"
@@ -0,0 +1,13 @@
1
+ module Stall
2
+ module AuthorizeDotNet
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def copy_config_template
7
+ inject_into_file 'config/initializers/stall.rb', after: "Stall.configure do |config|\n" do
8
+ File.read(File.join(self.class.source_root, 'config.rb'))
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # Authorize.net payment gateway configuration
2
+ # Fill with the informations provided by your Authorize.net account
3
+ #
4
+ config.payment.authorize_dot_net do |authorize_dot_net|
5
+ # Your authorize.net account number
6
+ authorize_dot_net.account = ENV['AUTHORIZE_NET_ACCOUNT']
7
+ # Your authorize.net transaction key
8
+ authorize_dot_net.transaction_key = ENV['AUTHORIZE_NET_TRANSACTION_KEY']
9
+ # The authorize.net md5 hash filled in your customer interface to
10
+ # authenticate incoming gateway requests
11
+ authorize_dot_net.md5_hash = ENV['AUTHORIZE_NET_MD5_HASH']
12
+
13
+ # Test or production mode, default to false, changes the payment
14
+ # gateway target URL
15
+ #
16
+ # By default, the test mode is activated in all environments but you just
17
+ # need to add `AUTHORIZE_NET_PRODUCTION_MODE=true` in your environment variables
18
+ # and restart your server to switch to production mode
19
+ #
20
+ authorize_dot_net.test_mode = (ENV['AUTHORIZE_NET_PRODUCTION_MODE'] != 'true')
21
+ end
22
+
@@ -0,0 +1,14 @@
1
+ require 'stall'
2
+ require 'offsite_payments'
3
+
4
+ module Stall
5
+ module AuthorizeDotNet
6
+ extend ActiveSupport::Autoload
7
+
8
+ autoload :Version
9
+ autoload :FakeGatewayPaymentNotification
10
+ end
11
+ end
12
+
13
+ require 'stall/authorize_dot_net/gateway'
14
+ require 'stall/authorize_dot_net/engine'
@@ -0,0 +1,11 @@
1
+ module Stall
2
+ module AuthorizeDotNet
3
+ class Engine < ::Rails::Engine
4
+ initializer 'stall-authorize_dot_net.include_offsite_payments_action_view_helpers' do
5
+ ActiveSupport.on_load(:action_view) do
6
+ include OffsitePayments::ActionViewHelper
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Stall
2
+ module AuthorizeDotNet
3
+ class FakeGatewayPaymentNotification < Stall::Payments::FakeGatewayPaymentNotification
4
+ def params
5
+ {}
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,104 @@
1
+ module Stall
2
+ module AuthorizeDotNet
3
+ class Gateway < Stall::Payments::Gateway
4
+ register :authorize_dot_net
5
+
6
+ class_attribute :account
7
+ class_attribute :transaction_key
8
+ class_attribute :md5_hash
9
+
10
+ # Test or production mode, default to false, changes the payment
11
+ # gateway target URL
12
+ class_attribute :test_mode
13
+ self.test_mode = !Rails.env.production?
14
+
15
+ def self.test_mode=(value)
16
+ OffsitePayments.mode = value ? :test : :production
17
+ @test_mode = value
18
+ end
19
+
20
+ def self.request(cart)
21
+ Request.new(cart)
22
+ end
23
+
24
+ def self.response(request)
25
+ Response.new(request)
26
+ end
27
+
28
+ def self.fake_payment_notification_for(cart)
29
+ Stall::AuthorizeDotNet::FakeGatewayPaymentNotification.new(cart)
30
+ end
31
+
32
+ class Request
33
+ attr_reader :cart
34
+
35
+ delegate :currency, to: :cart, allow_nil: true
36
+
37
+ def initialize(cart)
38
+ @cart = cart
39
+ end
40
+
41
+ def payment_form_partial_path
42
+ 'stall/authorize_dot_net/payment_form'
43
+ end
44
+
45
+ def gateway
46
+ @gateway = Stall::AuthorizeDotNet::Gateway.new(cart)
47
+ end
48
+ end
49
+
50
+ class Response
51
+ attr_reader :request
52
+
53
+ def initialize(request)
54
+ @request = request
55
+ end
56
+
57
+ def valid?
58
+ @valid ||= notification.acknowledge(gateway.md5_hash, gateway.account)
59
+ end
60
+
61
+ def success?
62
+ @success ||= valid? && notification.complete?
63
+ end
64
+
65
+ def process
66
+ valid? && success?
67
+ end
68
+
69
+ def rendering_options
70
+ {
71
+ file: relay_response_partial_path,
72
+ layout: false,
73
+ locals: { gateway: gateway }
74
+ }
75
+ end
76
+
77
+ def relay_response_partial_path
78
+ [
79
+ 'stall/authorize_dot_net/',
80
+ (success? ? 'success' : 'error'),
81
+ '_relay_response'
82
+ ].join
83
+ end
84
+
85
+ def gateway
86
+ @gateway ||= Stall::AuthorizeDotNet::Gateway.new(cart)
87
+ end
88
+
89
+ def cart
90
+ @cart ||= ProductList.find_by_reference(notification.invoice_num)
91
+ end
92
+
93
+ private
94
+
95
+ def notification
96
+ @notification ||=
97
+ OffsitePayments::Integrations::AuthorizeNetSim::Notification.new(
98
+ request.raw_post
99
+ )
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,5 @@
1
+ module Stall
2
+ module AuthorizeDotNet
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stall/authorize_dot_net/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'stall-authorize_dot_net'
8
+ spec.version = Stall::AuthorizeDotNet::VERSION
9
+ spec.authors = ['vala']
10
+ spec.email = ['vala@glyph.fr']
11
+
12
+ spec.summary = %q{Stall e-commerce Authorize.net payment gateway integration}
13
+ spec.description = %q{Allows easy Authorize.net gateway integration in a Stall e-commerce app}
14
+ spec.homepage = 'https://github.com/rails-stall/stall-authorize_dot_net'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'stall', '~> 0.3'
23
+ spec.add_dependency 'offsite_payments', '~> 2.0'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.11'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stall-authorize_dot_net
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - vala
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: stall
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: offsite_payments
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Allows easy Authorize.net gateway integration in a Stall e-commerce app
84
+ email:
85
+ - vala@glyph.fr
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - app/views/stall/authorize_dot_net/_payment_form.html.erb
98
+ - app/views/stall/authorize_dot_net/error_relay_response.html.haml
99
+ - app/views/stall/authorize_dot_net/success_relay_response.html.haml
100
+ - bin/console
101
+ - bin/setup
102
+ - config/locales/stall-authorize_dot_net.en.yml
103
+ - config/locales/stall-authorize_dot_net.fr.yml
104
+ - lib/generators/stall/authorize_dot_net/install/install_generator.rb
105
+ - lib/generators/stall/authorize_dot_net/install/templates/config.rb
106
+ - lib/stall/authorize_dot_net.rb
107
+ - lib/stall/authorize_dot_net/engine.rb
108
+ - lib/stall/authorize_dot_net/fake_gateway_payment_notification.rb
109
+ - lib/stall/authorize_dot_net/gateway.rb
110
+ - lib/stall/authorize_dot_net/version.rb
111
+ - stall-authorize_dot_net.gemspec
112
+ homepage: https://github.com/rails-stall/stall-authorize_dot_net
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.6.8
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Stall e-commerce Authorize.net payment gateway integration
136
+ test_files: []