alipay_global 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eddedc835b2bfbb0f10a759faea33ab63e9afd95
4
- data.tar.gz: 04033f489681672e64d7e653bc312683eaf21d7c
3
+ metadata.gz: 7e25a163c6a105f882363330ab4c883b76dcd9cc
4
+ data.tar.gz: d87038772fa03ac173230766ea799f3a4d801938
5
5
  SHA512:
6
- metadata.gz: f8706e2ede93062f2472978a777ada9277870d729ec802d5b288428e53dfd0ba2b7bacfff76d2aca4be00a9c57879c3762f012539e6bf3d0be6f4ec261e3bebc
7
- data.tar.gz: 44cfecd9b76dd39396e98b2ec8c165244da4023fd8e55463be7da28d491452d36b4c0b466a997f232ace4257eee59e87a763309a2fe5f9ceabe653be5d5a6917
6
+ metadata.gz: 4203de1fbf2710247b042217ba1021c88614a38218f26eb18c20cfcf7b1cad31d6169ef7ffcab73ef8746509b543f8f4eab5998c1f2872b21d3583fd89a17f47
7
+ data.tar.gz: 47c2678c31ef89aacaca21fd6535ff2ffd67278b490409e307771747d1d275c9a6ba42f9c3a9f4383d3faf82b6a3ab92a5f29c7c071d34fa67d5df1fda520c64
data/lib/alipay_global.rb CHANGED
@@ -10,6 +10,7 @@ require 'alipay_global/service/trade'
10
10
  require 'alipay_global/service/exchange'
11
11
  require 'alipay_global/service/notification'
12
12
  require 'alipay_global/service/reconciliation'
13
+ require 'alipay_global/service/settlement'
13
14
 
14
15
  module AlipayGlobal
15
16
 
