ogone2 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e717a4abda71a6b0ffec65d7182a7ad909b8282d3a63dfcdc3688cb0eb244d37
4
+ data.tar.gz: cc87467cd9bf6d9acf489cf3c0916abc3b99d035fa31a45c741d4cd65802cae0
5
+ SHA512:
6
+ metadata.gz: 6522478e1a9efacc41e18614673a6f5928239490fa53eeec78cda0a65382551933bab63b241e47a4bea59f7b5a00ebb01d9ef0acc30b2de56113933dad8a3489
7
+ data.tar.gz: 0ff1a0c670204006c1be046e517da11ff0707f16cd405aa46212e450856ca3a7cc8567477e9d5758ff56c0e6c1df266f39d1b7fb2adcf3bd24a01845f9cb19ff
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Metrics/BlockLength:
4
+ CountComments: false
5
+ Max: 25
6
+ Exclude:
7
+ - 'Rakefile'
8
+ - 'spec/**/*.rb'
9
+ Documentation:
10
+ Enabled: false
11
+ Style/Lambda:
12
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ogone.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2013 Applidget
2
+ Copyright (c) 2013 Sébastien Saunier
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # Ogone
2
+
3
+ This gem helps you to quickly get a `form` that can be submitted and redirect
4
+ your users to the ogone ecommerce form where they can pay. This gem is flexible
5
+ as it does not rely on a hard-coded configuration to be used. Therefore you can
6
+ dynamically handle several PSPIDs.
7
+
8
+ You can also use Flexcheckout combined with direct order (see Flexcheckout and direct order).
9
+
10
+ ## Usage
11
+
12
+ In your controller,
13
+
14
+ ```ruby
15
+ require "ogone"
16
+
17
+ class PaymentController
18
+ def ogone_form
19
+ @ogone = Ogone::Ecommerce.new :pspid => "your_pspid",
20
+ :environment => "prod",
21
+ :sha_algo => "SHA1", # Configured in your back-office
22
+ :sha_in => "......", # Configured in your back-office
23
+ :sha_out => "....." # Configured in your back-office
24
+
25
+ # Add mandatory parameters. Alternatively can be passed directly in `@ogone.fields_for_payment`
26
+ @ogone.add_parameters(
27
+ :CURRENCY => "EUR",
28
+ :AMOUNT => 2000, # Beware, that would be 20 EUR
29
+ :ORDERID => "...",
30
+ :LANGUAGE => "en_US"
31
+ # And many more parameters, refer to the Ogone documentation
32
+ )
33
+
34
+ # Configure where the user should be redirected once the payment is completed
35
+ # This sets the following urls:
36
+ # - ACCEPTURL
37
+ # - DECLINEURL
38
+ # - EXCEPTIONURL
39
+ # - CANCELURL
40
+ @ogone.add_single_return_url "http://your_application/route/to/ogone/return"
41
+ end
42
+ end
43
+ ```
44
+
45
+ Then in your view, you can quickly get the form up and running:
46
+
47
+ ```erb
48
+ <%# ogone_form.html.erb %>
49
+
50
+ <%= form_tag @ogone.form_action, :method => :post %>
51
+ <% @ogone.fields_for_payment.each do |name, value| %>
52
+ <%= hidden_field_tag name, value %>
53
+ <% end %>
54
+
55
+ <%= submit_tag "Pay" %>
56
+ <% end %>
57
+ ```
58
+
59
+ When clicking on the `Pay` button, your user will be redirected to the Ogone
60
+ Ecommerce platform to enter his/her credit card info and pay. When the payment
61
+ is completed, the user will be redirected to your application.
62
+
63
+ This will be done via a `POST` request from Ogone to your app. This request contains
64
+ parameters that Ogone gives to you so that you can update your own database. Before
65
+ doing anything, you should check that the request signature is correct to make sure
66
+ it comes from Ogone. To do so, just call:
67
+
68
+ ```ruby
69
+ require "ogone"
70
+
71
+ class PaymentController
72
+ def ogone_return
73
+ @ogone = Ogone::Ecommerce.new :sha_algo => "SHA1", :sha_out => "...."
74
+
75
+ begin
76
+ @ogone.check_shasign_out! params
77
+
78
+ status = params[:STATUS].to_i
79
+ if Ogone::PAID_STATUSES.include? status
80
+ # TODO: update database with payment info.
81
+ end
82
+ rescue Ogone::Ecommerce::OutboundSignatureMismatch
83
+ # The request did not come from Ogone, or there is a misconfiguration of sha_out.
84
+ end
85
+ end
86
+ end
87
+ ```
88
+
89
+ ## Flexcheckout and direct order
90
+
91
+ ```ruby
92
+ @ogone = Ogone::Flexcheckout.new opts # same options than Ogone::Ecommerce
93
+
94
+ @ogone.add_parameters(
95
+ 'CARD.PAYMENTMETHOD' => 'CreditCard',
96
+ 'PARAMETERS.ACCEPTURL' => 'http://my_app/ogone_flexcheckout_success',
97
+ 'PARAMETERS.EXCEPTIONURL' => 'http://my_app/ogone_flexcheckout_failure',
98
+ 'LANGUAGE' => 'en_US',
99
+ )
100
+
101
+ @ogone.form_url # this is the URL with the Flexcheckout form, you shoudl redirect_to it
102
+ ```
103
+
104
+ Once you fill the form, Ogone will redirect to the `ACCEPTURL` or `EXCEPTIONURL`. If you go to the `ACCEPTURL`,
105
+ you can proceed with the order :
106
+
107
+ ```ruby
108
+ # first ensure sha_out matches
109
+ @ogone = Ogone::Flexcheckout.new opts # same options than Ogone::Ecommerce
110
+ @ogone.check_shasign_out!(params)
111
+
112
+ # ok sha_out matches proceed to the order
113
+ @ogone = Ogone::OrderDirect.new opts # same options than Ogone::Ecommerce
114
+
115
+ @ogone.add_parameters(
116
+ 'ORDERID' => params['Alias.OrderId'],
117
+ 'AMOUNT' => 10 * 100,
118
+ 'CURRENCY' => 'EUR',
119
+ 'ALIAS' => params['Alias.AliasId'], # comes from the HTTP params set in the flexcheckout redirect
120
+ 'USERID' => 'my_api_user', # you need to have an API user https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/directlink
121
+ 'PSWD' => 'super_secret@',
122
+ 'OPERATION' => 'RES'
123
+ # extra parameters may be set for 3D Secure : https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/directlink-3-d/3-d-transaction-flow-via-directlink#comments
124
+ )
125
+
126
+ result = @ogone.perform_order
127
+
128
+ # handle result
129
+ ```
130
+
131
+ ## Contributing
132
+
133
+ 1. Fork it
134
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
135
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
136
+ 4. Push to the branch (`git push origin my-new-feature`)
137
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/ogone.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'ogone/version'
2
+ require 'ogone/status'
3
+ require 'ogone/ecommerce'
4
+ require 'ogone/flexcheckout'
5
+ require 'ogone/order_direct'
data/lib/ogone/base.rb ADDED
@@ -0,0 +1,98 @@
1
+ require 'digest'
2
+
3
+ module Ogone
4
+ class Base
5
+ VALID_ENVIRONMENTS = %w[test prod].freeze unless const_defined? :VALID_ENVIRONMENTS
6
+ SIGNING_ALGORITHMS = %w[SHA1 SHA256 SHA512].freeze unless const_defined? :SIGNING_ALGORITHMS
7
+
8
+ class ConfigurationError < StandardError; end
9
+ class MandatoryParameterMissing < StandardError; end
10
+ class OutboundSignatureMismatch < StandardError; end
11
+
12
+ attr_accessor :sha_in, :sha_out
13
+
14
+ def initialize(options = {})
15
+ @parameters = {}
16
+ %i[sha_algo environment pspid sha_in sha_out].each do |config|
17
+ send :"#{config}=", options[config] unless options[config].nil?
18
+ end
19
+ end
20
+
21
+ def sha_algo=(sha_algo)
22
+ raise ArgumentError, "Unsupported signature algorithm: #{sha_algo}" unless SIGNING_ALGORITHMS.include?(sha_algo)
23
+ @sha_algo = sha_algo
24
+ end
25
+
26
+ def environment=(environment)
27
+ unless VALID_ENVIRONMENTS.include? environment.to_s
28
+ raise ArgumentError, "Unsupported Ogone environment: #{environment}"
29
+ end
30
+ @environment = environment
31
+ end
32
+
33
+ def pspid=(pspid)
34
+ raise ArgumentError, 'PSPID cannot be empty' if pspid.nil? || pspid == ''
35
+ @pspid = pspid
36
+ end
37
+
38
+ def add_parameters(parameters)
39
+ @parameters.merge! parameters
40
+ end
41
+
42
+ def fields_for_payment(parameters = {}, shasign_key = 'SHASIGN')
43
+ add_parameters(parameters || {})
44
+ check_mandatory_parameters!
45
+
46
+ upcase_keys(@parameters).merge(shasign_key.to_sym => sha_in_sign)
47
+ end
48
+
49
+ def check_shasign_out!(params)
50
+ params = upcase_keys(params)
51
+ raise OutboundSignatureMismatch if sha_out_sign(params) != params[:SHASIGN]
52
+ end
53
+
54
+ def upcase_keys(hash)
55
+ hash.each_with_object({}) { |(k, v), h| h[k.upcase.to_sym] = v; }
56
+ end
57
+
58
+ protected
59
+
60
+ def ogone_host
61
+ @environment == 'test' ? 'ogone.test.v-psp.com' : 'secure.ogone.com'
62
+ end
63
+
64
+ private
65
+
66
+ def sha_in_sign
67
+ to_hash = sorted_upcased_parameters.each_with_object([]) do |(k, v), a|
68
+ a << "#{k}=#{v}#{@sha_in}" unless v.nil? || v == ''
69
+ end.join
70
+ sign to_hash
71
+ end
72
+
73
+ def sha_out_sign(params)
74
+ to_hash = self.class.const_get('OUTBOUND_SIGNATURE_PARAMETERS').each_with_object([]) do |p, a|
75
+ a << "#{p}=#{params[p]}#{@sha_out}" unless params[p].nil? || params[p] == ''
76
+ end.join
77
+ sign to_hash
78
+ end
79
+
80
+ def sign(to_hash)
81
+ unless SIGNING_ALGORITHMS.include?(@sha_algo)
82
+ raise ArgumentError, "Unsupported signature algorithm: '#{@sha_algo}'"
83
+ end
84
+ Digest.const_get(@sha_algo).hexdigest(to_hash).upcase
85
+ end
86
+
87
+ def sorted_upcased_parameters
88
+ upcase_keys(@parameters).sort
89
+ end
90
+
91
+ def check_mandatory_parameters!
92
+ keys = @parameters.keys.map(&:to_sym)
93
+ self.class.const_get('MANDATORY_PARAMETERS').each do |parameter|
94
+ raise MandatoryParameterMissing, parameter unless keys.include? parameter.to_sym
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,75 @@
1
+ require 'ogone/base'
2
+
3
+ module Ogone
4
+ class Ecommerce < Base
5
+ MANDATORY_PARAMETERS = %w[PSPID ORDERID AMOUNT CURRENCY LANGUAGE].freeze
6
+
7
+ OUTBOUND_SIGNATURE_PARAMETERS = %i[
8
+ AAVADDRESS
9
+ AAVCHECK
10
+ AAVZIP
11
+ ACCEPTANCE
12
+ ALIAS
13
+ AMOUNT
14
+ BIN
15
+ BRAND
16
+ CARDNO
17
+ CCCTY
18
+ CN
19
+ COMPLUS
20
+ CREATION_STATUS
21
+ CURRENCY
22
+ CVCCHECK
23
+ DCC_COMMPERCENTAGE
24
+ DCC_CONVAMOUNT
25
+ DCC_CONVCCY
26
+ DCC_EXCHRATE
27
+ DCC_EXCHRATESOURCE
28
+ DCC_EXCHRATETS
29
+ DCC_INDICATOR
30
+ DCC_MARGINPERCENTAGE
31
+ DCC_VALIDHOURS
32
+ DIGESTCARDNO
33
+ ECI
34
+ ED
35
+ ENCCARDNO
36
+ FXAMOUNT
37
+ FXCURRENCY
38
+ IP
39
+ IPCTY
40
+ NBREMAILUSAGE
41
+ NBRIPUSAGE
42
+ NBRIPUSAGE_ALLTX
43
+ NBRUSAGE
44
+ NCERROR
45
+ ORDERID
46
+ PAYID
47
+ PM
48
+ SCO_CATEGORY
49
+ SCORING
50
+ STATUS
51
+ SUBBRAND
52
+ SUBSCRIPTION_ID
53
+ TRXDATE
54
+ VC
55
+ ].freeze
56
+
57
+ def pspid=(pspid)
58
+ super(pspid)
59
+ @parameters[:PSPID] = pspid
60
+ end
61
+
62
+ def form_action
63
+ unless VALID_ENVIRONMENTS.include? @environment.to_s
64
+ raise ConfigurationError, "Unsupported Ogone environment: '#{@environment}'."
65
+ end
66
+ "https://secure.ogone.com/ncol/#{@environment}/orderstandard_utf8.asp"
67
+ end
68
+
69
+ def add_single_return_url(return_url)
70
+ %i[ACCEPTURL DECLINEURL EXCEPTIONURL CANCELURL].each do |field|
71
+ @parameters[field] = return_url
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,45 @@
1
+ require 'ogone/base'
2
+
3
+ module Ogone
4
+ class Flexcheckout < Base
5
+ MANDATORY_PARAMETERS = %w[
6
+ ACCOUNT.PSPID
7
+ PARAMETERS.ACCEPTURL
8
+ PARAMETERS.EXCEPTIONURL
9
+ CARD.PAYMENTMETHOD
10
+ LANGUAGE
11
+ ].freeze
12
+
13
+ OUTBOUND_SIGNATURE_PARAMETERS = %i[
14
+ ALIAS.ALIASID
15
+ ALIAS.NCERROR
16
+ ALIAS.NCERRORCARDNO
17
+ ALIAS.NCERRORCN
18
+ ALIAS.NCERRORCVC
19
+ ALIAS.NCERRORED
20
+ ALIAS.ORDERID
21
+ ALIAS.STATUS
22
+ ALIAS.STOREPERMANENTLY
23
+ CARD.BIC
24
+ CARD.BIN
25
+ CARD.BRAND
26
+ CARD.CARDHOLDERNAME
27
+ CARD.CARDNUMBER
28
+ CARD.CVC
29
+ CARD.EXPIRYDATE
30
+ ].freeze
31
+
32
+ def pspid=(pspid)
33
+ super(pspid)
34
+ @parameters[:'ACCOUNT.PSPID'] = pspid
35
+ end
36
+
37
+ def fields_for_payment(parameters = {})
38
+ super(parameters, 'SHASIGNATURE.SHASIGN')
39
+ end
40
+
41
+ def form_url
42
+ "https://#{ogone_host}/Tokenization/HostedPage?#{URI.encode_www_form(fields_for_payment)}"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ require 'ogone/base'
2
+
3
+ module Ogone
4
+ class OrderDirect < Base
5
+ MANDATORY_PARAMETERS = %w[
6
+ PSPID
7
+ ORDERID
8
+ AMOUNT
9
+ CURRENCY
10
+ ALIAS
11
+ USERID
12
+ PSWD
13
+ OPERATION
14
+ ].freeze
15
+
16
+ def pspid=(pspid)
17
+ super(pspid)
18
+ @parameters[:PSPID] = pspid
19
+ end
20
+
21
+ def perform_order
22
+ url = "https://#{ogone_host}/ncol/#{@environment}/orderdirect.asp"
23
+ res = HTTParty.get("#{url}?#{URI.encode_www_form(fields_for_payment)}")
24
+ res.body
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ module Ogone
2
+ unless const_defined? :STATUS
3
+ STATUS = {
4
+ 0 => 'Incomplete or invalid',
5
+ 1 => 'Cancelled by client',
6
+ 2 => 'Authorization refused',
7
+ 4 => 'Order stored',
8
+ 41 => 'Waiting client payment',
9
+ 5 => 'Authorized',
10
+ 51 => 'Authorization waiting',
11
+ 52 => 'Authorization not known',
12
+ 55 => 'Stand-by',
13
+ 59 => 'Authoriz. to get manually',
14
+ 6 => 'Authorized and cancelled',
15
+ 61 => 'Author. deletion waiting',
16
+ 62 => 'Author. deletion uncertain',
17
+ 63 => 'Author. deletion refused',
18
+ 64 => 'Authorized and cancelled',
19
+ 7 => 'Payment deleted',
20
+ 71 => 'Payment deletion pending',
21
+ 72 => 'Payment deletion uncertain',
22
+ 73 => 'Payment deletion refused',
23
+ 74 => 'Payment deleted',
24
+ 75 => 'Deletion processed by merchant',
25
+ 8 => 'Refund',
26
+ 81 => 'Refund pending',
27
+ 82 => 'Refund uncertain',
28
+ 83 => 'Refund refused',
29
+ 84 => 'Payment declined by the acquirer',
30
+ 85 => 'Refund processed by merchant',
31
+ 9 => 'Payment requested',
32
+ 91 => 'Payment processing',
33
+ 92 => 'Payment uncertain',
34
+ 93 => 'Payment refused',
35
+ 94 => 'Refund declined by the acquirer',
36
+ 95 => 'Payment processed by merchant',
37
+ 99 => 'Being processed'
38
+ }.freeze
39
+ end
40
+
41
+ PAID_STATUSES = [4, 5, 9].freeze unless const_defined? :PAID_STATUSES
42
+ PENDING_STATUSES = [41, 51, 52, 91, 92, 99].freeze unless const_defined? :PENDING_STATUSES
43
+ CANCELLED_STATUSES = [1].freeze unless const_defined? :CANCELLED_STATUSES
44
+ REFUNDED_STATUSES = [8].freeze unless const_defined? :REFUNDED_STATUSES
45
+ end
@@ -0,0 +1,3 @@
1
+ module Ogone
2
+ VERSION = '0.2.0'.freeze
3
+ end
data/ogone.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ogone/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ogone2'
7
+ spec.version = Ogone::VERSION
8
+ spec.authors = ['Sebastien Saunier']
9
+ spec.email = ['seb@saunier.me']
10
+ spec.description = 'Flexible Ogone ecommerce wrapper
11
+
12
+ Deal simply with multiple ogone ecommerce account within your application.
13
+ No hard coded configuration read from a *.yml file.
14
+ '
15
+ spec.summary = 'Flexible Ogone ecommerce wrapper'
16
+ spec.homepage = 'https://github.com/applidget/ogone'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rubocop'
28
+ spec.add_dependency 'httparty'
29
+ end
@@ -0,0 +1,116 @@
1
+ require 'ogone/ecommerce'
2
+
3
+ module Ogone
4
+ describe Ecommerce do
5
+ before(:each) do
6
+ @ogone = Ogone::Ecommerce.new
7
+ end
8
+
9
+ it 'should raise an error if incorrect sha algorithm given' do
10
+ lambda { @ogone.sha_algo = 'WRONG_SHA' }.should raise_error ArgumentError
11
+ end
12
+
13
+ it 'should raise an error if incorrect ogone environment given' do
14
+ lambda { @ogone.environment = 'WRONG_ENV' }.should raise_error ArgumentError
15
+ end
16
+
17
+ it 'should raise an error if an empty PSPID is specified' do
18
+ lambda { @ogone.pspid = '' }.should raise_error ArgumentError
19
+ end
20
+
21
+ it 'should render the test Ogone url' do
22
+ @ogone.environment = 'test'
23
+ @ogone.form_action.should eq 'https://secure.ogone.com/ncol/test/orderstandard_utf8.asp'
24
+ end
25
+
26
+ it 'should render the production Ogone url' do
27
+ @ogone.environment = 'prod'
28
+ @ogone.form_action.should eq 'https://secure.ogone.com/ncol/prod/orderstandard_utf8.asp'
29
+ end
30
+
31
+ it 'should have the PSPID stored in the parameters' do
32
+ @ogone.pspid = 'pspid'
33
+ parameters[:PSPID].should eq 'pspid'
34
+ end
35
+
36
+ describe '#check_shasign_out!' do
37
+ before(:each) do
38
+ @ogone = Ogone::Ecommerce.new sha_out: 'sha_out', sha_algo: 'SHA1'
39
+ end
40
+
41
+ it 'should check an inbound signature' do
42
+ params = ogone_return_parameters
43
+ lambda { @ogone.check_shasign_out! params }.should_not raise_error Ogone::Ecommerce::OutboundSignatureMismatch
44
+ end
45
+
46
+ it 'should throw an error if the outbound shasign does not match' do
47
+ params = {
48
+ 'amonut' => '160',
49
+ 'SHASIGN' => 'FOO'
50
+ }
51
+ lambda { @ogone.check_shasign_out! params }.should raise_error Ogone::Ecommerce::OutboundSignatureMismatch
52
+ end
53
+ end
54
+
55
+ describe '#fields_for_payment' do
56
+ before(:each) do
57
+ @ogone = Ogone::Ecommerce.new pspid: 'pspid', sha_in: 'sha_in', sha_algo: 'SHA1'
58
+ end
59
+
60
+ it 'should give a hash ready to be used in `hidden_field_tag`' do
61
+ fields = @ogone.fields_for_payment AMOUNT: 100,
62
+ CURRENCY: 'EUR',
63
+ ORDERID: '123',
64
+ LANGUAGE: 'en_US'
65
+
66
+ fields[:SHASIGN].should eq 'AA7CA1F98159D14D0943311092F5435F239B4B36'
67
+ end
68
+
69
+ it 'should also work if parameters were given with #add_parameters' do
70
+ @ogone.add_parameters AMOUNT: 100, CURRENCY: 'EUR', ORDERID: '123', LANGUAGE: 'en_US'
71
+
72
+ fields = @ogone.fields_for_payment
73
+ fields[:SHASIGN].should eq 'AA7CA1F98159D14D0943311092F5435F239B4B36'
74
+ end
75
+ end
76
+
77
+ describe '#add_single_return_url' do
78
+ it 'should allow lazy folks to give just one back url' do
79
+ @ogone.add_single_return_url 'http://iamsola.zy'
80
+ parameters[:ACCEPTURL].should eq 'http://iamsola.zy'
81
+ parameters[:DECLINEURL].should eq 'http://iamsola.zy'
82
+ parameters[:EXCEPTIONURL].should eq 'http://iamsola.zy'
83
+ parameters[:CANCELURL].should eq 'http://iamsola.zy'
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ def parameters
90
+ @ogone.instance_variable_get :@parameters
91
+ end
92
+
93
+ # rubocop:disable Metrics/MethodLength
94
+ def ogone_return_parameters
95
+ {
96
+ 'orderID' => 'r_511b52f7230b430b3f000003_19',
97
+ 'currency' => 'EUR',
98
+ 'amount' => '160',
99
+ 'PM' => 'CreditCard',
100
+ 'ACCEPTANCE' => '',
101
+ 'STATUS' => '1',
102
+ 'CARDNO' => '',
103
+ 'ED' => '',
104
+ 'CN' => 'Sebastien Saunier',
105
+ 'TRXDATE' => '02/13/13',
106
+ 'PAYID' => '19113975',
107
+ 'NCERROR' => '',
108
+ 'BRAND' => '',
109
+ 'COMPLUS' => 'registration_511b52f7230b430b3f000003',
110
+ 'IP' => '80.12.86.33',
111
+ 'SHASIGN' => 'F3F5F963C700F56B69EA36173F5BFB3B28CA25E5'
112
+ }
113
+ end
114
+ # rubocop:enable Metrics/MethodLength
115
+ end
116
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'ogone'
5
+
6
+ # RSpec.configure do |config|
7
+ # end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ogone2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastien Saunier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: "Flexible Ogone ecommerce wrapper\n\nDeal simply with multiple ogone
84
+ ecommerce account within your application.\nNo hard coded configuration read from
85
+ a *.yml file.\n "
86
+ email:
87
+ - seb@saunier.me
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - lib/ogone.rb
100
+ - lib/ogone/base.rb
101
+ - lib/ogone/ecommerce.rb
102
+ - lib/ogone/flexcheckout.rb
103
+ - lib/ogone/order_direct.rb
104
+ - lib/ogone/status.rb
105
+ - lib/ogone/version.rb
106
+ - ogone.gemspec
107
+ - spec/ogone/ecommerce_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: https://github.com/applidget/ogone
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.7.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Flexible Ogone ecommerce wrapper
133
+ test_files:
134
+ - spec/ogone/ecommerce_spec.rb
135
+ - spec/spec_helper.rb