2009-08-17 10:40:22 +02:00
# Paiement CIC
2009-12-21 11:24:45 +01:00
Paiement CIC is a plugin to ease credit card payment with the CIC / Crédit Mutuel banks system version 3.0.
2009-08-17 10:40:22 +02:00
It's a Ruby on Rails port of the connexion kits published by the bank.
* The Plugin [site ](http://github.com/novelys/cicpayment )
* The banks payment [site ](http://www.cmcicpaiement.fr )
## INSTALL
2012-01-30 13:55:44 +01:00
gem 'paiement_cic'
2009-08-17 10:40:22 +02:00
## USAGE
2013-06-11 14:11:12 +02:00
### in an initializer (`config/initializers/paiement_cic.rb`) :
```ruby
PaiementCic.configure do |config|
# here the hmac key calculated with the js calculator given by CIC
config.hmac_key = "########################################"
# Here the TPE number
config.tpe = "#######"
# Here the Merchant name
config.societe = "xxxxxxxxxxxxx"
# You can specify the target URL
config.target_url = "https://ssl.paiement.cic-banques.fr/test/paiement.cgi"
# Or used predefined ones by specifying environment and bank
config.bank = :cm # or :cic
config.env = :test # or :production
end
```
You can also specify `hmac_key` , `tpe` and `societe` when initializing `PaiementCic::TPE` and with `paiement_cic_hidden_fields` helper by passing an hash.
```ruby
{
hmac_key: "########################################",
tpe: "#######",
societe: "xxxxxxxxxxxxx",
}
```
2009-08-17 10:40:22 +02:00
### in the payment by card view :
2013-06-11 14:11:12 +02:00
```
- form_tag PaiementCic.target_url do
= paiement_cic_hidden_fields(@order.reference, @order .amount, mail: 'email@example.com', 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))
= submit_tag "Accéder au site de la banque", :style => "font-weight: bold;"
= image_tag "reassuring_pictograms.jpg", :alt => "Pictogrammes rassurants", :style => "width: 157px;"
```
2009-08-17 10:40:22 +02:00
### in a controller for call back from the bank :
2013-06-11 14:11:12 +02:00
```ruby
class OrderTransactionsController < ApplicationController
2009-08-17 10:40:22 +02:00
2013-06-11 14:11:12 +02:00
protect_from_forgery :except => [:bank_callback]
2009-08-17 10:40:22 +02:00
2013-06-11 14:11:12 +02:00
def bank_callback
tpe = PaiementCic::TPE.new
2009-08-17 10:40:22 +02:00
2013-06-11 14:11:12 +02:00
if tpe.verify_hmac(params)
order_transaction = OrderTransaction.find_by_reference params[:reference], :last
order = order_transaction.order
2009-08-17 10:40:22 +02:00
2013-06-11 14:11:12 +02:00
code_retour = params['code-retour']
2009-08-17 10:40:22 +02:00
2013-06-11 14:11:12 +02:00
if code_retour == "Annulation"
order.cancel!
order.update_attribute :description, "Paiement refusé par la banque."
2009-08-17 10:40:22 +02:00
2013-06-11 14:11:12 +02:00
elsif code_retour == "payetest"
order.pay!
order.update_attribute :description, "TEST accepté par la banque."
order_transaction.update_attribute :test, true
2009-08-17 10:40:22 +02:00
2013-06-11 14:11:12 +02:00
elsif code_retour == "paiement"
order.pay!
order.update_attribute :description, "Paiement accepté par la banque."
order_transaction.update_attribute :test, false
2009-08-17 10:40:22 +02:00
end
2013-06-11 14:11:12 +02:00
order_transaction.update_attribute :success, true
2009-08-17 10:40:22 +02:00
2013-06-11 14:11:12 +02:00
receipt = "0"
else
order.transaction_declined!
order.update_attribute :description, "Document Falsifie."
order_transaction.update_attribute :success, false
receipt = "1\n#{tpe.mac_string}"
2009-08-17 10:40:22 +02:00
end
2013-06-11 14:11:12 +02:00
render :text => "Pragma: no-cache\nContent-type: text/plain\n\nversion=2\ncdr=#{receipt}"
end
def bank_ok
@order_transaction = OrderTransaction.find params[:id]
@order = @order_transaction .order
end
def bank_err
order_transaction = OrderTransaction.find params[:id]
order = order_transaction.order
end
end
```
2009-08-17 10:40:22 +02:00
## License
2012-01-30 13:55:44 +01:00
Copyright (c) 2008-2012 Novelys Team, released under the MIT license