alipay_dualfun 0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTRiMGFmZjEwMzMzNTg5MDkyZjg4MGRjNDQzNDc0NzcyMTg0NDRlNw==
5
+ data.tar.gz: !binary |-
6
+ Y2M2MTViNWRiYTY1MGEzNTViOGRmMWQ2MDUwNmMxY2U4YmM5OWMyZg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NjllOGVmMWM1YzBlZGI3ZTNkYTFkOTdkNDdjMjJmOTAwZDE5M2MxOTExNmIz
10
+ OTI0ZDI2MTU1ZjQyYTdkNGVkYzA1MDA0OTVhYmRiZmY3OGJhNWExNjNkNzUz
11
+ ZDhiZDY1YWM3YmRmNTA4YTIyZDkyZjVlYTMwZTgyMDQ1ZmJlZDI=
12
+ data.tar.gz: !binary |-
13
+ M2IxOGRiMGQ3MDY2NDE3Mjc2OGVjYjI1Y2I5ZTVmYzNhZGMzMjNlOGU1YjU0
14
+ MmQ1MGVmY2RjNjA0YmJlNzkwOTQ4YjA0NjE1NDQ0NzY5ODI1N2QzYTdlMTk0
15
+ YTg0MjczMTBkMjhjMzM5MmYyMDg3MDgxNjEzZGU3NmU4ZTQzOWQ=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 happypeter
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # alipay_dualfun 双功能收款
2
+
3
+ A ruby gem.
4
+
5
+ ## 安装方法
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'alipay_dualfun'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ### Thanks
16
+
17
+ The code started as a fork from @daqing china_pay
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "alipay_dualfun"
7
+ gem.version = "0.0"
8
+ gem.authors = ["happypeter"]
9
+ gem.email = ["happypeter1983@gmail.com"]
10
+ gem.description = %q{This gem can help you integrate Alipay to your application.}
11
+ gem.summary = %q{A simple payment library for alipay dual function payment gateways}
12
+ gem.homepage = "https://github.com/happypeter/alipay_dualfun"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,181 @@
1
+ # encoding: utf-8
2
+ require 'digest'
3
+ require 'uri'
4
+ require 'net/http'
5
+
6
+ module AlipayDualfun
7
+ GATEWAY_URL = 'https://mapi.alipay.com/gateway.do'
8
+
9
+ module Product
10
+ class Base
11
+ DEFAULT_CHARSET = 'utf-8'
12
+ SIGN_TYPE_MD5 = 'MD5'
13
+
14
+ # all the 'required` field from offical SDK pdf
15
+ ATTR_REQUIRED = [:service, :partner, :_input_charset,
16
+ :sign_type, :sign, :notify_url, :return_url,
17
+ :out_trade_no, :subject, :payment_type, :seller_email,
18
+ :logistics_type, :logistics_fee, :logistics_payment,
19
+ :price, :quantity
20
+ ]
21
+
22
+ end
23
+
24
+ class DualfunPay < Base
25
+ NAME = '双功能收款'
26
+ SERVICE_LABEL = :trade_create_by_buyer
27
+
28
+ def initialize(order)
29
+ @order = order
30
+
31
+ @params = {}
32
+ end
33
+
34
+ def notification_callback_url(url)
35
+ @params[:notify_url] = url
36
+ self
37
+ end
38
+
39
+ def after_payment_redirect_url(url)
40
+ @params[:return_url] = url
41
+ self
42
+ end
43
+
44
+ def gateway_api_url
45
+ secure_signature = create_signature
46
+ request_params = sign_params.merge(
47
+ :sign_type => SIGN_TYPE_MD5,
48
+ :sign => secure_signature
49
+ )
50
+
51
+ lost_attributes = ATTR_REQUIRED - request_params.keys
52
+ if lost_attributes.any?
53
+ raise "the following keys are lost: #{lost_attributes.inspect}"
54
+ end
55
+
56
+ uri = URI(GATEWAY_URL)
57
+ uri.query = URI.encode_www_form(request_params.sort)
58
+
59
+ uri.to_s
60
+ end
61
+
62
+ # 出错通知异步调用 URL
63
+ #
64
+ # NOTE: 需要联系技术支持才能开通
65
+ def error_callback_url(url)
66
+ @params[:error_notify_url] = url
67
+ self
68
+ end
69
+
70
+ private
71
+ def sign_params
72
+ params = @order.attributes.merge(@params)
73
+ params[:service] = SERVICE_LABEL
74
+ params[:partner] = @order.merchant.partner
75
+ params[:_input_charset] = DEFAULT_CHARSET
76
+ @sign_params ||= params
77
+ end
78
+
79
+ def create_signature
80
+ sequence = sign_params.sort.map {|k, v| "#{k}=#{v}"}.join('&')
81
+ Digest::MD5.hexdigest(sequence + @order.merchant.key)
82
+ end
83
+ end
84
+ end
85
+
86
+ class Order
87
+ PAYMENT_TYPE_BUYING = 1
88
+ PAYMENT_TYPE_DONATION = 4
89
+
90
+ attr_accessor :merchant
91
+ attr_reader :attributes
92
+
93
+ def initialize(order_id, subject, description)
94
+ @attributes = {
95
+ :out_trade_no => order_id,
96
+ :subject => subject,
97
+ :body => description }
98
+
99
+ @attributes[:payment_type] = PAYMENT_TYPE_BUYING
100
+ end
101
+
102
+ def seller_email(email)
103
+ @attributes[:seller_email] = email
104
+ self
105
+ end
106
+
107
+ def logistics_and_price_settings
108
+ @attributes[:logistics_type] = 'POST'
109
+ @attributes[:logistics_payment] = 'BUYER_PAY'
110
+ @attributes[:logistics_fee] = '10'
111
+ @attributes[:price] = '0.1'
112
+ @attributes[:quantity] = '2'
113
+ self
114
+ end
115
+
116
+ def buyer_email(email)
117
+ @attributes[:buyer_email] = email
118
+ self
119
+ end
120
+
121
+ def total_fee(fee)
122
+ @attributes[:total_fee] = fee
123
+
124
+ self
125
+ end
126
+
127
+ def product_url(url)
128
+ @attributes[:show_url] = url
129
+ self
130
+ end
131
+
132
+ def as_donation
133
+ @attributes[:payment_type] = PAYMENT_TYPE_DONATION
134
+ self
135
+ end
136
+
137
+ def dualfun_pay
138
+ Product::DualfunPay.new(self)
139
+ end
140
+ end
141
+
142
+ class Merchant
143
+ attr_accessor :partner, :key
144
+
145
+ def initialize(partner, key)
146
+ @partner = partner
147
+ @key = key
148
+ end
149
+
150
+ def create_order(order_id, subject, description)
151
+ order = Order.new(order_id, subject, description)
152
+ order.merchant = self
153
+ order
154
+ end
155
+ end
156
+
157
+ class Notification
158
+ def initialize(partner, notification_id)
159
+ @partner = partner
160
+ @notification_id = notification_id
161
+ end
162
+
163
+ def valid?
164
+ uri = URI(GATEWAY_URL)
165
+ params = {
166
+ :service => :notify_verify,
167
+ :partner => @partner,
168
+ :notify_id => @notification_id
169
+ }
170
+ uri.query = params.map {|k, v| "#{k}=#{URI.escape(v.to_s)}"}.join('&')
171
+
172
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
173
+ req = Net::HTTP::Get.new uri.request_uri
174
+
175
+ response = http.request(req)
176
+ response.body == 'true'
177
+ end
178
+ end
179
+ end
180
+ end
181
+
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alipay_dualfun
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.0'
5
+ platform: ruby
6
+ authors:
7
+ - happypeter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem can help you integrate Alipay to your application.
14
+ email:
15
+ - happypeter1983@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - LICENSE.txt
22
+ - README.md
23
+ - Rakefile
24
+ - alipay_dualfun.gemspec
25
+ - lib/alipay_dualfun.rb
26
+ homepage: https://github.com/happypeter/alipay_dualfun
27
+ licenses: []
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.0.3
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: A simple payment library for alipay dual function payment gateways
49
+ test_files: []
50
+ has_rdoc: