ccb_connect_client 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +9 -0
- data/README.md +1 -0
- data/lib/ccb_connect_client/models/base_request.rb +18 -0
- data/lib/ccb_connect_client/models/base_response.rb +22 -0
- data/lib/ccb_connect_client/models/payment_details_query_request.rb +51 -0
- data/lib/ccb_connect_client/models/payment_details_query_response.rb +65 -0
- data/lib/ccb_connect_client/models/refund_request.rb +39 -0
- data/lib/ccb_connect_client/models/refund_response.rb +39 -0
- data/lib/ccb_connect_client/service.rb +54 -0
- data/lib/ccb_connect_client/version.rb +3 -0
- data/lib/ccb_connect_client.rb +16 -3
- data/spec/ccb_connect_client_service_spec.rb +29 -0
- metadata +57 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aa8b35d86e633600a752178983e3c81e1ff98c3
|
4
|
+
data.tar.gz: 9c79175e570d327e7c00e5f4f3c3ef966ebe71e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83ba2ada8f3df3828d4b0834248af25264a1224029f17cae41fbd6927882ad3443c293b9ee0de571e13e3c379a46605a56e139bf6768d6395e56a0340cd617f6
|
7
|
+
data.tar.gz: af807df5ef7a8de5553faa036a1cf1fc9572a16cc8433f9630561cf176578346e2c0eaa385b2987b439cbf70c872c664df950e3268289fe1f090fd547816e688
|
data/LICENSE.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2009-2013 Nicholas J Humfrey
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ccb payment connect client
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'builder'
|
2
|
+
|
3
|
+
module CcbConnectClient
|
4
|
+
|
5
|
+
class BaseRequest
|
6
|
+
attr_reader :tx_code, :request_sn
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
generate_request_sn
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_request_sn
|
13
|
+
@request_sn = Time.now.strftime '%Y%m%d%H%M%S' + rand(10).to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CcbConnectClient
|
2
|
+
|
3
|
+
class BaseResponse
|
4
|
+
|
5
|
+
attr_accessor :request_sn, :return_code, :return_msg, :successful
|
6
|
+
|
7
|
+
def self.from_xml xml
|
8
|
+
|
9
|
+
response = BaseResponse.new
|
10
|
+
doc = Document.new(xml)
|
11
|
+
|
12
|
+
response.request_sn = doc.elements["TX/REQUEST_SN"].text
|
13
|
+
response.return_code = doc.elements["TX/RETURN_CODE"].text
|
14
|
+
response.return_msg = doc.elements["TX/RETURN_MSG"].text
|
15
|
+
|
16
|
+
if CcbConnectClient.debug_mode
|
17
|
+
puts "BaseResponse response : #{response.inspect}"
|
18
|
+
end
|
19
|
+
response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'builder'
|
2
|
+
|
3
|
+
module CcbConnectClient
|
4
|
+
|
5
|
+
class PaymentDetailsQueryRequest < BaseRequest
|
6
|
+
attr_accessor :order
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@tx_code = '5W1002'
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_xml
|
14
|
+
xml = Builder::XmlMarkup.new(:indent=>2)
|
15
|
+
xml.instruct! :xml, :version=>"1.0", :encoding=>"GB2312"
|
16
|
+
xml.TX{
|
17
|
+
xml.REQUEST_SN "#{@request_sn}"
|
18
|
+
xml.CUST_ID "#{CcbConnectClient.cust_id}"
|
19
|
+
xml.USER_ID"#{CcbConnectClient.user_id}"
|
20
|
+
xml.PASSWORD "#{CcbConnectClient.password}"
|
21
|
+
xml.TX_CODE "#{@tx_code}"
|
22
|
+
xml.LANGUAGE "#{CcbConnectClient.language}"
|
23
|
+
xml.TX_INFO{
|
24
|
+
# xml.START "#{@start_day}"
|
25
|
+
# xml.STARTHOUR "#{@start_hour}"
|
26
|
+
# xml.STARTMIN "#{@start_min}"
|
27
|
+
# xml.END "#{@end_day}"
|
28
|
+
# xml.ENDHOUR "#{@end_hour}"
|
29
|
+
# xml.ENDMIN "#{@end_min}"
|
30
|
+
# xml.KIND "0"
|
31
|
+
xml.ORDER "#{@order}"
|
32
|
+
# xml.ACCOUNT ""
|
33
|
+
# xml.DEXCEL "1"
|
34
|
+
# xml.MONEY "#{@money}"
|
35
|
+
# xml.NORDERBY "1"
|
36
|
+
# xml.PAGE "1"
|
37
|
+
# xml.POS_CODE ""
|
38
|
+
# xml.STATUS ""
|
39
|
+
# xml.Mrch_No ""
|
40
|
+
}
|
41
|
+
}
|
42
|
+
target = xml.target!
|
43
|
+
if CcbConnectClient.debug_mode
|
44
|
+
puts "RefundRequest xml : #{target}"
|
45
|
+
end
|
46
|
+
target
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#encoding:utf-8
|
2
|
+
require 'rexml/document'
|
3
|
+
include REXML
|
4
|
+
|
5
|
+
module CcbConnectClient
|
6
|
+
|
7
|
+
class PaymentDetailsQueryResponse < BaseResponse
|
8
|
+
attr_accessor :cust_id, :tx_code, :language, :cur_page, :page_count, :notice, :tran_date, :acc_date,
|
9
|
+
:order, :account, :acc_name, :payment_money, :refund_money, :pos_id, :rem1, :order_status, :order_status_name
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_xml xml
|
16
|
+
response = PaymentDetailsQueryResponse.new
|
17
|
+
doc = Document.new(xml)
|
18
|
+
|
19
|
+
if CcbConnectClient.debug_mode
|
20
|
+
puts "RefundResponse response : #{doc}"
|
21
|
+
end
|
22
|
+
|
23
|
+
response.request_sn = doc.elements["TX/REQUEST_SN"].text
|
24
|
+
response.cust_id = doc.elements["TX/CUST_ID"].text
|
25
|
+
response.tx_code = doc.elements["TX/TX_CODE"].text
|
26
|
+
response.return_code = doc.elements["TX/RETURN_CODE"].text
|
27
|
+
response.return_msg = doc.elements["TX/RETURN_MSG"].text
|
28
|
+
response.language = doc.elements["TX/LANGUAGE"].text
|
29
|
+
# INFO
|
30
|
+
response.cur_page = doc.elements["TX/TX_INFO/CUR_PAGE"].text
|
31
|
+
response.page_count = doc.elements["TX/TX_INFO/PAGE_COUNT"].text
|
32
|
+
# LIST
|
33
|
+
response.tran_date = doc.elements["TX/TX_INFO/LIST/TRAN_DATE"].text
|
34
|
+
response.acc_date = doc.elements["TX/TX_INFO/LIST/ACC_DATE"].text
|
35
|
+
response.order = doc.elements["TX/TX_INFO/LIST/ORDER"].text
|
36
|
+
response.account = doc.elements["TX/TX_INFO/LIST/ACCOUNT"].text
|
37
|
+
response.acc_name = doc.elements["TX/TX_INFO/LIST/ACC_NAME"].text
|
38
|
+
response.payment_money = doc.elements["TX/TX_INFO/LIST/PAYMENT_MONEY"].text
|
39
|
+
response.refund_money = doc.elements["TX/TX_INFO/LIST/REFUND_MONEY"].text
|
40
|
+
response.pos_id = doc.elements["TX/TX_INFO/LIST/POS_ID"].text
|
41
|
+
response.rem1 = doc.elements["TX/TX_INFO/LIST/REM1"].text
|
42
|
+
response.order_status = doc.elements["TX/TX_INFO/LIST/ORDER_STATUS"].text
|
43
|
+
|
44
|
+
case response.order_status
|
45
|
+
when '0'
|
46
|
+
response.order_status_name = "失败"
|
47
|
+
when '1'
|
48
|
+
response.order_status_name = "成功"
|
49
|
+
when '2'
|
50
|
+
response.order_status_name = "待银行确认"
|
51
|
+
when '3'
|
52
|
+
response.order_status_name = "已部分退款"
|
53
|
+
when '4'
|
54
|
+
response.order_status_name = "已全额退款"
|
55
|
+
else
|
56
|
+
response.order_status_name = "待银行确认"
|
57
|
+
end
|
58
|
+
|
59
|
+
if CcbConnectClient.debug_mode
|
60
|
+
puts "RefundResponse response : #{response.inspect}"
|
61
|
+
end
|
62
|
+
response
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'builder'
|
2
|
+
|
3
|
+
module CcbConnectClient
|
4
|
+
|
5
|
+
class RefundRequest < BaseRequest
|
6
|
+
attr_accessor :money, :order, :refund_code
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@tx_code = '5W1004'
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_xml
|
14
|
+
xml = Builder::XmlMarkup.new(:indent=>2)
|
15
|
+
xml.instruct! :xml, :version=>"1.0", :encoding=>"GB2312"
|
16
|
+
xml.TX{
|
17
|
+
xml.REQUEST_SN "#{@request_sn}"
|
18
|
+
xml.CUST_ID "#{CcbConnectClient.cust_id}"
|
19
|
+
xml.USER_ID"#{CcbConnectClient.user_id}"
|
20
|
+
xml.PASSWORD "#{CcbConnectClient.password}"
|
21
|
+
xml.TX_CODE "#{@tx_code}"
|
22
|
+
xml.LANGUAGE "#{CcbConnectClient.language}"
|
23
|
+
xml.TX_INFO{
|
24
|
+
xml.MONEY "#{@money}"
|
25
|
+
xml.ORDER "#{@order}"
|
26
|
+
#xml.REFUND_CODE "#{@refund_code}"
|
27
|
+
}
|
28
|
+
#xml.SIGN_INFO "#{}"
|
29
|
+
}
|
30
|
+
target = xml.target!
|
31
|
+
if CcbConnectClient.debug_mode
|
32
|
+
puts "RefundRequest xml : #{target}"
|
33
|
+
end
|
34
|
+
target
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
include REXML
|
3
|
+
|
4
|
+
module CcbConnectClient
|
5
|
+
|
6
|
+
class RefundResponse < BaseResponse
|
7
|
+
attr_accessor :cust_id, :tx_code, :language, :order_num, :pay_amount, :amount
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.from_xml xml
|
14
|
+
response = RefundResponse.new
|
15
|
+
doc = Document.new(xml)
|
16
|
+
|
17
|
+
if CcbConnectClient.debug_mode
|
18
|
+
puts "RefundResponse response : #{doc}"
|
19
|
+
end
|
20
|
+
|
21
|
+
response.request_sn = doc.elements["TX/REQUEST_SN"].text
|
22
|
+
response.cust_id = doc.elements["TX/CUST_ID"].text
|
23
|
+
response.tx_code = doc.elements["TX/TX_CODE"].text
|
24
|
+
response.return_code = doc.elements["TX/RETURN_CODE"].text
|
25
|
+
response.return_msg = doc.elements["TX/RETURN_MSG"].text
|
26
|
+
response.language = doc.elements["TX/LANGUAGE"].text
|
27
|
+
# INFO
|
28
|
+
response.order_num = doc.elements["TX/TX_INFO/ORDER_NUM"].text
|
29
|
+
response.pay_amount = doc.elements["TX/TX_INFO/PAY_AMOUNT"].text
|
30
|
+
response.amount = doc.elements["TX/TX_INFO/AMOUNT"].text
|
31
|
+
|
32
|
+
if CcbConnectClient.debug_mode
|
33
|
+
puts "RefundResponse response : #{response.inspect}"
|
34
|
+
end
|
35
|
+
response
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module CcbConnectClient
|
5
|
+
|
6
|
+
module Service
|
7
|
+
def self.refund refund_request
|
8
|
+
res = http_post_form CcbConnectClient.server, refund_request.to_xml
|
9
|
+
doc = Document.new(res.body)
|
10
|
+
|
11
|
+
if doc.elements["TX/RETURN_CODE"].text != "000000"
|
12
|
+
response = BaseResponse.from_xml res.body
|
13
|
+
response.successful = false
|
14
|
+
response
|
15
|
+
else
|
16
|
+
response = RefundResponse.from_xml res.body
|
17
|
+
response.successful = true
|
18
|
+
|
19
|
+
if CcbConnectClient.debug_mode
|
20
|
+
puts "RefundResponse response : #{response.inspect}"
|
21
|
+
end
|
22
|
+
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.payment_details_query payment_details_query_request
|
29
|
+
res = http_post_form CcbConnectClient.server, payment_details_query_request.to_xml
|
30
|
+
doc = Document.new(res.body)
|
31
|
+
|
32
|
+
if doc.elements["TX/RETURN_CODE"].text != "000000"
|
33
|
+
response = BaseResponse.from_xml res.body
|
34
|
+
response.successful = false
|
35
|
+
response
|
36
|
+
else
|
37
|
+
response = PaymentDetailsQueryResponse.from_xml res.body
|
38
|
+
response.successful = true
|
39
|
+
|
40
|
+
if CcbConnectClient.debug_mode
|
41
|
+
puts "PaymentDetailsQueryResponse response : #{response.inspect}"
|
42
|
+
end
|
43
|
+
|
44
|
+
response
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.http_post_form(url, xml)
|
50
|
+
response = Net::HTTP.post_form URI(url), requestXml: xml
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/lib/ccb_connect_client.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'ccb_connect_client/service'
|
2
|
+
require 'ccb_connect_client/models/base_request'
|
3
|
+
require 'ccb_connect_client/models/refund_request'
|
4
|
+
require 'ccb_connect_client/models/base_response'
|
5
|
+
require 'ccb_connect_client/models/refund_response'
|
6
|
+
require 'ccb_connect_client/models/payment_details_query_request'
|
7
|
+
require 'ccb_connect_client/models/payment_details_query_response'
|
8
|
+
|
9
|
+
module CcbConnectClient
|
10
|
+
|
11
|
+
@debug_mode = true
|
12
|
+
|
13
|
+
class<< self
|
14
|
+
attr_accessor :server, :debug_mode
|
15
|
+
attr_accessor :cust_id, :user_id, :password, :language
|
4
16
|
end
|
17
|
+
|
5
18
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CcbConnectClient::Service do
|
4
|
+
|
5
|
+
it 'should be successful' do
|
6
|
+
CcbConnectClient.server = "http://192.168.10.90:9000"
|
7
|
+
CcbConnectClient.cust_id = '105000148164407'
|
8
|
+
CcbConnectClient.user_id = '001'
|
9
|
+
CcbConnectClient.password = 'SbusTrade9'
|
10
|
+
CcbConnectClient.language = 'CN'
|
11
|
+
request = CcbConnectClient::RefundRequest.new
|
12
|
+
request.money = 7.01
|
13
|
+
request.order = 'L238201903071717YKIHNW'
|
14
|
+
CcbConnectClient::Service.refund request
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should be successful' do
|
18
|
+
CcbConnectClient.server = "http://192.168.10.90:9000"
|
19
|
+
CcbConnectClient.cust_id = '105000148164407'
|
20
|
+
CcbConnectClient.user_id = '001'
|
21
|
+
CcbConnectClient.password = 'SbusTrade9'
|
22
|
+
CcbConnectClient.language = 'CN'
|
23
|
+
request = CcbConnectClient::PaymentDetailsQueryRequest.new
|
24
|
+
# request.money = 7.01
|
25
|
+
request.order = 'L238201903071717YKIHNW'
|
26
|
+
CcbConnectClient::Service.payment_details_query request
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ccb_connect_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LCola
|
@@ -9,14 +9,67 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-03-05 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: builder
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rexml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.0
|
13
55
|
description: An unofficial simple ccb payment connect client gem
|
14
56
|
email: developer@lcola.cn
|
15
57
|
executables: []
|
16
58
|
extensions: []
|
17
59
|
extra_rdoc_files: []
|
18
60
|
files:
|
61
|
+
- LICENSE.md
|
62
|
+
- README.md
|
19
63
|
- lib/ccb_connect_client.rb
|
64
|
+
- lib/ccb_connect_client/models/base_request.rb
|
65
|
+
- lib/ccb_connect_client/models/base_response.rb
|
66
|
+
- lib/ccb_connect_client/models/payment_details_query_request.rb
|
67
|
+
- lib/ccb_connect_client/models/payment_details_query_response.rb
|
68
|
+
- lib/ccb_connect_client/models/refund_request.rb
|
69
|
+
- lib/ccb_connect_client/models/refund_response.rb
|
70
|
+
- lib/ccb_connect_client/service.rb
|
71
|
+
- lib/ccb_connect_client/version.rb
|
72
|
+
- spec/ccb_connect_client_service_spec.rb
|
20
73
|
homepage: http://rubygems.org/gems/ccb_connect_client
|
21
74
|
licenses:
|
22
75
|
- MIT
|
@@ -41,4 +94,5 @@ rubygems_version: 2.6.14
|
|
41
94
|
signing_key:
|
42
95
|
specification_version: 4
|
43
96
|
summary: CCB connect client
|
44
|
-
test_files:
|
97
|
+
test_files:
|
98
|
+
- spec/ccb_connect_client_service_spec.rb
|