epaybg 0.1.2
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.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/epaybg.gemspec +25 -0
- data/lib/epaybg.rb +40 -0
- data/lib/epaybg/railtie.rb +13 -0
- data/lib/epaybg/response.rb +47 -0
- data/lib/epaybg/transaction.rb +75 -0
- data/lib/epaybg/version.rb +3 -0
- data/lib/epaybg/view_helpers.rb +17 -0
- data/log/test.log +0 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/unit/transaction_spec.rb +40 -0
- metadata +146 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 gmitrev
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Epaybg
|
2
|
+
[](https://codeclimate.com/github/gmitrev/epaybg)
|
3
|
+
[](https://travis-ci.org/gmitrev/epaybg)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'epaybg'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install epaybg
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/epaybg.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'epaybg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "epaybg"
|
8
|
+
gem.version = Epaybg::VERSION
|
9
|
+
gem.authors = ["gmitrev"]
|
10
|
+
gem.email = ["gvmitrev@gmail.com"]
|
11
|
+
gem.description = %q{Framework for dealing with epay.bg payments.}
|
12
|
+
gem.summary = %q{Epaybg provides integration with the epay.bg payment services. It supports payments through epay.bg, credit cards and in EasyPay offices. }
|
13
|
+
gem.homepage = "http://github.com/gmitrev/epaybg"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'rspec-rails'
|
23
|
+
gem.add_development_dependency 'rails'
|
24
|
+
gem.add_development_dependency 'coveralls'
|
25
|
+
end
|
data/lib/epaybg.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'epaybg/railtie'
|
2
|
+
require 'epaybg/transaction'
|
3
|
+
require 'epaybg/response'
|
4
|
+
require "epaybg/version"
|
5
|
+
|
6
|
+
module Epaybg
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def hmac(data)
|
11
|
+
OpenSSL::HMAC.hexdigest('sha1', config["secret"], data)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Configuration is loaded based on this property.
|
15
|
+
# Values are [:production, :test]. Defaults to :production
|
16
|
+
def mode
|
17
|
+
@@mode
|
18
|
+
end
|
19
|
+
|
20
|
+
def mode=(mode)
|
21
|
+
valid = [:test, :production]
|
22
|
+
raise ArgumentError, "#{mode} is not a valid mode for Epaybg.
|
23
|
+
Valid modes are #{valid.to_s}." unless valid.include?(mode)
|
24
|
+
@@mode = mode
|
25
|
+
end
|
26
|
+
|
27
|
+
@@mode = :production
|
28
|
+
|
29
|
+
# A hash containing the configuration options found in the
|
30
|
+
# config/epaybg.yml file.
|
31
|
+
def config
|
32
|
+
@@config[self.mode.to_s]
|
33
|
+
end
|
34
|
+
|
35
|
+
def config=(config)
|
36
|
+
@@config = config
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'epaybg/view_helpers'
|
2
|
+
|
3
|
+
module Epaybg
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "epaybg.view_helpers" do
|
6
|
+
ActionView::Base.send :include, Epaybg::ViewHelpers
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer "epaybg.configure" do |app|
|
10
|
+
Epaybg.config = YAML.load_file(app.root.join("config", "epaybg.yml"))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Epaybg
|
2
|
+
|
3
|
+
class Response
|
4
|
+
attr_accessor :encoded, :checksum
|
5
|
+
|
6
|
+
def initialize(encoded, checksum)
|
7
|
+
@encoded = encoded
|
8
|
+
@checksum = checksum
|
9
|
+
end
|
10
|
+
|
11
|
+
def decoded
|
12
|
+
Base64.strict_decode64(@encoded)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
i = decoded.strip.split(":").flat_map{ |c| c.split("=")}
|
17
|
+
Hash[*i]
|
18
|
+
end
|
19
|
+
|
20
|
+
def valid?
|
21
|
+
Epaybg::hmac(@encoded) == @checksum
|
22
|
+
end
|
23
|
+
|
24
|
+
def status
|
25
|
+
to_hash["STATUS"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def invoice
|
29
|
+
to_hash["INVOICE"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def paid_on
|
33
|
+
DateTime.parse(to_hash["PAY_TIME"]) if status == "PAID"
|
34
|
+
end
|
35
|
+
|
36
|
+
def [](key)
|
37
|
+
to_hash[key]
|
38
|
+
end
|
39
|
+
|
40
|
+
def response_for(status)
|
41
|
+
response_statuses = [:ok, :err]
|
42
|
+
raise "Status must be one of #{response_statuses}" unless response_statuses.include? status
|
43
|
+
"INVOICE=#{self.to_hash["INVOICE"]}:STATUS=#{status.to_s.upcase}"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Epaybg
|
4
|
+
|
5
|
+
class Transaction
|
6
|
+
|
7
|
+
attr_accessor :url, :url_idn, :invoice, :amount, :expires_on,
|
8
|
+
:description, :encoding, :url_ok, :url_cancel
|
9
|
+
|
10
|
+
def initialize(args = {})
|
11
|
+
set_defaults!
|
12
|
+
args.each do |k,v|
|
13
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
14
|
+
end
|
15
|
+
yield self if block_given?
|
16
|
+
validate!
|
17
|
+
end
|
18
|
+
|
19
|
+
def encoded
|
20
|
+
exp_time = self.expires_on.strftime("%d.%m.%Y")
|
21
|
+
|
22
|
+
data = <<-DATA
|
23
|
+
MIN=#{Epaybg.config["min"]}
|
24
|
+
LANG=bg
|
25
|
+
INVOICE=#{self.invoice}
|
26
|
+
AMOUNT=#{self.amount}
|
27
|
+
EXP_TIME=#{exp_time}
|
28
|
+
DATA
|
29
|
+
|
30
|
+
Base64.strict_encode64(data)
|
31
|
+
end
|
32
|
+
|
33
|
+
def checksum
|
34
|
+
Epaybg::hmac(encoded)
|
35
|
+
end
|
36
|
+
|
37
|
+
def register_payment
|
38
|
+
uri = URI("#{self.url_idn}/?ENCODED=#{self.encoded}&CHECKSUM=#{self.checksum}")
|
39
|
+
|
40
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
41
|
+
http.use_ssl = true
|
42
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
res = http.get(uri.request_uri)
|
44
|
+
res.body
|
45
|
+
end
|
46
|
+
|
47
|
+
def epay_link
|
48
|
+
base_link "paylogin"
|
49
|
+
end
|
50
|
+
|
51
|
+
def credit_card_link
|
52
|
+
base_link "credit_paydirect"
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def base_link(action)
|
58
|
+
"#{self.url}/?PAGE=#{action}&ENCODED=#{self.encoded}&CHECKSUM=#{self.checksum}&URL_OK=#{self.url_ok}&URL_CANCEL=#{self.url_cancel}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def validate!
|
62
|
+
[:invoice, :amount, :expires_on].each do |a|
|
63
|
+
raise ArgumentError, "Missing requried attribute: #{a}" if self.send(a).blank?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_defaults!
|
68
|
+
@url ||= Epaybg.config["url"]
|
69
|
+
@url_idn ||= Epaybg.config["url_idn"]
|
70
|
+
@encoding ||= 'utf-8'
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Epaybg
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
def link_base(p, action, image="")
|
5
|
+
link_to image_tag(image), "#{p.url}/?PAGE=#{action}&ENCODED=#{p.encoded}&CHECKSUM=#{p.checksum}&URL_OK=#{p.url_ok}&URL_CANCEL=#{p.url_cancel}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def epay_link(p)
|
9
|
+
link_base p, "paylogin", "pay_with_epay.png"
|
10
|
+
end
|
11
|
+
|
12
|
+
def credit_card_link(p)
|
13
|
+
link_base p, "credit_paydirect", 'pay_with_credit_card.jpg'
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/log/test.log
ADDED
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
|
6
|
+
require "action_controller/railtie"
|
7
|
+
require 'rspec/rails'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'epaybg'
|
13
|
+
Epaybg.config = {
|
14
|
+
"test" => {"secret"=>"QESI7RA4BCW95TZPH2OM7583DCP250CEVWZYMM69E8GRS38932W54DWYI9KNCMZ0", "min"=>"D760738416", "url"=>"https://demo.epay.bg", "url_idn"=>"https://demo.epay.bg/ezp/reg_bill.cgi"},
|
15
|
+
"production" => {"secret"=>"n/a", "min"=>"n/a", "url"=>"https://epay.bg", "url_idn"=>"https://epay.bg/ezp/reg_bill.cgi"}
|
16
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Epaybg::Transaction do
|
4
|
+
let :attributes do
|
5
|
+
{ invoice: "12345", amount: 69.99, expires_on: Date.tomorrow }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "initialization" do
|
9
|
+
it "accepts a hash with options" do
|
10
|
+
lambda do
|
11
|
+
Epaybg::Transaction.new(attributes)
|
12
|
+
end.should_not raise_error ArgumentError
|
13
|
+
end
|
14
|
+
|
15
|
+
it "accepts a block with options" do
|
16
|
+
lambda do
|
17
|
+
Epaybg::Transaction.new do |t|
|
18
|
+
t.amount = attributes[:amount]
|
19
|
+
t.price = attributes[:price]
|
20
|
+
t.expires_on = attributes[:expires_on]
|
21
|
+
end
|
22
|
+
end.should_not raise_error ArgumentError
|
23
|
+
end
|
24
|
+
|
25
|
+
it "doesn't initialize without no options" do
|
26
|
+
lambda do
|
27
|
+
Epaybg::Transaction.new
|
28
|
+
end.should raise_error ArgumentError
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
[:invoice, :amount, :expires_on].each do |attr|
|
33
|
+
it "fails when no #{attr} is given" do
|
34
|
+
lambda do
|
35
|
+
Epaybg::Transaction.new(attributes.except(attr))
|
36
|
+
end.should raise_error ArgumentError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: epaybg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- gmitrev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '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: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec-rails
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rails
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: coveralls
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Framework for dealing with epay.bg payments.
|
95
|
+
email:
|
96
|
+
- gvmitrev@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- .travis.yml
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- epaybg.gemspec
|
109
|
+
- lib/epaybg.rb
|
110
|
+
- lib/epaybg/railtie.rb
|
111
|
+
- lib/epaybg/response.rb
|
112
|
+
- lib/epaybg/transaction.rb
|
113
|
+
- lib/epaybg/version.rb
|
114
|
+
- lib/epaybg/view_helpers.rb
|
115
|
+
- log/test.log
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/unit/transaction_spec.rb
|
118
|
+
homepage: http://github.com/gmitrev/epaybg
|
119
|
+
licenses: []
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.8.23
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: Epaybg provides integration with the epay.bg payment services. It supports
|
142
|
+
payments through epay.bg, credit cards and in EasyPay offices.
|
143
|
+
test_files:
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
- spec/unit/transaction_spec.rb
|
146
|
+
has_rdoc:
|