stall-cmcic 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a914e16220b8089b5a56aba8e4b44430125a3fb0
4
+ data.tar.gz: 3b2e4f24fab5f541702dd37bbb8978622717d47f
5
+ SHA512:
6
+ metadata.gz: 1c08e7b74c182a287e5d8307f935cc78a5f789d3563838c9d70caa2f1929a43ca84c5b170a5c64f32534cbcaecf8f10a2e7789dcd4a06b70f95df2fa744b1d8e
7
+ data.tar.gz: f7d7ff2892f5a1bcda448040b05537104c1274882f3d2f6b60cd41b9a02282965a68987e0474aa8cdfc6368003c9c83a9f9bde603fac21819076e9dbd903fccb
@@ -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-cmcic.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,74 @@
1
+ # Stall::Cmcic
2
+
3
+ This gem allows integrating your [Stall](https://github.com/stall-rails/stall)
4
+ e-commerce app with the CM-CIC online payment gateway solution.
5
+
6
+ This gem is just the glue between [Stall](https://github.com/stall-rails/stall)
7
+ and the [cic_payment](https://github.com/Kulgar/cic_payment/) gem.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'stall-cmcic'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install stall-cmcic
24
+
25
+ Then use the install generator to copy the config template file :
26
+
27
+ $ rails generator stall:cmcic: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
+ - `CMCIC_HMAC_KEY`
39
+ - `CMCIC_TPE`
40
+ - `CMCIC_SOCIETE`
41
+
42
+ Restart your server, and you should now be able to use the CM-CIC payment
43
+ gateway in test mode.
44
+
45
+ When you're ready to switch to production, juste set the following environment
46
+ variable :
47
+
48
+ - `CMCIC_PRODUCTION_MODE=true`
49
+
50
+ Just like the other settings, you can change the way it's configured in the
51
+ stall initializer file.
52
+
53
+ ### Automatic response URL
54
+
55
+ You need to provide a payment response URL to your bank which will be :
56
+
57
+ ```text
58
+ <http|http>://<YOUR_DOMAIN>/cmcic/payment/notify
59
+ ```
60
+
61
+ You can find the route with :
62
+
63
+ ```bash
64
+ rake routes | grep payment/notify
65
+ ```
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/stall-rails/stall-cmcic.
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
74
+
@@ -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,17 @@
1
+ %form.payment-gateway-form{ action: request.params.target_url, method: "post" }
2
+ %input#version{ name: "version", type: "hidden", value: request.params.version }
3
+ %input#tpe{ name: "TPE", type: "hidden", value: request.params.tpe }
4
+ %input#date{ name: "date", type: "hidden", value: request.params.date }
5
+ %input#montant{ name: "montant", type: "hidden", value: request.params.montant }
6
+ %input#reference{ name: "reference", type: "hidden", value: request.params.reference }
7
+ %input#mac{ name: "MAC", type: "hidden", value: request.params.hmac_token }
8
+ %input#url-retour{ name: "url_retour", type: "hidden", value: request.params.url_retour }
9
+ %input#url-retour-ok{ name: "url_retour_ok", type: "hidden", value: request.params.url_retour_ok }
10
+ %input#url-retour-err{ name: "url_retour_err", type: "hidden", value: request.params.url_retour_err }
11
+ %input#lgue{ name: "lgue", type: "hidden", value: request.params.lgue }
12
+ %input#societe{ name: "societe", type: "hidden", value: request.params.societe }
13
+ %input#texte-libre{ name: "texte-libre", type: "hidden", value: request.params.texte_libre }
14
+ %input#mail{ name: "mail", type: "hidden", value: request.params.mail }
15
+
16
+ %button.btn.btn-primary{ name: "submit_cic_payment_form", type: "submit" }
17
+ = t('stall.payments.gateway.pay')
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "stall/cmcic"
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,13 @@
1
+ module Stall
2
+ module Cmcic
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,21 @@
1
+ # CM-CIC payment gateway configuration
2
+ # Fill in the informations provided by your CM or CIC provider
3
+ #
4
+ config.payment.cmcic do |cmcic|
5
+ # Hmac key calculated with the js calculator given by CIC
6
+ cmcic.hmac_key = ENV['CMCIC_HMAC_KEY']
7
+ # TPE number
8
+ cmcic.tpe = ENV['CMCIC_TPE']
9
+ # Merchant name
10
+ cmcic.societe = ENV['CMCIC_SOCIETE']
11
+
12
+ # Test or production mode, default to false, changes the payment
13
+ # gateway target URL
14
+ #
15
+ # By default, the test mode is activated in all environments but you just
16
+ # need to add `CMCIC_PRODUCTION_MODE=true` in your environment variables
17
+ # and restart your server to switch to production mode
18
+ #
19
+ cmcic.test_mode = ENV['CMCIC_PRODUCTION_MODE'] == 'true'
20
+ end
21
+
@@ -0,0 +1,16 @@
1
+ require 'cic_payment'
2
+ require 'stall'
3
+
4
+ module Stall
5
+ module Cmcic
6
+ extend ActiveSupport::Autoload
7
+
8
+ autoload :CicPayment
9
+ autoload :Version
10
+ autoload :Utils
11
+ autoload :FakeGatewayPaymentNotification
12
+ end
13
+ end
14
+
15
+ require 'stall/cmcic/gateway'
16
+ require 'stall/cmcic/engine'
@@ -0,0 +1,36 @@
1
+ module Stall
2
+ module Cmcic
3
+ class CicPayment < ::CicPayment
4
+ # Override constructor to avoid loading a YAML file and use gateway's dynamic
5
+ # configuration instead
6
+ #
7
+ def initialize(gateway, parse_urls: false)
8
+ @@tpe = gateway.tpe
9
+ @@version = gateway.version
10
+ @@societe = gateway.societe
11
+ @@hmac_key = gateway.hmac_key
12
+
13
+ # Handle initialization from gateway class and not a gateway instance
14
+ if parse_urls
15
+ @@target_url = gateway.target_url
16
+ @@url_retour = gateway.payment_urls.payment_failure_return_url
17
+ @@url_retour_ok = gateway.payment_urls.payment_success_return_url
18
+ @@url_retour_err = gateway.payment_urls.payment_failure_return_url
19
+ end
20
+ end
21
+
22
+ # Override this method to avoid implicit "EUR" currency appending
23
+ def required_params(payment)
24
+ @settings ||= {}
25
+
26
+ [:montant, :reference].each do |key|
27
+ if (value = payment[key])
28
+ @settings.update(key => value)
29
+ else
30
+ raise "CicPayment error ! Missing required parameter :#{ key }"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ module Stall
2
+ module Cmcic
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,55 @@
1
+ module Stall
2
+ module Cmcic
3
+ class FakeGatewayPaymentNotification < Stall::Payments::FakeGatewayPaymentNotification
4
+ include Stall::Cmcic::Utils
5
+
6
+ delegate :currency, to: :cart
7
+
8
+ def params
9
+ {}.tap do |params|
10
+ params.merge!(options)
11
+ params['MAC'] = bank_mac_key
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def format_date(date)
18
+ date.strftime("%d/%m/%Y_a_%H:%M:%S")
19
+ end
20
+
21
+ def options
22
+ @options ||= {
23
+ 'TPE' => Stall::Cmcic::Gateway.tpe,
24
+ 'date' => format_date(Time.now),
25
+ 'montant' => price_with_currency(cart.total_price),
26
+ 'reference' => transaction_id,
27
+ 'texte-libre' => cart.reference,
28
+ 'code-retour' => "payetest",
29
+ 'cvx' => "oui",
30
+ 'vld' => "1219",
31
+ 'brand' => "na",
32
+ 'status3ds' => "-1",
33
+ 'numauto' => 'xxxx',
34
+ 'motifrefus' => "",
35
+ 'originecb' => "00x",
36
+ 'bincb' => "000001",
37
+ 'hpancb' => "F6FBF44A7EC30941DA2E411AA8A50C77F174B2BB",
38
+ 'ipclient' => "01.01.01.01",
39
+ 'originetr' => "FRA",
40
+ 'veres' => "",
41
+ 'pares' => "",
42
+ 'modepaiement' => "CB"
43
+ }
44
+ end
45
+
46
+ def bank_mac_key
47
+ @bank_mac_key ||= cic_payment.response_mac(options)
48
+ end
49
+
50
+ def cic_payment
51
+ @cic_payment ||= Stall::Cmcic::CicPayment.new(gateway)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,119 @@
1
+ module Stall
2
+ module Cmcic
3
+ class Gateway < Stall::Payments::Gateway
4
+ register :cmcic
5
+
6
+ # Hmac key calculated with the js calculator given by CIC
7
+ class_attribute :hmac_key
8
+ # TPE number
9
+ class_attribute :tpe
10
+ # Merchant name
11
+ class_attribute :societe
12
+
13
+ # Test or production mode, default to false, changes the payment
14
+ # gateway target URL
15
+ class_attribute :test_mode
16
+ self.test_mode = !Rails.env.production?
17
+
18
+ # Remote API version, should not change any time soon ...
19
+ class_attribute :version
20
+ self.version = "3.0"
21
+
22
+ def self.request(cart)
23
+ Request.new(cart)
24
+ end
25
+
26
+ def self.response(request)
27
+ Response.new(request)
28
+ end
29
+
30
+ def self.fake_payment_notification_for(cart)
31
+ Stall::Cmcic::FakeGatewayPaymentNotification.new(cart)
32
+ end
33
+
34
+ def target_url
35
+ if test_mode
36
+ "https://paiement.creditmutuel.fr/test/paiement.cgi"
37
+ else
38
+ "https://paiement.creditmutuel.fr/paiement.cgi"
39
+ end
40
+ end
41
+
42
+ class Request
43
+ include Stall::Cmcic::Utils
44
+
45
+ attr_reader :cart
46
+
47
+ delegate :currency, to: :cart, allow_nil: true
48
+
49
+ def initialize(cart)
50
+ @cart = cart
51
+ end
52
+
53
+ def payment_form_partial_path
54
+ 'stall/cmcic/payment_form'
55
+ end
56
+
57
+ def params
58
+ @params ||= Stall::Cmcic::CicPayment.new(gateway, parse_urls: true).request(
59
+ montant: price_with_currency(cart.total_price),
60
+ reference: gateway.transaction_id,
61
+ texte_libre: cart.reference
62
+ )
63
+ end
64
+
65
+ def gateway
66
+ @gateway = Stall::Cmcic::Gateway.new(cart)
67
+ end
68
+ end
69
+
70
+ class Response
71
+ attr_reader :request
72
+
73
+ def initialize(request)
74
+ @request = request
75
+ end
76
+
77
+ def valid?
78
+ response.length > 1
79
+ end
80
+
81
+ def success?
82
+ response[:success]
83
+ end
84
+
85
+ def process
86
+ valid? && success?
87
+ end
88
+
89
+ def rendering_options
90
+ { text: "version=2\ncdr=#{ return_code }\n" }
91
+ end
92
+
93
+ def cart
94
+ @cart ||= ProductList.find_by_reference(response['texte-libre'])
95
+ end
96
+
97
+ def gateway
98
+ @gateway = Stall::Cmcic::Gateway
99
+ end
100
+
101
+ private
102
+
103
+ def response
104
+ @response ||= Stall::Cmcic::CicPayment.new(gateway).response(
105
+ Rack::Utils.parse_nested_query(request.raw_post)
106
+ )
107
+ end
108
+
109
+ def return_code
110
+ if success? || (response['code-retour'].try(:downcase) == 'annulation')
111
+ '0'
112
+ else
113
+ '1'
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,14 @@
1
+ module Stall
2
+ module Cmcic
3
+ module Utils
4
+ protected
5
+
6
+ def price_with_currency(price)
7
+ [
8
+ price.format(symbol: '', separator: '.', delimiter: ''),
9
+ currency
10
+ ].join
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Stall
2
+ module Cmcic
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/cmcic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'stall-cmcic'
8
+ spec.version = Stall::Cmcic::VERSION
9
+ spec.authors = ['vala']
10
+ spec.email = ['vala@glyph.fr']
11
+
12
+ spec.summary = %q{Stall e-commerce CM-CIC payment gateway integration}
13
+ spec.description = %q{Allows easy CM-CIC gateway integration in a Stall e-commerce app}
14
+ spec.homepage = 'https://github.com/rails-stall/stall-cmcic'
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 'cic_payment', '~> 0.4'
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,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stall-cmcic
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: cic_payment
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
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 CM-CIC 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/cmcic/_payment_form.html.haml
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/generators/stall/cmcic/install/install_generator.rb
101
+ - lib/generators/stall/cmcic/install/templates/config.rb
102
+ - lib/stall/cmcic.rb
103
+ - lib/stall/cmcic/cic_payment.rb
104
+ - lib/stall/cmcic/engine.rb
105
+ - lib/stall/cmcic/fake_gateway_payment_notification.rb
106
+ - lib/stall/cmcic/gateway.rb
107
+ - lib/stall/cmcic/utils.rb
108
+ - lib/stall/cmcic/version.rb
109
+ - stall-cmcic.gemspec
110
+ homepage: https://github.com/rails-stall/stall-cmcic
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.6.8
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Stall e-commerce CM-CIC payment gateway integration
134
+ test_files: []