daicadp 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/daicadp-0.1.0.gem +0 -0
- data/daicadp.gemspec +3 -5
- data/lib/daicadp/helper.rb +8 -0
- data/lib/daicadp/type.rb +0 -0
- data/lib/daicadp/version.rb +1 -1
- data/lib/daicadp.rb +72 -3
- metadata +8 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47742cf925ab1eff4a5446932ec1991d9a7d91b283f7977513d176b9fd9b3ade
|
4
|
+
data.tar.gz: ccb426de62a31ce57e07024ebc1ada30d7706b3e3890584657f65e0ed1facd75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daf489d11aa9793fc4e4902eedd40006fd0feb7127356c607ba12073cdf7e5c779621678f91432e915e90a214e136141bb9f0c3b94378a32c33f4383ddb3c2a9
|
7
|
+
data.tar.gz: ee77cccb45e54c937dfe0ab3b4b62dd6bb38f5d4c9f0cb5d9b709a8c44a72d8c0cd803e7767207d186ab4da0af7dbe824229d87b10cb79abc7d3e5c9fe5afdfa
|
data/daicadp-0.1.0.gem
ADDED
Binary file
|
data/daicadp.gemspec
CHANGED
@@ -16,11 +16,9 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
18
|
|
19
|
-
spec.add_dependency '
|
20
|
-
spec.add_dependency '
|
21
|
-
spec.add_dependency '
|
22
|
-
spec.add_dependency 'tty-pager'
|
23
|
-
spec.add_dependency 'tty-prompt'
|
19
|
+
spec.add_dependency 'json'
|
20
|
+
spec.add_dependency 'net/http'
|
21
|
+
spec.add_dependency 'openssl'
|
24
22
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
25
23
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
26
24
|
if spec.respond_to?(:metadata)
|
data/lib/daicadp/type.rb
ADDED
File without changes
|
data/lib/daicadp/version.rb
CHANGED
data/lib/daicadp.rb
CHANGED
@@ -1,6 +1,75 @@
|
|
1
|
-
require
|
1
|
+
require 'daicadp/version'
|
2
|
+
require 'daicadp/helper'
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
|
7
|
+
$ZkConstants = {
|
8
|
+
ZKPAY_HOST: "https://api.zkpay.vn",
|
9
|
+
ZKPAY_HOST_DEV: "https://zkpay-dev.onsky.services",
|
10
|
+
ZKPAY_WEB: "https://zkpay.vn",
|
11
|
+
ZKPAY_WEB_DEV: "https://zk-pay.pages.dev",
|
12
|
+
};
|
2
13
|
|
3
14
|
module Daicadp
|
4
|
-
class
|
5
|
-
|
15
|
+
class Client
|
16
|
+
attr_reader :options
|
17
|
+
|
18
|
+
def initialize(options)
|
19
|
+
options[:host] = options[:test] ? ZkConstants.ZKPAY_HOST_DEV : ZkConstants.ZKPAY_HOST
|
20
|
+
@options = options
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_order_redirect_url(order)
|
24
|
+
data = {
|
25
|
+
merchantId: options[:code],
|
26
|
+
amount: order[:amount],
|
27
|
+
merchantOrder: order[:orderId],
|
28
|
+
}
|
29
|
+
data[:merchantUser] = order[:userId] if order[:userId]
|
30
|
+
|
31
|
+
sorted_params = data.sort.to_h
|
32
|
+
query = sorted_params.map { |key, value| "#{key}=#{value}" }.join('&')
|
33
|
+
signed_data = Helper.sign(query, options[:secret], 'sha256')
|
34
|
+
|
35
|
+
return "#{options[:test] ? ZkConstants.ZKPAY_WEB_DEV : ZkConstants.ZKPAY_WEB}?#{query}&secureHash=#{signed_data}&returnUrl=#{options[:returnUrl]}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_merchant_transaction(id)
|
39
|
+
resource = "#{options[:host]}/merchant-apis/merchant-transactions/#{id}"
|
40
|
+
uri = URI(resource)
|
41
|
+
|
42
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
43
|
+
http.use_ssl = true if uri.scheme == 'https'
|
44
|
+
|
45
|
+
request = Net::HTTP::Get.new(uri)
|
46
|
+
request['x-api-key'] = options[:apiKey]
|
47
|
+
|
48
|
+
response = http.request(request)
|
49
|
+
raise 'Error fetching merchant transaction' if response.code != '200'
|
50
|
+
|
51
|
+
plain_to_instance(JSON.parse(response.body))
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate_order_url(order)
|
55
|
+
resource = "#{options[:host]}/merchant-apis/transactions"
|
56
|
+
uri = URI(resource)
|
57
|
+
|
58
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
59
|
+
http.use_ssl = true if uri.scheme == 'https'
|
60
|
+
|
61
|
+
data = {
|
62
|
+
merchantId: options[:code],
|
63
|
+
amount: order[:amount],
|
64
|
+
merchantOrder: order[:orderId],
|
65
|
+
}
|
66
|
+
|
67
|
+
data[:merchantUser] = order[:userId] if order[:userId]
|
68
|
+
|
69
|
+
sorted_params = sort_object(data)
|
70
|
+
query = sorted_params.map { |key, value| "#{key}=#{value}" }.join('&')
|
71
|
+
signed_data = sign(query, options[:secret], 'sha256')
|
72
|
+
data[:secureHash] = signed_data
|
73
|
+
end
|
74
|
+
end
|
6
75
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daicadp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- daicadp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: net/http
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,35 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: tty-pager
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: tty-prompt
|
42
|
+
name: openssl
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
72
44
|
requirements:
|
73
45
|
- - ">="
|
@@ -140,9 +112,12 @@ files:
|
|
140
112
|
- Rakefile
|
141
113
|
- bin/console
|
142
114
|
- bin/setup
|
115
|
+
- daicadp-0.1.0.gem
|
143
116
|
- daicadp.gemspec
|
144
117
|
- exe/daicadp
|
145
118
|
- lib/daicadp.rb
|
119
|
+
- lib/daicadp/helper.rb
|
120
|
+
- lib/daicadp/type.rb
|
146
121
|
- lib/daicadp/version.rb
|
147
122
|
homepage:
|
148
123
|
licenses:
|