Update README
parent
7b428b5b61
commit
fd565f3e6f
143
README.markdown
143
README.markdown
|
@ -9,95 +9,102 @@ It's a Ruby on Rails port of the connexion kits published by the bank.
|
||||||
|
|
||||||
## INSTALL
|
## INSTALL
|
||||||
|
|
||||||
script/plugin install git://github.com/novelys/paiementcic.git
|
|
||||||
|
|
||||||
or, in your Gemfile
|
|
||||||
|
|
||||||
gem 'paiement_cic'
|
gem 'paiement_cic'
|
||||||
|
|
||||||
## USAGE
|
## USAGE
|
||||||
|
|
||||||
### in environment.rb :
|
### in an initializer (`config/initializers/paiement_cic.rb`) :
|
||||||
|
|
||||||
# here the hmac key calculated with the js calculator given by CIC
|
```ruby
|
||||||
PaiementCic.hmac_key = "########################################"
|
PaiementCic.configure do |config|
|
||||||
# Here the TPE number
|
# here the hmac key calculated with the js calculator given by CIC
|
||||||
PaiementCic.tpe = "#######"
|
config.hmac_key = "########################################"
|
||||||
# Here the Merchant name
|
# Here the TPE number
|
||||||
PaiementCic.societe = "xxxxxxxxxxxxx"
|
config.tpe = "#######"
|
||||||
|
# Here the Merchant name
|
||||||
|
config.societe = "xxxxxxxxxxxxx"
|
||||||
|
|
||||||
### in development.rb :
|
# 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
|
||||||
|
```
|
||||||
|
|
||||||
PaiementCic.target_url = "https://ssl.paiement.cic-banques.fr/test/paiement.cgi" # or https://paiement.creditmutuel.fr/test/paiement.cgi
|
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
|
||||||
### in production.rb :
|
{
|
||||||
|
hmac_key: "########################################",
|
||||||
PaiementCic.target_url = "https://ssl.paiement.cic-banques.fr/paiement.cgi" # or https://paiement.creditmutuel.fr/paiement.cgi
|
tpe: "#######",
|
||||||
|
societe: "xxxxxxxxxxxxx",
|
||||||
### in order controller :
|
}
|
||||||
|
```
|
||||||
helper :'paiement_cic/form'
|
|
||||||
|
|
||||||
### in the payment by card view :
|
### in the payment by card view :
|
||||||
|
|
||||||
- form_tag PaiementCic.target_url do
|
```
|
||||||
= 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))
|
- form_tag PaiementCic.target_url do
|
||||||
= submit_tag "Accéder au site de la banque", :style => "font-weight: bold;"
|
= 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))
|
||||||
= image_tag "reassuring_pictograms.jpg", :alt => "Pictogrammes rassurants", :style => "width: 157px;"
|
= submit_tag "Accéder au site de la banque", :style => "font-weight: bold;"
|
||||||
|
= image_tag "reassuring_pictograms.jpg", :alt => "Pictogrammes rassurants", :style => "width: 157px;"
|
||||||
|
```
|
||||||
|
|
||||||
### in a controller for call back from the bank :
|
### in a controller for call back from the bank :
|
||||||
|
|
||||||
class OrderTransactionsController < ApplicationController
|
```ruby
|
||||||
|
class OrderTransactionsController < ApplicationController
|
||||||
|
|
||||||
protect_from_forgery :except => [:bank_callback]
|
protect_from_forgery :except => [:bank_callback]
|
||||||
|
|
||||||
def bank_callback
|
def bank_callback
|
||||||
if PaiementCic.verify_hmac(params)
|
tpe = PaiementCic::TPE.new
|
||||||
order_transaction = OrderTransaction.find_by_reference params[:reference], :last
|
|
||||||
order = order_transaction.order
|
|
||||||
|
|
||||||
code_retour = params['code-retour']
|
if tpe.verify_hmac(params)
|
||||||
|
order_transaction = OrderTransaction.find_by_reference params[:reference], :last
|
||||||
|
order = order_transaction.order
|
||||||
|
|
||||||
if code_retour == "Annulation"
|
code_retour = params['code-retour']
|
||||||
order.cancel!
|
|
||||||
order.update_attribute :description, "Paiement refusé par la banque."
|
|
||||||
|
|
||||||
elsif code_retour == "payetest"
|
if code_retour == "Annulation"
|
||||||
order.pay!
|
|
||||||
order.update_attribute :description, "TEST accepté par la banque."
|
|
||||||
order_transaction.update_attribute :test, true
|
|
||||||
|
|
||||||
elsif code_retour == "paiement"
|
|
||||||
order.pay!
|
|
||||||
order.update_attribute :description, "Paiement accepté par la banque."
|
|
||||||
order_transaction.update_attribute :test, false
|
|
||||||
end
|
|
||||||
|
|
||||||
order_transaction.update_attribute :success, true
|
|
||||||
|
|
||||||
receipt = "0"
|
|
||||||
else
|
|
||||||
order.transaction_declined!
|
|
||||||
order.update_attribute :description, "Document Falsifie."
|
|
||||||
order_transaction.update_attribute :success, false
|
|
||||||
|
|
||||||
receipt = "1\n#{PaiementCic.mac_string}"
|
|
||||||
end
|
|
||||||
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
|
|
||||||
@order.pay!
|
|
||||||
end
|
|
||||||
|
|
||||||
def bank_err
|
|
||||||
order_transaction = OrderTransaction.find params[:id]
|
|
||||||
order = order_transaction.order
|
|
||||||
order.cancel!
|
order.cancel!
|
||||||
|
order.update_attribute :description, "Paiement refusé par la banque."
|
||||||
|
|
||||||
|
elsif code_retour == "payetest"
|
||||||
|
order.pay!
|
||||||
|
order.update_attribute :description, "TEST accepté par la banque."
|
||||||
|
order_transaction.update_attribute :test, true
|
||||||
|
|
||||||
|
elsif code_retour == "paiement"
|
||||||
|
order.pay!
|
||||||
|
order.update_attribute :description, "Paiement accepté par la banque."
|
||||||
|
order_transaction.update_attribute :test, false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
order_transaction.update_attribute :success, true
|
||||||
|
|
||||||
|
receipt = "0"
|
||||||
|
else
|
||||||
|
order.transaction_declined!
|
||||||
|
order.update_attribute :description, "Document Falsifie."
|
||||||
|
order_transaction.update_attribute :success, false
|
||||||
|
|
||||||
|
receipt = "1\n#{tpe.mac_string}"
|
||||||
end
|
end
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue