rails4-przelewy24 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f37ff279b63fa0d281e6fb1a5a5598137117110
4
+ data.tar.gz: 9d98d586c156501efca4b08dd3c5a23594e13ab1
5
+ SHA512:
6
+ metadata.gz: 4da113ee841fa080ce4d535b16f15c4f03a021f6bf3cf0ed4bc5b7f6e2ed712aee0eec0fc23046e7bc19e801ab8d8fad6b45f69da05ac82e4ec5ef8e32118d84
7
+ data.tar.gz: fd8b32f70999a2c06343cb9c7db35d0d74439cefbf1ff2c7804c46d393ac4cf4fb87ac23a4baa7ae451184eeb23c45aa76e77753d6b046691dede9b2a026dc75
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails4-przelewy24.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Mariusz Henn
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # Przelewy24 for rails4
2
+
3
+ This gem provide basic communication wrapper with przelewy24 payment API v.3.2
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rails4-przelewy24'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Configuration
16
+
17
+ Required in Your config file:
18
+
19
+ Przelewy24.configure do |config|
20
+ config.merchant_id = <Integer:your_merchant_id>
21
+ config.crc = <String:your_crc_from_przelewy24_profile>
22
+ config.return_url = <String:url_to_return_from_payment_page>
23
+ end
24
+
25
+ You can add separate configuration for your sandbox in development and test environments.
26
+
27
+ ## Testing and Developing
28
+
29
+ In environments other than production, this module communicate with przelewy24 sandbox. This prevents requirement to make real money transfer when testing.
30
+
31
+ ## Usage
32
+
33
+ Since this gem is only a function wrapper, You have to create Your own model for payments and transaction flow controller
34
+ according to przelewy24 specification: https://www.przelewy24.pl/files/cms/13/przelewy24_specification.pdf.
35
+
36
+ ### Initializing
37
+ Dont place p24_ prefix for options. Dont format Your amount to CURRENCY/100 type. This gem will do it for You.
38
+
39
+ example_options = {session_id: 123, amount: 1.23, currency:'PLN', description:'desc', email:'mariusz.henn@gmail.com', country:'pl', url_status: 'http://example.com/status', url_return: 'http://example.com/success_transaction'}
40
+ transaction = Przelewy24::Transaction.new example_options
41
+
42
+ ### Registering transaction
43
+
44
+ transaction.register_transaction
45
+
46
+ This function will provide transaction.token and transaction.transaction_url so You can redirect user to payment site.
47
+
48
+ ### Verifying transaction status
49
+ Przelewy24 will send You transaction status to url_status. To verify validity of received params You can do:
50
+
51
+ transaction.verify_transaction_status received_params
52
+
53
+ ### Confirming transaction
54
+ To confirm transaction (it is required to process money transfer from customer to You in przelewy24 system)
55
+
56
+ transaction.confirm_transaction
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/[my-github-username]/rails4-przelewy24/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
3
+
4
+ desc 'Open an irb session preloaded with this library'
5
+ task :console do
6
+ sh 'irb -rubygems -I lib -r rails4-przelewy24.rb'
7
+ end
@@ -0,0 +1,44 @@
1
+ require 'rails'
2
+
3
+ module Przelewy24
4
+ class Configuration
5
+ attr_accessor :merchant_id, :crc, :url_return, :url_status
6
+ attr_accessor :test_connection_params, :register_transaction_params, :confirm_transaction_params
7
+ attr_reader :test_url, :register_url, :request_url, :confirm_transaction_url
8
+
9
+ def initialize
10
+ @merchant_id = nil
11
+ @crc = nil
12
+ namespace = Rails.env=='production' ? 'secure' : 'sandbox'
13
+ @test_url = "https://#{namespace}.przelewy24.pl/testConnection"
14
+ @register_url = "https://#{namespace}.przelewy24.pl/trnRegister"
15
+ @request_url = "https://#{namespace}.przelewy24.pl/trnRequest/"
16
+ @confirm_transaction_url = "https://#{namespace}.przelewy24.pl/trnVerify"
17
+ @url_return = nil
18
+ @url_status = nil
19
+ @test_connection_params = hash_of %w(merchant_id pos_id sign)
20
+ @register_transaction_params = hash_of %w(session_id merchant_id pos_id amount currency description email country url_return url_status api_version sign)
21
+ @confirm_transaction_params = hash_of %w(merchant_id pos_id session_id amount currency order_id sign)
22
+ @api_version = '3.2'
23
+ end
24
+
25
+ def default_transaction_options
26
+ out = {}
27
+ self.instance_values.each do |o,v|
28
+ out[o.to_sym] = v
29
+ end
30
+ out
31
+ end
32
+
33
+ private
34
+
35
+ def hash_of(params)
36
+ new_hash = Hash.new
37
+ params.each do |k|
38
+ new_hash[('p24_'+k).to_sym] = nil
39
+ end
40
+ new_hash
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,100 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Przelewy24
5
+ class Transaction
6
+ attr_accessor :options
7
+ attr_reader :token, :transaction_url
8
+
9
+ def initialize(options = {})
10
+ @conf = Przelewy24.config
11
+ @options = p24_options(@conf.default_transaction_options).merge(p24_options(options))
12
+ end
13
+
14
+ def test_connection
15
+ params = create_params @conf.test_connection_params
16
+ sign params, %w(p24_pos_id)
17
+ verify_params params
18
+ response = query_p24 @conf.test_url, params
19
+ response['error'] == '0'
20
+ end
21
+
22
+ def register_transaction
23
+ params = create_params @conf.register_transaction_params
24
+ unless @options[:p24_order_id].present?
25
+ sign params, %w(p24_session_id p24_merchant_id p24_amount p24_currency)
26
+ verify_params params
27
+ response = query_p24 @conf.register_url, params
28
+ @token = response['token']
29
+ params.merge({:p24_token => @token})
30
+ else
31
+ @token = params[:p24_token]
32
+ end
33
+ @transaction_url = @conf.request_url + @token
34
+ end
35
+
36
+ def verify_transaction_status(params)
37
+ test = [params[:p24_session_id],params[:p24_order_id],params[:p24_amount],params[:p24_currency],@conf.crc]
38
+ raise 'malformed sign' unless Digest::MD5.hexdigest(test.join('|')) == params[:p24_sign]
39
+ %i(p24_session_id p24_amount p24_currency).each do |t|
40
+ raise "param #{t} not match" unless params[t].to_s == @options[t].to_s
41
+ end
42
+ @options[:p24_order_id] = params[:p24_order_id]
43
+ true
44
+ end
45
+
46
+ def confirm_transaction
47
+ params = create_params @conf.confirm_transaction_params
48
+ sign params, %w(p24_session_id p24_order_id p24_amount p24_currency)
49
+ verify_params params
50
+ response = query_p24 @conf.confirm_transaction_url, params
51
+ response['error'] == '0'
52
+ end
53
+
54
+ private
55
+
56
+ attr_writer :conf
57
+
58
+ def p24_options(options)
59
+ out = {}
60
+ options.each do |k, v|
61
+ out[('p24_'+k.to_s).to_sym] = v
62
+ end
63
+ out[:p24_pos_id] = @conf.merchant_id unless out[:p24_pos_id].present?
64
+ out[:p24_amount] = (out[:p24_amount]*100).to_int if out[:p24_amount].present?
65
+ out
66
+ end
67
+
68
+ def query_p24(url, params)
69
+ response = HTTParty.post url, body: params
70
+ response = Rack::Utils.parse_nested_query response.parsed_response
71
+ raise response['error']+': '+response['errorMessage'] unless response['error'] == '0'
72
+ response
73
+ end
74
+
75
+ def verify_params(params)
76
+ params.each do |p, v|
77
+ raise "#{p} cannot be nil" unless v.present?
78
+ end
79
+ end
80
+
81
+ def create_params(source_params = {})
82
+ params = {}
83
+ source_params.each do |k, v|
84
+ params[k] = @options[k]
85
+ end
86
+ params
87
+ end
88
+
89
+ def sign(params, with_params = {})
90
+ p = []
91
+ with_params.each do |k|
92
+ p << @options[k.to_sym]
93
+ end
94
+ p << @conf.crc
95
+ s = Digest::MD5.hexdigest p.join('|')
96
+ params[:p24_sign] = s
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ module Przelewy24
2
+ VERSION = '0.1.6'
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'przelewy24/version'
2
+ require 'przelewy24/configuration'
3
+ require 'przelewy24/transaction'
4
+ require 'action_view'
5
+
6
+ module Przelewy24
7
+ attr_writer :config
8
+
9
+ def self.config
10
+ @config ||= Configuration.new
11
+ end
12
+
13
+ def self.configure
14
+ yield(config) if block_given?
15
+ end
16
+
17
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'przelewy24/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rails4-przelewy24'
8
+ spec.version = Przelewy24::VERSION
9
+ spec.authors = ['Mariusz Henn']
10
+ spec.email = ['mariusz.henn@gmail.com']
11
+ spec.summary = %q{przelewy24 payment provider}
12
+ spec.description = %q{This gem provide basic methods to communicate with przelewy24 payment system}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake', '>= 10.3.2'
23
+ spec.add_development_dependency 'rspec-rails', '>= 3.3.0'
24
+ spec.add_runtime_dependency 'httparty', '~> 0.13.5'
25
+ spec.add_runtime_dependency 'rails', '>= 4.0.0'
26
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'action_controller'
3
+ describe Przelewy24 do
4
+
5
+ before do
6
+ Przelewy24.configure do |config|
7
+ config.merchant_id = 37154
8
+ config.crc = 'a65ac19629e9c9fa'
9
+ config.url_return = 'http://example.com/success_transaction'
10
+ end
11
+ end
12
+
13
+ context 'is configurable' do
14
+ let(:merchant_id) { Przelewy24.config.merchant_id }
15
+ it { expect(merchant_id).to equal 37154 }
16
+ end
17
+
18
+ describe Przelewy24::Transaction do
19
+ let(:options) {{order_id:18506028, session_id: 1, amount: 1.23, currency:'PLN', description:'desc', email:'mariusz.henn@gmail.com', country:'pl', url_status: 'example.com/status', url_return: 'http://example.com/success_transaction'}}
20
+ subject (:transaction){ Przelewy24::Transaction.new options }
21
+
22
+ context '#transaction' do
23
+ xit 'register transaction' do
24
+ transaction.register_transaction
25
+ puts transaction.token
26
+ expect(transaction.token).to be_a_kind_of String
27
+ end
28
+
29
+ it 'verifying received transaction status' do
30
+ params =ActionController::Parameters.new({'p24_merchant_id' => 37154,
31
+ 'p24_pos_id' => 37154,
32
+ 'p24_session_id' => 1,
33
+ 'p24_amount'=> 123,
34
+ 'p24_currency' => 'PLN',
35
+ 'p24_order_id'=> 18506028,
36
+ 'p24_method'=> 16,
37
+ 'p24_statement'=> 'payment for invoice',
38
+ 'p24_sign'=> '8d2137c81c95c449c7dea25354c34dc4'})
39
+ expect(transaction.verify_transaction_status(params)).to equal true
40
+ end
41
+
42
+ it {expect(transaction.confirm_transaction).to equal true}
43
+ end
44
+
45
+ context '#test_connection' do
46
+ it { expect(transaction.test_connection).to equal true }
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1 @@
1
+ require 'rails4-przelewy24'
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails4-przelewy24
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Mariusz Henn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 10.3.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 10.3.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.3.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.13.5
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.13.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 4.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 4.0.0
83
+ description: This gem provide basic methods to communicate with przelewy24 payment
84
+ system
85
+ email:
86
+ - mariusz.henn@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/przelewy24/configuration.rb
98
+ - lib/przelewy24/transaction.rb
99
+ - lib/przelewy24/version.rb
100
+ - lib/rails4-przelewy24.rb
101
+ - rails4-przelewy24.gemspec
102
+ - spec/przelewy24_spec.rb
103
+ - spec/spec_helper.rb
104
+ - tasks/przelewy24/rspec.rake
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: przelewy24 payment provider
129
+ test_files:
130
+ - spec/przelewy24_spec.rb
131
+ - spec/spec_helper.rb