gp_webpay 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -2
- data/Rakefile +9 -1
- data/certs/muzo.signing_prod.pem +20 -0
- data/certs/muzo.signing_test.pem +20 -0
- data/gp_webpay.gemspec +2 -0
- data/lib/gp_webpay.rb +1 -0
- data/lib/gp_webpay/config.rb +16 -5
- data/lib/gp_webpay/payment.rb +11 -21
- data/lib/gp_webpay/payment_attributes.rb +37 -0
- data/lib/gp_webpay/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3704468b1cb10f523a0c2de0d9215c6f84fa96fe
|
4
|
+
data.tar.gz: 0cef9ec7cb18b482bb5d73c7b8e1b1d468ee42cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0705d32a614169b52e050ed8d5c95467bc65ef368d27a9208eb697e36c53e8e6157831d583a10f2e6d4c979b81df8b612941946e728ae3bd071ec89cfb61280
|
7
|
+
data.tar.gz: 9999ec362e1348afd389dd48f80c9eb57a8089de7cd15fdd18332926904ef9e4caa6c38084cb8055d354283ffc998b2457c87aeed6b6e15d1320f43fe59a699b
|
data/README.md
CHANGED
@@ -18,8 +18,13 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
Generate own certificate, put into your repository.
|
22
|
+
|
23
|
+
### Initialize
|
24
|
+
|
25
|
+
config/initializers/gp_webpay.rb
|
26
|
+
|
21
27
|
```ruby
|
22
|
-
# Configures global settings for Kaminari
|
23
28
|
GpWebpay.configure do |config|
|
24
29
|
config.merchant_number = ##########
|
25
30
|
config.pem_path = 'my_cert.pem'
|
@@ -27,7 +32,36 @@ GpWebpay.configure do |config|
|
|
27
32
|
end
|
28
33
|
```
|
29
34
|
|
30
|
-
|
35
|
+
### Payment
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class Payment
|
39
|
+
include GpWebpay::Payment
|
40
|
+
|
41
|
+
def order_number
|
42
|
+
id
|
43
|
+
end
|
44
|
+
|
45
|
+
def amount_in_cents
|
46
|
+
100
|
47
|
+
end
|
48
|
+
|
49
|
+
def currency
|
50
|
+
840 # USD
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
### Controller
|
56
|
+
```ruby
|
57
|
+
class OrdersController
|
58
|
+
def create
|
59
|
+
...
|
60
|
+
payment = Payment.create
|
61
|
+
redirect_to payment.pay_url(redirect_url: 'http://app/callback')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
31
65
|
|
32
66
|
## Development
|
33
67
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDLzCCAhegAwIBAgIBAjANBgkqhkiG9w0BAQUFADBNMRgwFgYDVQQDEw9NZXNz
|
3
|
+
YWdlIFNpZ25pbmcxEDAOBgNVBAsTB1BheU1VWk8xEjAQBgNVBAoTCU1VWk8sYS5z
|
4
|
+
LjELMAkGA1UEBhMCQ1owHhcNMDQwNjExMTAyMzU5WhcNMTQwNzI5MTAyMzU5WjBN
|
5
|
+
MRgwFgYDVQQDEw9NZXNzYWdlIFNpZ25pbmcxEDAOBgNVBAsTB1BheU1VWk8xEjAQ
|
6
|
+
BgNVBAoTCU1VWk8sYS5zLjELMAkGA1UEBhMCQ1owggEiMA0GCSqGSIb3DQEBAQUA
|
7
|
+
A4IBDwAwggEKAoIBAQDimVN4A77p26u2yx6x+gC9nQ4bVqEuTk6Qj18EKPftws2W
|
8
|
+
hZavsQIZPK6Xq3mVkM5teTdn0To1EA2jr5gySkTeBPWEKTn3pqrcx1hgri/J9MnX
|
9
|
+
v+csD5ThAgW/IZKpfETxZqzF+1biX1/4tjWDOFi7VPrl1E+M5BTd8C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GpWebpay
|
|
21
21
|
config_accessor :merchant_pem_path
|
22
22
|
config_accessor :merchant_password
|
23
23
|
config_accessor :gpe_pem_path
|
24
|
+
config_accessor :environment
|
24
25
|
|
25
26
|
def param_name
|
26
27
|
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
|
27
28
|
end
|
28
29
|
|
29
30
|
def pay_url
|
30
|
-
if
|
31
|
+
if production?
|
31
32
|
'https://3dsecure.gpwebpay.com/kb/order.do'
|
32
33
|
else
|
33
34
|
'https://test.3dsecure.gpwebpay.com/kb/order.do'
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
38
|
+
def gpe_pem_path
|
39
|
+
file_name = production? ? 'muzo.signing_prod.pem' : 'muzo.signing_test.pem'
|
40
|
+
|
41
|
+
File.expand_path("../../../certs/#{file_name}", __FILE__)
|
42
|
+
end
|
43
|
+
|
44
|
+
def production?
|
45
|
+
config.environment == 'production'
|
46
|
+
end
|
47
|
+
|
37
48
|
# define param_name writer (copied from AS::Configurable)
|
38
49
|
writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
|
39
50
|
singleton_class.class_eval writer, __FILE__, line
|
@@ -42,9 +53,9 @@ module GpWebpay
|
|
42
53
|
|
43
54
|
# this is ugly. why can't we pass the default value to config_accessor...?
|
44
55
|
configure do |config|
|
45
|
-
config.merchant_number
|
46
|
-
config.merchant_pem_path
|
47
|
-
config.merchant_password
|
48
|
-
config.
|
56
|
+
config.merchant_number = nil
|
57
|
+
config.merchant_pem_path = nil
|
58
|
+
config.merchant_password = nil
|
59
|
+
config.environment = defined?(Rails) && Rails.env || 'test'
|
49
60
|
end
|
50
61
|
end
|
data/lib/gp_webpay/payment.rb
CHANGED
@@ -4,6 +4,16 @@ module GpWebpay
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
attr_accessor :redirect_url
|
7
|
+
|
8
|
+
delegate :merchant_number, to: :config
|
9
|
+
end
|
10
|
+
|
11
|
+
def deposit_flag
|
12
|
+
1
|
13
|
+
end
|
14
|
+
|
15
|
+
def operation
|
16
|
+
'CREATE_ORDER'
|
7
17
|
end
|
8
18
|
|
9
19
|
def pay_url(options = {})
|
@@ -19,18 +29,6 @@ module GpWebpay
|
|
19
29
|
|
20
30
|
private
|
21
31
|
|
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
32
|
def config
|
35
33
|
GpWebpay.config
|
36
34
|
end
|
@@ -54,15 +52,7 @@ module GpWebpay
|
|
54
52
|
end
|
55
53
|
|
56
54
|
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
|
-
}
|
55
|
+
@payment_attributes ||= PaymentAttributes.new(self).to_h
|
66
56
|
end
|
67
57
|
|
68
58
|
def payment_attributes_with_digest
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module GpWebpay
|
2
|
+
class PaymentAttributes
|
3
|
+
|
4
|
+
KEYS = %w(MERCHANTNUMBER OPERATION ORDERNUMBER AMOUNT CURRENCY DEPOSITFLAG
|
5
|
+
MERORDERNUM URL DESCRIPTION MD)
|
6
|
+
|
7
|
+
OPTIONAL_KEYS = %w(MERORDERNUM DESCRIPTION MD)
|
8
|
+
|
9
|
+
TRANSITIONS = {
|
10
|
+
'MERCHANTNUMBER' => :merchant_number,
|
11
|
+
'ORDERNUMBER' => :order_number,
|
12
|
+
'AMOUNT' => :amount_in_cents,
|
13
|
+
'DEPOSITFLAG' => :deposit_flag,
|
14
|
+
'MERORDERNUM' => :merchant_order_number,
|
15
|
+
'URL' => :redirect_url,
|
16
|
+
'MD' => :merchant_description
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize(payment)
|
20
|
+
@payment = payment
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_h
|
24
|
+
KEYS.each_with_object({}) do |key, hash|
|
25
|
+
method = TRANSITIONS[key] || key.downcase.to_sym
|
26
|
+
|
27
|
+
if @payment.respond_to?(method)
|
28
|
+
hash[key] = @payment.public_send(method)
|
29
|
+
elsif !OPTIONAL_KEYS.include?(key)
|
30
|
+
method_missing(method)
|
31
|
+
end
|
32
|
+
|
33
|
+
hash
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/gp_webpay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gp_webpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Magnusek
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04
|
11
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.6.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.6.0
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- magnusekm@gmail.com
|
@@ -67,10 +81,13 @@ files:
|
|
67
81
|
- Rakefile
|
68
82
|
- bin/console
|
69
83
|
- bin/setup
|
84
|
+
- certs/muzo.signing_prod.pem
|
85
|
+
- certs/muzo.signing_test.pem
|
70
86
|
- gp_webpay.gemspec
|
71
87
|
- lib/gp_webpay.rb
|
72
88
|
- lib/gp_webpay/config.rb
|
73
89
|
- lib/gp_webpay/payment.rb
|
90
|
+
- lib/gp_webpay/payment_attributes.rb
|
74
91
|
- lib/gp_webpay/version.rb
|
75
92
|
homepage: https://github.com/blueberryapps/gp_webpay
|
76
93
|
licenses:
|