alipay 0.0.1 → 0.0.2

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: 76821d020f3247b02202d5253dae2df6a8ce1288
4
- data.tar.gz: db6abc47a810d5390ddce5e2506c09bc2b11e0b4
3
+ metadata.gz: 88d669e91705790c16000241168d66901de8d477
4
+ data.tar.gz: 9c99d503d9f08840a5d4184a5eac0289e15bfe59
5
5
  SHA512:
6
- metadata.gz: c6774216b77ea292b1169dfd3ca0ac9475e76881a66fb7ac824eb7cffcf2528215637114b527989b2d0a56187b8152c182e3fdaeeb4594f3920bccba2874b0a6
7
- data.tar.gz: 42f41ead9ce83eaca5c30bd4cc477b3119ec4323190077b1387a729c2ad5e5c218ca542000c5bbeb9c1c816bcac969ec9b8d3610053b58a0f9b8cfd2ce4c1f8d
6
+ metadata.gz: 3f01a960ef34e8742828c63691ed400d96318585db592f03fae3d633d2b081a632764fc1c56a78852becba9239c64a5c53874b66ee49ebd9e46b0243b2c1a37d
7
+ data.tar.gz: 81b2d0743a4f7904002c523cf2a67196b1fe5615b59200808d910a719185b22a662ee3d26cb90f9545c8893d938bf7015c7628abc01283f5ba77fb474729f08e
data/README.md CHANGED
@@ -6,14 +6,20 @@ It contain this API:
6
6
 
7
7
  * Generate payment url
8
8
  * Send goods
9
- * Verify when receive alipay notify
9
+ * Verify notify
10
10
 
11
- Please read alipay official document first: https://b.alipay.com/order/techService.htm
11
+ Please read alipay official document first: https://b.alipay.com/order/techService.htm .
12
12
 
13
13
  ## Installation
14
14
 
15
15
  Add this line to your application's Gemfile:
16
16
 
17
+ ```ruby
18
+ gem 'alipay', '~> 0.0.2'
19
+ ```
20
+
21
+ or development version
22
+
17
23
  ```ruby
18
24
  gem 'alipay', :github => 'chloerei/alipay'
19
25
  ```
@@ -26,7 +32,7 @@ $ bundle
26
32
 
27
33
  ## Usage
28
34
 
29
- ### Init
35
+ ### Config
30
36
 
31
37
  ```ruby
32
38
  Alipay.pid = 'YOUR_PID'
@@ -66,7 +72,7 @@ Current support three payment type:
66
72
 
67
73
  ```ruby
68
74
  options = {
69
- :trade_no => 'trade_no_id',
75
+ :trade_no => 'TRADE_NO',
70
76
  :logistics_name => 'writings.io',
71
77
  :transport_type => 'DIRECT'
72
78
  }
@@ -75,13 +81,14 @@ Alipay::Service.send_goods_confirm_by_platform(options)
75
81
  # => '<!xml version="1.0" encoding="utf-8"?><alipay><is_success>T</is_success></alipay>'
76
82
  ```
77
83
 
78
- ### Verify when receive alipay notify
84
+ ### Verify notify
79
85
 
80
86
  ```ruby
81
- # exxample in rails
87
+ # example in rails
82
88
  # The notify url MUST be set when generate payment url
83
89
  def alipay_notify
84
- notify_params = params.except(*request.path_parameters.keys) # except :controller_name, :action_name, :host
90
+ # except :controller_name, :action_name, :host, etc.
91
+ notify_params = params.except(*request.path_parameters.keys)
85
92
  if Alipay::Notify.verify?(notify_params)
86
93
  # valid notify, code your business logic.
87
94
  render :text => 'success'
@@ -93,7 +100,7 @@ end
93
100
 
94
101
  ## Contributing
95
102
 
96
- Bug report or pull request is welcome.
103
+ Bug report or pull request are welcome.
97
104
 
98
105
  ### Make a pull request
99
106
 
data/alipay.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["chloerei@gmail.com"]
11
11
  spec.description = %q{An unofficial simple alipay gem}
12
12
  spec.summary = %q{An unofficial simple alipay gem}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/chloerei/alipay"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
data/lib/alipay/notify.rb CHANGED
@@ -2,8 +2,8 @@ module Alipay
2
2
  class Notify
3
3
  def self.verify?(params)
4
4
  if Sign.verify?(params)
5
- params = Utils.symbolize_keys(params)
6
- open("https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{CGI.escape params[:notify_id].to_s}").read == 'true'
5
+ params = Utils.stringify_keys(params)
6
+ open("https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{CGI.escape params['notify_id'].to_s}").read == 'true'
7
7
  else
8
8
  false
9
9
  end
@@ -9,12 +9,12 @@ module Alipay
9
9
  # alipayescow
10
10
  def self.create_partner_trade_by_buyer_url(options)
11
11
  options = {
12
- :service => 'create_partner_trade_by_buyer',
13
- :_input_charset => 'utf-8',
14
- :partner => Alipay.pid,
15
- :seller_email => Alipay.seller_email,
16
- :payment_type => '1'
17
- }.merge(Utils.symbolize_keys(options))
12
+ 'service' => 'create_partner_trade_by_buyer',
13
+ '_input_charset' => 'utf-8',
14
+ 'partner' => Alipay.pid,
15
+ 'seller_email' => Alipay.seller_email,
16
+ 'payment_type' => '1'
17
+ }.merge(Utils.stringify_keys(options))
18
18
 
19
19
  check_required_options(options, TRADE_CREATE_BY_BUYER_REQUIRED_OPTIONS)
20
20
 
@@ -25,12 +25,12 @@ module Alipay
25
25
  # alipaydualfun
26
26
  def self.trade_create_by_buyer_url(options = {})
