alipay_global 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ require 'test_config'
2
+
3
+ describe "AlipayGlobal::Service::Trade", "Forex trade actions" do
4
+
5
+ before do
6
+ @alipay = AlipayGlobal
7
+ @alipay.environment = 'TESTING'
8
+ @alipay.api_partner_id = '2088101122136241'
9
+ @alipay.api_secret_key = '760bdzec6y9goq7ctyx96ezkz78287de'
10
+ end
11
+
12
+ describe "#create" do
13
+
14
+ describe "Mobile friendly interface" do
15
+ it "total_fee_mobile: should create the correct mobile friendly url" do
16
+ params = {
17
+ mobile: true,
18
+ notify_url: 'https://example.com/notify',
19
+ subject: 'product_name',
20
+ out_trade_no: '12345',
21
+ total_fee: 350.45,
22
+ currency: 'USD',
23
+ supplier: 'company_name'
24
+ }
25
+ assert_equal 'https://mapi.alipay.net/gateway.do?service=create_forex_trade_wap&_input_charset=utf-8&partner=2088101122136241&notify_url=https%3A%2F%2Fexample.com%2Fnotify&subject=product_name&out_trade_no=12345&total_fee=350.45&currency=USD&supplier=company_name&sign_type=MD5&sign=c19f42a597963f118c4f99f2fc7f716f', @alipay::Service::Trade.create(params)
26
+ end
27
+ end
28
+
29
+ describe "MD5 sign" do
30
+ #RMB_FEE mode doesn't integrate with Alipay. Awaiting response from the Alipay team
31
+ it "rmb_fee: should create the correct url" do
32
+ params = {
33
+ notify_url: 'https://example.com/notify',
34
+ subject: 'product_name',
35
+ out_trade_no: '12345',
36
+ rmb_fee: 0.10,
37
+ currency: 'USD',
38
+ supplier: 'company_name'
39
+ }
40
+ assert_equal 'https://mapi.alipay.net/gateway.do?service=create_forex_trade&_input_charset=utf-8&partner=2088101122136241&notify_url=https%3A%2F%2Fexample.com%2Fnotify&subject=product_name&out_trade_no=12345&rmb_fee=0.10&currency=USD&supplier=company_name&sign_type=MD5&sign=4986b31c8febb978ee6d6c45f76614ac', @alipay::Service::Trade.create(params)
41
+ end
42
+
43
+ it "total_fee: should create the correct url" do
44
+ params = {
45
+ notify_url: 'https://example.com/notify',
46
+ subject: 'product_name',
47
+ out_trade_no: '12345',
48
+ total_fee: 350.45,
49
+ currency: 'USD',
50
+ supplier: 'company_name'
51
+ }
52
+ assert_equal 'https://mapi.alipay.net/gateway.do?service=create_forex_trade&_input_charset=utf-8&partner=2088101122136241&notify_url=https%3A%2F%2Fexample.com%2Fnotify&subject=product_name&out_trade_no=12345&total_fee=350.45&currency=USD&supplier=company_name&sign_type=MD5&sign=2dd75a3023c0a3a795a83109966bbc7d', @alipay::Service::Trade.create(params)
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ describe "#refund" do
59
+ it "should transact refund correctly" do
60
+ sample_refunds = [
61
+ { new_transaction_id: '111222333', old_transaction_id: '444555666', currency: 'USD', refund_sum: 200.00, refund_time: '20120330235959', refund_reason: 'bello minions' },
62
+ { new_transaction_id: '111222333', old_transaction_id: '444555667', currency: 'USD', refund_sum: 150.00, refund_time: '20120330235959', refund_reason: 'monkey' }
63
+ ]
64
+
65
+ @alipay::Service::Trade.refund(sample_refunds)
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_config'
2
+
3
+ describe "AlipayGlobal::Service", "basic service config" do
4
+
5
+ before do
6
+ @alipay = AlipayGlobal
7
+ end
8
+
9
+ describe "#gateway" do
10
+
11
+ describe "gateway is test environment by default" do
12
+ it "should return test environment gateway" do
13
+ assert_equal @alipay::Service.gateway_url, "https://mapi.alipay.net/gateway.do?"
14
+ end
15
+ end
16
+
17
+ describe "gateway is in production" do
18
+ before do
19
+ @alipay.environment = "PRODUCTION"
20
+ end
21
+
22
+ it "should return production environment gateway" do
23
+ assert_equal @alipay::Service.gateway_url, "https://mapi.alipay.com/gateway.do?"
24
+ end
25
+
26
+ after do
27
+ @alipay.environment = "TEST"
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_config'
2
+
3
+ describe "AlipayGlobal::Sign::DSA", "dsa not implemented test" do
4
+
5
+ before do
6
+ @alipay = AlipayGlobal
7
+ end
8
+
9
+ describe "RSA#sign" do
10
+ it "should throw a NotImplementedError when DSA based sign is called" do
11
+ exception = proc{ (@alipay::Sign::DSA.sign("no_content","no_key")).call }.must_raise(NotImplementedError)
12
+ exception.message.must_include "DSA is not implemented"
13
+ end
14
+ end
15
+
16
+ describe "DSA#verify?" do
17
+ it "should throw a NotImplementedError when DSA based verify is called" do
18
+ exception = proc{ (@alipay::Sign::DSA.verify?("no_content","no_key")).call }.must_raise(NotImplementedError)
19
+ exception.message.must_include "DSA is not implemented"
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_config'
2
+
3
+ describe "AlipayGlobal::Sign::MD5", "md5 signature test" do
4
+
5
+ before do
6
+ @alipay = AlipayGlobal
7
+ @alipay.api_partner_id = '2088101122136241'
8
+ @alipay.api_secret_key = '760bdzec6y9goq7ctyx96ezkz78287de'
9
+
10
+ @params = "_input_charset=gbk&out_trade_no=6741334835157966&partner=2088101568338364&payment_type=1&return_url=http://www.test.com/alipay/return_url.asp&currency=USD&service=create_forex_trade&subject=a book&bodu=nice book&total_fee=100"
11
+
12
+ @md5_signature = "db017da14ac139afef3bb7357bb284b2"
13
+ end
14
+
15
+ describe "MD5#sign" do
16
+ it "should generate the correct signature" do
17
+ assert_equal @md5_signature, @alipay::Sign::MD5.sign(@params, @alipay.api_secret_key)
18
+ end
19
+ end
20
+
21
+ describe "MD5#verify?" do
22
+ it "should return true for the correct signature match" do
23
+ @alipay::Sign::MD5.verify?(@params, @alipay.api_secret_key, @md5_signature).must_equal true
24
+ end
25
+
26
+ it "should return false for incorrect signature match" do
27
+ @alipay::Sign::MD5.verify?(@params, @alipay.api_secret_key, "mike#{@md5_signature}").must_equal false
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,64 @@
1
+ require 'test_config'
2
+
3
+ describe "AlipayGlobal::Sign::RSA", "rsa signature test" do
4
+
5
+ before do
6
+ @alipay = AlipayGlobal
7
+
8
+ @params = "_input_charset=gbk&out_trade_no=6741334835157966&partner=2088101568338364&payment_type=1&return_url=http://www.test.com/alipay/return_url.asp&currency=USD&service=create_forex_trade&subject=a book&bodu=nice book&total_fee=100"
9
+
10
+ @rsa_signature = "i6GcANd+q8dTGY5kif3ClSqQbysmvPwf+gFowbB+ukKLKdcd4dlEUAWKlirK\nBviHoJwydMkUwavi5XvUieU6582UdqrlZgz1UlRSgL5NHSv7DWckhnYL7IKL\n2sTHb5derwrhjcJD/diYSnAMA0K+sRwVZ6Rs4fvQH3NN7sY4x0rb5W54QkPe\nCLqI+MzTggrcfqme2Grx19jOXSigETGWAm74CoI2lztlNgEjBpuqTmXHaBz1\nJ968XI9hVBj2mGnHU4EXj5hPSY/bFK2gVItOQ3w5RbTQCgjdpBYkM1LwTOlc\nu1/BlmWuUh82NGEK/qBrmne6z/W4GnG+6sqoAERA4g==\n"
11
+
12
+ @test_rsa_private_key = File.read("#{File.dirname __dir__}/../keys/test_private_key.pem")
13
+ @test_rsa_public_key = File.read("#{File.dirname __dir__}/../keys/test_public_key.pem")
14
+ end
15
+
16
+ describe "RSA#sign" do
17
+ describe "AlipayGlobal.private_key_location is empty" do
18
+ before do
19
+ @alipay.private_key_location = nil
20
+ end
21
+
22
+ it "should throw an Argument Error when private_key is not supplied :: #sign(params)" do
23
+ exception = proc{ (@alipay::Sign::RSA.sign(@params)).call }.must_raise(ArgumentError)
24
+ exception.message.must_equal "Assign valid location for RSA private key location :: #AlipayGlobal.private_key_location = #{@alipay.private_key_location}"
25
+ end
26
+
27
+ it "should generate the correct signature :: #sign(params, private_key)" do
28
+ assert_equal @rsa_signature, @alipay::Sign::RSA.sign(@params, @test_rsa_private_key)
29
+ end
30
+ end
31
+
32
+ describe "AlipayGlobal.private_key_location is invalid" do
33
+ before do
34
+ @alipay.private_key_location = "#{File.dirname __dir__}/../keys/test_private_key.danger.pem"
35
+ end
36
+
37
+ it "should throw an Argument Error when private_key is not supplied :: #sign(params)" do
38
+ exception = proc{ (@alipay::Sign::RSA.sign(@params)).call }.must_raise(Errno::ENOENT)
39
+ exception.message.must_include "No such file or directory"
40
+ end
41
+ end
42
+
43
+ describe "AlipayGlobal.private_key_location is filled with a valid location" do
44
+ before do
45
+ @alipay.private_key_location = "#{File.dirname __dir__}/../keys/test_private_key.pem"
46
+ end
47
+
48
+ it "should generate the correct signature :: #sign(params)" do
49
+ assert_equal @rsa_signature, @alipay::Sign::RSA.sign(@params)
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "RSA#verify?" do
55
+ it "should return true for the correct signature match" do
56
+ @alipay::Sign::RSA.verify?(@params, @test_rsa_public_key, @rsa_signature).must_equal true
57
+ end
58
+
59
+ it "should return false for incorrect signature match" do
60
+ @alipay::Sign::RSA.verify?(@params, @test_rsa_public_key, "mike#{@rsa_signature}").must_equal false
61
+ end
62
+ end
63
+
64
+ end
data/test/sign_test.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'test_config'
2
+
3
+ describe "Sign", "signature test" do
4
+
5
+ before do
6
+ @alipay = AlipayGlobal
7
+ end
8
+
9
+ describe "#verify?" do
10
+
11
+ before do
12
+ @sample_notification_params = {
13
+ notify_id: '13f1e773aeb299e26eb5d02bbb71219d50',
14
+ notify_type: 'trade_status_sync',
15
+ trade_no: '4061800001000100000574688',
16
+ total_fee: 0.10,
17
+ out_trade_no: '4028608899131221',
18
+ currency: 'HKD',
19
+ notify_time: '2013-09-02 10:41:43',
20
+ trade_status: 'TRADE_FINISHED',
21
+ sign_type: 'MD5',
22
+ _input_charset: 'utf-8',
23
+ sign: 'a27572b0a6dee50d2d4a1449bfd55e92'
24
+ }
25
+ end
26
+
27
+ it "should verify partner params correctly" do
28
+ assert_equal true, @alipay::Sign.verify?(@sample_notification_params)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest'
2
+ require 'minitest/autorun'
3
+ require 'alipay_global'
4
+ require 'fakeweb'
@@ -0,0 +1,25 @@
1
+ require 'test_config'
2
+
3
+ describe "AlipayGlobal::Utils", "service functions" do
4
+ before do
5
+ @alipay = AlipayGlobal
6
+ end
7
+
8
+ describe "#stringify_keys" do
9
+ it "should convert all keys to string values" do
10
+ hash = { 'a' => 1, :b => 2 }
11
+ assert_equal({ 'a' => 1, 'b' => 2 }.sort, @alipay::Utils.stringify_keys(hash).sort)
12
+ end
13
+ end
14
+
15
+ describe "#write_refund_file" do
16
+ it "should write the file correctly" do
17
+ sample_refunds = [
18
+ { new_transaction_id: '111222333', old_transaction_id: '444555666', currency: 'USD', refund_sum: 200.00, refund_time: '20120330235959', refund_reason: 'bello minions' },
19
+ { new_transaction_id: '111222333', old_transaction_id: '444555667', currency: 'USD', refund_sum: 150.00, refund_time: '20120330235959' }
20
+ ]
21
+
22
+ assert_equal "2088101122136241|111222333|444555666|USD|200.00|20120330235959|bello minions\n2088101122136241|111222333|444555667|USD|150.00|20120330235959|", @alipay::Utils.write_refund_content(sample_refunds)
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alipay_global
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Melvrick Goh, Ng Junyang, Grzegorz Witek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: fakeweb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: An unofficial simple global.alipay gem
98
+ email:
99
+ - melvrickgoh@kaligo.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - Gemfile
105
+ - LICENSE
106
+ - README.md
107
+ - Rakefile
108
+ - alipay_global.gemspec
109
+ - keys/alipay_public_key.pem
110
+ - keys/test_private_key.pem
111
+ - keys/test_public_key.pem
112
+ - lib/alipay_global.rb
113
+ - lib/alipay_global/service.rb
114
+ - lib/alipay_global/service/exchange.rb
115
+ - lib/alipay_global/service/notification.rb
116
+ - lib/alipay_global/service/reconciliation.rb
117
+ - lib/alipay_global/service/trade.rb
118
+ - lib/alipay_global/sign.rb
119
+ - lib/alipay_global/sign/dsa.rb
120
+ - lib/alipay_global/sign/md5.rb
121
+ - lib/alipay_global/sign/rsa.rb
122
+ - lib/alipay_global/utils.rb
123
+ - lib/alipay_global/version.rb
124
+ - test/alipay_global_test.rb
125
+ - test/service/exchange_test.rb
126
+ - test/service/notification_test.rb
127
+ - test/service/reconciliation_test.rb
128
+ - test/service/trade_test.rb
129
+ - test/service_test.rb
130
+ - test/sign/dsa_test.rb
131
+ - test/sign/md5_test.rb
132
+ - test/sign/rsa_test.rb
133
+ - test/sign_test.rb
134
+ - test/test_config.rb
135
+ - test/utils_test.rb
136
+ homepage: https://github.com/Kaligo/alipay-global.git
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.3
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: An unofficial simple global.alipay gem
160
+ test_files:
161
+ - test/alipay_global_test.rb
162
+ - test/service/exchange_test.rb
163
+ - test/service/notification_test.rb
164
+ - test/service/reconciliation_test.rb
165
+ - test/service/trade_test.rb
166
+ - test/service_test.rb
167
+ - test/sign/dsa_test.rb
168
+ - test/sign/md5_test.rb
169
+ - test/sign/rsa_test.rb
170
+ - test/sign_test.rb
171
+ - test/test_config.rb
172
+ - test/utils_test.rb