active_merchant_ogone 0.1.2
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/MIT-LICENSE +20 -0
- data/README.rdoc +67 -0
- data/Rakefile +38 -0
- data/VERSION.yml +4 -0
- data/active_merchant_ogone.gemspec +58 -0
- data/init.rb +1 -0
- data/lib/active_merchant_ogone/helper.rb +51 -0
- data/lib/active_merchant_ogone/notification.rb +125 -0
- data/lib/active_merchant_ogone.rb +58 -0
- data/test/active_merchant_ogone/helper_test.rb +48 -0
- data/test/active_merchant_ogone/notification_test.rb +38 -0
- data/test/active_merchant_ogone_test.rb +37 -0
- data/test/test_helper.rb +184 -0
- metadata +80 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jan De Poorter
|
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.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= ActiveMerchantOgone
|
2
|
+
|
3
|
+
A plugin for Ogone support in ActiveRecord.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
=== Requirements
|
8
|
+
|
9
|
+
First you need the ActiveMerchant gem / rails-plugin installed. More info about ActiveMerchant installation can be found at http://activemerchant.rubyforge.org/.
|
10
|
+
|
11
|
+
=== As a Rails plugin
|
12
|
+
|
13
|
+
To install ActiveMerchantOgone in your rails app you can just do:
|
14
|
+
|
15
|
+
> ./script/plugin install git://github.com/DefV/active_merchant_ogone.git
|
16
|
+
|
17
|
+
=== As a gem
|
18
|
+
|
19
|
+
To install ActiveMerchantOgone in your rails app you can just do:
|
20
|
+
|
21
|
+
config.gem 'simonmenke-active_merchant_ogone', :lib => 'active_merchant_ogone', :source => 'http://gems.github.com'
|
22
|
+
|
23
|
+
== Configuration
|
24
|
+
|
25
|
+
As Ogone works with in and out signatures, you will have to set these as constants in your configuration file.
|
26
|
+
|
27
|
+
OGONE_ACCOUNT = 'account_name'
|
28
|
+
Ogone.setup do |c|
|
29
|
+
c.outbound_signature = '094598439859385938958398494' # Item 3.2 of the technical information
|
30
|
+
c.inbound_signature = '094598439859385938958398494' # Item 4.4 of the technical information
|
31
|
+
end
|
32
|
+
|
33
|
+
== Example Usage
|
34
|
+
|
35
|
+
Once you've configured the Ogone settings you need to set up a leaving page with in your view:
|
36
|
+
|
37
|
+
<% payment_service_for @order.ogone_id, OGONE_ACCOUNT,
|
38
|
+
:amount => @order.price * 100 # needs to be in cents
|
39
|
+
:currency => 'EUR',
|
40
|
+
:service => :ogone do |service| %>
|
41
|
+
|
42
|
+
<% service.redirect :accepturl => checkout_url(@order),
|
43
|
+
:cancelurl => checkout_url(@order),
|
44
|
+
:declineurl => checkout_url(@order),
|
45
|
+
:exceptionurl => checkout_url(@order) %>
|
46
|
+
|
47
|
+
<%= submit_tag "Pay with Ogone!" %>
|
48
|
+
<% end %>
|
49
|
+
|
50
|
+
And in your controller you should have an enter path:
|
51
|
+
|
52
|
+
class CheckoutsController < ApplicationController
|
53
|
+
include ActiveMerchant::Billing::Integrations
|
54
|
+
|
55
|
+
def show
|
56
|
+
@notification = Ogone::Notification.new(request.query_string)
|
57
|
+
|
58
|
+
@order = Order.find_by_ogone_id(@notification.order_id)
|
59
|
+
if @notification.complete?
|
60
|
+
@order.paid!
|
61
|
+
else
|
62
|
+
@order.failed!
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Copyright (c) 2009 Openminds BVBVA, 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 active_merchant_ogone 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 active_merchant_ogone plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'ActiveMerchantOgone'
|
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 = "active_merchant_ogone"
|
29
|
+
gemspec.summary = "A plugin for Ogone support in ActiveRecord."
|
30
|
+
gemspec.description = "A plugin for Ogone support in ActiveRecord. "
|
31
|
+
gemspec.email = "github@defv.be"
|
32
|
+
gemspec.homepage = "http://github.com/DefV/active_merchant_ogone/tree/master"
|
33
|
+
gemspec.authors = ["Jan De Poorter", "Simon Menke"]
|
34
|
+
gemspec.add_dependency 'activemerchant', '>= 1.4.2'
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
38
|
+
end
|
data/VERSION.yml
ADDED
@@ -0,0 +1,58 @@
|
|
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{active_merchant_ogone}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jan De Poorter", "Simon Menke"]
|
12
|
+
s.date = %q{2009-12-15}
|
13
|
+
s.description = %q{A plugin for Ogone support in ActiveRecord. }
|
14
|
+
s.email = %q{github@defv.be}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION.yml",
|
23
|
+
"active_merchant_ogone.gemspec",
|
24
|
+
"init.rb",
|
25
|
+
"lib/active_merchant_ogone.rb",
|
26
|
+
"lib/active_merchant_ogone/helper.rb",
|
27
|
+
"lib/active_merchant_ogone/notification.rb",
|
28
|
+
"test/active_merchant_ogone/helper_test.rb",
|
29
|
+
"test/active_merchant_ogone/notification_test.rb",
|
30
|
+
"test/active_merchant_ogone_test.rb",
|
31
|
+
"test/test_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/DefV/active_merchant_ogone/tree/master}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.5}
|
37
|
+
s.summary = %q{A plugin for Ogone support in ActiveRecord.}
|
38
|
+
s.test_files = [
|
39
|
+
"test/active_merchant_ogone/helper_test.rb",
|
40
|
+
"test/active_merchant_ogone/notification_test.rb",
|
41
|
+
"test/active_merchant_ogone_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
|
+
s.add_runtime_dependency(%q<activemerchant>, [">= 1.4.2"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<activemerchant>, [">= 1.4.2"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<activemerchant>, [">= 1.4.2"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_merchant_ogone'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
module Integrations #:nodoc:
|
4
|
+
module Ogone
|
5
|
+
class Helper < ActiveMerchant::Billing::Integrations::Helper
|
6
|
+
|
7
|
+
# required
|
8
|
+
mapping :order, 'orderID'
|
9
|
+
mapping :account, 'PSPID'
|
10
|
+
mapping :amount, 'amount'
|
11
|
+
mapping :currency, 'currency'
|
12
|
+
|
13
|
+
# optional - TODO
|
14
|
+
mapping :billing_address, :city => 'ownertown',
|
15
|
+
:address1 => 'owneraddress',
|
16
|
+
:zip => 'ownerZIP',
|
17
|
+
:country => 'ownercty'
|
18
|
+
|
19
|
+
# mapping :description, 'COM'
|
20
|
+
# mapping :tax, ''
|
21
|
+
# mapping :shipping, ''
|
22
|
+
|
23
|
+
# redirection
|
24
|
+
mapping :redirect, :accepturl => 'accepturl',
|
25
|
+
:declineurl => 'declineurl',
|
26
|
+
:cancelurl => 'cancelurl',
|
27
|
+
:exceptionurl => 'exceptionurl'
|
28
|
+
|
29
|
+
def customer(mapping = {})
|
30
|
+
add_field('ownertelno', mapping[:phone])
|
31
|
+
add_field('EMAIL', mapping[:email])
|
32
|
+
add_field('CN', "#{mapping[:first_name]} #{mapping[:last_name]}")
|
33
|
+
end
|
34
|
+
|
35
|
+
# return the fields
|
36
|
+
def form_fields
|
37
|
+
add_field('SHASign', outbound_message_signature)
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def outbound_message_signature
|
44
|
+
Ogone.outbound_message_signature(@fields)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
module Integrations #:nodoc:
|
6
|
+
module Ogone
|
7
|
+
class Notification < ActiveMerchant::Billing::Integrations::Notification
|
8
|
+
|
9
|
+
# params on a successfull payment
|
10
|
+
# orderID=order_342
|
11
|
+
# currency=EUR
|
12
|
+
# amount=50
|
13
|
+
# PM=CreditCard
|
14
|
+
# ACCEPTANCE=test123
|
15
|
+
# STATUS=9
|
16
|
+
# CARDNO=XXXXXXXXXXXX1111
|
17
|
+
# PAYID=2396925
|
18
|
+
# NCERROR=0
|
19
|
+
# BRAND=VISA
|
20
|
+
# IPCTY=BE
|
21
|
+
# CCCTY=US
|
22
|
+
# ECI=7
|
23
|
+
# CVCCheck=NO
|
24
|
+
# AAVCheck=NO
|
25
|
+
# VC=NO
|
26
|
+
# SHASIGN=FE220C6F4492165533488E35F47F231D6BC357FC
|
27
|
+
# IP=82.146.99.233
|
28
|
+
|
29
|
+
STATUS_MAPPING = {
|
30
|
+
0 => 'Incomplete or invalid',
|
31
|
+
1 => 'Cancelled by client',
|
32
|
+
2 => 'Authorization refused',
|
33
|
+
4 => 'Order stored',
|
34
|
+
41 => 'Waiting client payment',
|
35
|
+
5 => 'Authorized',
|
36
|
+
51 => 'Authorization waiting',
|
37
|
+
52 => 'Authorization not known',
|
38
|
+
55 => 'Stand-by',
|
39
|
+
59 => 'Authoriz. to get manually',
|
40
|
+
6 => 'Authorized and cancelled',
|
41
|
+
61 => 'Author. deletion waiting',
|
42
|
+
62 => 'Author. deletion uncertain',
|
43
|
+
63 => 'Author. deletion refused',
|
44
|
+
64 => 'Authorized and cancelled',
|
45
|
+
7 => 'Payment deleted',
|
46
|
+
71 => 'Payment deletion pending',
|
47
|
+
72 => 'Payment deletion uncertain',
|
48
|
+
73 => 'Payment deletion refused',
|
49
|
+
74 => 'Payment deleted',
|
50
|
+
75 => 'Deletion processed by merchant',
|
51
|
+
8 => 'Refund',
|
52
|
+
81 => 'Refund pending',
|
53
|
+
82 => 'Refund uncertain',
|
54
|
+
83 => 'Refund refused',
|
55
|
+
84 => 'Payment declined by the acquirer',
|
56
|
+
85 => 'Refund processed by merchant',
|
57
|
+
9 => 'Payment requested',
|
58
|
+
91 => 'Payment processing',
|
59
|
+
92 => 'Payment uncertain',
|
60
|
+
93 => 'Payment refused',
|
61
|
+
94 => 'Refund declined by the acquirer',
|
62
|
+
95 => 'Payment processed by merchant',
|
63
|
+
99 => 'Being processed'
|
64
|
+
}
|
65
|
+
|
66
|
+
OK_STATUSSES = [4,5,9]
|
67
|
+
|
68
|
+
def initialize(post, options={})
|
69
|
+
super
|
70
|
+
|
71
|
+
unless params['STATUS'].match(/^\d+$/)
|
72
|
+
raise OgoneError, "Faulty Ogone result: '#{params['STATUS']}'"
|
73
|
+
end
|
74
|
+
|
75
|
+
sign = Ogone::inbound_message_signature(params, options[:signature])
|
76
|
+
unless params['SHASIGN'] == sign
|
77
|
+
raise OgoneError, "Faulty Ogone SHA1 signature: '#{params['SHASIGN']}' != '#{sign}'"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def status
|
82
|
+
OK_STATUSSES.include?(params['STATUS'].to_i) ? 'Completed' : 'Failed'
|
83
|
+
end
|
84
|
+
|
85
|
+
def status_message # needed?
|
86
|
+
STATUS_MAPPING[params['STATUS'].to_i]
|
87
|
+
end
|
88
|
+
|
89
|
+
def gross
|
90
|
+
params['amount'].to_f
|
91
|
+
end
|
92
|
+
|
93
|
+
def complete?
|
94
|
+
status == 'Completed'
|
95
|
+
end
|
96
|
+
|
97
|
+
def payment_method
|
98
|
+
params['PM']
|
99
|
+
end
|
100
|
+
|
101
|
+
def order_id
|
102
|
+
params['orderID']
|
103
|
+
end
|
104
|
+
|
105
|
+
def transaction_id
|
106
|
+
params['PAYID']
|
107
|
+
end
|
108
|
+
|
109
|
+
def brand
|
110
|
+
params['BRAND']
|
111
|
+
end
|
112
|
+
|
113
|
+
def currency
|
114
|
+
params['currency']
|
115
|
+
end
|
116
|
+
|
117
|
+
def acknowledge
|
118
|
+
true
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Ogone Integration developed by Openminds (www.openminds.be)
|
2
|
+
# For problems contact us at ogone@openminds.be
|
3
|
+
require 'active_merchant'
|
4
|
+
require 'active_merchant_ogone/helper.rb'
|
5
|
+
require 'active_merchant_ogone/notification.rb'
|
6
|
+
|
7
|
+
module ActiveMerchant #:nodoc:
|
8
|
+
module Billing #:nodoc:
|
9
|
+
module Integrations #:nodoc:
|
10
|
+
module Ogone
|
11
|
+
|
12
|
+
mattr_accessor :inbound_signature
|
13
|
+
mattr_accessor :outbound_signature
|
14
|
+
|
15
|
+
mattr_accessor :test_service_url
|
16
|
+
mattr_accessor :live_service_url
|
17
|
+
|
18
|
+
self.test_service_url = 'https://secure.ogone.com/ncol/test/orderstandard.asp'
|
19
|
+
self.live_service_url = 'https://secure.ogone.com/ncol/prod/orderstandard.asp'
|
20
|
+
|
21
|
+
def self.setup
|
22
|
+
yield(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.service_url
|
26
|
+
mode = ActiveMerchant::Billing::Base.integration_mode
|
27
|
+
case mode
|
28
|
+
when :production then self.live_service_url
|
29
|
+
when :test then self.test_service_url
|
30
|
+
else
|
31
|
+
raise StandardError, "Integration mode set to an invalid value: #{mode}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.notification(post, options={})
|
36
|
+
Notification.new(post, options={})
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.outbound_message_signature(fields, signature=nil)
|
40
|
+
signature ||= self.outbound_signature
|
41
|
+
keys = %w( orderID amount currency PSPID )
|
42
|
+
datastring = keys.collect{|key| fields[key]}.join('')
|
43
|
+
Digest::SHA1.hexdigest("#{datastring}#{signature}").upcase
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.inbound_message_signature(fields, signature=nil)
|
47
|
+
signature ||= self.inbound_signature
|
48
|
+
keys = %w( orderID currency amount PM ACCEPTANCE STATUS CARDNO PAYID NCERROR BRAND )
|
49
|
+
datastring = keys.collect{|key| fields[key]}.join('')
|
50
|
+
Digest::SHA1.hexdigest("#{datastring}#{signature}").upcase
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class OgoneError < ActiveMerchantError; end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OgoneHelperTest < Test::Unit::TestCase
|
4
|
+
include ActiveMerchant::Billing::Integrations
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@helper = Ogone::Helper.new('order-500','openminds', :amount => 900, :currency => 'EUR')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_basic_helper_fields
|
11
|
+
assert_field 'PSPID', 'openminds'
|
12
|
+
|
13
|
+
assert_field 'orderID', 'order-500'
|
14
|
+
assert_field 'amount', '900'
|
15
|
+
assert_field 'currency', 'EUR'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_customer_fields
|
19
|
+
@helper.customer :first_name => 'Jan', :last_name => 'De Poorter', :email => 'ogone@openminds.be'
|
20
|
+
assert_field 'CN', 'Jan De Poorter'
|
21
|
+
assert_field 'EMAIL', 'ogone@openminds.be'
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_address_mapping
|
25
|
+
@helper.billing_address :address1 => 'Zilverenberg 39',
|
26
|
+
:address2 => '',
|
27
|
+
:city => 'Ghent',
|
28
|
+
:zip => '9000',
|
29
|
+
:country => 'BE'
|
30
|
+
|
31
|
+
assert_field 'owneraddress', 'Zilverenberg 39'
|
32
|
+
assert_field 'ownertown', 'Ghent'
|
33
|
+
assert_field 'ownerZIP', '9000'
|
34
|
+
assert_field 'ownercty', 'BE'
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_unknown_mapping
|
38
|
+
assert_nothing_raised do
|
39
|
+
@helper.company_address :address => 'Zilverenberg 39'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_setting_invalid_address_field
|
44
|
+
fields = @helper.fields.dup
|
45
|
+
@helper.billing_address :street => 'Zilverenberg'
|
46
|
+
assert_equal fields, @helper.fields
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OgoneNotificationTest < Test::Unit::TestCase
|
4
|
+
include ActiveMerchant::Billing::Integrations
|
5
|
+
|
6
|
+
Ogone.inbound_signature = '08445a31a78661b5c746feff39a9db6e4e2cc5cf'
|
7
|
+
|
8
|
+
SUCCESSFULL_HTTP_RAW_DATA = "orderID=order_342¤cy=EUR&amount=50&PM=CreditCard&ACCEPTANCE=test123&STATUS=9&CARDNO=XXXXXXXXXXXX1111&PAYID=2396925&NCERROR=0&BRAND=VISA&IPCTY=BE&CCCTY=US&ECI=7&CVCCheck=NO&AAVCheck=NO&VC=NO&SHASIGN=FE220C6F4492165533488E35F47F231D6BC357FC&IP=82.146.99.233"
|
9
|
+
|
10
|
+
FAULTY_HTTP_RAW_DATA = "orderID=order_342¤cy=EUR&amount=50&PM=CreditCard&ACCEPTANCE=test123&STATUS=abc&CARDNO=XXXXXXXXXXXX1111&PAYID=2396925&NCERROR=0&BRAND=VISA&IPCTY=BE&CCCTY=US&ECI=7&CVCCheck=NO&AAVCheck=NO&VC=NO&SHASIGN=FE220C6F4492165533488E35F47F231D6BC357FC&IP=82.146.99.233"
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@ogone = Ogone::Notification.new(SUCCESSFULL_HTTP_RAW_DATA)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_accessors
|
17
|
+
assert @ogone.complete?
|
18
|
+
assert_equal "Completed", @ogone.status
|
19
|
+
assert_equal "2396925", @ogone.transaction_id
|
20
|
+
assert_equal 50.0, @ogone.gross
|
21
|
+
assert_equal "EUR", @ogone.currency
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_status_completed
|
25
|
+
assert_equal "Completed", @ogone.status
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_compositions
|
29
|
+
assert_equal Money.new(5000, 'EUR'), @ogone.amount
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_invalid_status_should_raise_an_error
|
33
|
+
assert_raise(ActiveMerchant::OgoneError) do
|
34
|
+
Ogone::Notification.new(FAULTY_HTTP_RAW_DATA)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActiveMerchantOgoneTest < Test::Unit::TestCase
|
4
|
+
include ActiveMerchant::Billing::Integrations
|
5
|
+
|
6
|
+
def test_sha1_signature_out
|
7
|
+
# input values and return value taken from BASIC documentation
|
8
|
+
data = {'orderID' => '1234',
|
9
|
+
'currency' => 'EUR',
|
10
|
+
'amount' => 1500,
|
11
|
+
'PSPID' => 'MyPSPID' }
|
12
|
+
|
13
|
+
signature = 'Mysecretsig'
|
14
|
+
|
15
|
+
assert_equal 'CC88E974F684C0804FD98BEA2FE403E9D11534BB',
|
16
|
+
Ogone.outbound_message_signature(data, signature)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_sha1_signature_in
|
20
|
+
# input values and return value taken from BASIC documentation
|
21
|
+
data = {'orderID' => '12',
|
22
|
+
'currency' => 'EUR',
|
23
|
+
'amount' => '15',
|
24
|
+
'PM' => 'CreditCard',
|
25
|
+
'ACCEPTANCE' => '1234',
|
26
|
+
'STATUS' => '9',
|
27
|
+
'CARDNO' => 'xxxxxxxxxxxx1111',
|
28
|
+
'PAYID' => '32100123',
|
29
|
+
'NCERROR' => '0',
|
30
|
+
'BRAND' => 'VISA'}
|
31
|
+
|
32
|
+
signature = 'Mysecretsig'
|
33
|
+
|
34
|
+
assert_equal '6DDD8C4538ACD0462837DB66F5EAB39C58086A29',
|
35
|
+
Ogone.inbound_message_signature(data, signature)
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'active_merchant'
|
6
|
+
require 'money'
|
7
|
+
require 'test/unit'
|
8
|
+
require 'mocha'
|
9
|
+
require 'yaml'
|
10
|
+
|
11
|
+
begin
|
12
|
+
gem 'actionpack'
|
13
|
+
rescue LoadError
|
14
|
+
raise StandardError, "The view tests need ActionPack installed as gem to run"
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'action_controller'
|
18
|
+
require 'action_controller/test_process'
|
19
|
+
require 'active_merchant/billing/integrations/action_view_helper'
|
20
|
+
|
21
|
+
require 'active_merchant_ogone'
|
22
|
+
|
23
|
+
ActiveMerchant::Billing::Base.mode = :test
|
24
|
+
|
25
|
+
# Test gateways
|
26
|
+
class SimpleTestGateway < ActiveMerchant::Billing::Gateway
|
27
|
+
end
|
28
|
+
|
29
|
+
class SubclassGateway < SimpleTestGateway
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
module ActiveMerchant
|
34
|
+
module Assertions
|
35
|
+
def assert_field(field, value)
|
36
|
+
clean_backtrace do
|
37
|
+
assert_equal value, @helper.fields[field]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Allows the testing of you to check for negative assertions:
|
42
|
+
#
|
43
|
+
# # Instead of
|
44
|
+
# assert !something_that_is_false
|
45
|
+
#
|
46
|
+
# # Do this
|
47
|
+
# assert_false something_that_should_be_false
|
48
|
+
#
|
49
|
+
# An optional +msg+ parameter is available to help you debug.
|
50
|
+
def assert_false(boolean, message = nil)
|
51
|
+
message = build_message message, '<?> is not false or nil.', boolean
|
52
|
+
|
53
|
+
clean_backtrace do
|
54
|
+
assert_block message do
|
55
|
+
not boolean
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# A handy little assertion to check for a successful response:
|
61
|
+
#
|
62
|
+
# # Instead of
|
63
|
+
# assert_success response
|
64
|
+
#
|
65
|
+
# # DRY that up with
|
66
|
+
# assert_success response
|
67
|
+
#
|
68
|
+
# A message will automatically show the inspection of the response
|
69
|
+
# object if things go afoul.
|
70
|
+
def assert_success(response)
|
71
|
+
clean_backtrace do
|
72
|
+
assert response.success?, "Response failed: #{response.inspect}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# The negative of +assert_success+
|
77
|
+
def assert_failure(response)
|
78
|
+
clean_backtrace do
|
79
|
+
assert_false response.success?, "Response expected to fail: #{response.inspect}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def assert_valid(validateable)
|
84
|
+
clean_backtrace do
|
85
|
+
assert validateable.valid?, "Expected to be valid"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def assert_not_valid(validateable)
|
90
|
+
clean_backtrace do
|
91
|
+
assert_false validateable.valid?, "Expected to not be valid"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
def clean_backtrace(&block)
|
97
|
+
yield
|
98
|
+
rescue Test::Unit::AssertionFailedError => e
|
99
|
+
path = File.expand_path(__FILE__)
|
100
|
+
raise Test::Unit::AssertionFailedError, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
module Fixtures
|
105
|
+
HOME_DIR = RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'] unless defined?(HOME_DIR)
|
106
|
+
LOCAL_CREDENTIALS = File.join(HOME_DIR.to_s, '.active_merchant/fixtures.yml') unless defined?(LOCAL_CREDENTIALS)
|
107
|
+
DEFAULT_CREDENTIALS = File.join(File.dirname(__FILE__), 'fixtures.yml') unless defined?(DEFAULT_CREDENTIALS)
|
108
|
+
|
109
|
+
private
|
110
|
+
def credit_card(number = '4242424242424242', options = {})
|
111
|
+
defaults = {
|
112
|
+
:number => number,
|
113
|
+
:month => 9,
|
114
|
+
:year => Time.now.year + 1,
|
115
|
+
:first_name => 'Longbob',
|
116
|
+
:last_name => 'Longsen',
|
117
|
+
:verification_value => '123',
|
118
|
+
:type => 'visa'
|
119
|
+
}.update(options)
|
120
|
+
|
121
|
+
Billing::CreditCard.new(defaults)
|
122
|
+
end
|
123
|
+
|
124
|
+
def check(options = {})
|
125
|
+
defaults = {
|
126
|
+
:name => 'Jim Smith',
|
127
|
+
:routing_number => '244183602',
|
128
|
+
:account_number => '15378535',
|
129
|
+
:account_holder_type => 'personal',
|
130
|
+
:account_type => 'checking',
|
131
|
+
:number => '1'
|
132
|
+
}.update(options)
|
133
|
+
|
134
|
+
Billing::Check.new(defaults)
|
135
|
+
end
|
136
|
+
|
137
|
+
def address(options = {})
|
138
|
+
{
|
139
|
+
:name => 'Jim Smith',
|
140
|
+
:address1 => '1234 My Street',
|
141
|
+
:address2 => 'Apt 1',
|
142
|
+
:company => 'Widgets Inc',
|
143
|
+
:city => 'Ottawa',
|
144
|
+
:state => 'ON',
|
145
|
+
:zip => 'K1C2N6',
|
146
|
+
:country => 'CA',
|
147
|
+
:phone => '(555)555-5555',
|
148
|
+
:fax => '(555)555-6666'
|
149
|
+
}.update(options)
|
150
|
+
end
|
151
|
+
|
152
|
+
def all_fixtures
|
153
|
+
@@fixtures ||= load_fixtures
|
154
|
+
end
|
155
|
+
|
156
|
+
def fixtures(key)
|
157
|
+
data = all_fixtures[key] || raise(StandardError, "No fixture data was found for '#{key}'")
|
158
|
+
|
159
|
+
data.dup
|
160
|
+
end
|
161
|
+
|
162
|
+
def load_fixtures
|
163
|
+
file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS
|
164
|
+
yaml_data = YAML.load(File.read(file))
|
165
|
+
symbolize_keys(yaml_data)
|
166
|
+
|
167
|
+
yaml_data
|
168
|
+
end
|
169
|
+
|
170
|
+
def symbolize_keys(hash)
|
171
|
+
return unless hash.is_a?(Hash)
|
172
|
+
|
173
|
+
hash.symbolize_keys!
|
174
|
+
hash.each{|k,v| symbolize_keys(v)}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
Test::Unit::TestCase.class_eval do
|
180
|
+
include ActiveMerchant::Billing
|
181
|
+
include ActiveMerchant::Assertions
|
182
|
+
include ActiveMerchant::Utils
|
183
|
+
include ActiveMerchant::Fixtures
|
184
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_merchant_ogone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan De Poorter
|
8
|
+
- Simon Menke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-12-15 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: activemerchant
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.4.2
|
25
|
+
version:
|
26
|
+
description: "A plugin for Ogone support in ActiveRecord. "
|
27
|
+
email: github@defv.be
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- VERSION.yml
|
39
|
+
- active_merchant_ogone.gemspec
|
40
|
+
- init.rb
|
41
|
+
- lib/active_merchant_ogone.rb
|
42
|
+
- lib/active_merchant_ogone/helper.rb
|
43
|
+
- lib/active_merchant_ogone/notification.rb
|
44
|
+
- test/active_merchant_ogone/helper_test.rb
|
45
|
+
- test/active_merchant_ogone/notification_test.rb
|
46
|
+
- test/active_merchant_ogone_test.rb
|
47
|
+
- test/test_helper.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/DefV/active_merchant_ogone/tree/master
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: A plugin for Ogone support in ActiveRecord.
|
76
|
+
test_files:
|
77
|
+
- test/active_merchant_ogone/helper_test.rb
|
78
|
+
- test/active_merchant_ogone/notification_test.rb
|
79
|
+
- test/active_merchant_ogone_test.rb
|
80
|
+
- test/test_helper.rb
|