Skip to content

Commit

Permalink
Getting tests to work outside of ActiveMerchant and preparing Gemfile
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Feb 25, 2011
1 parent 0a42be7 commit 4ecbbbc
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 45 deletions.
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@

source :rubygems
gemspec

54 changes: 54 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,54 @@
PATH
remote: .
specs:
active_merchant_sermepa (0.0.1)
activemerchant (>= 1.9.4)

GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionpack (3.0.4)
activemodel (= 3.0.4)
activesupport (= 3.0.4)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.4)
rack (~> 1.2.1)
rack-mount (~> 0.6.13)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemerchant (1.11.0)
activesupport (>= 2.3.8)
braintree (>= 2.0.0)
builder (>= 2.0.0)
activemodel (3.0.4)
activesupport (= 3.0.4)
builder (~> 2.1.2)
i18n (~> 0.4)
activesupport (3.0.4)
braintree (2.8.0)
builder
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.5.0)
mocha (0.9.12)
money (3.5.5)
i18n (~> 0.4)
rack (1.2.1)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
tzinfo (0.3.24)

PLATFORMS
ruby

DEPENDENCIES
actionpack (~> 3.0.3)
active_merchant_sermepa!
activemerchant (>= 1.9.4)
mocha (~> 0.9.10)
money (~> 3.5.4)
2 changes: 1 addition & 1 deletion MIT-LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2010 Samuel Lown
Copyright (c) 2010-2011 Samuel Lown

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
157 changes: 157 additions & 0 deletions README.rdoc
@@ -1,5 +1,162 @@
= Active Merchant Sermepa Plugin

Basic support for the Spanish SERMEPA Virtual POS payment gateway provided by Servired.
Used by many banks in Spain and known locally as a "TPV Virtual".

Include this library along with the standard active merchant package and a new
Integration payment gateway will be available.


== Install

Add to your Gemfile as follows:

gem 'activemerchant_sermepa'

That should automatically install a usable version of active merchant as a dependency.

== Usage

This is an integrated payment gateway and as such requires all credit card details
to be provided outside of your own website's pages. The basic purchase process is:

1. HTML form shown on website with payment details
2. Form is submitted directly to Sermepa's servers
3. User provides credit card and completes validatation proceedures (this can be a
pain in the *** for your clients if they don't have the necessary login details, ask
your bank to disable it if you get lots of complaints.)
4. Optional: website receives notification from sermepa of sale result
5. User forwarded back to your website. If the "Parameters in URL" (Parámetros en las URLs)
option is set in the point of sale's configuration, the user will be forwarded with a set
of parameters that can be used to validate the purchase.
6. Confirm that the purchase is successful using either notification or parameters in URL.

Sermepa, unlike the similar BBVA system, does not support manual requests to confirm
the success of a sale. Validation must be done using the parameters received either
from the notification or paremeters in forwarded URL.


=== Configuration

Your bank should provide you with three keys, known as the "terminal id", "commercial id",
and "secret key". These when combined allow requests to be signed and incoming confirmations
to be validated. A final option is available to set the the type of key used in the
transactions. The "key type" can be set to either "sha1_complete" or "sha1_extended
according to whatever is set by your bank.

These configuration options can either be set globally or on a per-request basis. The
following would be included in an initializer to prepare the gateway for use:

ActiveMerchant::Billing::Integrations::Sermepa::Helper.credentials = {
:terminal_id => '9',
:commercial_id => ''999008881,
:secret_key => 'qwertyasdf0123456789',
:key_type => 'sha1_complete'
}

If the credentials are not set this way, they'll need to be included with each call to
the library's methods.

=== Form

Active Merchant provides a helper called "payment_service_for" which handles the preparation
of the request to the gateway. The following code sample shows what this might look like:

= payment_service_for @invoice.transactions.last.code, 'The Shop', :amount => @invoice.total.cents, :currency => 'EUR', :service => :sermepa do |service|
- service.description "Some description of the purchase"
- service.customer_name @invoice.client.name
- service.notify_url notify_invoice_url(@invoice)
- service.success_url complete_invoice_url(@invoice)
- service.failure_url complete_invoice_url(@invoice)

= submit_tag "Go to payment gateway!"

A few important things to bare in mind:

- Each request to the service *must* have a unique transaction or order id. This is the first parameter provided to the helper.
- If a purchase fails, the order id *must* be updated.
- As per the Sermepa documentation the transaction id must be between 4 and 12 digits long and always start with 4 numbers.
- The credentials can be provided in the ":credentials" option to the helper if preferred.
- The URLs set where the user will be sent after the purchase.


=== Notification and Confirmation

While confirming the purchase is optional, it is highly recommended as it allows you
to let the client know instantly that the transaction has completed successfully.

If HTTP notification has been enabled in the Sermepa configuration, a private
request will be sent from the gateway to your website confirming the success of
the transaction. The notification URL can be provided either in the form's parameters
or in the administrator configuration. You'll most likely not be able to test this
during development on your local machine for obvious reasons.

Ensuring that the parameters are provided from the returning user is much more
convenient for testing and allows for an instant response to the user.

