daicadp 0.1.0 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb93d71b81773dedbe420d4d9fbeea2a25a8f24f4f520983d098994e6ad1cabc
4
- data.tar.gz: b8c1f4aeefc1dc1f8e569fc432ef7d3796216717421a8b947c16b307d595d796
3
+ metadata.gz: a41689b926a3ae445a4f211d887bf8ca6d33ae3c6408107fc2830d4e4410506f
4
+ data.tar.gz: 18607da2a352ebea0c4ee3986b3bd60b29437ec389f6c984e9d9c6930a8c4eef
5
5
  SHA512:
6
- metadata.gz: 8c1dd88a4dd12b99123610d163b9822a229c0003bdb136a13d16528337125514e04a272af619e4456b7e74130be9addab80eb736e6896822ef22a6d11afa13d0
7
- data.tar.gz: 5cd01eef5cda42172dc90bd30abb742f4fd591a4efadd8af2a8445225c83cfdcda7093fbd8a21cfb6c82d0537d229e3a9c52e1208f27b0698a0455d650a869bd
6
+ metadata.gz: 4e1ad3bc6b8adf4a838c8ed079fc60701131a8c82114ec4f7b833ce89234a62366d06ab8fbad5b957f18603dc50c755b70139c26ddfc83831ffb80206f2042c7
7
+ data.tar.gz: b08b59c25438ea471ccf244645121485ba51bf4ad4e4fa04afd0035972cb02c39a1a4562620bd542a9e27605f9f7b423697aff4271f821550da8ed75f9441d24
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 'unirest'
20
- spec.add_dependency 'oj'
21
- spec.add_dependency 'tty-spinner'
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)
@@ -0,0 +1,8 @@
1
+ require 'openssl'
2
+
3
+ module Daicadp::Helper
4
+ def self.sign(data, secret, type = 'sha256')
5
+ digest = OpenSSL::Digest.new(type)
6
+ OpenSSL::HMAC.hexdigest(digest, secret, data)
7
+ end
8
+ end
File without changes
@@ -1,3 +1,3 @@
1
1
  module Daicadp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/daicadp.rb CHANGED
@@ -1,6 +1,74 @@
1
- require "daicadp/version"
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 Error < StandardError; end
5
- # Your code goes here...
15
+ include Daicadp::Helper
16
+ class Client
17
+ attr_reader :options
18
+
19
+ def initialize(options)
20
+ options[:host] = options[:test] ? ZkConstants[:ZKPAY_HOST_DEV] : ZkConstants[:ZKPAY_HOST]
21
+ @options = options
22
+ end
23
+
24
+ def get_order_redirect_url(order)
25
+ data = {
26
+ merchantId: options[:code],
27
+ amount: order[:amount],
28
+ merchantOrder: order[:orderId],
29
+ }
30
+ data[:merchantUser] = order[:userId] if order[:userId]
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
+ return "#{options[:test] ? ZkConstants[:ZKPAY_WEB_DEV] : ZkConstants[:ZKPAY_WEB]}?#{query}&secureHash=#{signed_data}&returnUrl=#{options[:returnUrl]}"
35
+ end
36
+
37
+ def get_merchant_transaction(id)
38
+ resource = "#{options[:host]}/merchant-apis/merchant-transactions/#{id}"
39
+ uri = URI(resource)
40
+
41
+ http = Net::HTTP.new(uri.host, uri.port)
42
+ http.use_ssl = true if uri.scheme == 'https'
43
+
44
+ request = Net::HTTP::Get.new(uri)
45
+ request['x-api-key'] = options[:apiKey]
46
+
47
+ response = http.request(request)
48
+ raise 'Error fetching merchant transaction' if response.code != '200'
49
+
50
+ plain_to_instance(JSON.parse(response.body))
51
+ end
52
+
53
+ def generate_order_url(order)
54
+ resource = "#{options[:host]}/merchant-apis/transactions"
55
+ uri = URI(resource)
56
+
57
+ http = Net::HTTP.new(uri.host, uri.port)
58
+ http.use_ssl = true if uri.scheme == 'https'
59
+
60
+ data = {
61
+ merchantId: options[:code],
62
+ amount: order[:amount],
63
+ merchantOrder: order[:orderId],
64
+ }
65
+
66
+ data[:merchantUser] = order[:userId] if order[:userId]
67
+
68
+ sorted_params = sort_object(data)
69
+ query = sorted_params.map { |key, value| "#{key}=#{value}" }.join('&')
70
+ signed_data = sign(query, options[:secret], 'sha256')
71
+ data[:secureHash] = signed_data
72
+ end
73
+ end
6
74
  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.0
4
+ version: 0.1.3
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-02 00:00:00.000000000 Z
11
+ date: 2023-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: unirest
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: oj
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: tty-spinner
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: