paiement_cic 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ *.gem
@@ -0,0 +1,83 @@
1
+ Copyright (c) 2009 Novelys
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.
21
+
22
+ #==============================================================================
23
+ #
24
+ # "Open source" kit for P@iement CM-CIC(TM).
25
+ # Integration sample in a merchant site for Ruby
26
+ #
27
+ # Author : Euro-Information/e-Commerce (contact: centrecom@e-i.com)
28
+ # Version : 1.0
29
+ # Date : 01/01/2009
30
+ #
31
+ # Copyright: (c) 2009 Euro-Information. All rights reserved.
32
+ #
33
+ #==============================================================================
34
+
35
+ Redistribution and use in source and binary forms, with or without
36
+ modification, are permitted provided that the following conditions are
37
+ met:
38
+ - Redistributions of source code must retain the above copyright
39
+ notice and the following disclaimer.
40
+ - Redistributions in binary form must reproduce the above copyright
41
+ notice and the following disclaimer in the documentation and/or
42
+ other materials provided with the distribution.
43
+ - Neither the name of Euro-Information nor the names of its
44
+ contributors may be used to endorse or promote products derived
45
+ from this software without specific prior written permission.
46
+
47
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50
+ A PARTICULAR PURPOSE ARE DISCLAIMED.
51
+ IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
52
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
54
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
56
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
58
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
+
60
+ Note: Euro-Information does not provide person-to-person technical
61
+ support for tryout of CM-CIC P@iement examples. We do however
62
+ welcome your feedback which can be sent to <centrecom@e-i.com>.
63
+
64
+ #------------------------------------------------------------------------------
65
+
66
+ This software uses RSA Data Security, Inc. MD5 Message-Digest Algorithm.
67
+
68
+ License to copy and use this software is granted provided that it is
69
+ identified as the "RSA Data Security, Inc. MD5 Message-Digest
70
+ Algorithm" in all material mentioning or referencing this software or
71
+ this function.
72
+ License is also granted to make and use derivative works provided that
73
+ such works are identified as "derived from the RSA Data Security,
74
+ Inc. MD5 Message-Digest Algorithm" in all material mentioning or
75
+ referencing the derived work.
76
+ RSA Data Security, Inc. makes no representations concerning either the
77
+ merchantability of this software or the suitability of this software
78
+ for any particular purpose. It is provided "as is" without express or
79
+ implied warranty of any kind.
80
+ These notices must be retained in any copies of any part of this
81
+ documentation and/or software.
82
+
83
+ #==============================================================================
@@ -0,0 +1,105 @@
1
+ # Paiement CIC
2
+
3
+ Paiement CIC is a plugin to ease credit card payment with the CIC / Crédit Mutuel banks system version 3.0.
4
+ It's a Ruby on Rails port of the connexion kits published by the bank.
5
+
6
+ * The Plugin [site](http://github.com/novelys/cicpayment)
7
+ * The banks payment [site](http://www.cmcicpaiement.fr)
8
+
9
+
10
+ ## INSTALL
11
+
12
+ script/plugin install git://github.com/novelys/paiementcic.git
13
+
14
+ or, in your Gemfile
15
+
16
+ gem 'paiement_cic'
17
+
18
+ ## USAGE
19
+
20
+ ### in environment.rb :
21
+
22
+ # here the hmac key calculated with the js calculator given by CIC
23
+ PaiementCic.hmac_key = "########################################"
24
+ # Here the TPE number
25
+ PaiementCic.tpe = "#######"
26
+ # Here the Merchant name
27
+ PaiementCic.societe = "xxxxxxxxxxxxx"
28
+
29
+ ### in development.rb :
30
+
31
+ PaiementCic.target_url = "https://ssl.paiement.cic-banques.fr/test/paiement.cgi" # or https://paiement.creditmutuel.fr/test/paiement.cgi
32
+
33
+ ### in production.rb :
34
+
35
+ PaiementCic.target_url = "https://ssl.paiement.cic-banques.fr/paiement.cgi" # or https://paiement.creditmutuel.fr/paiement.cgi
36
+
37
+ ### in order controller :
38
+
39
+ helper :'paiement_cic/form'
40
+
41
+ ### in the payment by card view :
42
+
43
+ - form_tag PaiementCic.target_url do
44
+ = paiement_cic_hidden_fields(@order, @order_transaction, :url_retour => edit_order_url(order), :url_retour_ok => bank_ok_order_transaction_url(order_transaction), :url_retour_err => bank_err_order_transaction_url(order_transaction))
45
+ = submit_tag "Accéder au site de la banque", :style => "font-weight: bold;"
46
+ = image_tag "reassuring_pictograms.jpg", :alt => "Pictogrammes rassurants", :style => "width: 157px;"
47
+
48
+ ### in a controller for call back from the bank :
49
+
50
+ class OrderTransactionsController < ApplicationController
51
+
52
+ protect_from_forgery :except => [:bank_callback]
53
+
54
+ def bank_callback
55
+ if PaiementCic.verify_hmac(params)
56
+ order_transaction = OrderTransaction.find_by_reference params[:reference], :last
57
+ order = order_transaction.order
58
+
59
+ code_retour = params['code-retour']
60
+
61
+ if code_retour == "Annulation"
62
+ order.cancel!
63
+ order.update_attribute :description, "Paiement refusé par la banque."
64
+
65
+ elsif code_retour == "payetest"
66
+ order.pay!
67
+ order.update_attribute :description, "TEST accepté par la banque."
68
+ order_transaction.update_attribute :test, true
69
+
70
+ elsif code_retour == "paiement"
71
+ order.pay!
72
+ order.update_attribute :description, "Paiement accepté par la banque."
73
+ order_transaction.update_attribute :test, false
74
+ end
75
+
76
+ order_transaction.update_attribute :success, true
77
+
78
+ receipt = "0"
79
+ else
80
+ order.transaction_declined!
81
+ order.update_attribute :description, "Document Falsifie."
82
+ order_transaction.update_attribute :success, false
83
+
84
+ receipt = "1\n#{PaiementCic.mac_string}"
85
+ end
86
+ render :text => "Pragma: no-cache\nContent-type: text/plain\n\nversion=2\ncdr=#{receipt}"
87
+ end
88
+
89
+ def bank_ok
90
+ @order_transaction = OrderTransaction.find params[:id]
91
+ @order = @order_transaction.order
92
+ @order.pay!
93
+ end
94
+
95
+ def bank_err
96
+ order_transaction = OrderTransaction.find params[:id]
97
+ order = order_transaction.order
98
+ order.cancel!
99
+ end
100
+ end
101
+
102
+
103
+
104
+ ## License
105
+ Copyright (c) 2008-2012 Novelys Team, released under the MIT license
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "paiement_cic"
2
+ require "paiement_cic/form_helper"
@@ -0,0 +1,114 @@
1
+ require 'digest/sha1'
2
+ require 'openssl'
3
+
4
+ class String
5
+
6
+ def ^(other)
7
+ raise ArgumentError, "Can't bitwise-XOR a String with a non-String" \
8
+ unless other.kind_of? String
9
+ raise ArgumentError, "Can't bitwise-XOR strings of different length" \
10
+ unless self.length == other.length
11
+ result = (0..self.length-1).collect { |i| self[i].ord ^ other[i].ord }
12
+ result.pack("C*")
13
+ end
14
+ end
15
+
16
+ class PaiementCic
17
+ autoload :FormHelper, "paiement_cic/form_helper"
18
+
19
+ @@version = "3.0" # clé extraite grâce à extract2HmacSha1.html fourni par le Crédit Mutuel
20
+ cattr_accessor :version
21
+
22
+ @@hmac_key = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" # clé extraite grâce à extract2HmacSha1.html fourni par le Crédit Mutuel
23
+ cattr_accessor :hmac_key
24
+
25
+ @@target_url = "https://paiement.creditmutuel.fr/test/paiement.cgi" # "https://ssl.paiement.cic-banques.fr/paiement.cgi"
26
+ cattr_accessor :target_url
27
+
28
+ @@tpe = "123456"
29
+ cattr_accessor :tpe
30
+
31
+ @@societe = "masociete"
32
+ cattr_accessor :societe
33
+
34
+ @@url_ok = ""
35
+ cattr_accessor :url_ok
36
+
37
+ def self.date_format
38
+ "%d/%m/%Y:%H:%M:%S"
39
+ end
40
+
41
+ def self.config(amount_in_cents, reference)
42
+ oa = ActiveSupport::OrderedHash.new
43
+ oa["version"] = "3.0"
44
+ oa["TPE"] = tpe
45
+ oa["date"] = Time.now.strftime(date_format)
46
+ oa["montant"] = ("%.2f" % amount_in_cents) + "EUR"
47
+ oa["reference"] = reference
48
+ oa["texte-libre"] = ""
49
+ oa["lgue"] = "FR"
50
+ oa["societe"] = societe
51
+ oa["mail"] = ""
52
+ oa
53
+ end
54
+
55
+ def self.mac_string params
56
+ hmac_key = PaiementCic.new
57
+ mac_string = [hmac_key.tpe, params["date"], params['montant'], params['reference'], params['texte-libre'], hmac_key.version, params['code-retour'], params['cvx'], params['vld'], params['brand'], params['status3ds'], params['numauto'], params['motifrefus'], params['originecb'], params['bincb'], params['hpancb'], params['ipclient'], params['originetr'], params['veres'], params['pares']].join('*') + "*"
58
+ end
59
+
60
+ def self.verify_hmac params
61
+ hmac_key = PaiementCic.new
62
+ mac_string = [hmac_key.tpe, params["date"], params['montant'], params['reference'], params['texte-libre'], hmac_key.version, params['code-retour'], params['cvx'], params['vld'], params['brand'], params['status3ds'], params['numauto'], params['motifrefus'], params['originecb'], params['bincb'], params['hpancb'], params['ipclient'], params['originetr'], params['veres'], params['pares']].join('*') + "*"
63
+
64
+ hmac_key.valid_hmac?(mac_string, params['MAC'])
65
+ end
66
+
67
+ # Check if the HMAC matches the HMAC of the data string
68
+ def valid_hmac?(mac_string, sent_mac)
69
+ computeHMACSHA1(mac_string) == sent_mac.downcase
70
+ end
71
+
72
+ # Return the HMAC for a data string
73
+ def computeHMACSHA1(data)
74
+ hmac_sha1(usable_key(self), data).downcase
75
+ end
76
+
77
+ def hmac_sha1(key, data)
78
+ length = 64
79
+
80
+ if (key.length > length)
81
+ key = [Digest::SHA1.hexdigest(key)].pack("H*")
82
+ end
83
+
84
+ key = key.ljust(length, 0.chr)
85
+ ipad = ''.ljust(length, 54.chr)
86
+ opad = ''.ljust(length, 92.chr)
87
+
88
+ k_ipad = key ^ ipad
89
+ k_opad = key ^ opad
90
+
91
+ #Digest::SHA1.hexdigest(k_opad + [Digest::SHA1.hexdigest(k_ipad + sData)].pack("H*"))
92
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new("sha1"), key, data)
93
+ end
94
+
95
+ private
96
+ # Return the key to be used in the hmac function
97
+ def usable_key(payement)
98
+
99
+ hex_string_key = payement.hmac_key[0..37]
100
+ hex_final = payement.hmac_key[38..40] + "00";
101
+
102
+ cca0 = hex_final[0].ord
103
+
104
+ if cca0 > 70 && cca0 < 97
105
+ hex_string_key += (cca0 - 23).chr + hex_final[1..2]
106
+ elsif hex_final[1..2] == "M"
107
+ hex_string_key += hex_final[0..1] + "0"
108
+ else
109
+ hex_string_key += hex_final[0..2]
110
+ end
111
+
112
+ [hex_string_key].pack("H*")
113
+ end
114
+ end
@@ -0,0 +1,32 @@
1
+ ## refactor this
2
+ module PaiementCic::FormHelper
3
+ def paiement_cic_hidden_fields(order, price, order_transaction, options = {})
4
+ oa = PaiementCic.config(price, order_transaction.reference)
5
+
6
+ oMac = PaiementCic.new
7
+ sDate = Time.now.strftime("%d/%m/%Y:%H:%M:%S")
8
+ chaine = [oMac.tpe, sDate, oa["montant"], oa["reference"].to_s, oa["texte-libre"], oMac.version, "FR", oMac.societe, "", "", "", "", "", "", "", "", "", "", ""].join("*")
9
+ chaineMAC = oMac.computeHMACSHA1(chaine)
10
+
11
+ url_retour = options[:url_retour] || bank_callback_order_transactions_url
12
+ url_retour_ok = options[:url_retour_ok] || bank_callback_order_transactions_url(order)
13
+ url_retour_err = options[:url_retour_err] || bank_err_order_transaction_url(order)
14
+
15
+ html = '
16
+ <input type="hidden" name="version" id="version" value="' + oa["version"] + '" />
17
+ <input type="hidden" name="TPE" id="TPE" value="' + oa["TPE"] + '" />
18
+ <input type="hidden" name="date" id="date" value="' + oa["date"] + '" />
19
+ <input type="hidden" name="montant" id="montant" value="' + oa["montant"] + '" />
20
+ <input type="hidden" name="reference" id="reference" value="' + oa["reference"].to_s + '" />
21
+ <input type="hidden" name="MAC" id="MAC" value="' + chaineMAC + '" />
22
+ <input type="hidden" name="url_retour" id="url_retour" value="' + url_retour + '" />
23
+ <input type="hidden" name="url_retour_ok" id="url_retour_ok" value="' + url_retour_ok + '" />
24
+ <input type="hidden" name="url_retour_err" id="url_retour_err" value="' + url_retour_err + '" />
25
+ <input type="hidden" name="lgue" id="lgue" value="' + oa["lgue"] + '" />
26
+ <input type="hidden" name="societe" id="societe" value="' + oa["societe"] + '" />
27
+ <input type="hidden" name="texte-libre" id="texte-libre" value="' + oa["texte-libre"] + '" />
28
+ <input type="hidden" name="mail" id="mail" value="''" />'
29
+
30
+ html.respond_to?(:html_safe) ? html.html_safe : html
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ class PaiementCic
2
+ VERSION = "0.2"
3
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "paiement_cic/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "paiement_cic"
7
+ s.version = PaiementCic::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Novelys Team"]
10
+ s.homepage = "https://github.com/novelys/paiementcic"
11
+ s.summary = %q{CIC / Crédit Mutuel credit card payment toolbox}
12
+ s.description = %q{Paiement CIC is a gem to ease credit card payment with the CIC / Crédit Mutuel banks system. It's a Ruby on Rails port of the connexion kits published by the bank.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.require_paths = ["lib"]
16
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paiement_cic
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ version: "0.2"
10
+ platform: ruby
11
+ authors:
12
+ - Novelys Team
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-01-30 00:00:00 Z
18
+ dependencies: []
19
+
20
+ description: "Paiement CIC is a gem to ease credit card payment with the CIC / Cr\xC3\xA9dit Mutuel banks system. It's a Ruby on Rails port of the connexion kits published by the bank."
21
+ email:
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - .gitignore
30
+ - MIT-LICENSE
31
+ - README.markdown
32
+ - init.rb
33
+ - lib/paiement_cic.rb
34
+ - lib/paiement_cic/form_helper.rb
35
+ - lib/paiement_cic/version.rb
36
+ - paiement_cic.gemspec
37
+ homepage: https://github.com/novelys/paiementcic
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.15
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: "CIC / Cr\xC3\xA9dit Mutuel credit card payment toolbox"
70
+ test_files: []
71
+