alipay 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88d669e91705790c16000241168d66901de8d477
4
- data.tar.gz: 9c99d503d9f08840a5d4184a5eac0289e15bfe59
3
+ metadata.gz: 0d60076cf2356166bd875f3a1fa236752fb52dfe
4
+ data.tar.gz: 4516e869df857e7615bf7942b87d50523323c1c2
5
5
  SHA512:
6
- metadata.gz: 3f01a960ef34e8742828c63691ed400d96318585db592f03fae3d633d2b081a632764fc1c56a78852becba9239c64a5c53874b66ee49ebd9e46b0243b2c1a37d
7
- data.tar.gz: 81b2d0743a4f7904002c523cf2a67196b1fe5615b59200808d910a719185b22a662ee3d26cb90f9545c8893d938bf7015c7628abc01283f5ba77fb474729f08e
6
+ metadata.gz: 2f5a78cf5dea50ff39cadb14ee4e2d905623659c8b6cc37a82a3373b99cb09757bafa541234c54b5c5105eb4beed24ad9a319e3bfff6e175abe385e3748d418b
7
+ data.tar.gz: 9d9789a9e2e074108ccec8a0eefc82cec93efa8425e90abba1ecfd4f2b3c55a6f8aaf0babf27abd2db9bc97594ee885c7a9c68c69181b06a1ce253dfbbc8a5ec
data/README.md CHANGED
@@ -15,7 +15,7 @@ Please read alipay official document first: https://b.alipay.com/order/techServi
15
15
  Add this line to your application's Gemfile:
16
16
 
17
17
  ```ruby
18
- gem 'alipay', '~> 0.0.2'
18
+ gem 'alipay', '~> 0.0.3'
19
19
  ```
20
20
 
21
21
  or development version
@@ -81,6 +81,22 @@ Alipay::Service.send_goods_confirm_by_platform(options)
81
81
  # => '<!xml version="1.0" encoding="utf-8"?><alipay><is_success>T</is_success></alipay>'
82
82
  ```
83
83
 
84
+ ### Refund
85
+
86
+ ```ruby
87
+ batch_no = Alipay::Utils.generate_batch_no # refund batch no, you SHOULD store it to db to avoid alipay duplicate refund
88
+ options = {
89
+ batch_no: batch_no,
90
+ data: [{:trade_no => 'TRADE_NO', :amount => '10.0', :reason => 'REFUND_REASON'}],
91
+ notify_url: 'YOUR_ORDER_NOTIFY_URL' # https://writings.io/orders/20130801000001/alipay_refund_notify
92
+ }
93
+
94
+ Alipay::Service.create_refund_url(options)
95
+ ```
96
+
97
+ Batch No. Generate Demo: http://git.io/GcXKJw
98
+ Notify Url Demo: http://git.io/pst4Tw
99
+
84
100
  ### Verify notify
85
101
 
86
102
  ```ruby
@@ -57,6 +57,31 @@ module Alipay
57
57
  "#{GATEWAY_URL}?#{query_string(options)}"
58
58
  end
59
59
 
60
+ CREATE_REFUND_URL_REQUIRED_OPTIONS = %w( batch_no data notify_url )
61
+ # 支付宝即时到帐批量退款有密接口(此为异步接口,有密指通过此接口打开 url 后需要用户输入支付宝的支付密码进行退款)
62
+ def self.create_refund_url(options)
63
+ options = Utils.stringify_keys(options)
64
+ check_required_options(options, CREATE_REFUND_URL_REQUIRED_OPTIONS)
65
+
66
+ data = options.delete('data')
67
+ detail_data = data.map do|item|
68
+ item = Utils.stringify_keys(item)
69
+ "#{item['trade_no']}^#{item['amount']}^#{item['reason']}"
70
+ end.join('#')
71
+
72
+ options = {
73
+ 'service' => 'refund_fastpay_by_platform_pwd', # 接口名称
74
+ '_input_charset' => 'utf-8',
75
+ 'partner' => Alipay.pid,
76
+ 'seller_email' => Alipay.seller_email,
77
+ 'refund_date' => Time.now.strftime('%Y-%m-%d %H:%M:%S'), # 申请退款时间
78
+ 'batch_num' => data.size, # 总笔数
79
+ 'detail_data' => detail_data # 转换后的单笔数据集字符串
80
+ }.merge(options)
81
+
82
+ "#{GATEWAY_URL}?#{query_string(options)}"
83
+ end
84
+
60
85
  SEND_GOODS_CONFIRM_BY_PLATFORM_REQUIRED_OPTIONS = %w( service partner _input_charset trade_no logistics_name )
61
86
  def self.send_goods_confirm_by_platform(options)
62
87
  options = {
data/lib/alipay/utils.rb CHANGED
@@ -7,5 +7,12 @@ module Alipay
7
7
  end
8
8
  new_hash
9
9
  end
10
+
11
+ # 退款批次号,支付宝通过此批次号来防止重复退款操作,所以此号生成后最好直接保存至数据库,不要在显示页面的时候生成
12
+ # 共 24 位(8 位当前日期 + 9 位纳秒 + 1 位随机数)
13
+ def self.generate_batch_no
14
+ time = Time.now
15
+ time.strftime('%Y%m%d%H%M%S') + time.nsec.to_s + Random.new.rand(1..9).to_s
16
+ end
10
17
  end
11
18
  end
@@ -1,3 +1,3 @@
1
1
  module Alipay
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -37,6 +37,20 @@ class Alipay::ServiceTest < Test::Unit::TestCase
37
37
  assert_not_nil Alipay::Service.create_direct_pay_by_user_url(options)
38
38
  end
39
39
 
40
+ def test_generate_create_refund_url
41
+ data = [{
42
+ :trade_no => '1',
43
+ :amount => '0.01',
44
+ :reason => 'test'
45
+ }]
46
+ options = {
47
+ :batch_no => '123456789',
48
+ :data => data,
49
+ :notify_url => '/some_url'
50
+ }
51
+ assert_not_nil Alipay::Service.create_refund_url(options)
52
+ end
53
+
40
54
 
41
55
  def test_should_send_goods_confirm_by_platform
42
56
  body = <<-EOF
@@ -5,4 +5,8 @@ class Alipay::UtilsTest < Test::Unit::TestCase
5
5
  hash = { 'a' => 1, :b => 2 }
6
6
  assert_equal({ 'a' => 1, 'b' => 2 }.sort, Alipay::Utils.stringify_keys(hash).sort)
7
7
  end
8
+
9
+ def test_generate_batch_no
10
+ assert_equal(24, Alipay::Utils.generate_batch_no.size)
11
+ end
8
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alipay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-21 00:00:00.000000000 Z
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler