Class: SystemPay::Vads
- Inherits:
-
Object
- Object
- SystemPay::Vads
- Defined in:
- lib/system_pay/vads.rb
Constant Summary collapse
- VADS_RISK_CONTROL_RESULT =
pre-defined messages (from 2.2 Guide)
{ '' => 'Pas de contrôle effectué.', '00' => 'Tous les contrôles se sont déroulés avec succès.', '02' => 'La carte a dépassé l’encours autorisé.', '03' => 'La carte appartient à la liste grise du commerçant.', '04' => 'Le pays d’émission de la carte appartient à la liste grise du commerçant ou le pays d’émission de la carte n’appartient pas à la liste blanche du commerçant.', '05' => 'L’adresse IP appartient à la liste grise du commerçant.', '07' => 'La carte appartient à la liste grise BIN du commerçant.', '99' => 'Problème technique rencontré par le serveur lors du traitement d’un des contrôles locaux.', }
- VADS_QUERY_FORMAT_ERROR =
{ '01' => 'vads_version', '02' => 'vads_site_id', '03' => 'vads_trans_id', '04' => 'vads_trans_date', '05' => 'vads_validation_mode', '06' => 'vads_capture_delay', '07' => 'vads_payment_config', '08' => 'vads_payment_cards', '09' => 'vads_amount', '10' => 'vads_currency', '11' => 'vads_ctx_mode', '12' => 'vads_language', '13' => 'vads_order_id', '14' => 'vads_order_info', '15' => 'vads_cust_email', '16' => 'vads_cust_id', '17' => 'vads_cust_title', '18' => 'vads_cust_name', '19' => 'vads_cust_address', '20' => 'vads_cust_zip', '21' => 'vads_cust_city', '22' => 'vads_cust_country', '23' => 'vads_cust_phone', '24' => 'vads_url_success', '25' => 'vads_url_refused', '26' => 'vads_url_referral', '27' => 'vads_url_cancel', '28' => 'vads_url_return', '29' => 'vads_url_error', '31' => 'vads_contrib', '32' => 'vads_theme_config', '46' => 'vads_page_action', '47' => 'vads_action_mode', '48' => 'vads_return_mode', '61' => 'vads_user_info', '62' => 'vads_contracts', '77' => 'vads_cust_cell_phone' }
- @@target_url =
fixed params per shop are class variables
"https://paiement.systempay.fr/vads-payment/"
- @@vads_action_mode =
'INTERACTIVE'
- @@vads_ctx_mode =
or ‘PRODUCTION’
'TEST'
- @@vads_contrib =
'Ruby'
- @@vads_page_action =
'PAYMENT'
- @@vads_payment_config =
'SINGLE'
- @@vads_return_mode =
or ‘GET’, but request in GET could be too large
'POST'
- @@vads_site_id =
'000000'
- @@vads_validation_mode =
'1'
- @@vads_version =
'V2'
- @@certificat =
'0000000000000000'
- @@vads_shop_name =
''
- @@vads_shop_url =
''
Instance Attribute Summary collapse
-
#vads_amount ⇒ Object
transaction parameters are instance variables.
-
#vads_available_languages ⇒ Object
transaction parameters are instance variables.
-
#vads_capture_delay ⇒ Object
transaction parameters are instance variables.
-
#vads_contracts ⇒ Object
transaction parameters are instance variables.
-
#vads_currency ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_address ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_cell_phone ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_city ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_country ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_email ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_id ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_name ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_phone ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_title ⇒ Object
transaction parameters are instance variables.
-
#vads_cust_zip ⇒ Object
transaction parameters are instance variables.
-
#vads_language ⇒ Object
transaction parameters are instance variables.
-
#vads_order_id ⇒ Object
transaction parameters are instance variables.
-
#vads_order_info ⇒ Object
transaction parameters are instance variables.
-
#vads_order_info2 ⇒ Object
transaction parameters are instance variables.
-
#vads_order_info3 ⇒ Object
transaction parameters are instance variables.
-
#vads_payment_cards ⇒ Object
transaction parameters are instance variables.
-
#vads_redirect_error_message ⇒ Object
transaction parameters are instance variables.
-
#vads_redirect_error_timeout ⇒ Object
transaction parameters are instance variables.
-
#vads_redirect_success_message ⇒ Object
transaction parameters are instance variables.
-
#vads_redirect_success_timeout ⇒ Object
transaction parameters are instance variables.
-
#vads_ship_to_city ⇒ Object
transaction parameters are instance variables.
-
#vads_ship_to_country ⇒ Object
transaction parameters are instance variables.
-
#vads_ship_to_name ⇒ Object
transaction parameters are instance variables.
-
#vads_ship_to_phone_num ⇒ Object
transaction parameters are instance variables.
-
#vads_ship_to_state ⇒ Object
transaction parameters are instance variables.
-
#vads_ship_to_street ⇒ Object
transaction parameters are instance variables.
-
#vads_ship_to_street2 ⇒ Object
transaction parameters are instance variables.
-
#vads_ship_to_zip ⇒ Object
transaction parameters are instance variables.
-
#vads_theme_config ⇒ Object
transaction parameters are instance variables.
-
#vads_trans_date ⇒ Object
transaction parameters are instance variables.
-
#vads_trans_id ⇒ Object
transaction parameters are instance variables.
-
#vads_url_cancel ⇒ Object
transaction parameters are instance variables.
-
#vads_url_error ⇒ Object
transaction parameters are instance variables.
-
#vads_url_referral ⇒ Object
transaction parameters are instance variables.
-
#vads_url_refused ⇒ Object
transaction parameters are instance variables.
-
#vads_url_return ⇒ Object
transaction parameters are instance variables.
-
#vads_url_success ⇒ Object
transaction parameters are instance variables.
Class Method Summary collapse
-
.diagnose(params) ⇒ Object
Public: Diagnose result from returned params.
-
.valid_signature?(params) ⇒ Boolean
Public: Verify that the returned signature is valid.
Instance Method Summary collapse
-
#initialize(args = nil) ⇒ Vads
constructor
Public: Creation of new instance.
-
#params ⇒ Object
Public: Hash with non-nil parameters (and value) and their signature.
-
#signature ⇒ Object
Public: Compute the signature of the request based on the parameters.
Constructor Details
#initialize(args = nil) ⇒ Vads
Public: Creation of new instance.
args - The hash of systempay parameters as described in the implementation
document. Note that each key should *not* contain the vads_ prefix.
:amount - Should be in cents
:trans_id - Will be automatically padded with zeros
Examples
SystemPay::Vads.new(:amount => 100, :trans_id => 10, :url_return => 'http://mywebsite.com/return_url')
Returns a new instance object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/system_pay/vads.rb', line 119 def initialize(args=nil) args.each do |k,v| if k.to_s.match(/^vads_/) instance_variable_set("@#{k}", v) if v.present? && respond_to?(k) else instance_variable_set("@vads_#{k}", v) if v.present? && respond_to?("vads_#{k}") end end if args raise ArgumentError.new("You must specify a non blank :amount parameter") unless @vads_amount.present? raise ArgumentError.new("You must specify a non blank :trans_id parameter") unless @vads_trans_id.present? @vads_currency ||= '978' # Euros @vads_trans_date ||= Time.now.utc.strftime("%Y%m%d%H%M%S") @vads_trans_id = (@vads_trans_id % 900000).to_s.rjust(6, '0') end |
Instance Attribute Details
#vads_amount ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_amount @vads_amount end |
#vads_available_languages ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_available_languages @vads_available_languages end |
#vads_capture_delay ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_capture_delay @vads_capture_delay end |
#vads_contracts ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_contracts @vads_contracts end |
#vads_currency ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_currency @vads_currency end |
#vads_cust_address ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_address @vads_cust_address end |
#vads_cust_cell_phone ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_cell_phone @vads_cust_cell_phone end |
#vads_cust_city ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_city @vads_cust_city end |
#vads_cust_country ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_country @vads_cust_country end |
#vads_cust_email ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_email @vads_cust_email end |
#vads_cust_id ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_id @vads_cust_id end |
#vads_cust_name ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_name @vads_cust_name end |
#vads_cust_phone ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_phone @vads_cust_phone end |
#vads_cust_title ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_title @vads_cust_title end |
#vads_cust_zip ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_cust_zip @vads_cust_zip end |
#vads_language ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_language @vads_language end |
#vads_order_id ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_order_id @vads_order_id end |
#vads_order_info ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_order_info @vads_order_info end |
#vads_order_info2 ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_order_info2 @vads_order_info2 end |
#vads_order_info3 ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_order_info3 @vads_order_info3 end |
#vads_payment_cards ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_payment_cards @vads_payment_cards end |
#vads_redirect_error_message ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def @vads_redirect_error_message end |
#vads_redirect_error_timeout ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_redirect_error_timeout @vads_redirect_error_timeout end |
#vads_redirect_success_message ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def @vads_redirect_success_message end |
#vads_redirect_success_timeout ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_redirect_success_timeout @vads_redirect_success_timeout end |
#vads_ship_to_city ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_ship_to_city @vads_ship_to_city end |
#vads_ship_to_country ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_ship_to_country @vads_ship_to_country end |
#vads_ship_to_name ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_ship_to_name @vads_ship_to_name end |
#vads_ship_to_phone_num ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_ship_to_phone_num @vads_ship_to_phone_num end |
#vads_ship_to_state ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_ship_to_state @vads_ship_to_state end |
#vads_ship_to_street ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_ship_to_street @vads_ship_to_street end |
#vads_ship_to_street2 ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_ship_to_street2 @vads_ship_to_street2 end |
#vads_ship_to_zip ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_ship_to_zip @vads_ship_to_zip end |
#vads_theme_config ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_theme_config @vads_theme_config end |
#vads_trans_date ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_trans_date @vads_trans_date end |
#vads_trans_id ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_trans_id @vads_trans_id end |
#vads_url_cancel ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_url_cancel @vads_url_cancel end |
#vads_url_error ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_url_error @vads_url_error end |
#vads_url_referral ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_url_referral @vads_url_referral end |
#vads_url_refused ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_url_refused @vads_url_refused end |
#vads_url_return ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_url_return @vads_url_return end |
#vads_url_success ⇒ Object
transaction parameters are instance variables
96 97 98 |
# File 'lib/system_pay/vads.rb', line 96 def vads_url_success @vads_url_success end |
Class Method Details
.diagnose(params) ⇒ Object
Public: Diagnose result from returned params
params - The hash of params returned by the bank.
Returns a hash { :status => :error | :success | :canceled | :bad_params,
:user_msg => "msg for user",
:tech_msg => "msg for back-office" }
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/system_pay/vads.rb', line 164 def self.diagnose(params) if params[:vads_result].blank? { :status => :bad_params, :user_msg => 'Vous allez être redirigé vers la page d’accueil', :tech_msg => 'vads_result est vide. Suspicion de tentative de fraude.' } elsif !valid_signature?(params) { :status => :bad_params, :user_msg => 'Vous allez être redirigé vers la page d’accueil', :tech_msg => 'La signature ne correspond pas. Suspicion de tentative de fraude.' } else case params[:vads_result] when '00' { :status => :success, :user_msg => 'Votre paiement a été accepté par la banque.', :tech_msg => "Paiement accepté. #{VADS_RISK_CONTROL_RESULT[params[:vads_extra_result]]}" } when '02' { :status => :error, :user_msg => 'Nous devons entrer en relation avec votre banque avant d’obtenir confirmation du paiement.', :tech_msg => 'Le commerçant doit contacter la banque du porteur.' } when '05' { :status => :error, :user_msg => 'Le paiement a été refusé par la banque.', :tech_msg => "Paiement refusé par la banque. #{VADS_RISK_CONTROL_RESULT[params[:vads_extra_result]]}" } when '17' { :status => :canceled, :user_msg => 'Vous avez annulé votre paiement.', :tech_msg => 'Paiement annulé par le client.' } when '30' { :status => :bad_params, :user_msg => 'En raison d’une erreur technique, le paiement n’a pu être validé.', :tech_msg => "Erreur de format dans la requête (champ #{VADS_QUERY_FORMAT_ERROR[params[:vads_extra_result]]}). Signaler au développeur." } when '96' { :status => :bad_params, :user_msg => 'En raison d’une erreur technique, le paiement n’a pu être validé.', :tech_msg => 'Code vads_result inconnu. Signaler au développeur.' } else { :status => :bad_params, :user_msg => 'En raison d’une erreur technique, le paiement n’a pu être validé.', :tech_msg => 'Code vads_result inconnu. Signaler au développeur.' } end end end |
.valid_signature?(params) ⇒ Boolean
Public: Verify that the returned signature is valid. Return boolean
152 153 154 155 |
# File 'lib/system_pay/vads.rb', line 152 def self.valid_signature?(params) vads_params = params.sort.select{|value| value[0].to_s.match(/^vads_/)}.map{|value| value[1]} sign(vads_params) == params['signature'] end |
Instance Method Details
#params ⇒ Object
Public: Hash with non-nil parameters (and value) and their signature
Returns a hash
146 147 148 |
# File 'lib/system_pay/vads.rb', line 146 def params Hash[sorted_array + [['signature', signature]]] end |
#signature ⇒ Object
Public: Compute the signature of the request based on the parameters
Returns the signature string
139 140 141 |
# File 'lib/system_pay/vads.rb', line 139 def signature self.class.sign(sorted_values) end |