gp_webpay 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +44 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/gp_webpay.gemspec +25 -0
- data/lib/gp_webpay.rb +6 -0
- data/lib/gp_webpay/config.rb +50 -0
- data/lib/gp_webpay/payment.rb +95 -0
- data/lib/gp_webpay/version.rb +3 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9393b12417c6b8c3c33bde1c03741e07b8ddf19
|
4
|
+
data.tar.gz: 62bf128bdd80b90297a68116a4ad7ed86cf3845d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4591ae7e2150fcf4a4cc2d690090ce423ac4539802a0cafe646c4701fb035e87a666c8f62857d717f49220affbb0774fb44eaa0ff58461218ecb71c1a73b0ef
|
7
|
+
data.tar.gz: 7deb8f6cf25c03badcef130d6186a54e04d6c0d6ea3c201392b3cc57d726179858df52fcbb5f25f0c50c64663a00c62ec6197cf77659216e0c2f01cdf074d728
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# GpWebpay
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'gp_webpay'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install gp_webpay
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# Configures global settings for Kaminari
|
23
|
+
GpWebpay.configure do |config|
|
24
|
+
config.merchant_number = ##########
|
25
|
+
config.pem_path = 'my_cert.pem'
|
26
|
+
config.password = 'password'
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
TODO: Write usage instructions here
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
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.
|
35
|
+
|
36
|
+
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).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/[my-github-username]/gp_webpay/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gp/webpay"
|
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
data/gp_webpay.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gp_webpay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gp_webpay"
|
8
|
+
spec.version = GpWebpay::VERSION
|
9
|
+
spec.authors = ["Martin Magnusek"]
|
10
|
+
spec.email = ["magnusekm@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{GP webpay, easy to implement payment gateway}
|
13
|
+
spec.homepage = "https://github.com/blueberryapps/gp_webpay"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'activesupport', '~> 3.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
data/lib/gp_webpay.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
3
|
+
module GpWebpay
|
4
|
+
# Configures global settings for Kaminari
|
5
|
+
# GpWebpay.configure do |config|
|
6
|
+
# config.default_per_page = 10
|
7
|
+
# end
|
8
|
+
def self.configure(&block)
|
9
|
+
yield @config ||= GpWebpay::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# Global settings for Kaminari
|
13
|
+
def self.config
|
14
|
+
@config
|
15
|
+
end
|
16
|
+
|
17
|
+
# need a Class for 3.0
|
18
|
+
class Configuration #:nodoc:
|
19
|
+
include ActiveSupport::Configurable
|
20
|
+
config_accessor :merchant_number
|
21
|
+
config_accessor :merchant_pem_path
|
22
|
+
config_accessor :merchant_password
|
23
|
+
config_accessor :gpe_pem_path
|
24
|
+
|
25
|
+
def param_name
|
26
|
+
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
|
27
|
+
end
|
28
|
+
|
29
|
+
def pay_url
|
30
|
+
if Rails.env.production?
|
31
|
+
'https://3dsecure.gpwebpay.com/kb/order.do'
|
32
|
+
else
|
33
|
+
'https://test.3dsecure.gpwebpay.com/kb/order.do'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# define param_name writer (copied from AS::Configurable)
|
38
|
+
writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
|
39
|
+
singleton_class.class_eval writer, __FILE__, line
|
40
|
+
class_eval writer, __FILE__, line
|
41
|
+
end
|
42
|
+
|
43
|
+
# this is ugly. why can't we pass the default value to config_accessor...?
|
44
|
+
configure do |config|
|
45
|
+
config.merchant_number = nil
|
46
|
+
config.merchant_pem_path = nil
|
47
|
+
config.merchant_password = nil
|
48
|
+
config.gpe_pem_path = 'certs/muzo.signing_test.pem'
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module GpWebpay
|
2
|
+
module Payment
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attr_accessor :redirect_url
|
7
|
+
end
|
8
|
+
|
9
|
+
def pay_url(options = {})
|
10
|
+
self.redirect_url = options[:redirect_url]
|
11
|
+
|
12
|
+
"#{config.pay_url}?#{payment_attributes_with_digest.to_param}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def success?(params)
|
16
|
+
verified_response?(params) &&
|
17
|
+
params['PRCODE'] == '0' && params['SRCODE'] == '0'
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def order_number
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
|
26
|
+
def payment_amount_in_cents
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
29
|
+
|
30
|
+
def payment_currency
|
31
|
+
raise NotImplementedError
|
32
|
+
end
|
33
|
+
|
34
|
+
def config
|
35
|
+
GpWebpay.config
|
36
|
+
end
|
37
|
+
|
38
|
+
def digest
|
39
|
+
sign = merchant_key.sign(OpenSSL::Digest::SHA1.new, digest_text)
|
40
|
+
Base64.encode64(sign).gsub("\n", '')
|
41
|
+
end
|
42
|
+
|
43
|
+
def digest_text
|
44
|
+
payment_attributes.values.join('|')
|
45
|
+
end
|
46
|
+
|
47
|
+
def digest_verification(params)
|
48
|
+
%w(OPERATION ORDERNUMBER PRCODE SRCODE RESULTTEXT).
|
49
|
+
map { |key| params[key] }.join('|')
|
50
|
+
end
|
51
|
+
|
52
|
+
def digest1_verification(params)
|
53
|
+
digest_verification(params) + "|#{config.merchant_number}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def payment_attributes
|
57
|
+
{
|
58
|
+
'MERCHANTNUMBER' => config.merchant_number,
|
59
|
+
'OPERATION' => 'CREATE_ORDER',
|
60
|
+
'ORDERNUMBER' => order_number,
|
61
|
+
'AMOUNT' => payment_amount_in_cents,
|
62
|
+
'CURRENCY' => payment_currency,
|
63
|
+
'DEPOSITFLAG' => 1,
|
64
|
+
'URL' => redirect_url
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def payment_attributes_with_digest
|
69
|
+
payment_attributes.merge('DIGEST' => digest)
|
70
|
+
end
|
71
|
+
|
72
|
+
def verified_response?(params)
|
73
|
+
verify_digest(params['DIGEST'], digest_verification(params)) &&
|
74
|
+
verify_digest(params['DIGEST1'], digest1_verification(params))
|
75
|
+
end
|
76
|
+
|
77
|
+
def verify_digest(signature, data)
|
78
|
+
gpe_key.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(signature), data)
|
79
|
+
end
|
80
|
+
|
81
|
+
def merchant_key
|
82
|
+
@merchant_key ||= begin
|
83
|
+
pem = File.read config.merchant_pem_path
|
84
|
+
OpenSSL::PKey::RSA.new(pem, config.merchant_password)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def gpe_key
|
89
|
+
@gpe_key ||= begin
|
90
|
+
pem = File.read config.gpe_pem_path
|
91
|
+
OpenSSL::X509::Certificate.new(pem).public_key
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gp_webpay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Magnusek
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- magnusekm@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- gp_webpay.gemspec
|
71
|
+
- lib/gp_webpay.rb
|
72
|
+
- lib/gp_webpay/config.rb
|
73
|
+
- lib/gp_webpay/payment.rb
|
74
|
+
- lib/gp_webpay/version.rb
|
75
|
+
homepage: https://github.com/blueberryapps/gp_webpay
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.6
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: GP webpay, easy to implement payment gateway
|
99
|
+
test_files: []
|