clt-sdk 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +31 -25
- data/lib/clt-sdk.rb +11 -8
- data/lib/clt/core_ext/hash.rb +9 -0
- data/lib/clt/credit_card.rb +69 -29
- data/lib/clt/cvs.rb +57 -47
- data/lib/clt/error_message.rb +2 -4
- data/lib/clt/general_methods.rb +16 -0
- data/lib/clt/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c1abca04bba99773ae3ec26193f14009553c099
|
4
|
+
data.tar.gz: 5acbc8ac75b3ba2a02135abb5455be647301e817
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d05873d9c4fe3eb930d430b4575f6f13e42ac5145d91d7af483c79399408d1f0457201f5b0440f5a4ab3817354ed54218b58819f280010ba615b0d84be8546e6
|
7
|
+
data.tar.gz: 3450de500406f4e5a1ce83769cdc2aa994e6b8ee52606f93d115d398ff6c00c9a55219b38105a7ee78ebc8548d01e05c4fc74336527dab8880eafa2fff1e09fd
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
# Clt SDK
|
5
5
|
|
6
|
-
|
6
|
+
API client for President Collect Service.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -33,59 +33,62 @@ $ gem install clt-sdk
|
|
33
33
|
require "clt-sdk"
|
34
34
|
|
35
35
|
Clt.setup do |config|
|
36
|
-
config.cvs_cust_id = "
|
37
|
-
config.cvs_cust_password = "
|
38
|
-
config.
|
39
|
-
config.cocs_link_id = "
|
40
|
-
config.cocs_hash_base = "
|
36
|
+
config.cvs_cust_id = "CVS_CUST_ID"
|
37
|
+
config.cvs_cust_password = "CVS_CUST_PASSWORD"
|
38
|
+
config.cvs_default_expire_day = 1
|
39
|
+
config.cocs_link_id = "COCS_LINK_ID"
|
40
|
+
config.cocs_hash_base = "COCS_HASH_BASE"
|
41
41
|
end
|
42
42
|
```
|
43
43
|
|
44
|
-
`
|
44
|
+
`cvs_default_expire_day`: **Optional.** ibon code will expired after this day (Default: 1)
|
45
45
|
|
46
46
|
## Example
|
47
47
|
|
48
48
|
* ibon
|
49
49
|
|
50
50
|
```ruby
|
51
|
-
|
51
|
+
cvs_client = Clt::Cvs.new
|
52
52
|
```
|
53
53
|
|
54
54
|
#### Order Create
|
55
55
|
|
56
56
|
```ruby
|
57
|
-
result =
|
57
|
+
result = cvs_client.order_create(
|
58
58
|
service_url: "SERVICE_URL",
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
cust_order_number: "TESTORDER000001",
|
60
|
+
order_amount: 100,
|
61
|
+
payer_mobile: "0987654321",
|
62
|
+
payer_email: "test@localhost.com"
|
63
63
|
)
|
64
64
|
```
|
65
65
|
|
66
|
-
Optional parameters: `
|
66
|
+
Optional parameters: `expire_date`, `payer_name`, `payer_postcode`, `payer_address`
|
67
|
+
|
68
|
+
> `expired_date` will overwrite `cvs_default_expire_day` setting.
|
67
69
|
|
68
70
|
#### Order Query
|
69
71
|
|
70
72
|
```ruby
|
71
|
-
result =
|
73
|
+
result = cvs_client.order_query(
|
72
74
|
service_url: "SERVICE_URL",
|
73
|
-
|
75
|
+
process_code_update_time_begin: "2016-08-08T00:00:00+08:00",
|
76
|
+
process_code_update_time_end: "2016-08-08T23:59:59+08:00"
|
74
77
|
)
|
75
78
|
```
|
76
79
|
|
77
|
-
Optional parameters: `update_time_end`
|
78
|
-
|
79
80
|
* Credit Card
|
80
81
|
|
81
82
|
```ruby
|
82
|
-
|
83
|
+
cocs_client = Clt::CreditCard.new
|
83
84
|
```
|
84
85
|
|
86
|
+
> `chk` will be automatically generated by default.
|
87
|
+
|
85
88
|
#### Order Create
|
86
89
|
|
87
90
|
```ruby
|
88
|
-
result =
|
91
|
+
result = cocs_client.order_create(
|
89
92
|
service_url: "SERVICE_URL",
|
90
93
|
cust_order_no: "TESTORDER000001",
|
91
94
|
order_amount: 100,
|
@@ -93,24 +96,26 @@ end
|
|
93
96
|
)
|
94
97
|
```
|
95
98
|
|
96
|
-
Optional parameters: `cust_order_no`, `limit_product_id`
|
99
|
+
Optional parameters: `cust_order_no`, `limit_product_id`, `chk`
|
97
100
|
|
98
|
-
>
|
101
|
+
> `cust_order_no` will be automatically generated if empty.
|
99
102
|
|
100
103
|
#### Order Cancel
|
101
104
|
|
102
105
|
```ruby
|
103
|
-
result =
|
106
|
+
result = cocs_client.order_cancel(
|
104
107
|
service_url: "SERVICE_URL",
|
105
108
|
cust_order_no: "TESTORDER000001",
|
106
109
|
order_amount: 100
|
107
110
|
)
|
108
111
|
```
|
109
112
|
|
113
|
+
Optional parameters: `chk`
|
114
|
+
|
110
115
|
#### Order Refund
|
111
116
|
|
112
117
|
```ruby
|
113
|
-
result =
|
118
|
+
result = cocs_client.order_refund(
|
114
119
|
service_url: "SERVICE_URL",
|
115
120
|
cust_order_no: "TESTORDER000001",
|
116
121
|
order_amount: 100,
|
@@ -118,11 +123,12 @@ end
|
|
118
123
|
)
|
119
124
|
```
|
120
125
|
|
126
|
+
Optional parameters: `chk`
|
127
|
+
|
121
128
|
## Contributing
|
122
129
|
|
123
130
|
Bug reports and pull requests are welcome on GitHub at https://github.com/CalvertYang/clt-sdk.
|
124
131
|
|
125
|
-
|
126
132
|
## License
|
127
133
|
|
128
134
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/clt-sdk.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
1
|
-
require "clt/version"
|
2
|
-
require "clt/error_message"
|
3
|
-
require "clt/cvs"
|
4
|
-
require "clt/credit_card"
|
5
|
-
|
6
1
|
require "nokogiri"
|
7
2
|
require "nori"
|
8
3
|
require "json"
|
4
|
+
require "digest"
|
9
5
|
require "net/http"
|
10
6
|
require "net/https"
|
11
7
|
|
8
|
+
require "clt/version"
|
9
|
+
require "clt/error_message"
|
10
|
+
require "clt/general_methods"
|
11
|
+
require "clt/core_ext/hash"
|
12
|
+
require "clt/cvs"
|
13
|
+
require "clt/credit_card"
|
14
|
+
|
12
15
|
module Clt
|
13
16
|
class << self
|
14
|
-
attr_accessor :cvs_cust_id, :cvs_cust_password, :
|
17
|
+
attr_accessor :cvs_cust_id, :cvs_cust_password, :cvs_default_expire_day
|
15
18
|
attr_accessor :cocs_link_id, :cocs_hash_base
|
16
19
|
end
|
17
20
|
|
18
|
-
def self.
|
19
|
-
@
|
21
|
+
def self.cvs_default_expire_day
|
22
|
+
@cvs_default_expire_day || 1
|
20
23
|
end
|
21
24
|
|
22
25
|
def self.setup
|
data/lib/clt/credit_card.rb
CHANGED
@@ -1,41 +1,49 @@
|
|
1
1
|
module Clt
|
2
2
|
class CreditCard
|
3
|
+
include GeneralMethods
|
4
|
+
|
3
5
|
def initialize
|
4
6
|
raise ArgumentError, "Please setup cocs_link_id first" if Clt.cocs_link_id.nil?
|
5
|
-
ErrorMessage.raise_argument_error(msg: :
|
7
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cocs_link_id, data: "String") unless Clt.cocs_link_id.is_a? String
|
6
8
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :cocs_link_id) if Clt.cocs_link_id.empty?
|
7
9
|
|
8
10
|
raise ArgumentError, "Please setup cocs_hash_base first" if Clt.cocs_hash_base.nil?
|
9
|
-
ErrorMessage.raise_argument_error(msg: :
|
11
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cocs_hash_base, data: "String") unless Clt.cocs_hash_base.is_a? String
|
10
12
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :cocs_hash_base) if Clt.cocs_hash_base.empty?
|
11
13
|
end
|
12
14
|
|
13
15
|
# Order Create
|
14
16
|
def order_create params = {}
|
15
|
-
ErrorMessage.raise_argument_error(msg: :
|
17
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: "Parameter", data: "Hash") unless params.is_a? Hash
|
16
18
|
|
17
19
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :service_url) if params[:service_url].nil?
|
18
|
-
ErrorMessage.raise_argument_error(msg: :
|
20
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :service_url, data: "String") unless params[:service_url].is_a? String
|
19
21
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :service_url) if params[:service_url].empty?
|
20
22
|
|
21
23
|
if params.has_key? :cust_order_no
|
22
|
-
ErrorMessage.raise_argument_error(msg: :
|
24
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cust_order_no, data: "String") unless params[:cust_order_no].is_a? String
|
23
25
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :cust_order_no) if params[:cust_order_no].empty?
|
24
26
|
ErrorMessage.raise_argument_error(msg: :data_length_too_short, field: :cust_order_no) if params[:cust_order_no].size < 3
|
25
27
|
end
|
26
28
|
|
27
29
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :order_amount) if params[:order_amount].nil?
|
28
|
-
ErrorMessage.raise_argument_error(msg: :
|
30
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :order_amount, data: "Integer") unless params[:order_amount].is_a? Integer
|
31
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :order_amount, data: "greater than 0") if params[:order_amount] <= 0
|
29
32
|
|
30
33
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :order_detail) if params[:order_detail].nil?
|
31
|
-
ErrorMessage.raise_argument_error(msg: :
|
34
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :order_detail, data: "String") unless params[:order_detail].is_a? String
|
32
35
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :order_detail) if params[:order_detail].empty?
|
33
36
|
|
34
37
|
if params.has_key? :limit_product_id
|
35
|
-
ErrorMessage.raise_argument_error(msg: :
|
38
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :limit_product_id, data: "String") unless params[:limit_product_id].is_a? String
|
36
39
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :limit_product_id) if params[:limit_product_id].empty?
|
37
40
|
end
|
38
41
|
|
42
|
+
if params.has_key? :chk
|
43
|
+
raise_argument_error(msg: :parameter_should_be, field: :chk, data: "String") unless params[:chk].is_a? String
|
44
|
+
raise_argument_error(msg: :cannot_be_empty, field: :chk) if params[:chk].empty?
|
45
|
+
end
|
46
|
+
|
39
47
|
service_url = params[:service_url]
|
40
48
|
params.delete :service_url
|
41
49
|
|
@@ -46,75 +54,107 @@ module Clt
|
|
46
54
|
send_time: Time.now.strftime("%F %T"),
|
47
55
|
return_type: "json"
|
48
56
|
}.merge(params)
|
49
|
-
|
57
|
+
|
58
|
+
unless params.has_key? :chk
|
59
|
+
data[:chk] = generate_checksum "#{Clt.cocs_hash_base}$#{params[:order_amount]}$#{data[:send_time]}"
|
60
|
+
end
|
50
61
|
|
51
62
|
request(method: "POST", service_url: service_url, data: data)
|
52
63
|
end
|
53
64
|
|
54
65
|
# Order Cancel
|
55
66
|
def order_cancel params = {}
|
56
|
-
ErrorMessage.raise_argument_error(msg: :
|
67
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: "Parameter", data: "Hash") unless params.is_a? Hash
|
57
68
|
|
58
69
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :service_url) if params[:service_url].nil?
|
59
|
-
ErrorMessage.raise_argument_error(msg: :
|
70
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :service_url, data: "String") unless params[:service_url].is_a? String
|
60
71
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :service_url) if params[:service_url].empty?
|
61
72
|
|
62
|
-
ErrorMessage.raise_argument_error(msg: :
|
73
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cust_order_no, data: "String") unless params[:cust_order_no].is_a? String
|
63
74
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :cust_order_no) if params[:cust_order_no].empty?
|
64
75
|
|
65
76
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :order_amount) if params[:order_amount].nil?
|
66
|
-
ErrorMessage.raise_argument_error(msg: :
|
77
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :order_amount, data: "Integer") unless params[:order_amount].is_a? Integer
|
78
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :order_amount, data: "greater than 0") if params[:order_amount] <= 0
|
79
|
+
|
80
|
+
if params.has_key? :chk
|
81
|
+
raise_argument_error(msg: :parameter_should_be, field: :chk, data: "String") unless params[:chk].is_a? String
|
82
|
+
raise_argument_error(msg: :cannot_be_empty, field: :chk) if params[:chk].empty?
|
83
|
+
end
|
67
84
|
|
68
85
|
data = {
|
69
86
|
link_id: Clt.cocs_link_id,
|
70
87
|
send_time: Time.now.strftime("%F %T"),
|
71
88
|
return_type: "json"
|
72
89
|
}.merge(params)
|
73
|
-
|
90
|
+
|
91
|
+
unless params.has_key? :chk
|
92
|
+
data[:chk] = generate_checksum "#{Clt.cocs_hash_base}$#{params[:cust_order_no]}$#{params[:order_amount]}$#{data[:send_time]}"
|
93
|
+
end
|
74
94
|
|
75
95
|
request(method: "POST", service_url: params[:service_url], data: data)
|
76
96
|
end
|
77
97
|
|
78
98
|
# Order Refund
|
79
99
|
def order_refund params = {}
|
80
|
-
ErrorMessage.raise_argument_error(msg: :
|
100
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: "Parameter", data: "Hash") unless params.is_a? Hash
|
81
101
|
|
82
102
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :service_url) if params[:service_url].nil?
|
83
|
-
ErrorMessage.raise_argument_error(msg: :
|
103
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :service_url, data: "String") unless params[:service_url].is_a? String
|
84
104
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :service_url) if params[:service_url].empty?
|
85
105
|
|
86
|
-
ErrorMessage.raise_argument_error(msg: :
|
106
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cust_order_no, data: "String") unless params[:cust_order_no].is_a? String
|
87
107
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :cust_order_no) if params[:cust_order_no].empty?
|
88
108
|
|
89
109
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :order_amount) if params[:order_amount].nil?
|
90
|
-
ErrorMessage.raise_argument_error(msg: :
|
110
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :order_amount, data: "Integer") unless params[:order_amount].is_a? Integer
|
111
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :order_amount, data: "greater than 0") if params[:order_amount] <= 0
|
91
112
|
|
92
113
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :refund_amount) if params[:refund_amount].nil?
|
93
|
-
ErrorMessage.raise_argument_error(msg: :
|
114
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :refund_amount, data: "Integer") unless params[:refund_amount].is_a? Integer
|
115
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :refund_amount, data: "greater than 0") if params[:refund_amount] <= 0
|
116
|
+
|
117
|
+
if params[:refund_amount] > params[:order_amount]
|
118
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :refund_amount, data: "less than or equal to order_amount")
|
119
|
+
end
|
120
|
+
|
121
|
+
if params.has_key? :chk
|
122
|
+
raise_argument_error(msg: :parameter_should_be, field: :chk, data: "String") unless params[:chk].is_a? String
|
123
|
+
raise_argument_error(msg: :cannot_be_empty, field: :chk) if params[:chk].empty?
|
124
|
+
end
|
94
125
|
|
95
126
|
data = {
|
96
127
|
link_id: Clt.cocs_link_id,
|
97
128
|
send_time: Time.now.strftime("%F %T"),
|
98
129
|
return_type: "json"
|
99
130
|
}.merge(params)
|
100
|
-
|
131
|
+
|
132
|
+
unless params.has_key? :chk
|
133
|
+
data[:chk] = generate_checksum "#{Clt.cocs_hash_base}$#{params[:cust_order_no]}$#{params[:order_amount]}$#{params[:refund_amount]}$#{data[:send_time]}"
|
134
|
+
end
|
101
135
|
|
102
136
|
request(method: "POST", service_url: params[:service_url], data: data)
|
103
137
|
end
|
104
138
|
|
105
|
-
#
|
106
|
-
def
|
107
|
-
|
108
|
-
|
139
|
+
# Authorize success response validation
|
140
|
+
def auth_success_response_valid? params
|
141
|
+
params = params.stringify_keys
|
142
|
+
checksum = params["chk"]
|
143
|
+
new_checksum = generate_checksum "#{Clt.cocs_hash_base}$#{params['order_amount']}$#{params['send_time']}$#{params['ret']}$#{params['acquire_time']}$#{params['auth_code']}$#{params['card_no']}$#{params['notify_time']}$#{params['cust_order_no']}"
|
109
144
|
|
110
|
-
|
145
|
+
checksum == new_checksum
|
111
146
|
end
|
112
147
|
|
113
|
-
|
148
|
+
# Authorize fail response validation
|
149
|
+
def auth_fail_response_valid? params
|
150
|
+
params = params.stringify_keys
|
151
|
+
checksum = params["chk"]
|
152
|
+
new_checksum = generate_checksum "#{Clt.cocs_hash_base}$#{params['order_amount']}$#{params['send_time']}$#{params['ret']}$#{params['notify_time']}$#{params['cust_order_no']}"
|
114
153
|
|
115
|
-
|
116
|
-
|
117
|
-
|
154
|
+
checksum == new_checksum
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
118
158
|
|
119
159
|
def request method:, service_url:, data:
|
120
160
|
api_url = URI.parse(service_url)
|
data/lib/clt/cvs.rb
CHANGED
@@ -1,55 +1,64 @@
|
|
1
1
|
module Clt
|
2
2
|
class Cvs
|
3
|
+
include GeneralMethods
|
4
|
+
|
3
5
|
def initialize
|
4
6
|
raise ArgumentError, "Please setup cvs_cust_id first" if Clt.cvs_cust_id.nil?
|
5
|
-
ErrorMessage.raise_argument_error(msg: :
|
7
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cvs_cust_id, data: "String") unless Clt.cvs_cust_id.is_a? String
|
6
8
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :cvs_cust_id) if Clt.cvs_cust_id.empty?
|
7
9
|
|
8
10
|
raise ArgumentError, "Please setup cvs_cust_password first" if Clt.cvs_cust_password.nil?
|
9
|
-
ErrorMessage.raise_argument_error(msg: :
|
11
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cvs_cust_password, data: "String") unless Clt.cvs_cust_password.is_a? String
|
10
12
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :cvs_cust_password) if Clt.cvs_cust_password.empty?
|
11
13
|
|
12
|
-
ErrorMessage.raise_argument_error(msg: :
|
14
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cvs_default_expire_day, data: "Integer") unless Clt.cvs_default_expire_day.is_a? Integer
|
15
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cvs_default_expire_day, data: "greater than 0") if Clt.cvs_default_expire_day <= 0
|
13
16
|
end
|
14
17
|
|
15
18
|
def order_create params = {}
|
16
|
-
ErrorMessage.raise_argument_error(msg: :
|
19
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: "Parameter", data: "Hash") unless params.is_a? Hash
|
17
20
|
|
18
21
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :service_url) if params[:service_url].nil?
|
19
|
-
ErrorMessage.raise_argument_error(msg: :
|
22
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :service_url, data: "String") unless params[:service_url].is_a? String
|
20
23
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :service_url) if params[:service_url].empty?
|
21
24
|
|
22
|
-
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :
|
23
|
-
ErrorMessage.raise_argument_error(msg: :
|
24
|
-
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :
|
25
|
+
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :cust_order_number) if params[:cust_order_number].nil?
|
26
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :cust_order_number, data: "String") unless params[:cust_order_number].is_a? String
|
27
|
+
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :cust_order_number) if params[:cust_order_number].empty?
|
28
|
+
|
29
|
+
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :order_amount) if params[:order_amount].nil?
|
30
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :order_amount, data: "Integer") unless params[:order_amount].is_a? Integer
|
25
31
|
|
26
|
-
|
27
|
-
|
32
|
+
if params.has_key? :expire_date
|
33
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :expire_date, data: "String") unless params[:expire_date].is_a? String
|
34
|
+
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :expire_date) if params[:expire_date].empty?
|
35
|
+
ErrorMessage.raise_argument_error(msg: :wrong_data_format, field: :expire_date) unless /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}\z/.match(params[:expire_date])
|
36
|
+
end
|
28
37
|
|
29
|
-
if params.has_key? :
|
30
|
-
ErrorMessage.raise_argument_error(msg: :
|
31
|
-
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :
|
38
|
+
if params.has_key? :payer_name
|
39
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :payer_name, data: "String") unless params[:payer_name].is_a? String
|
40
|
+
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :payer_name) if params[:payer_name].empty?
|
32
41
|
end
|
33
42
|
|
34
|
-
if params.has_key? :
|
35
|
-
ErrorMessage.raise_argument_error(msg: :
|
36
|
-
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :
|
43
|
+
if params.has_key? :payer_postcode
|
44
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :payer_postcode, data: "String") unless params[:payer_postcode].is_a? String
|
45
|
+
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :payer_postcode) if params[:payer_postcode].empty?
|
37
46
|
end
|
38
47
|
|
39
|
-
if params.has_key? :
|
40
|
-
ErrorMessage.raise_argument_error(msg: :
|
41
|
-
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :
|
48
|
+
if params.has_key? :payer_address
|
49
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :payer_address, data: "String") unless params[:payer_address].is_a? String
|
50
|
+
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :payer_address) if params[:payer_address].empty?
|
42
51
|
end
|
43
52
|
|
44
|
-
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :
|
45
|
-
ErrorMessage.raise_argument_error(msg: :
|
46
|
-
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :
|
53
|
+
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :payer_mobile) if params[:payer_mobile].nil?
|
54
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :payer_mobile, data: "String") unless params[:payer_mobile].is_a? String
|
55
|
+
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :payer_mobile) if params[:payer_mobile].empty?
|
47
56
|
|
48
|
-
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :
|
49
|
-
ErrorMessage.raise_argument_error(msg: :
|
50
|
-
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :
|
57
|
+
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :payer_email) if params[:payer_email].nil?
|
58
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :payer_email, data: "String") unless params[:payer_email].is_a? String
|
59
|
+
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :payer_email) if params[:payer_email].empty?
|
51
60
|
|
52
|
-
expire_date =
|
61
|
+
expire_date = params.has_key?(:expire_date) ? params[:expire_date] : cvs_default_expire_date
|
53
62
|
|
54
63
|
# build xml data
|
55
64
|
builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do
|
@@ -60,14 +69,14 @@ module Clt
|
|
60
69
|
cust_password Clt.cvs_cust_password
|
61
70
|
}
|
62
71
|
order {
|
63
|
-
cust_order_number params[:
|
64
|
-
order_amount params[:
|
72
|
+
cust_order_number params[:cust_order_number]
|
73
|
+
order_amount params[:order_amount]
|
65
74
|
expire_date expire_date
|
66
|
-
payer_name params[:
|
67
|
-
payer_postcode params[:
|
68
|
-
payer_address params[:
|
69
|
-
payer_mobile params[:
|
70
|
-
payer_email params[:
|
75
|
+
payer_name params[:payer_name] if params.has_key? :payer_name
|
76
|
+
payer_postcode params[:payer_postcode] if params.has_key? :payer_postcode
|
77
|
+
payer_address params[:payer_address] if params.has_key? :payer_address
|
78
|
+
payer_mobile params[:payer_mobile]
|
79
|
+
payer_email params[:payer_email]
|
71
80
|
}
|
72
81
|
}
|
73
82
|
end
|
@@ -76,21 +85,21 @@ module Clt
|
|
76
85
|
end
|
77
86
|
|
78
87
|
def order_query params = {}
|
79
|
-
ErrorMessage.raise_argument_error(msg: :
|
88
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: "Parameter", data: "Hash") unless params.is_a? Hash
|
80
89
|
|
81
90
|
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :service_url) if params[:service_url].nil?
|
82
|
-
ErrorMessage.raise_argument_error(msg: :
|
91
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :service_url, data: "String") unless params[:service_url].is_a? String
|
83
92
|
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :service_url) if params[:service_url].empty?
|
84
93
|
|
85
|
-
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :
|
86
|
-
ErrorMessage.raise_argument_error(msg: :
|
87
|
-
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :
|
94
|
+
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :process_code_update_time_begin) if params[:process_code_update_time_begin].nil?
|
95
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :process_code_update_time_begin, data: "String") unless params[:process_code_update_time_begin].is_a? String
|
96
|
+
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :process_code_update_time_begin) if params[:process_code_update_time_begin].empty?
|
97
|
+
ErrorMessage.raise_argument_error(msg: :wrong_data_format, field: :process_code_update_time_begin) unless /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}\z/.match(params[:process_code_update_time_begin])
|
88
98
|
|
89
|
-
if params.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
99
|
+
ErrorMessage.raise_argument_error(msg: :missing_parameter, field: :process_code_update_time_end) if params[:process_code_update_time_end].nil?
|
100
|
+
ErrorMessage.raise_argument_error(msg: :parameter_should_be, field: :process_code_update_time_end, data: "String") unless params[:process_code_update_time_end].is_a? String
|
101
|
+
ErrorMessage.raise_argument_error(msg: :cannot_be_empty, field: :process_code_update_time_end) if params[:process_code_update_time_end].empty?
|
102
|
+
ErrorMessage.raise_argument_error(msg: :wrong_data_format, field: :process_code_update_time_end) unless /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}\z/.match(params[:process_code_update_time_end])
|
94
103
|
|
95
104
|
builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do
|
96
105
|
request {
|
@@ -100,8 +109,8 @@ module Clt
|
|
100
109
|
cust_password Clt.cvs_cust_password
|
101
110
|
}
|
102
111
|
query {
|
103
|
-
process_code_update_time_begin params[:
|
104
|
-
process_code_update_time_end params[:
|
112
|
+
process_code_update_time_begin params[:process_code_update_time_begin]
|
113
|
+
process_code_update_time_end params[:process_code_update_time_end]
|
105
114
|
}
|
106
115
|
}
|
107
116
|
end
|
@@ -111,8 +120,9 @@ module Clt
|
|
111
120
|
|
112
121
|
private
|
113
122
|
|
114
|
-
def
|
115
|
-
|
123
|
+
def get_cvs_default_expire_date
|
124
|
+
seconds_in_a_day = 60 * 60 * 24
|
125
|
+
offset = seconds_in_a_day * Clt.cvs_default_expire_day
|
116
126
|
|
117
127
|
(Time.now + offset).iso8601
|
118
128
|
end
|
data/lib/clt/error_message.rb
CHANGED
@@ -6,13 +6,11 @@ module Clt
|
|
6
6
|
case params[:msg]
|
7
7
|
when :missing_parameter
|
8
8
|
message = "Missing required parameter: #{params[:field]}"
|
9
|
-
when :
|
10
|
-
message = "Parameter should be #{params[:type]}"
|
11
|
-
when :wrong_data
|
9
|
+
when :parameter_should_be
|
12
10
|
message = "#{params[:field]} should be #{params[:data]}"
|
13
11
|
when :data_length_too_short
|
14
12
|
message = "The length of #{params[:field]} is too short"
|
15
|
-
when :
|
13
|
+
when :wrong_data_format
|
16
14
|
message = "The format for #{params[:field]} is wrong"
|
17
15
|
when :cannot_be_empty
|
18
16
|
message = "#{params[:field]} cannot be empty"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Clt
|
2
|
+
module GeneralMethods
|
3
|
+
# APN(Active Payment Notification) response validation
|
4
|
+
def apn_response_valid? params
|
5
|
+
params = params.stringify_keys
|
6
|
+
checksum = params["checksum"]
|
7
|
+
new_checksum = generate_checksum "#{params['api_id']}:#{params['trans_id']}:#{params['amount']}:#{params['status']}:#{params['nonce']}"
|
8
|
+
|
9
|
+
checksum == new_checksum
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_checksum data
|
13
|
+
Digest::MD5.hexdigest data
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/clt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clt-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Calvert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -85,9 +85,11 @@ files:
|
|
85
85
|
- bin/setup
|
86
86
|
- clt-sdk.gemspec
|
87
87
|
- lib/clt-sdk.rb
|
88
|
+
- lib/clt/core_ext/hash.rb
|
88
89
|
- lib/clt/credit_card.rb
|
89
90
|
- lib/clt/cvs.rb
|
90
91
|
- lib/clt/error_message.rb
|
92
|
+
- lib/clt/general_methods.rb
|
91
93
|
- lib/clt/version.rb
|
92
94
|
homepage: https://github.com/CalvertYang/clt-sdk
|
93
95
|
licenses:
|