activemerchant_patch_for_china 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,136 +47,11 @@ require 'active_merchant/billing/integrations/action_view_helper'
47
47
  ActionView::Base.send(:include, ActiveMerchant::Billing::Integrations::ActionViewHelper)
48
48
  </code></pre>
49
49
 
50
- then define your api key, account and email
51
-
52
- <pre><code>
53
- ActiveMerchant::Billing::Integrations::Alipay::KEY
54
- ActiveMerchant::Billing::Integrations::Alipay::ACCOUNT
55
- ActiveMerchant::Billing::Integrations::Alipay::EMAIL
56
- </code></pre>
57
-
58
50
  **************************************************************************
59
51
 
60
52
  h2. Usage
61
53
 
62
- *Alipay*
63
-
64
- Request Form:
65
-
66
- <pre><code>
67
- <% payment_service_for 'payment code', ActiveMerchant::Billing::Integrations::Alipay::ACCOUNT,
68
- :service => :alipay,
69
- :html => { :id => 'payment-form', :method => :get } do |service| %>
70
- <% service.total_fee 0.02 %>
71
- <%# service.price 0.01 %>
72
- <%# service.quantity 2 %>
73
- <% service.seller :email => ActiveMerchant::Billing::Integrations::Alipay::EMAIL %>
74
- <% service.notify_url url_for(:only_path => false, :action => 'notify') %>
75
- <% service.return_url url_for(:only_path => false, :action => 'done') %>
76
- <% service.show_url url_for(:only_path => false, :action => 'show') %>
77
- <% service.body 'payment body' %>
78
- <% service.charset "utf-8" %>
79
- <% service.service "create_direct_pay_by_user" %>
80
- <% service.payment_type 1 %>
81
- <% service.subject 'payment subject' %>
82
- <% service.sign %>
83
- <% end %>
84
- <%= button_to_function "Submit", "document.getElementById('payment-form').submit();" %>
85
- </code></pre>
86
-
87
- *payment code is the out_trade_no, it must be unique.*
88
- amount is the total_fee.
89
- payment body is the body of the payment.
90
- payment subject is the subject of the payment.
91
-
92
-
93
- Notify action:
94
-
95
- <pre><code>
96
- notification = ActiveMerchant::Billing::Integrations::Alipay::Notification.new(request.raw_post)
97
-
98
- txn = AlipayTxn.create(:notify_id => notification.notify_id,
99
- :total_fee => notification.total_fee,
100
- :status => notification.trade_status,
101
- :trade_no => notification.trade_no,
102
- :received_at => notification.notify_time)
103
-
104
- if notification.complete?
105
- txn.pay!
106
- else
107
- txn.pending!
108
- end
109
- </code></pre>
110
-
111
- Return action:
112
-
113
- <pre><code>
114
- def done
115
- r = ActiveMerchant::Billing::Integrations::Alipay::Return.new(request.query_string)
116
- unless @result = r.success?
117
- logger.warn(r.message)
118
- end
119
- end
120
- </code></pre>
121
-
122
- **************************************************************************
123
-
124
- h2. Interface
125
-
126
- *Alipay*
127
-
128
- for helper
129
-
130
- <pre><code>
131
- mapping :account, 'partner'
132
- mapping :total_fee, 'total_fee'
133
- mapping :price, 'price'
134
- mapping :quantity, 'quantity'
135
- mapping :order, 'out_trade_no'
136
- mapping :seller, :email => 'seller_email',
137
- :id => 'seller_id'
138
- mapping :buyer, :email => 'buyer_email',
139
- :id => 'buyer_id'
140
- mapping :notify_url, 'notify_url'
141
- mapping :return_url, 'return_url'
142
- mapping :show_url, 'show_url'
143
- mapping :body, 'body'
144
- mapping :subject, 'subject'
145
- mapping :charset, '_input_charset'
146
- mapping :service, 'service'
147
- mapping :payment_type, 'payment_type'
148
- mapping :paymethod, 'paymethod'
149
- mapping :defaultbank, 'defaultbank'
150
- mapping :royalty_type, 'royalty_type'
151
- mapping :royalty_parameters, 'royalty_parameters'
152
- mapping :it_b_pay, 'it_b_pay'
153
- </code></pre>
154
-
155
- for notification
156
-
157
- <pre><code>
158
- notify_type
159
- notify_id
160
- notify_time
161
- out_trade_no
162
- trade_no
163
- payment_type
164
- subject
165
- body
166
- price
167
- quantity
168
- total_fee
169
- trade_status
170
- refund_status
171
- seller_email
172
- seller_id
173
- buyer_email
174
- buyer_id
175
- gmt_create
176
- gmt_payment
177
- gmt_close
178
- gmt_refund
179
- </code></pre>
54
+ "Alipay (支付宝)":http://wiki.github.com/flyerhzm/activemerchant_patch_for_china/alipay
180
55
 
181
56
  **************************************************************************
182
57
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{activemerchant_patch_for_china}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Richard Huang"]
12
- s.date = %q{2009-11-26}
12
+ s.date = %q{2009-12-16}
13
13
  s.description = %q{A rails plugin to add an active_merchant patch for china online payment platform}