27
27
  options = {
28
- :service => 'trade_create_by_buyer',
29
- :_input_charset => 'utf-8',
30
- :partner => Alipay.pid,
31
- :seller_email => Alipay.seller_email,
32
- :payment_type => '1'
33
- }.merge(Utils.symbolize_keys(options))
28
+ 'service' => 'trade_create_by_buyer',
29
+ '_input_charset' => 'utf-8',
30
+ 'partner' => Alipay.pid,
31
+ 'seller_email' => Alipay.seller_email,
32
+ 'payment_type' => '1'
33
+ }.merge(Utils.stringify_keys(options))
34
34
 
35
35
  check_required_options(options, TRADE_CREATE_BY_BUYER_REQUIRED_OPTIONS)
36
36
 
@@ -41,16 +41,16 @@ module Alipay
41
41
  # direct
42
42
  def self.create_direct_pay_by_user_url(options)
43
43
  options = {
44
- :service => 'create_direct_pay_by_user',
45
- :_input_charset => 'utf-8',
46
- :partner => Alipay.pid,
47
- :seller_email => Alipay.seller_email,
48
- :payment_type => '1'
49
- }.merge(Utils.symbolize_keys(options))
44
+ 'service' => 'create_direct_pay_by_user',
45
+ '_input_charset' => 'utf-8',
46
+ 'partner' => Alipay.pid,
47
+ 'seller_email' => Alipay.seller_email,
48
+ 'payment_type' => '1'
49
+ }.merge(Utils.stringify_keys(options))
50
50
 
51
51
  check_required_options(options, CREATE_DIRECT_PAY_BY_USER_REQUIRED_OPTIONS)
52
52
 
53
- if options[:total_fee].nil? and (options[:price].nil? || options[:quantity].nil?)
53
+ if options['total_fee'].nil? and (options['price'].nil? || options['quantity'].nil?)
54
54
  warn("Ailpay Warn: total_fee or (price && quantiry) must have one")
55
55
  end
56
56
 
@@ -60,14 +60,14 @@ module Alipay
60
60
  SEND_GOODS_CONFIRM_BY_PLATFORM_REQUIRED_OPTIONS = %w( service partner _input_charset trade_no logistics_name )
61
61
  def self.send_goods_confirm_by_platform(options)
62
62
  options = {
63
- :service => 'send_goods_confirm_by_platform',
64
- :partner => Alipay.pid,
65
- :_input_charset => 'utf-8'
66
- }.merge(Utils.symbolize_keys(options))
63
+ 'service' => 'send_goods_confirm_by_platform',
64
+ 'partner' => Alipay.pid,
65
+ '_input_charset' => 'utf-8'
66
+ }.merge(Utils.stringify_keys(options))
67
67
 
68
68
  check_required_options(options, SEND_GOODS_CONFIRM_BY_PLATFORM_REQUIRED_OPTIONS)
69
69
 
70
- if options[:transport_type].nil? and options[:create_transport_type].nil?
70
+ if options['transport_type'].nil? and options['create_transport_type'].nil?
71
71
  warn("Ailpay Warn: transport_type or create_transport_type must have one")
72
72
  end
73
73
 
@@ -75,14 +75,14 @@ module Alipay
75
75
  end
76
76
 
77
77
  def self.query_string(options)
78
- options.merge(:sign_type => 'MD5', :sign => Alipay::Sign.generate(options)).map do |key, value|
78
+ options.merge('sign_type' => 'MD5', 'sign' => Alipay::Sign.generate(options)).map do |key, value|
79
79
  "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
80
80
  end.join('&')
81
81
  end
82
82
 
83
83
  def self.check_required_options(options, names)
84
84
  names.each do |name|
85
- warn("Ailpay Warn: missing required option: #{name}") unless options.has_key?(name.to_sym)
85
+ warn("Ailpay Warn: missing required option: #{name}") unless options.has_key?(name)
86
86
  end
87
87
  end
88
88
  end
data/lib/alipay/sign.rb CHANGED
@@ -11,9 +11,9 @@ module Alipay
11
11
  end
12
12
 
13
13
  def self.verify?(params)
14
- params = Utils.symbolize_keys(params)
15
- params.delete(:sign_type)
16
- sign = params.delete(:sign)
14
+ params = Utils.stringify_keys(params)
15
+ params.delete('sign_type')
16
+ sign = params.delete('sign')
17
17
 
18
18
  generate(params) == sign
19
19
  end
data/lib/alipay/utils.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  module Alipay
2
2
  module Utils
3
- def self.symbolize_keys(hash)
3
+ def self.stringify_keys(hash)
4
4
  new_hash = {}
5
5
  hash.each do |key, value|
6
- new_hash[(key.to_sym rescue key) || key] = value
6
+ new_hash[(key.to_s rescue key) || key] = value
7
7
  end
8
8
  new_hash
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Alipay
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Alipay::UtilsTest < Test::Unit::TestCase
4
- def test_symbolize_keys
4
+ def test_stringify_keys
5
5
  hash = { 'a' => 1, :b => 2 }
6
- assert_equal({ :a => 1, :b => 2 }.sort, Alipay::Utils.symbolize_keys(hash).sort)
6
+ assert_equal({ 'a' => 1, 'b' => 2 }.sort, Alipay::Utils.stringify_keys(hash).sort)
7
7
  end
8
8
  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.1
4
+ version: 0.0.2
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-02 00:00:00.000000000 Z
11
+ date: 2013-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,7 +76,7 @@ files:
76
76
  - test/alipay/sign_test.rb
77
77
  - test/alipay/utils_test.rb
78
78
  - test/test_helper.rb
79
- homepage: ''
79
+ homepage: https://github.com/chloerei/alipay
80
80
  licenses:
81
81
  - MIT
82
82
  metadata: {}