cic_payment 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7a9ab1ef67d2fa58b5d65ea218357c23309af5f
4
- data.tar.gz: d6fa62f8539328b668989efa02990321301e1f99
3
+ metadata.gz: 8871afe40aa1ae38a2866977e68de252f4f82a45
4
+ data.tar.gz: 53ffbc797742f39cf8967de16437a93df3fd8878
5
5
  SHA512:
6
- metadata.gz: 90b86638090ab0a557fd21027e963ca72658475e01e42c34a659fd0a03399cd8059396cbc681b34e880e290d03b01fc03eaeb12b3146f67e5b4a439d33677688
7
- data.tar.gz: 93bda4215ce221d1f59a429e37a1e48a252d9a791b01394fd6b8f96d3dc60b80558da008425d9a79aae37a55eaf5264e2742016e18a992670f29242c09e0e2c0
6
+ metadata.gz: 2c253796bf67f908754ec5c71e9b2232362ff6719f8b1318dbdccf3ec520edcd3d9136d94dbd868ce9edb9e561dd7687dcdb32d84086bee33c1bb4eb7304a883
7
+ data.tar.gz: ed603293928cbba1a1350898e6750472de42a6db0c58404348cce327774c079e0642204206c9b43eaf601164bbaf8c575aa5c63b5d25f27219627d7776f8d105
data/cic_payment.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "cic_payment"
6
- s.version = "0.4"
6
+ s.version = "0.4.1"
7
7
  s.date = "2014-03-18"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Novelys Team", 'Guillaume Barillot', 'Regis Millet (aka Kulgar)']
data/lib/cic_payment.rb CHANGED
@@ -51,44 +51,44 @@ class CicPayment < PaymentSettings
51
51
  end
52
52
 
53
53
  def response(params)
54
-
55
54
  if verify_hmac(params)
56
-
57
- if params['code-retour'] == "Annulation"
55
+ case params['code-retour']
56
+ when "Annulation"
58
57
  params.update(:success => false)
59
-
60
- elsif params['code-retour'] == "payetest"
61
- params.update(:success => true)
62
-
63
- elsif params['code-retour'] == "paiement"
58
+ when "payetest", "paiement"
64
59
  params.update(:success => true)
60
+ else
61
+ params.update(:success => false)
65
62
  end
66
-
67
63
  else
68
64
  params.update(:success => false)
69
65
  end
70
-
71
66
  end
72
67
 
73
- def self.mac_string params
74
- hmac_key = CicPayment.new
75
- 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('*') + "*"
68
+ # Use this function for your tests to create the mac properly
69
+ def response_mac params
70
+ # The HMAC returned by the bank uses this chain:
71
+ # <TPE>*<date>*<montant>*<reference>*<texte-libre>*3.0*<code-retour>*
72
+ # <cvx>*<vld>*<brand>*<status3ds>*<numauto>*<motifrefus>*<originecb>*
73
+ # <bincb>*<hpancb>*<ipclient>*<originetr>*<veres>*<pares>*
74
+ chain = [
75
+ self.tpe, params['date'], params['montant'], params['reference'], params['texte-libre'], self.version, params['code-retour'],
76
+ params['cvx'], params['vld'], params['brand'], params['status3ds'], params["numauto"], params['motifrefus'], params['originecb'],
77
+ params['bincb'], params['hpancb'], params['ipclient'], params['originetr'], params['veres'], params['pares'], ""
78
+ ].join('*')
79
+
80
+ hmac_token(false, chain)
76
81
  end
77
82
 
78
83
  def verify_hmac params
79
- mac_string = [self.tpe, params['date'], params['montant'], params['reference'], params['texte-libre'], self.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('*') + "*"
80
-
81
84
  params['MAC'] ? hmac = params['MAC'] : hmac = ""
82
- self.valid_hmac?(hmac)
83
- end
84
85
 
85
- # Check if the HMAC matches the HMAC of the data string
86
- def valid_hmac?(sent_mac)
87
- hmac_token == sent_mac.downcase
88
- end
86
+ # Check if the HMAC matches the HMAC of the data string
87
+ response_mac(params) == hmac
88
+ end
89
89
 
90
90
  # Return the HMAC for a data string
91
- def hmac_token
91
+ def hmac_token(form_hmac = true, chain = nil)
92
92
  # This chain must contains:
93
93
  # <TPE>*<date>*<montant>*<reference>*<texte-libre>*<version>*<lgue>*<societe>*<mail>*
94
94
  # <nbrech>*<dateech1>*<montantech1>*<dateech2>*<montantech2>*<dateech3>*<montantech3>*
@@ -103,17 +103,19 @@ class CicPayment < PaymentSettings
103
103
  # For a fragmented payment:
104
104
  # 1234567*05/12/2006:11:55:23*62.73EUR*ABERTYP00145*ExempleTexteLibre*3.0*FR*monSite1*internaute@sonemail.fr*
105
105
  # 4*05/12/2006*16.23EUR*05/01/2007*15.5EUR*05/02/2007*15.5EUR*05/03/2007*15.5EUR*
106
- chain = [self.tpe,
107
- self.date,
108
- self.montant,
109
- self.reference,
110
- self.texte_libre,
111
- self.version,
112
- self.lgue,
113
- self.societe,
114
- self.mail,
115
- "", "", "", "", "", "", "", "", "", "" # 10 stars: 9 for fragmented unfilled params + 1 final star
116
- ].join("*")
106
+ if form_hmac && chain.blank?
107
+ chain = [self.tpe,
108
+ self.date,
109
+ self.montant,
110
+ self.reference,
111
+ self.texte_libre,
112
+ self.version,
113
+ self.lgue,
114
+ self.societe,
115
+ self.mail,
116
+ "", "", "", "", "", "", "", "", "", "" # 10 stars: 9 for fragmented unfilled params + 1 final star
117
+ ].join("*")
118
+ end
117
119
 
118
120
  hmac_sha1(usable_key(self.hmac_key), chain).downcase
119
121
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CicPayment
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cic_payment
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Novelys Team