@@ -0,0 +1,75 @@
1
+ require 'open-uri'
2
+
3
+ module AlipayGlobal
4
+ module Service
5
+ module Settlement
6
+
7
+ RequestError = Class.new(RuntimeError)
8
+
9
+ SETTLEMENT_REQUIRED_PARAMS = %w( start_date end_date )
10
+
11
+ SETTLEMENT_ERROR_MESSAGES = [
12
+ "Over 10 days to Date period",
13
+ "Over limit balance amount record",
14
+ "System exception",
15
+ "No balance amount data in the period",
16
+ "<alipay><is_success>F</is_success><error>ILLEGAL_PARTNER</error></alipay>",
17
+ "Finish date not ahead of today",
18
+ "Finish date ahead of begin date",
19
+ "Illegal Date period!",
20
+ "Date format incorrect YYYYMMDD",
21
+ "Internet connected exception ,please try later"
22
+ ]
23
+
24
+ def self.request(params)
25
+ settlement_resp = []
26
+ open(build_request(params)) do |data|
27
+ results = data.read
28
+
29
+ return false if results.include? "No balance account data in the period"
30
+ raise RequestError, "#{results}" if error_check(results)
31
+
32
+ results.each_line do |line|
33
+ transaction = line.strip.split("|")
34
+
35
+ settlement_resp << {
36
+ partner_transaction_id: transaction[0],
37
+ amount: transaction[1],
38
+ currency: transaction[2],
39
+ payment_time: valid_alipay_date(transaction[3]) ? DateTime.strptime(transaction[3],"%Y%m%d%H%M%S") : '',
40
+ settlement_time: valid_alipay_date(transaction[4]) ? DateTime.strptime(transaction[4],"%Y%m%d%H%M%S") : '',
41
+ transaction_type: transaction[5],
42
+ service_charge: transaction[6],
43
+ status: transaction[7],
44
+ remarks: transaction[8] ? transaction[8] : ''
45
+ }
46
+ end
47
+
48
+ end
49
+ settlement_resp
50
+ end
51
+
52
+ def self.build_request(params)
53
+ AlipayGlobal::Service.check_required_params(params, SETTLEMENT_REQUIRED_PARAMS)
54
+
55
+ params = AlipayGlobal::Utils.stringify_keys(params)
56
+
57
+ params = {
58
+ 'service' => 'forex_liquidation_file',
59
+ 'partner' => AlipayGlobal.api_partner_id,
60
+ }.merge(params)
61
+
62
+ AlipayGlobal::Service.request_uri(params).to_s
63
+ end
64
+
65
+ def self.error_check(data)
66
+ SETTLEMENT_ERROR_MESSAGES.any? { |w| data =~ /#{w}/ }
67
+ end
68
+
69
+ def self.valid_alipay_date(raw_date)
70
+ raw_date && raw_date.length > 0
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -84,8 +84,6 @@ module AlipayGlobal
84
84
  alipay_resp = Nokogiri::XML(resp.body)
85
85
 
86
86
  alipay_results = alipay_resp.at_xpath('//alipay')
87
- #puts "success = " + alipay_results.at_xpath('//is_success').content
88
- #puts "error = " + alipay_results.at_xpath('//error').content
89
87
 
90
88
  file.unlink
91
89
  end
@@ -1,3 +1,3 @@
1
1
  module AlipayGlobal
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,72 @@
1
+ require 'test_config'
2
+
3
+ describe "AlipayGlobal::Service::Settlement", "Settlement request check" do
4
+
5
+ before do
6
+ @alipay = AlipayGlobal
7
+ @alipay.api_partner_id = '2088101122136241'
8
+ @alipay.api_secret_key = '760bdzec6y9goq7ctyx96ezkz78287de'
9
+
10
+ @params = {
11
+ 'start_date'=> '20120202',
12
+ 'end_date'=> '20120205'
13
+ }
14
+ end
15
+
16
+ describe "#build_request" do
17
+ it "should get params correctly" do
18
+ assert_equal "https://mapi.alipay.net/gateway.do?service=forex_liquidation_file&partner=2088101122136241&start_date=20120202&end_date=20120205&sign_type=MD5&sign=68c26fcba73dc3134bc88bb04a8be865", @alipay::Service::Settlement.build_request(@params)
19
+ end
20
+ end
21
+
22
+ describe "#request" do
23
+ describe "Error scenarios" do
24
+
25
+ it "return false for no records in period" do
26
+ assert_equal false, @alipay::Service::Settlement.request(@params)
27
+ end
28
+
29
+ it "should throw an AlipayGlobal::Service::Settlement::RequestError for date range > 10 days" do
30
+ proc{ (@alipay::Service::Settlement.request({
31
+ 'start_date'=> '20120202',
32
+ 'end_date'=> '20120305'
33
+ })).call }.must_raise(AlipayGlobal::Service::Settlement::RequestError)
34
+ end
35
+
36
+ it "should throw an AlipayGlobal::Service::Settlement::RequestError for an errorneous date range" do
37
+ proc{ (@alipay::Service::Settlement.request({
38
+ 'start_date'=> '20130202',
39
+ 'end_date'=> '20120305'
40
+ })).call }.must_raise(AlipayGlobal::Service::Settlement::RequestError)
41
+ end
42
+
43
+ it "should throw an AlipayGlobal::Service::Settlement::RequestError for no dates supplied (or nil)" do
44
+ proc{ (@alipay::Service::Settlement.request({})).call }.must_raise(AlipayGlobal::Service::Settlement::RequestError)
45
+ proc{ (@alipay::Service::Settlement.request(nil)).call }.must_raise(NoMethodError)
46
+ end
47
+
48
+ it "should throw an AlipayGlobal::Service::Settlement::RequestError for finish date ahead of today" do
49
+ proc{ (@alipay::Service::Settlement.request({
50
+ 'start_date'=> '20151300',
51
+ 'end_date'=> '20151333'
52
+ })).call }.must_raise(AlipayGlobal::Service::Settlement::RequestError)
53
+ end
54
+
55
+ describe "Incorrect Merchant" do
56
+ before do
57
+ @alipay.api_partner_id = 'daftpunk'
58
+ end
59
+
60
+ it "should throw an AlipayGlobal::Service::Settlement::RequestError for Merchant ID incorrect" do
61
+ proc{ (@alipay::Service::Settlement.request(@params)).call }.must_raise(AlipayGlobal::Service::Settlement::RequestError)
62
+ end
63
+
64
+ after do
65
+ @alipay.api_partner_id = '2088101122136241'
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alipay_global
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Melvrick Goh, Ng Junyang, Grzegorz Witek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,6 +114,7 @@ files:
114
114
  - lib/alipay_global/service/exchange.rb
115
115
  - lib/alipay_global/service/notification.rb
116
116
  - lib/alipay_global/service/reconciliation.rb
117
+ - lib/alipay_global/service/settlement.rb
117
118
  - lib/alipay_global/service/trade.rb
118
119
  - lib/alipay_global/sign.rb
119
120
  - lib/alipay_global/sign/dsa.rb
@@ -125,6 +126,7 @@ files:
125
126
  - test/service/exchange_test.rb
126
127
  - test/service/notification_test.rb
127
128
  - test/service/reconciliation_test.rb
129
+ - test/service/settlement_test.rb
128
130
  - test/service/trade_test.rb
129
131
  - test/service_test.rb
130
132
  - test/sign/dsa_test.rb
@@ -153,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  version: '0'
154
156
  requirements: []
155
157
  rubyforge_project:
156
- rubygems_version: 2.4.3
158
+ rubygems_version: 2.2.2
157
159
  signing_key:
158
160
  specification_version: 4
159
161
  summary: An unofficial simple global.alipay gem
@@ -162,6 +164,7 @@ test_files:
162
164
  - test/service/exchange_test.rb
163
165
  - test/service/notification_test.rb
164
166
  - test/service/reconciliation_test.rb
167
+ - test/service/settlement_test.rb
165
168
  - test/service/trade_test.rb
166
169
  - test/service_test.rb
167
170
  - test/sign/dsa_test.rb