newebpay 0.1.0 → 0.2.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 +4 -4
- data/.travis.yml +9 -0
- data/Gemfile.lock +7 -5
- data/README.md +38 -3
- data/lib/newebpay.rb +21 -1
- data/lib/newebpay/config.rb +35 -1
- data/lib/newebpay/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6626a7b6e1890e170bf753cb672da37c18cf31f16d242dc50f426a4ee406bff
|
4
|
+
data.tar.gz: 223d12185ed1a3f7526fed95f0d881256fcc456698dd322acbed3d05c387c44b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4fc9a75905e1d69c7d8092fc005d18bb60670efb494f5d0e5fc4f9a8125eb2d80a57b4e5a596c1f675a984ea287d8d0828a362ca69697e9bf87b441761cc8ef
|
7
|
+
data.tar.gz: 3d89871e1ccb71222c90f45423c8a38d87079e731262c087eb8163d97e3806133aa12eae99710e5942d6f2d5cbf618755c80961e2e143ccec4f7a4718689b124
|
data/.travis.yml
CHANGED
@@ -3,4 +3,13 @@ language: ruby
|
|
3
3
|
cache: bundler
|
4
4
|
rvm:
|
5
5
|
- 2.6.6
|
6
|
+
- 2.7.0
|
6
7
|
before_install: gem install bundler -v 2.1.4
|
8
|
+
before_script:
|
9
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
10
|
+
- chmod +x ./cc-test-reporter
|
11
|
+
- ./cc-test-reporter before-build
|
12
|
+
script:
|
13
|
+
- bundle exec rspec
|
14
|
+
after_script:
|
15
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
newebpay (0.
|
4
|
+
newebpay (0.2.0)
|
5
5
|
offsite_payments (>= 2.7.26)
|
6
6
|
|
7
7
|
GEM
|
@@ -38,18 +38,20 @@ GEM
|
|
38
38
|
concurrent-ruby (1.1.7)
|
39
39
|
crass (1.0.6)
|
40
40
|
diff-lcs (1.4.4)
|
41
|
-
docile (1.3.
|
41
|
+
docile (1.3.5)
|
42
42
|
erubi (1.10.0)
|
43
43
|
i18n (1.8.7)
|
44
44
|
concurrent-ruby (~> 1.0)
|
45
45
|
iniparse (1.5.0)
|
46
|
-
loofah (2.
|
46
|
+
loofah (2.9.0)
|
47
47
|
crass (~> 1.0.2)
|
48
48
|
nokogiri (>= 1.5.9)
|
49
|
+
mini_portile2 (2.5.0)
|
49
50
|
minitest (5.14.3)
|
50
51
|
money (6.13.8)
|
51
52
|
i18n (>= 0.6.4, <= 2)
|
52
|
-
nokogiri (1.11.1
|
53
|
+
nokogiri (1.11.1)
|
54
|
+
mini_portile2 (~> 2.5.0)
|
53
55
|
racc (~> 1.4)
|
54
56
|
offsite_payments (2.7.26)
|
55
57
|
actionpack (>= 5.2.3)
|
@@ -108,7 +110,7 @@ GEM
|
|
108
110
|
rubocop (~> 1.0)
|
109
111
|
rubocop-ast (>= 1.1.0)
|
110
112
|
ruby-progressbar (1.11.0)
|
111
|
-
simplecov (0.
|
113
|
+
simplecov (0.21.2)
|
112
114
|
docile (~> 1.1)
|
113
115
|
simplecov-html (~> 0.11)
|
114
116
|
simplecov_json_formatter (~> 0.1)
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
NewebPay
|
2
2
|
===
|
3
3
|
|
4
|
+
[](https://travis-ci.com/elct9620/newebpay-ruby) [](https://codeclimate.com/github/elct9620/newebpay-ruby/test_coverage) [](https://codeclimate.com/github/elct9620/newebpay-ruby/maintainability)
|
5
|
+
|
4
6
|
The [Offsite Payments](https://github.com/activemerchant/offsite_payments) implement for NewebPay(藍新金流)
|
5
7
|
|
6
8
|
## Installation
|
@@ -21,6 +23,33 @@ Or install it yourself as:
|
|
21
23
|
|
22
24
|
## Usage
|
23
25
|
|
26
|
+
### Configure Newebpay
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# config/initializes/newebpay.rb
|
30
|
+
|
31
|
+
# Set to test mode if under development
|
32
|
+
OffsitePayments.mode = :test
|
33
|
+
|
34
|
+
Newebpay::Config.config do |c|
|
35
|
+
c.hash_key = ''
|
36
|
+
c.hash_iv = ''
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
### Temporary switch config
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
config = Newebpay::Config.new do |c|
|
44
|
+
c.hash_key = 'A' * 32
|
45
|
+
c.hash_iv = 'B' * 16
|
46
|
+
end
|
47
|
+
|
48
|
+
Newebpay.use(config) do
|
49
|
+
Newebpay::Config.current == config # => true
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
24
53
|
### Create payment button
|
25
54
|
|
26
55
|
In your controller
|
@@ -33,9 +62,11 @@ options = {
|
|
33
62
|
notify_url: newebpay_notify_url
|
34
63
|
}
|
35
64
|
|
36
|
-
@helper =
|
65
|
+
@helper = Newebpay.helper(order_id, merchant_id, options)
|
37
66
|
```
|
38
67
|
|
68
|
+
> The `Newebpay.helper` is an alias to `OffsitePayment::Integrations::Newebpay::Helper.new`
|
69
|
+
|
39
70
|
In your view
|
40
71
|
|
41
72
|
```erb
|
@@ -56,7 +87,7 @@ In your view
|
|
56
87
|
In your controller
|
57
88
|
|
58
89
|
```ruby
|
59
|
-
@return =
|
90
|
+
@return = Newebpay.return(request.body.read)
|
60
91
|
@return.trade_info # The decrypted TradeInfo from NewebPay
|
61
92
|
```
|
62
93
|
|
@@ -67,13 +98,17 @@ In your controller
|
|
67
98
|
In you controller
|
68
99
|
|
69
100
|
```ruby
|
70
|
-
@notification =
|
101
|
+
@notification = Newebpay.notification(request.body.read)
|
71
102
|
@notification.trade_info # The decrypted TradeInfo from NewebPay
|
72
103
|
```
|
73
104
|
|
74
105
|
## Roadmap
|
75
106
|
|
76
107
|
* [x] MPG Support
|
108
|
+
* [x] Allow switch config
|
109
|
+
* [ ] Refund API
|
110
|
+
* [ ] Unauthorized API
|
111
|
+
* [ ] Order Status API
|
77
112
|
* [ ] Rails Support
|
78
113
|
* [ ] Form Object
|
79
114
|
* [ ] Form Helper
|
data/lib/newebpay.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'forwardable'
|
4
|
+
|
3
5
|
require 'newebpay/version'
|
4
6
|
require 'newebpay/config'
|
5
7
|
require 'newebpay/cipher'
|
6
8
|
|
7
9
|
require 'offsite_payments/integrations/newebpay'
|
8
10
|
|
11
|
+
# NewebPay
|
12
|
+
#
|
13
|
+
# @since 0.1.0
|
9
14
|
module Newebpay
|
10
15
|
class Error < StandardError; end
|
11
|
-
|
16
|
+
|
17
|
+
class << self
|
18
|
+
extend Forwardable
|
19
|
+
|
20
|
+
delegate %i[service_url helper return notification] => OffsitePayments::Integrations::Newebpay
|
21
|
+
|
22
|
+
# Use specify config
|
23
|
+
#
|
24
|
+
# @param [Newebpay::Config] the config to switch
|
25
|
+
# @param [Proc] the block to use temporary config
|
26
|
+
#
|
27
|
+
# @since 0.2.0
|
28
|
+
def use(config, &block)
|
29
|
+
Config.switch(config, &block)
|
30
|
+
end
|
31
|
+
end
|
12
32
|
end
|
data/lib/newebpay/config.rb
CHANGED
@@ -10,11 +10,34 @@ module Newebpay
|
|
10
10
|
class << self
|
11
11
|
extend Forwardable
|
12
12
|
|
13
|
+
# @since 0.1.0
|
14
|
+
LOCK = Mutex.new
|
15
|
+
|
13
16
|
# Current activate config
|
14
17
|
#
|
15
18
|
# @since 0.1.0
|
16
19
|
def current
|
17
|
-
@current
|
20
|
+
return @current if @current
|
21
|
+
|
22
|
+
LOCK.synchronize do
|
23
|
+
return @current if @current
|
24
|
+
|
25
|
+
@current ||= new
|
26
|
+
end
|
27
|
+
|
28
|
+
@current
|
29
|
+
end
|
30
|
+
|
31
|
+
# Temporary switch to another config
|
32
|
+
#
|
33
|
+
# @since 0.2.0
|
34
|
+
def switch(config, &_block)
|
35
|
+
LOCK.synchronize do
|
36
|
+
temp = @current
|
37
|
+
@current = config
|
38
|
+
yield @current if defined?(yield)
|
39
|
+
@current = temp
|
40
|
+
end
|
18
41
|
end
|
19
42
|
|
20
43
|
delegate %i[hash_key hash_iv config] => :current
|
@@ -23,6 +46,17 @@ module Newebpay
|
|
23
46
|
# @since 0.1.0
|
24
47
|
attr_accessor :hash_key, :hash_iv
|
25
48
|
|
49
|
+
# Initialize
|
50
|
+
#
|
51
|
+
# @since 0.2.0
|
52
|
+
def initialize(attributes = {}, &block)
|
53
|
+
attributes.each do |name, value|
|
54
|
+
send("#{name}=", value) if respond_to?("#{name}=")
|
55
|
+
end
|
56
|
+
|
57
|
+
config(&block) if defined?(yield)
|
58
|
+
end
|
59
|
+
|
26
60
|
# Update current config
|
27
61
|
#
|
28
62
|
# @since 0.1.0
|
data/lib/newebpay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newebpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aotokitsuruya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: offsite_payments
|