Both types work using the same parameters in the URL so can be handled with the same method.

Your controller might have a actions like in the following example:

# Receive a direct notification from the gateway
def notify
notify = ActiveMerchant::Billing::Integrations::Sermepa.notification(request.query_parameters)
if notify.acknowledge
# Do something useful
end
render :text => 'OK'
end

# Handle the incoming user
def confirm
notify = ActiveMerchant::Billing::Integrations::Sermepa.notification(request.query_parameters)
if notify.acknowledge
# do something useful
render :action => 'success'
else
render :action => 'failure'
end
end

These examples are greatly simplified. It would be much better to handle these operations in
a model and provide support for recording each event that takes place.

The acknowledge method also accepts a hash of credentials should you prefer this
to setting them globally. It checks to see if by combining the received parameters
the same signature can be generated using our secret key. Assuming the operation
successful and the signature is valid, the purchase will be successful.


== Authors

Written by Sam Lown.

Special thanks go to {rentages.es}[http://www.rentages.es] for supporting the initial development.

Thanks should also go to {floresfrescas.com}[http://www.floresfrescas.com] for supporting the development of the BBVA TPV gateway method on which this is heavily based.

And of course, many thanks to the ActiveMerchan[http://www.activemerchant.org] team.

== License

Released under the MIT license.

Copyright (c) 2010-2011 Samuel Lown

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
25 changes: 14 additions & 11 deletions Rakefile
@@ -1,15 +1,18 @@
require 'rubygems'
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rake'
require 'echoe'
require 'rake/testtask'

desc "Run the unit test suite"
task :default => 'test:units'

Echoe.new('activemerchant_sermepa', '0.0.1') do |p|
p.description = "Add support to ActiveMerchant for the Spanish Sermepa payment gateway"
p.url = "http://github.com/samlown/active_merchant_sermepa"
p.author = "Sam Lown"
p.email = "me@samlown.com"
p.ignore_pattern = ["tmp/*", "script/*"]
p.runtime_dependencies = [
"activemerchant >=1.5.2"
]
p.development_dependencies = []
namespace :test do
Rake::TestTask.new(:units) do |t|
t.pattern = 'test/unit/**/*_test.rb'
t.ruby_opts << '-rubygems'
t.libs << 'test'
t.verbose = true
end
end
32 changes: 12 additions & 20 deletions active_merchant_sermepa.gemspec
Expand Up @@ -4,31 +4,23 @@ Gem::Specification.new do |s|
s.name = %q{active_merchant_sermepa}
s.version = "0.0.1"

s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Sam Lown"]
s.date = %q{2010-12-15}
s.date = %q{2011-02-25}
s.description = %q{Add support to ActiveMerchant for the Spanish Sermepa payment gateway}
s.email = %q{me@samlown.com}
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/active_merchant/billing/integrations/sermepa.rb", "lib/active_merchant/billing/integrations/sermepa/helper.rb", "lib/active_merchant/billing/integrations/sermepa/notification.rb", "lib/active_merchant/billing/integrations/sermepa/return.rb", "lib/active_merchant_sermepa.rb"]
s.files = ["CHANGELOG", "MIT-LICENSE", "Manifest", "README.rdoc", "Rakefile", "active_merchant_sermepa.gemspec", "lib/active_merchant/billing/integrations/sermepa.rb", "lib/active_merchant/billing/integrations/sermepa/helper.rb", "lib/active_merchant/billing/integrations/sermepa/notification.rb", "lib/active_merchant/billing/integrations/sermepa/return.rb", "lib/active_merchant_sermepa.rb", "test/test_helper.rb", "test/unit/integrations/helpers/sermepa_helper_test.rb", "test/unit/integrations/notifications/sermepa_notification_test.rb", "test/unit/integrations/sermepa_module_text.rb"]
s.extra_rdoc_files = ['MIT-LICENSE', 'CHANGELOG', 'README.rdoc']
s.homepage = %q{http://github.com/samlown/active_merchant_sermepa}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Active_merchant_sermepa", "--main", "README.rdoc"]
s.rubygems_version = "1.3.7"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.rubyforge_project = %q{active_merchant_sermepa}
s.rubygems_version = %q{1.3.7}
s.summary = %q{Add support to ActiveMerchant for the Spanish Sermepa payment gateway}
s.test_files = ["test/unit/integrations/notifications/sermepa_notification_test.rb", "test/unit/integrations/helpers/sermepa_helper_test.rb", "test/test_helper.rb"]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
s.add_dependency("activemerchant", ">= 1.9.4")
s.add_development_dependency("mocha", "~> 0.9.10")
s.add_development_dependency("money", "~> 3.5.4")
s.add_development_dependency("actionpack", "~> 3.0.3")

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<active_merchant>, [">= 1.9.2"])
else
s.add_dependency(%q<active_merchant>, [">= 1.9.2"])
end
else
s.add_dependency(%q<active_merchant>, [">= 1.9.2"])
end
end
@@ -1,6 +1,4 @@
# encoding: utf-8
require 'nokogiri'

module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
Expand Down

0 comments on commit 4ecbbbc

Please sign in to comment.