offsite_payments_przelewy24 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a9b1eb4f9866bd0dd1ab250de4308f46c2bbe6d667d6decfd84cd258af244678
4
+ data.tar.gz: '09d58ea2e3f1529b9cba983eea63198e901dcddd6519b0d14ebcd4a7be1da237'
5
+ SHA512:
6
+ metadata.gz: 22c7524124729e694a74b471217eebaec8e5ac0a4eaf462e34105ef8874ca8fb2c215e00be9f898813260b92f8e0c2a553c9fb61343ab280bc4c6c038ce01c74
7
+ data.tar.gz: 240462aea401ee9c6cd8bfe3de5ca0e9e8186d061e3b12db090bac258db5e2e2ab497a6fdcbb62a3b48e5a022f3c6d78f429312362914601705c41f3cf5fd36f
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2005-2014 Tobias Luetke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Offsite Payments
2
+
3
+ Offsite Payments is an extraction from the ecommerce system [Shopify](http://www.shopify.com). Shopify's requirements for a simple and unified API to handle dozens of different offsite payment pages (often called hosted payment pages) with very different exposed APIs was the chief principle in designing the library.
4
+
5
+ It was developed for usage in Ruby on Rails web applications and integrates seamlessly
6
+ as a Rails plugin. It should also work as a stand alone Ruby library, but much of the benefit is in the ActionView helpers which are Rails-specific.
7
+
8
+ This gem provides integration for Przelewy24 through the Offsite Payments gem.
9
+
10
+ ## Installation
11
+
12
+ ### From Git
13
+
14
+ You can check out the latest source from git:
15
+
16
+ git clone https://github.com/mbajur/offsite_payments_przelewy24.git
17
+
18
+ ### From RubyGems
19
+
20
+ Installation from RubyGems:
21
+
22
+ gem install offsite_payments_przelewy24
23
+
24
+ Or, if you're using Bundler, just add the following to your Gemfile:
25
+
26
+ gem 'offsite_payments_przelewy24'
27
+
28
+ ## Misc.
29
+
30
+ - This library is MIT licensed.
@@ -0,0 +1,225 @@
1
+ module OffsitePayments
2
+ module Integrations
3
+ module Przelewy24
4
+ mattr_accessor :test_url
5
+ self.test_url = 'https://sandbox.przelewy24.pl/trnDirect'
6
+
7
+ mattr_accessor :production_url
8
+ self.production_url = 'https://secure.przelewy24.pl/trnDirect'
9
+
10
+ mattr_accessor :test_verification_url
11
+ self.test_verification_url = 'https://sandbox.przelewy24.pl/trnVerify'
12
+
13
+ mattr_accessor :production_verification_url
14
+ self.production_verification_url = 'https://secure.przelewy24.pl/trnVerify'
15
+
16
+ def self.service_url
17
+ mode = OffsitePayments.mode
18
+
19
+ case mode
20
+ when :production
21
+ self.production_url
22
+ when :test
23
+ self.test_url
24
+ else
25
+ raise StandardError, "Integration mode set to an invalid value: #{mode}"
26
+ end
27
+ end
28
+
29
+ def self.verification_url
30
+ mode = OffsitePayments.mode
31
+
32
+ case mode
33
+ when :production
34
+ self.production_verification_url
35
+ when :test
36
+ self.test_verification_url
37
+ else
38
+ raise StandardError, "Integration mode set to an invalid value: #{mode}"
39
+ end
40
+ end
41
+
42
+ def self.make_amount(price)
43
+ price.present? ? (price.to_f.round(2) * 100).to_i : 0
44
+ end
45
+
46
+ def self.notification(post, options = {})
47
+ Notification.new(post)
48
+ end
49
+
50
+ def self.return(query_string, options = {})
51
+ Return.new(query_string)
52
+ end
53
+
54
+ class Helper < OffsitePayments::Helper
55
+ def initialize(order, account, options = {})
56
+ @secret = options.delete(:secret)
57
+ super
58
+
59
+ add_field 'p24_api_version', '3.2'
60
+ add_field 'p24_session_id', order
61
+ end
62
+
63
+ mapping :account, ['p24_merchant_id', 'p24_pos_id']
64
+ mapping :amount, 'p24_amount'
65
+ mapping :currency, 'p24_currency'
66
+ mapping :description, 'p24_description'
67
+ mapping :notify_url, 'p24_url_status'
68
+ mapping :return_url, 'p24_url_return'
69
+
70
+ def customer(params = {})
71
+ add_field 'p24_client', "#{params[:first_name]} #{params[:last_name]}"
72
+ add_field 'p24_email', params[:email]
73
+ end
74
+
75
+ def form_fields
76
+ @fields['p24_amount'] = Przelewy24.make_amount(@fields['p24_amount'])
77
+
78
+ @fields.merge(
79
+ p24_sign: generate_signature
80
+ )
81
+ end
82
+
83
+ private
84
+
85
+ def generate_signature
86
+ Digest::MD5.hexdigest([
87
+ @fields['p24_session_id'].to_s,
88
+ @fields['p24_merchant_id'].to_s,
89
+ @fields['p24_amount'].to_s,
90
+ @fields['p24_currency'].to_s,
91
+ ENV['PRZELEWY24_CRC_KEY'].to_s
92
+ ].join('|'))
93
+ end
94
+ end
95
+
96
+ class Notification < OffsitePayments::Notification
97
+ include ActiveUtils::PostsData
98
+
99
+ def self.recognizes?(params)
100
+ params.key?('p24_session_id') && params.key?('p24_amount')
101
+ end
102
+
103
+ def initialize(post, options = {})
104
+ raise ArgumentError if post.blank?
105
+ super
106
+ end
107
+
108
+ def complete?
109
+ !params['error'].present?
110
+ end
111
+
112
+ def account
113
+ params['p24_merchant_id']
114
+ end
115
+
116
+ def pos_id
117
+ params['p24_pos_id']
118
+ end
119
+
120
+ def amount
121
+ params['p24_amount']
122
+ end
123
+
124
+ def item_id
125
+ params['p24_session_id']
126
+ end
127
+
128
+ def transaction_id
129
+ params['p24_order_id']
130
+ end
131
+
132
+ def currency
133
+ params['p24_currency']
134
+ end
135
+
136
+ def method
137
+ params['p24_method']
138
+ end
139
+
140
+ def statement
141
+ params['p24_statement']
142
+ end
143
+
144
+ def security_key
145
+ params['p24_sign']
146
+ end
147
+
148
+ def acknowledge(_authcode = nil)
149
+ payload = {
150
+ p24_merchant_id: params['p24_merchant_id'],
151
+ p24_pos_id: params['p24_pos_id'],
152
+ p24_session_id: params['p24_session_id'],
153
+ p24_amount: params['p24_amount'],
154
+ p24_currency: params['p24_currency'],
155
+ p24_order_id: params['p24_order_id']
156
+ }
157
+
158
+ payload[:p24_sign] = verify_sign(payload)
159
+
160
+ response = ssl_post(Przelewy24.verification_url, parameterize(payload),
161
+ 'User-Agent' => 'Active Merchant -- http://activemerchant.org'
162
+ )
163
+ parsed_response = parse_response(response)
164
+ parsed_response.error == '0'
165
+ end
166
+
167
+ private
168
+
169
+ def parameterize(params)
170
+ params.reject { |k, v| v.blank? }.keys.sort.collect { |key| "#{key}=#{CGI.escape(params[key].to_s)}" }.join("&")
171
+ end
172
+
173
+ ## P24 Error codes
174
+ # err00: Incorrect call
175
+ # err01: Authorization answer confirmation was not received.
176
+ # err02: Authorization answer was not received.
177
+ # err03: This query has been already processed.
178
+ # err04: Authorization query incomplete or incorrect.
179
+ # err05: Store configuration cannot be read.
180
+ # err06: Saving of authorization query failed.
181
+ # err07: Another payment is being concluded.
182
+ # err08: Undetermined store connection status.
183
+ # err09: Permitted corrections amount has been exceeded.
184
+ # err10: Incorrect transaction value!
185
+ # err49: To high transaction risk factor.
186
+ # err51: Incorrect reference method.
187
+ # err52: Incorrect feedback on session information!
188
+ # err53: Transaction error !: err54: Incorrect transaction value!
189
+ # err55: Incorrect transaction id!
190
+ # err56: Incorrect card
191
+ # err57: Incompatibility of TEST flag
192
+ # err58: Incorrect sequence number !
193
+ # err101: Incorrect call
194
+ # err102: Allowed transaction time has expired
195
+ # err103: Incorrect transfer value.
196
+ # err104: Transaction awaits confirmation.
197
+ # err105: Transaction finished after allowed time.
198
+ # err106: Transaction result verification error
199
+ # err161: Transaction request terminated by user
200
+ # err162: Transaction request terminated by user
201
+ def parse_response(response)
202
+ ret = OpenStruct.new
203
+ response.split('&').each do |arg|
204
+ line = arg.split('=')
205
+ ret[line[0].strip] = line[1].force_encoding('ISO-8859-2').encode!('UTF-8')
206
+ end
207
+ ret
208
+ end
209
+
210
+ def verify_sign(payload)
211
+ Digest::MD5.hexdigest([
212
+ payload[:p24_session_id],
213
+ payload[:p24_order_id],
214
+ Przelewy24.make_amount(payload[:p24_amount]),
215
+ payload[:p24_currency],
216
+ ENV.fetch('PRZELEWY24_CRC_KEY')
217
+ ].join('|'))
218
+ end
219
+ end
220
+
221
+ class Return < OffsitePayments::Return
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,12 @@
1
+ module OffsitePaymentsPrzelewy24
2
+ require 'offsite_payments'
3
+ require_relative 'offsite_payments/integrations/przelewy24'
4
+
5
+ mattr_accessor :mode
6
+ self.mode = :production
7
+
8
+ # A check to see if we're in test mode
9
+ def self.test?
10
+ self.mode == :test
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module OffsitePaymentsPrzelewy24
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: offsite_payments_przelewy24
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michał Bajur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: offsite_payments
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: money
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: This gem extends the activemerchant offsite_payments gem providing integration
70
+ of Przelewy24.
71
+ email: mbajur@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - lib/offsite_payments/integrations/przelewy24.rb
79
+ - lib/offsite_payments_przelewy24.rb
80
+ - lib/offsite_payments_przelewy24/version.rb
81
+ homepage: https://github.com/mbajur/offsite_payments_migs
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.7.7
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Przelewy24 integration for the activemerchant offsite_payments gem.
105
+ test_files: []