system_pay 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemspec ADDED
@@ -0,0 +1 @@
1
+ gemspec
data/Readme.markdown ADDED
@@ -0,0 +1,97 @@
1
+ # SystemPay
2
+
3
+ SystemPay is a gem to ease credit card payment with Natixis Paiements / CyberplusPaiement (Credit du Nord) bank system. It's a Ruby on Rails port of the connexion kits published by the bank.
4
+
5
+ * Gem Homepage : [site](http://github.com/iMenlo/system_pay)
6
+ * Cyberplus SystemPay documentation : [site](https://systempay.cyberpluspaiement.com)
7
+
8
+ ## INSTALL
9
+
10
+ gem install git@github.com:iMenlo/system_pay.git
11
+
12
+ or, in your Gemfile
13
+
14
+ gem 'system_pay', :git => 'git://github.com/iMenlo/system_pay.git'
15
+
16
+ ## USAGE
17
+
18
+ ### in environment.rb :
19
+
20
+ # Your vads_site_id
21
+ SystemPay.vads_site_id = '654927625'
22
+
23
+ ### in development.rb :
24
+
25
+ # Your test certificat
26
+ SystemPay.certificat = '9123456299120752'
27
+
28
+ ### in production.rb :
29
+
30
+ # Your production certificat
31
+ SystemPay.certificat = '7193156219823756'
32
+ # Set the production mode
33
+ SystemPay.vads_ctx_mode = 'PRODUCTION'
34
+
35
+
36
+ ### in order controller :
37
+
38
+ helper :'system_pay/form'
39
+ @system_pay = SystemPay.new(:amount => @order.amount_in_cents, :trans_id => @order.id)
40
+
41
+ ### in order view :
42
+
43
+ = form_tag @system_pay.target_url do
44
+ = system_pay_hidden_fields(@system_pay)
45
+ = submit_tag "Access to the bank website"
46
+
47
+ ### in a controller for call back from the bank :
48
+
49
+ class OrderTransactionsController < ApplicationController
50
+
51
+ protect_from_forgery :except => [:bank_callback]
52
+
53
+ def bank_callback
54
+ @system_pay = SystemPay.new(params)
55
+ if @system_pay.valid_signature?(params[:signature])
56
+
57
+ order_transaction = OrderTransaction.find_by_reference params[:reference], :last
58
+ order = order_transaction.order
59
+
60
+ return_code = params['vads_result']
61
+
62
+ if return_code == "Annulation"
63
+ order.cancel!
64
+ order.update_attribute :description, "Paiement refusé par la banque."
65
+
66
+ elsif return_code == "payetest"
67
+ order.pay!
68
+ order.update_attribute :description, "TEST accepté par la banque."
69
+ order_transaction.update_attribute :test, true
70
+
71
+ elsif return_code == "00"
72
+ order.pay!
73
+ order.update_attribute :description, "Paiement accepté par la banque."
74
+ order_transaction.update_attribute :test, false
75
+ end
76
+
77
+ order_transaction.update_attribute :success, true
78
+
79
+ receipt = "0"
80
+ else
81
+ order.transaction_declined!
82
+ order.update_attribute :description, "Document Falsifie."
83
+ order_transaction.update_attribute :success, false
84
+
85
+ receipt = "1\n#{PaiementCic.mac_string}"
86
+ end
87
+ render :text => "Pragma: no-cache\nContent-type: text/plain\n\nversion=2\ncdr=#{receipt}"
88
+ end
89
+
90
+
91
+ ## Thanks
92
+
93
+ This gem is inspired by Novelys [paiement_cic](http://github.com/novelys/paiementcic), many thanks to the team.
94
+
95
+ ## License
96
+ Copyright (c) 2012 iMenlo Team, released under the MIT license
97
+
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "system_pay"
2
+ require "syetem_pay/form_helper"
@@ -0,0 +1,13 @@
1
+ module SystemPay::FormHelper
2
+
3
+ def system_pay_hidden_fields(system_pay)
4
+
5
+ res = "\n"
6
+ system_pay.params.each{|key, value|
7
+ res << hidden_field_tag(key, value) << "\n"
8
+ }
9
+ res.html_safe
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ class SystemPay
2
+ VERSION = '0.0.5'
3
+ end
data/lib/system_pay.rb ADDED
@@ -0,0 +1,112 @@
1
+ require 'active_support/all'
2
+ class SystemPay
3
+ autoload :FormHelper, "system_pay/form_helper"
4
+
5
+ @@target_url = "https://paiement.systempay.fr/vads-payment/"
6
+ cattr_accessor :target_url
7
+
8
+ @@vads_action_mode = 'INTERACTIVE'
9
+ cattr_accessor :vads_action_mode
10
+
11
+ @@vads_ctx_mode = 'TEST' # or 'PRODUCTION'
12
+ cattr_accessor :vads_ctx_mode
13
+
14
+ @@vads_contrib = 'Ruby'
15
+ cattr_accessor :vads_contrib
16
+
17
+ @@vads_page_action = 'PAYMENT'
18
+ cattr_accessor :vads_page_action
19
+
20
+ @@vads_payment_config = 'SINGLE'
21
+ cattr_accessor :vads_payment_config
22
+
23
+ @@vads_return_mode = 'GET'
24
+ cattr_accessor :vads_return_mode
25
+
26
+ @@vads_site_id = '123456' # change this value
27
+ cattr_accessor :vads_site_id
28
+
29
+ @@vads_validation_mode = '1'
30
+ cattr_accessor :vads_validation_mode
31
+
32
+ @@vads_version = 'V2'
33
+ cattr_accessor :vads_version
34
+
35
+ @@certificat = '1122334455667788'
36
+ cattr_accessor :certificat
37
+
38
+ attr_accessor :vads_amount, :vads_available_languages, :vads_capture_delay, :vads_contracts, :vads_currency, :vads_cust_address, :vads_cust_cell_phone,
39
+ :vads_cust_email, :vads_redirect_error_message, :vads_redirect_success_message, :vads_trans_date, :vads_trans_id, :vads_url_cancel, :vads_url_error,
40
+ :vads_url_referral, :vads_url_refused, :vads_url_success
41
+
42
+ # Public: Creation of new instance.
43
+ #
44
+ # args - The hash of systempay parameters as describe in the implementation
45
+ # document. Note that each key should *not* contain the vads_ prefix.
46
+ # :amount - Should be in cents
47
+ # :trans_id - Will be automatically padded with zeros
48
+ #
49
+ # Examples
50
+ #
51
+ # SystemPay.new(:amount => 100, :trans_id => 10, :url_return => 'http://mywebsite.com/return_url')
52
+ #
53
+ # Returns a new instance object
54
+ def initialize args=nil
55
+ args.each do |k,v|
56
+ if k.to_s.match(/^vads_/)
57
+ instance_variable_set("@#{k}", v) if v.present? && respond_to?(k)
58
+ else
59
+ instance_variable_set("@vads_#{k}", v) if v.present? && respond_to?("vads_#{k}")
60
+ end
61
+ end if args
62
+
63
+ raise ArgumentError.new("You must specify a non blank :amount parameter") unless @vads_amount.present?
64
+ raise ArgumentError.new("You must specify a non blank :trans_id parameter") unless @vads_trans_id.present?
65
+
66
+ @vads_currency ||= '978' # Euros
67
+ @vads_trans_date ||= Time.now.strftime("%Y%m%d%H%M%S")
68
+ @vads_trans_id = @vads_trans_id.to_s.rjust(6, '0')
69
+
70
+ end
71
+
72
+ # Public: Perform the signature of the request based on the parameters
73
+ def signature
74
+ self.class.sign(sorted_values)
75
+ end
76
+
77
+ # Public: Hash with parameters and value of the object
78
+ def params
79
+ Hash[sorted_array + [['signature', signature]]]
80
+ end
81
+
82
+ # Public: Verify that the returned signature is valid.
83
+ # Return boolean
84
+ def self.valid_signature?(params)
85
+ vads_params = params.sort.select{|value| value[0].match(/^vads_/)}.map{|value| value[1]}
86
+ sign(vads_params) == params['signature']
87
+ end
88
+
89
+
90
+ private
91
+
92
+ def self.sign(values)
93
+ Digest::SHA1.hexdigest((values+[certificat]).join("+"))
94
+ end
95
+
96
+ def instance_variables_array
97
+ instance_variables.map { |name| [name[1..-1], instance_variable_get(name)] }
98
+ end
99
+
100
+ def self.class_variables_array
101
+ class_variables.select{|name| name.match(/^@@vads_/)}.map { |name| [name[2..-1], class_variable_get(name)] }
102
+ end
103
+
104
+ def sorted_array
105
+ (instance_variables_array + self.class.class_variables_array).uniq.sort
106
+ end
107
+
108
+ def sorted_values
109
+ sorted_array.map{|value| value[1]}
110
+ end
111
+
112
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "system_pay/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'system_pay'
7
+ s.version = SystemPay::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+
10
+ s.summary = "Ruby wrapper for Natixis Paiements / CyberplusPaiement payment api"
11
+ s.description = "SystemPay is a gem to ease credit card payment with Natixis Paiements / CyberplusPaiement bank system. It's a Ruby on Rails port of the connexion kits published by the bank."
12
+
13
+ s.authors = ['Sylvain Gautier (iMenlo)']
14
+ s.email = ['sylvain@imenlo.com']
15
+ s.homepage = 'https://github.com/iMenlo/system_pay'
16
+
17
+ s.add_development_dependency "active_support", "~> 3.0.0"
18
+ s.add_development_dependency 'rake', '~> 0.9.2'
19
+ s.add_development_dependency 'rspec', '~> 2.6.0'
20
+
21
+ # ensure the gem is built out of versioned files
22
+ s.files = `git ls-files`.split("\n")
23
+ s.require_paths = ["lib"]
24
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: system_pay
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 5
10
+ version: 0.0.5
11
+ platform: ruby
12
+ authors:
13
+ - Sylvain Gautier (iMenlo)
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-20 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: active_support
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 63
46
+ segments:
47
+ - 0
48
+ - 9
49
+ - 2
50
+ version: 0.9.2
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 23
62
+ segments:
63
+ - 2
64
+ - 6
65
+ - 0
66
+ version: 2.6.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: SystemPay is a gem to ease credit card payment with Natixis Paiements / CyberplusPaiement bank system. It's a Ruby on Rails port of the connexion kits published by the bank.
70
+ email:
71
+ - sylvain@imenlo.com
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - Gemspec
80
+ - Readme.markdown
81
+ - init.rb
82
+ - lib/system_pay.rb
83
+ - lib/system_pay/form_helper.rb
84
+ - lib/system_pay/version.rb
85
+ - system_pay.gemspec
86
+ has_rdoc: true
87
+ homepage: https://github.com/iMenlo/system_pay
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.6.2
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Ruby wrapper for Natixis Paiements / CyberplusPaiement payment api
120
+ test_files: []
121
+