beanstreamy 0.1.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.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.swp
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,16 @@
1
+ Beanstreamy
2
+ ===========
3
+
4
+ A simple utility library for the Beanstream payment gateway. Currently includes a helper method for using beanstream's hosted payment page.
5
+
6
+ Example
7
+ =======
8
+
9
+ After setting your merchant id and hash key in the initializer file, you can create a form to submit to the hosted payment page using:
10
+
11
+ <% beanstream_hosted_payment_form :order_id => 5, :amount => 34.45 do -%>
12
+ <!-- any other beanstream fields you'd like to submit, e.g. ordName. -->
13
+ <%= submit_tag "Checkout with Beanstream" %>
14
+ <% end -%>
15
+
16
+ Copyright (c) 2010 Jeff Siegel, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the beanstreamy plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the beanstreamy plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'Beanstreamy'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |gemspec|
28
+ gemspec.name = "beanstreamy"
29
+ gemspec.summary = "A Beanstream utility library for Rails"
30
+ gemspec.description = "Currently provides a helper method for rendering forms that will submit to the beanstream hosted payment gateway"
31
+ gemspec.email = "jeff@stage2.ca"
32
+ gemspec.homepage = "http://github.com/jdsiegel/beanstreamy"
33
+ gemspec.authors = ["Jeff Siegel"]
34
+ end
35
+ rescue LoadError
36
+ puts "Jeweler not available. Install it with: gem install jeweler"
37
+ end
38
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{beanstreamy}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeff Siegel"]
12
+ s.date = %q{2010-06-16}
13
+ s.description = %q{Currently provides a helper method for rendering forms that will submit to the beanstream hosted payment gateway}
14
+ s.email = %q{jeff@stage2.ca}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "beanstreamy.gemspec",
25
+ "generators/beanstreamy/beanstreamy_generator.rb",
26
+ "generators/beanstreamy/templates/README",
27
+ "generators/beanstreamy/templates/beanstreamy.rb",
28
+ "init.rb",
29
+ "lib/beanstreamy.rb",
30
+ "lib/beanstreamy/hosted_payment_helper.rb",
31
+ "lib/tasks/beanstreamy.rake",
32
+ "test/beanstreamy_test.rb",
33
+ "test/test_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/jdsiegel/beanstreamy}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{A Beanstream utility library for Rails}
40
+ s.test_files = [
41
+ "test/beanstreamy_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ else
51
+ end
52
+ else
53
+ end
54
+ end
55
+
@@ -0,0 +1,10 @@
1
+ class BeanstreamyGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.directory "config/initializers"
5
+ m.template "beanstreamy.rb", "config/initializers/beanstreamy.rb"
6
+
7
+ m.readme "README"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ =============================================================================
2
+
3
+ There are two settings you need to specify in the
4
+ config/initializers/beanstreamy.rb file:
5
+
6
+ 1. Your Beanstream merchant id.
7
+
8
+ 2. Your hash key for hash validation. You can turn on hash validation and
9
+ set your hash key on the "order settings" page in your Beanstream account.
10
+
11
+ After these are set, you'll be able to generate a form for the hosted payment
12
+ page in your views with:
13
+
14
+ <% beanstream_hosted_payment_form :order_id => 5, :amount => 34.45 do -%>
15
+ <!-- any other beanstream fields you'd like to submit, e.g. ordName. -->
16
+ <%= submit_tag "Checkout with Beanstream" %>
17
+ <% end -%>
18
+
19
+ =============================================================================
@@ -0,0 +1,19 @@
1
+ # Beanstreamy configuration
2
+ #
3
+ # You'll need to set your merchant_id and hash key for hash validation. You can turn on hash validation
4
+ # and set your hash key in your Beanstream account in the "order settings" section.
5
+
6
+ # If you use your own payment page on Beanstream's secure webspace, you can set that here:
7
+ # Beanstreamy.config.payment_url = "https://www.beanstream.com/scripts/payment/payment.asp"
8
+
9
+ # Set your merchant id here
10
+ Beanstreamy.config.merchant_id = "000000000"
11
+
12
+ # Set your hash key here
13
+ Beanstreamy.config.hash_key = ""
14
+
15
+ # If you use your own approval page, you can set that here:
16
+ # Beanstreamy.config.approved_url = "/some/path"
17
+
18
+ # If you use your own declined page, you can set that here:
19
+ # Beanstreamy.config.declined_url = "/some/path"
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'beanstreamy'
@@ -0,0 +1,46 @@
1
+ module Beanstreamy
2
+ module HostedPaymentHelper
3
+
4
+ mattr_accessor :config
5
+ @@config = Beanstreamy.config
6
+
7
+ def beanstream_hosted_payment_form(options = {}, &block)
8
+
9
+ order_id = options.delete(:order_id) or raise("Missing order id")
10
+ amount = options.delete(:amount) or raise("Missing amount")
11
+ merchant_id = options.delete(:merchant_id) || config.merchant_id
12
+ hash_key = options.delete(:hash_key) || config.hash_key
13
+ approved_url = options.delete(:approved_url) || config.approved_url
14
+ declined_url = options.delete(:declined_url) || config.declined_url
15
+
16
+ form = content_tag(:form, options.merge(:action => config.payment_url, :method => "post")) do
17
+ concat hidden_field_tag("merchant_id", merchant_id)
18
+ concat hidden_field_tag("trnOrderNumber", order_id)
19
+ concat hidden_field_tag("trnAmount", amount)
20
+ if approved_url.present?
21
+ concat hidden_field_tag("approvedPage", approved_url)
22
+ end
23
+ if declined_url.present?
24
+ concat hidden_field_tag("declinedPage", declined_url)
25
+ end
26
+
27
+ # Beansream's hosted page uses hash validation to prevent price modification. This hash is computed from
28
+ # the url encoded string of the above inputs
29
+ query_params = [
30
+ ["merchant_id", merchant_id],
31
+ ["trnOrderNumber", order_id],
32
+ ["trnAmount", amount],
33
+ ["approvedPage", approved_url],
34
+ ["declinedPage", declined_url]
35
+ ]
36
+ query_string = query_params.reject { |k,v| v.blank? }.map { |k,v| v.to_query(k) }.join('&')
37
+ hash_value = Digest::SHA1.hexdigest(query_string + hash_key)
38
+
39
+ concat hidden_field_tag("hashValue", hash_value)
40
+
41
+ block.call(:hash_value => hash_value, :query_string => query_string)
42
+ end
43
+ concat form
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,16 @@
1
+ module Beanstreamy
2
+ class Config
3
+ attr_accessor :payment_url, :merchant_id, :hash_key, :approved_url, :declined_url
4
+
5
+ def initialize
6
+ @payment_url = "https://www.beanstream.com/scripts/payment/payment.asp"
7
+ end
8
+ end
9
+
10
+ mattr_accessor :config
11
+ @@config = Config.new
12
+ end
13
+
14
+ require 'beanstreamy/hosted_payment_helper'
15
+
16
+ ActionView::Base.send :include, Beanstreamy::HostedPaymentHelper
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :beanstreamy do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BeanstreamyTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beanstreamy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jeff Siegel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-16 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Currently provides a helper method for rendering forms that will submit to the beanstream hosted payment gateway
22
+ email: jeff@stage2.ca
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README
29
+ files:
30
+ - .gitignore
31
+ - MIT-LICENSE
32
+ - README
33
+ - Rakefile
34
+ - VERSION
35
+ - beanstreamy.gemspec
36
+ - generators/beanstreamy/beanstreamy_generator.rb
37
+ - generators/beanstreamy/templates/README
38
+ - generators/beanstreamy/templates/beanstreamy.rb
39
+ - init.rb
40
+ - lib/beanstreamy.rb
41
+ - lib/beanstreamy/hosted_payment_helper.rb
42
+ - lib/tasks/beanstreamy.rake
43
+ - test/beanstreamy_test.rb
44
+ - test/test_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/jdsiegel/beanstreamy
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.6
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: A Beanstream utility library for Rails
75
+ test_files:
76
+ - test/beanstreamy_test.rb
77
+ - test/test_helper.rb