14
14
  s.email = %q{flyerhzm@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -39,17 +39,17 @@ module ActiveMerchant #:nodoc:
39
39
  mapping :it_b_pay, 'it_b_pay'
40
40
 
41
41
  #################################################
42
- # create partner trade by buyer or trade create by user
42
+ # create partner trade by buyer and trade create by user
43
43
  #################################################
44
44
  mapping :price, 'price'
45
45
  mapping :quantity, 'quantity'
46
46
  mapping :discount, 'discount'
47
47
  ['', '_1', '_2', '_3'].each do |postfix|
48
- self.class_eval <<-EOF
48
+ self.class_eval <<-EOF
49
49
  mapping :logistics#{postfix}, :type => 'logistics_type#{postfix}',
50
50
  :fee => 'logistics_fee#{postfix}',
51
51
  :payment => 'logistics_payment#{postfix}'
52
- EOF
52
+ EOF
53
53
  end
54
54
  mapping :receive, :name => 'receive_name',
55
55
  :address => 'receive_address',
@@ -9,104 +9,62 @@ module ActiveMerchant #:nodoc:
9
9
  include Sign
10
10
 
11
11
  def complete?
12
- if trade_status != "TRADE_FINISHED"
13
- return false
14
- end
15
-
16
- unless verify_sign
17
- @message = "Alipay Error: ILLEGAL_SIGN"
18
- return false
19
- end
20
-
21
- true
22
- end
23
-
24
- def message
25
- @message
26
- end
27
-
28
- def notify_type
29
- params['notify_type']
30
- end
31
-
32
- def notify_id
33
- params['notify_id']
34
- end
35
-
36
- def notify_time
37
- Time.parse params['notify_time']
38
- end
39
-
40
- def out_trade_no
41
- params['out_trade_no']
42
- end
43
-
44
- def trade_no
45
- params['trade_no']
12
+ trade_status == "TRADE_FINISHED"
46
13
  end
47
14
 
48
- def payment_type
49
- params['payment_type']
15
+ def pending?
16
+ trade_status == 'WAIT_BUYER_PAY'
50
17
  end
51
18
 
52
- def subject
53
- params['subject']
54
- end
55
-
56
- def body
57
- params['body']
19
+ def status
20
+ trade_status
58
21
  end
59
22
 
60
- def price
61
- params['price']
62
- end
63
-
64
- def quantity
65
- params['quantity']
66
- end
67
-
68
- def total_fee
69
- params["total_fee"]
23
+ def acknowledge
24
+ raise StandardError.new("Faulty alipay result: ILLEGAL_SIGN") unless verify_sign
25
+ true
70
26
  end
71
27
 
72
- def trade_status
73
- params['trade_status']
74
- end
75
-
76
- def refund_status
77
- params['refund_status']
28
+ ['notify_type', 'notify_id', 'out_trade_no', 'trade_no', 'payment_type', 'subject', 'body',
29
+ 'seller_email', 'seller_id', 'buyer_email', 'buyer_id', 'logistics_type', 'logistics_payment',
30
+ 'receive_name', 'receive_address', 'receive_zip', 'receive_phone', 'receive_mobile'].each do |param|
31
+ self.class_eval <<-EOF
32
+ def #{param}
33
+ params['#{param}']
34
+ end
35
+ EOF
78
36
  end
79
37
 
80
- def seller_email
81
- params['seller_email']
38
+ ['price', 'discount', 'quantity', 'total_fee', 'coupon_discount', 'logistics_fee'].each do |param|
39
+ self.class_eval <<-EOF
40
+ def #{param}
41
+ params['#{param}']
42
+ end
43
+ EOF
82
44
  end
83
45
 
84
- def seller_id
85
- params['seller_id']
46
+ ['trade_status', 'refund_status', 'logistics_status'].each do |param|
47
+ self.class_eval <<-EOF
48
+ def #{param}
49
+ params['#{param}']
50
+ end
51
+ EOF
86
52
  end
87
53
 
88
- def buyer_email
89
- params['buyer_email']
54
+ ['notify_time', 'gmt_create', 'gmt_payment', 'gmt_close', 'gmt_refund', 'gmt_send_goods', 'gmt_logistics_modify'].each do |param|
55
+ self.class_eval <<-EOF
56
+ def #{param}
57
+ Time.parse params['#{param}']
58
+ end
59
+ EOF
90
60
  end
91
61
 
92
- def buyer_id
93
- params['buyer_id']
94
- end
95
-
96
- def gmt_create
97
- Time.parse params['gmt_create']
98
- end
99
-
100
- def gmt_payment
101
- Time.parse params['gmt_payment']
102
- end
103
-
104
- def gmt_close
105
- Time.parse params['gmt_close']
106
- end
107
-
108
- def gmt_refund
109
- Time.parse params['gmt_reund']
62
+ ['use_coupon', 'is_total_fee_adjust'].each do |param|
63
+ self.class_eval <<-EOF
64
+ def #{param}?
65
+ 'T' == params['#{param}']
66
+ end
67
+ EOF
110
68
  end
111
69
 
112
70
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemerchant_patch_for_china
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-26 00:00:00 +08:00
12
+ date: 2009-12-16 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency