payonline 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ffecc72ab316af139858d166bad9f2f061fee703
4
+ data.tar.gz: e37aa7b384f956ab5a019081a9a8da21efbe042d
5
+ SHA512:
6
+ metadata.gz: 73e84b51ee88012b49eb71a948b7676a285dcc1a7000a0d1d5bd0ae9b81ce9432f6d01af43dde8933516dbefc2c6986442e5edf079e24fcca7bf72b53265f0b6
7
+ data.tar.gz: fa5ad0967fc1ed6b014ea35140332bfb9f89f5a2ec1496aeb3e22b97306aa9bec0a024fd4ea3111f3db45d8037e484b88dd54ac26b7f64ae2bc85677044e3f39
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in payonline.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ ## Payonline
2
+
3
+ This is a thin wrapper library that makes using PayOnline API a bit easier.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'payonline'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle
17
+ ```
18
+
19
+ ## Configuring
20
+
21
+ Create initialize file. This file is usually located at /config/initializers/payonline.rb
22
+ ```ruby
23
+ Payonline.config do |c|
24
+ c.merchant_id = '12345'
25
+ c.private_security_key = '3844908d-4c2a-42e1-9be0-91bb5d068d22'
26
+ c.return_url = 'http://you_domain/payments/success'
27
+ c.fail_url = 'http://you_domain/payments/failed'
28
+ end
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ Get payment link
34
+
35
+ ```ruby
36
+ Payonline::PaymentGateway.new(order_id: 56789, amount: 9.99 , currency: 'USD').get_payment_url
37
+ ```
38
+
39
+ Check Call-back
40
+ ```ruby
41
+ @paymant_response = Payonline::PaymentResponse.new(prms)
42
+ if paymant_response.valid_payment?
43
+ Order.find(@paymant_response.order_id).pay
44
+ end
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Clone it `git clone http://github.com/path/to/your/fork`
51
+ 3. Create your feature branch `git checkout -b my-new-feature`
52
+ 4. Commit your changes `git commit -am 'Add some feature`
53
+ 5. Push to the branch `git push origin my-new-feature`
54
+ 6. Create new pull request through Github
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/payonline.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'yaml'
2
+ require 'payonline/config'
3
+ require 'payonline/payment_gateway'
4
+ require 'payonline/payment_response'
5
+ require 'payonline/signature'
6
+
7
+ module Payonline
8
+ extend self
9
+
10
+ def self.configuration
11
+ @configuration ||= Config.new
12
+ end
13
+
14
+ def self.config
15
+ config = configuration
16
+ yield(config)
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Payonline
2
+ class Config
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :merchant_id, :private_security_key, :return_url, :fail_url
6
+
7
+ def initialize(options = {})
8
+ options.each do |key, value|
9
+ config.send("#{key}=", value)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,70 @@
1
+ module Payonline
2
+ class PaymentGateway
3
+ class Params < SimpleDelegator
4
+
5
+ REQUIED_PARAMS = %w(order_id amount currency valid_until order_description return_url fail_url return_url)
6
+
7
+ def initialize(params)
8
+ @params = prepare_params(params)
9
+
10
+ filter_params
11
+
12
+ __setobj__ @params
13
+ end
14
+
15
+ def to_query
16
+ @params.each_with_object({}) do |(k, v), params|
17
+ params[k.camelize] = v
18
+ end.to_query
19
+ end
20
+
21
+ private
22
+
23
+ def prepare_params(params)
24
+ params[:amount] = '%.2f' % params[:amount]
25
+
26
+ default_params = { return_url: return_url, fail_url: fail_url }
27
+ params.merge(default_params)
28
+ end
29
+
30
+ def filter_params
31
+ @params.select! { |k, v| REQUIED_PARAMS.include?(k) && v }
32
+ end
33
+
34
+ def return_url
35
+ @return_url ||= Payonline.configuration.return_url
36
+ end
37
+
38
+ def fail_url
39
+ @fail_url ||= Payonline.configuration.fail_url
40
+ end
41
+ end
42
+
43
+ SIGNED_PARAMS = %w(order_id amount currency valid_until order_description)
44
+
45
+ def initialize(params={})
46
+ @params = Params.new(params.with_indifferent_access)
47
+ end
48
+
49
+ def get_payment_url(type = 'card')
50
+ params = Payonline::Signature.sign_params(@params, SIGNED_PARAMS)
51
+
52
+ "#{url_by_kind_of_payment(type)}?#{params.to_query}"
53
+ end
54
+
55
+ private
56
+
57
+ def url_by_kind_of_payment(type, language = 'ru')
58
+ case type.to_s
59
+ when 'qiwi'
60
+ "https://secure.payonlinesystem.com/#{language}/payment/select/qiwi/"
61
+ when 'webmoney'
62
+ "https://secure.payonlinesystem.com/#{language}/payment/select/webmoney/"
63
+ when 'yandexmoney'
64
+ "https://secure.payonlinesystem.com/#{language}/payment/select/webmoney/"
65
+ when 'card'
66
+ "https://secure.payonlinesystem.com/#{language}/payment/"
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,32 @@
1
+ module Payonline
2
+ class PaymentResponse
3
+ extend Forwardable
4
+
5
+ attr_accessor :response, :params
6
+
7
+ RESPONSE_PARAMS = %w(date_time transaction_id order_id amount currency)
8
+
9
+ def_delegators :params, *RESPONSE_PARAMS
10
+
11
+ def initialize(response = {})
12
+ self.response = response
13
+ self.params = OpenStruct.new(normalize_params)
14
+ end
15
+
16
+ def valid_payment?
17
+ keys = RESPONSE_PARAMS.each_with_object([]).each do |key, array|
18
+ array << response.keys.select{ |e| e.underscore == key }.first
19
+ end
20
+
21
+ params.security_key == Payonline::Signature.digest(response, keys)
22
+ end
23
+
24
+ private
25
+
26
+ def normalize_params
27
+ result = response.each_with_object({}) do |(k, v), params|
28
+ params[k.underscore] = v
29
+ end.with_indifferent_access
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ module Payonline
2
+ class Signature
3
+ def self.digest(sign_params, keys=[])
4
+ if keys.present?
5
+ sign_params = sign_params.slice(*keys)
6
+ end
7
+
8
+ sign_params.merge!({ private_security_key: Payonline.configuration.private_security_key })
9
+ Digest::MD5.hexdigest(sign_params.each.map{|k, v| "#{k.to_s.camelize}=#{v}"}.join('&'))
10
+ end
11
+
12
+ def self.sign_params(params, keys=[], add_merchant_id = true)
13
+ params.reverse_merge!({ 'merchant_id' => Payonline.configuration.merchant_id }) if add_merchant_id
14
+ if keys.present?
15
+ keys.unshift 'merchant_id' if add_merchant_id
16
+ end
17
+ digest = self.digest(params, keys)
18
+ params.merge!({ 'security_key' => digest, 'content_type' => 'text' })
19
+
20
+ params
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Payonline
2
+ VERSION = "0.1.0"
3
+ end
data/payonline.gemspec ADDED
@@ -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 'payonline/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "payonline"
8
+ spec.version = Payonline::VERSION
9
+ spec.authors = ["Yuri Zubov"]
10
+ spec.email = ["I0Result86@gmail.com"]
11
+
12
+ spec.summary = %q{This is a thin wrapper library that makes using PayOnline API a bit easier.}
13
+ spec.description = %q{This is a thin wrapper library that makes using PayOnline API a bit easier.}
14
+ spec.homepage = "https://github.com/I0Result/payonline"
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.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payonline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuri Zubov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-08 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This is a thin wrapper library that makes using PayOnline API a bit easier.
42
+ email:
43
+ - I0Result86@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - lib/payonline.rb
53
+ - lib/payonline/config.rb
54
+ - lib/payonline/payment_gateway.rb
55
+ - lib/payonline/payment_response.rb
56
+ - lib/payonline/signature.rb
57
+ - lib/payonline/version.rb
58
+ - payonline.gemspec
59
+ homepage: https://github.com/I0Result/payonline
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: This is a thin wrapper library that makes using PayOnline API a bit easier.
83
+ test_files: []