przelewy24 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in przelewy24.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Michał Młoźniak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Przelewy24
2
+
3
+ This gem implements basic integration with Przelewy24 payment gateway. It is not yet production ready. It lacks tests and error handling. Use at your own risk.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'przelewy24'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install przelewy24
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/ronin/przelewy24/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "przelewy24"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,69 @@
1
+ require 'net/http'
2
+ require 'digest'
3
+ require 'cgi'
4
+
5
+ module Przelewy24
6
+ class Client
7
+ attr_reader :merchant_id, :pos_id, :crc, :gateway_url
8
+
9
+ def initialize(merchant_id, pos_id, crc)
10
+ @merchant_id = merchant_id
11
+ @pos_id = pos_id
12
+ @crc = crc
13
+ @gateway_url = 'sandbox.przelewy24.pl'
14
+ end
15
+
16
+ def test_connection
17
+ signature = Digest::MD5.hexdigest("#{merchant_id}|#{crc}")
18
+
19
+ connection = Net::HTTP.new(gateway_url, 443)
20
+ connection.use_ssl = true
21
+
22
+ response = connection.start do |http|
23
+ post = Net::HTTP::Post.new('/testConnection')
24
+ post.set_form_data(p24_merchant_id: merchant_id, p24_pos_id: merchant_id, p24_sign: signature)
25
+ http.request(post)
26
+ end
27
+
28
+ Response.new(response)
29
+ end
30
+
31
+ def create_transaction(data = {})
32
+ Transaction.new(data.reverse_merge(merchant_id: merchant_id, pos_id: pos_id, crc: crc))
33
+ end
34
+
35
+ def register_transaction(transaction)
36
+ connection = Net::HTTP.new(gateway_url, 443)
37
+ connection.use_ssl = true
38
+
39
+ response = connection.start do |http|
40
+ post = Net::HTTP::Post.new('/trnRegister')
41
+ post.set_form_data(transaction.to_data)
42
+ http.request(post)
43
+ end
44
+
45
+ Response.new(response)
46
+ end
47
+
48
+ def verify_transaction(data = {})
49
+ connection = Net::HTTP.new(gateway_url, 443)
50
+ connection.use_ssl = true
51
+
52
+ signature = Digest::MD5.hexdigest([
53
+ data['p24_session_id'],
54
+ data['p24_order_id'],
55
+ data['p24_amount'],
56
+ data['p24_currency'],
57
+ crc
58
+ ].join('|'))
59
+
60
+ response = connection.start do |http|
61
+ post = Net::HTTP::Post.new('/trnVerify')
62
+ post.set_form_data(data.merge('p24_sign' => signature))
63
+ http.request(post)
64
+ end
65
+
66
+ Response.new(response)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,14 @@
1
+ module Przelewy24
2
+ class Response
3
+ attr_reader :attributes
4
+
5
+ def initialize(http_response)
6
+ puts http_response.body
7
+ @attributes = Rack::Utils.parse_nested_query(http_response.body)
8
+ end
9
+
10
+ def success?
11
+ attributes['error'] == '0'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,52 @@
1
+ module Przelewy24
2
+ class Transaction
3
+ attr_reader :session_id, :merchant_id, :amount, :crc, :description, :email, :signature
4
+
5
+ def initialize(data = {})
6
+ @data ||= {}
7
+
8
+ @session_id = data[:session_id] || generate_session_id
9
+ @merchant_id = data[:merchant_id]
10
+ @crc = data[:crc]
11
+ @amount = data[:amount]
12
+ @description = data[:description]
13
+ @email = data[:email]
14
+ @signature = calculate_signature
15
+ end
16
+
17
+ def to_data
18
+ {
19
+ p24_merchant_id: merchant_id,
20
+ p24_pos_id: merchant_id,
21
+ p24_session_id: session_id,
22
+ p24_amount: amount,
23
+ p24_currency: 'PLN',
24
+ p24_description: description,
25
+ p24_email: email,
26
+ p24_country: 'PL',
27
+ p24_url_return: 'http://54e3607b.ngrok.com/report',
28
+ p24_url_status: 'http://54e3607b.ngrok.com/report',
29
+ p24_wait_for_result: '1',
30
+ p24_sign: signature,
31
+ p24_encoding: 'UTF-8',
32
+ p24_api_version: '3.2'
33
+ }
34
+ end
35
+
36
+ private
37
+
38
+ def calculate_signature
39
+ @signature = Digest::MD5.hexdigest([
40
+ session_id,
41
+ merchant_id,
42
+ amount,
43
+ 'PLN',
44
+ crc
45
+ ].join('|'))
46
+ end
47
+
48
+ def generate_session_id
49
+ Time.zone.now.to_i
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Przelewy24
2
+ VERSION = "0.1.0"
3
+ end
data/lib/przelewy24.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "przelewy24/version"
2
+
3
+ module Przelewy24
4
+ end
@@ -0,0 +1,24 @@
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 = "przelewy24"
8
+ spec.version = Przelewy24::VERSION
9
+ spec.authors = ["Michał Młoźniak"]
10
+ spec.email = ["m.mlozniak@gmail.com"]
11
+
12
+ spec.summary = %q{Integration with Przelewy24 payment gateway.}
13
+ spec.description = %q{Integration with Przelewy24 payment gateway.}
14
+ spec.homepage = "https://github.com/visualitypl/przelewy24"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: przelewy24
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michał Młoźniak
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-05-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.8'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.8'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ description: Integration with Przelewy24 payment gateway.
47
+ email:
48
+ - m.mlozniak@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - .travis.yml
56
+ - CODE_OF_CONDUCT.md
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - bin/console
62
+ - bin/setup
63
+ - lib/przelewy24.rb
64
+ - lib/przelewy24/client.rb
65
+ - lib/przelewy24/response.rb
66
+ - lib/przelewy24/transaction.rb
67
+ - lib/przelewy24/version.rb
68
+ - przelewy24.gemspec
69
+ homepage: https://github.com/visualitypl/przelewy24
70
+ licenses:
71
+ - MIT
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.23
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Integration with Przelewy24 payment gateway.
94
+ test_files: []