alipay_global 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -6
- data/alipay_global.gemspec +2 -0
- data/lib/alipay_global/service.rb +1 -1
- data/lib/alipay_global/service/notification.rb +1 -4
- data/lib/alipay_global/service/trade.rb +34 -5
- data/lib/alipay_global/utils.rb +1 -2
- data/lib/alipay_global/version.rb +1 -1
- data/test/service/trade_test.rb +47 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d806d2aa21fbbc9eb231773eb0df9e468add4b0
|
4
|
+
data.tar.gz: 8b9c2c7df624401147e1d7187400ac912cddd897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e663a7259a74309f6bf10942dce4eaa37c86b2e96e752f6b108d41a79001db77b677c1b2ed37c52b7ca7892da27eda74e52c3f7616e3938390ef04983a73462
|
7
|
+
data.tar.gz: 27b7cadceb9d7ac35996b3581265fff5542681917eeeba73197280e024b60d93c50721a55be85d47c509a3ea00c95c1c30e8377e6d2eb29c30b1e1ceeb28c721
|
data/README.md
CHANGED
@@ -19,9 +19,25 @@ AlipayGlobal.api_secret_key = 'YOUR_KEY'
|
|
19
19
|
#AlipayGlobal.debug_mode = true # Enable parameter check. Default is true.
|
20
20
|
```
|
21
21
|
|
22
|
-
##
|
22
|
+
## Note
|
23
23
|
|
24
|
-
###
|
24
|
+
### Operational Functions
|
25
|
+
|
26
|
+
| Feature | Description |
|
27
|
+
| ------- | ----------- |
|
28
|
+
| AlipayGlobal::Service::Trade.create | |
|
29
|
+
| AlipayGlobal::Service::Trade.refund | |
|
30
|
+
| AlipayGlobal::Service::Notification.check | |
|
31
|
+
| AlipayGlobal::Service::Reconciliation.request | |
|
32
|
+
| AlipayGlobal::Service::Exchange.current_rates | |
|
33
|
+
|
34
|
+
### Incomplete/ Untested Functions
|
35
|
+
|
36
|
+
| Feature | Description |
|
37
|
+
| ------- | ----------- |
|
38
|
+
| AlipayGlobal::Sign | RSA | Not tested. I do not have an RSA based relationship with Alipay at the moment to test requests via RSA signing |
|
39
|
+
| AlipayGlobal::Sign | DSA | Not implemented |
|
40
|
+
| AlipayGlobal::Service::Trade.batch_refund | Awaiting verification and support from Alipay: Issue with signing for multipartforms |
|
25
41
|
|
26
42
|
## Usage
|
27
43
|
|
@@ -41,9 +57,8 @@ AlipayGlobal::Service::Trade.create({ARGUMENTS})
|
|
41
57
|
|
42
58
|
#### Issues (awaiting resolution)
|
43
59
|
|
44
|
-
1.
|
45
|
-
1.
|
46
|
-
2. RSA integration: User needs to work with Alipay team to exchange RSA public keys to properly test the content
|
60
|
+
1. create
|
61
|
+
1. RSA integration: User needs to work with Alipay team to exchange RSA public keys to properly test the content
|
47
62
|
2. testing environment
|
48
63
|
1. Alipay mobile site for testing is down. works in production.
|
49
64
|
|
@@ -88,6 +103,42 @@ AlipayGlobal::Service::Trade.create(
|
|
88
103
|
|
89
104
|
\*\*\* Attention2:The request parameters can only be accepted by the Alipay system if they are signed according to the signature mechanism specified in this document.The parameter “timeout_rule”, the default value is 12h. If you want to use this parameter to change timing, you need to contact Alipay technical. Otherwise you will have an error.
|
90
105
|
|
106
|
+
```ruby
|
107
|
+
refund
|
108
|
+
```
|
109
|
+
|
110
|
+
#### Definition
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
AlipayGlobal::Service::Trade.refund({ARGUMENTS})
|
114
|
+
```
|
115
|
+
|
116
|
+
#### Example
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
AlipayGlobal::Service::Trade.refund(
|
120
|
+
out_return_no: "SAMPLE_REFUND_ID",
|
121
|
+
out_trade_no: "SAMPLE_TRANSACTION_ID",
|
122
|
+
return_rmb_amount: 200.00,
|
123
|
+
reason: "hello",
|
124
|
+
gmt_return: (Time.parse("2015-03-20 12:00").getlocal("+08:00")).strftime("%Y%m%d%H%M%S"),
|
125
|
+
currency: "USD"
|
126
|
+
)
|
127
|
+
# => 'https://mapi.alipay.com/gateway.do?service=create_forex_trade...' #for production
|
128
|
+
```
|
129
|
+
|
130
|
+
#### ARGUMENTS
|
131
|
+
|
132
|
+
| Key | Requirement | Data Type | Description |
|
133
|
+
| --- | ----------- | --------- | ----------- |
|
134
|
+
| out_return_no | required | string | The new ID which created for refund. |
|
135
|
+
| out_trade_no | required | string | The ID for the original transaction. |
|
136
|
+
| return_amount | required | float | |
|
137
|
+
| currency | required | string | |
|
138
|
+
| reason | required | string | Reason for refund, out of supply e.g. |
|
139
|
+
| return_rmb_amount | optional* | float | This parameter related the RMB price function in the payment interface |
|
140
|
+
|
141
|
+
\* return_rmb_amount: if used, then leave return_amount empty
|
91
142
|
|
92
143
|
#### Service::Exchange
|
93
144
|
|
@@ -247,4 +298,8 @@ AlipayGlobal::Service::Reconciliation.request(params)
|
|
247
298
|
{:partner_transaction_id=>"1326555", :amount=>"2125.25", :currency=>"HKD", :transaction_time=>#<DateTime: 2013-12-19T17:56:37+00:00 ((2456646j,64597s,0n),+0s,2299161j)>, :settlement_time=>"", :transaction_type=>"P", :service_charge=>"21.25", :status=>"P", :remarks=>"Grey Hours Limited (Testing)"},
|
248
299
|
{:partner_transaction_id=>"1326244", :amount=>"0.01", :currency=>"HKD", :transaction_time=>#<DateTime: 2013-12-19T16:11:26+00:00 ((2456646j,58286s,0n),+0s,2299161j)>, :settlement_time=>"", :transaction_type=>"P", :service_charge=>"0.00", :status=>"P", :remarks=>"MICROS-Fidelio Information Systems Co. Limited (Testing)"}
|
249
300
|
]
|
250
|
-
```
|
301
|
+
```
|
302
|
+
|
303
|
+
### Contributing
|
304
|
+
|
305
|
+
Feel free to fork this repo and make a PR.
|
data/alipay_global.gemspec
CHANGED
@@ -7,7 +7,7 @@ module AlipayGlobal
|
|
7
7
|
def self.request_uri(params, sign = true)
|
8
8
|
uri = URI(gateway_url)
|
9
9
|
processed_params = sign ? sign_params(params) : params
|
10
|
-
uri.query = URI.encode_www_form(processed_params)
|
10
|
+
uri.query = URI.encode_www_form(AlipayGlobal::Utils.stringify_keys(processed_params))
|
11
11
|
uri
|
12
12
|
end
|
13
13
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'net/http'
|
2
2
|
|
3
3
|
module AlipayGlobal
|
4
4
|
module Service
|
@@ -10,9 +10,6 @@ module AlipayGlobal
|
|
10
10
|
'partner' => AlipayGlobal.api_partner_id,
|
11
11
|
}.merge(params)
|
12
12
|
|
13
|
-
Rails.logger.debug AlipayGlobal::Service.request_uri(params,false)
|
14
|
-
Rails.logger.debug Net::HTTP.get(AlipayGlobal::Service.request_uri(params,false))
|
15
|
-
|
16
13
|
Net::HTTP.get(AlipayGlobal::Service.request_uri(params,false))
|
17
14
|
end
|
18
15
|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require "net/http"
|
2
|
+
require "rest-client"
|
2
3
|
require "uri"
|
3
4
|
require "nokogiri"
|
4
5
|
|
5
6
|
module AlipayGlobal
|
6
7
|
module Service
|
7
8
|
module Trade
|
8
|
-
|
9
|
+
BOUNDARY = "AaB03x"
|
9
10
|
CREATE_TRADE_REQUIRED_PARAMS = %w( notify_url subject out_trade_no currency )
|
10
11
|
CREATE_TRADE_OPTIONAL_PARAMS = %w( return_url body total_fee rmb_fee order_gmt_create order_valid_time timeout_rule auth_token supplier seller_id seller_name seller_industry )
|
11
12
|
|
@@ -26,7 +27,19 @@ module AlipayGlobal
|
|
26
27
|
AlipayGlobal::Service.request_uri(params).to_s
|
27
28
|
end
|
28
29
|
|
29
|
-
def self.refund(
|
30
|
+
def self.refund(params)
|
31
|
+
resp = Net::HTTP.get(build_refund_uri(params))
|
32
|
+
|
33
|
+
alipay_results = Nokogiri::XML(resp).at_xpath('//alipay')
|
34
|
+
|
35
|
+
alipay_success = alipay_results.at_xpath('//is_success').content == "T"
|
36
|
+
|
37
|
+
alipay_reason = alipay_success ? "" : alipay_results.at_xpath('//error').content
|
38
|
+
|
39
|
+
{ success: alipay_success , message: alipay_reason }
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.batch_refund(refunds)
|
30
43
|
file = build_refund_file(refunds)
|
31
44
|
|
32
45
|
params = {
|
@@ -38,14 +51,18 @@ module AlipayGlobal
|
|
38
51
|
|
39
52
|
#p uri.to_s
|
40
53
|
|
41
|
-
form_params = { 'partner' => AlipayGlobal.api_partner_id, 'service' => 'forex_refund_file', 'refund_file' =>
|
54
|
+
form_params = { 'partner' => AlipayGlobal.api_partner_id, 'service' => 'forex_refund_file', 'refund_file' => File.read(file.path) }
|
55
|
+
|
56
|
+
#IO.read(file.path)
|
42
57
|
|
43
58
|
#p form_params
|
44
59
|
|
45
|
-
resp = Net::HTTP.post_form(uri, form_params)
|
60
|
+
#resp = Net::HTTP.post_form(uri, form_params)
|
46
61
|
|
47
62
|
#p resp.body
|
48
63
|
|
64
|
+
resp = RestClient.post uri.to_s, :partner => AlipayGlobal.api_partner_id, :file => File.new(file.path, 'rb'), :service => 'forex_refund_file'
|
65
|
+
|
49
66
|
alipay_resp = Nokogiri::XML(resp.body)
|
50
67
|
|
51
68
|
alipay_results = alipay_resp.at_xpath('//alipay')
|
@@ -56,12 +73,24 @@ module AlipayGlobal
|
|
56
73
|
end
|
57
74
|
|
58
75
|
def self.build_refund_file(refunds)
|
59
|
-
file = Tempfile.new(['
|
76
|
+
file = Tempfile.new(['refund','.txt'])
|
60
77
|
refund_content = AlipayGlobal::Utils.write_refund_content(refunds)
|
61
78
|
file.write(refund_content)
|
62
79
|
file.close
|
63
80
|
file
|
64
81
|
end
|
82
|
+
|
83
|
+
def self.build_refund_uri(refund)
|
84
|
+
refund[:reason] = "no_reason" if !refund[:reason]
|
85
|
+
refund[:reason] = "no_reason" if refund[:reason].strip.length == 0
|
86
|
+
params = {
|
87
|
+
'service' => 'forex_refund',
|
88
|
+
'_input_charset' => 'utf-8',
|
89
|
+
'partner' => AlipayGlobal.api_partner_id
|
90
|
+
}.merge(refund)
|
91
|
+
|
92
|
+
AlipayGlobal::Service.request_uri(params)
|
93
|
+
end
|
65
94
|
end
|
66
95
|
end
|
67
96
|
end
|
data/lib/alipay_global/utils.rb
CHANGED
@@ -4,8 +4,7 @@ module AlipayGlobal
|
|
4
4
|
new_hash = {}
|
5
5
|
hash.each do |key, value|
|
6
6
|
case key
|
7
|
-
when :total_fee, :rmb_fee, :refund_sum
|
8
|
-
value = value.round(2)
|
7
|
+
when :total_fee, :rmb_fee, :refund_sum, :return_rmb_amount, :return_amount
|
9
8
|
value = '%.2f' % value
|
10
9
|
end
|
11
10
|
new_hash[(key.to_s rescue key) || key] = value
|
data/test/service/trade_test.rb
CHANGED
@@ -56,13 +56,59 @@ describe "AlipayGlobal::Service::Trade", "Forex trade actions" do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
describe "#refund" do
|
59
|
+
it "should refund correctly for a valid refund url" do
|
60
|
+
params = {
|
61
|
+
out_return_no: "SAMPLE_REFUND_ID",
|
62
|
+
out_trade_no: "SAMPLE_TRANSACTION_ID",
|
63
|
+
return_rmb_amount: 200.00,
|
64
|
+
reason: "hello",
|
65
|
+
gmt_return: (Time.parse("2015-03-20 12:00").getlocal("+08:00")).strftime("%Y%m%d%H%M%S"),
|
66
|
+
currency: "USD"
|
67
|
+
}
|
68
|
+
expected_result = { success: false, message: "PURCHASE_TRADE_NOT_EXIST" }
|
69
|
+
|
70
|
+
assert_equal "https://mapi.alipay.net/gateway.do?service=forex_refund&_input_charset=utf-8&partner=2088101122136241&out_return_no=SAMPLE_REFUND_ID&out_trade_no=SAMPLE_TRANSACTION_ID&return_rmb_amount=200.00&reason=hello&gmt_return=20150320120000¤cy=USD&sign_type=MD5&sign=a77e894e71491f41e73ebe40319cc300", @alipay::Service::Trade.build_refund_uri(params).to_s
|
71
|
+
assert_equal expected_result, @alipay::Service::Trade.refund(params)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should handle nil reason correctly" do
|
75
|
+
params = {
|
76
|
+
out_return_no: "SAMPLE_REFUND_ID",
|
77
|
+
out_trade_no: "SAMPLE_TRANSACTION_ID",
|
78
|
+
return_rmb_amount: 200.00,
|
79
|
+
gmt_return: (Time.parse("2015-03-20 12:00").getlocal("+08:00")).strftime("%Y%m%d%H%M%S"),
|
80
|
+
currency: "USD"
|
81
|
+
}
|
82
|
+
expected_result = { success: false, message: "PURCHASE_TRADE_NOT_EXIST" }
|
83
|
+
|
84
|
+
assert_equal "https://mapi.alipay.net/gateway.do?service=forex_refund&_input_charset=utf-8&partner=2088101122136241&out_return_no=SAMPLE_REFUND_ID&out_trade_no=SAMPLE_TRANSACTION_ID&return_rmb_amount=200.00&gmt_return=20150320120000¤cy=USD&reason=no_reason&sign_type=MD5&sign=c4c09ca3fc78d04b88d9459b02673b1b", @alipay::Service::Trade.build_refund_uri(params).to_s
|
85
|
+
assert_equal expected_result, @alipay::Service::Trade.refund(params)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should handle empty reason correctly" do
|
89
|
+
params = {
|
90
|
+
out_return_no: "SAMPLE_REFUND_ID",
|
91
|
+
out_trade_no: "SAMPLE_TRANSACTION_ID",
|
92
|
+
return_rmb_amount: 200.00,
|
93
|
+
gmt_return: (Time.parse("2015-03-20 12:00").getlocal("+08:00")).strftime("%Y%m%d%H%M%S"),
|
94
|
+
reason: " ",
|
95
|
+
currency: "USD"
|
96
|
+
}
|
97
|
+
expected_result = { success: false, message: "PURCHASE_TRADE_NOT_EXIST" }
|
98
|
+
|
99
|
+
assert_equal "https://mapi.alipay.net/gateway.do?service=forex_refund&_input_charset=utf-8&partner=2088101122136241&out_return_no=SAMPLE_REFUND_ID&out_trade_no=SAMPLE_TRANSACTION_ID&return_rmb_amount=200.00&gmt_return=20150320120000&reason=no_reason¤cy=USD&sign_type=MD5&sign=c4c09ca3fc78d04b88d9459b02673b1b", @alipay::Service::Trade.build_refund_uri(params).to_s
|
100
|
+
assert_equal expected_result, @alipay::Service::Trade.refund(params)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#batch_refund" do
|
59
105
|
it "should transact refund correctly" do
|
60
106
|
sample_refunds = [
|
61
107
|
{ new_transaction_id: '111222333', old_transaction_id: '444555666', currency: 'USD', refund_sum: 200.00, refund_time: '20120330235959', refund_reason: 'bello minions' },
|
62
108
|
{ new_transaction_id: '111222333', old_transaction_id: '444555667', currency: 'USD', refund_sum: 150.00, refund_time: '20120330235959', refund_reason: 'monkey' }
|
63
109
|
]
|
64
110
|
|
65
|
-
@alipay::Service::Trade.
|
111
|
+
@alipay::Service::Trade.batch_refund(sample_refunds)
|
66
112
|
end
|
67
113
|
|
68
114
|
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
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2015-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rest-client
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.8.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.8.0
|
83
97
|
description: An unofficial simple global.alipay gem
|
84
98
|
email:
|
85
99
|
- melvrickgoh@kaligo.com
|