spree_alipay_payment 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/assets/images/alipay.png +0 -0
- data/app/assets/javascripts/spree/frontend/spree_alipay_payment.js +31 -0
- data/app/assets/stylesheets/spree/frontend/spree_alipay_payment.css +3 -0
- data/app/controllers/spree/alipay_controller.rb +26 -0
- data/app/controllers/spree/alipay_notify_controller.rb +69 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +27 -0
- data/app/models/spree/gateway/alipay_direct_pay.rb +109 -0
- data/app/models/spree/gateway/alipay_partner_trade.rb +109 -0
- data/app/models/spree/gateway/alipay_trade_direct.rb +92 -0
- data/app/models/spree/order_decorator.rb +6 -0
- data/app/views/spree/admin/payments/source_views/_alipay_partner_trade.erb +0 -0
- data/app/views/spree/checkout/payment/_alipay_direct_pay.erb +12 -0
- data/app/views/spree/checkout/payment/_alipay_partner_trade.erb +12 -0
- data/app/views/spree/checkout/payment/_alipay_trade_direct.erb +12 -0
- data/config/locales/en.yml +8 -0
- data/config/locales/zh-CN.yml +8 -0
- data/config/locales/zh-TW.yml +8 -0
- data/config/routes.rb +18 -0
- data/lib/spree_alipay_payment.rb +4 -0
- data/lib/spree_alipay_payment/engine.rb +28 -0
- data/lib/spree_alipay_payment/version.rb +3 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e6f479088eefc172688ce1dd1615087f021109fe
|
4
|
+
data.tar.gz: eb0a99be3f9d2f9a6e6a6c54f59a17cbfe643bee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5700be891149918a69f555bee2bcab59ba1110debe37c6763ee423502665f377ae9a0ebd66910dba7c643d8916efd5b5925feab39a3ac2e0de4be79cdb6180b9
|
7
|
+
data.tar.gz: 6aab0a81d9caaf8d733356e9a25de27fc099a2d0ba0902bd51c468b2ead49b0556b45ad1136170042aac66c92981b501e84e4867b424f5dbb3517686cdce9f7d
|
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
//= require spree/frontend
|
2
|
+
|
3
|
+
SpreeAlipayPayment = {
|
4
|
+
updateSaveAndContinueVisibility: function() {
|
5
|
+
if (this.isButtonHidden()) {
|
6
|
+
$(this).trigger('hideSaveAndContinue')
|
7
|
+
} else {
|
8
|
+
$(this).trigger('showSaveAndContinue')
|
9
|
+
}
|
10
|
+
},
|
11
|
+
isButtonHidden: function () {
|
12
|
+
paymentMethod = this.checkedPaymentMethod();
|
13
|
+
return (!$('#use_existing_card_yes:checked').length && SpreeAlipayPayment.paymentMethodID && paymentMethod.val() == SpreeAlipayPayment.paymentMethodID);
|
14
|
+
},
|
15
|
+
checkedPaymentMethod: function() {
|
16
|
+
return $('div[data-hook="checkout_payment_step"] input[type="radio"][name="order[payments_attributes][][payment_method_id]"]:checked');
|
17
|
+
},
|
18
|
+
hideSaveAndContinue: function() {
|
19
|
+
$("#checkout_form_payment [data-hook=buttons]").addClass('hidden_button');
|
20
|
+
},
|
21
|
+
showSaveAndContinue: function() {
|
22
|
+
$("#checkout_form_payment [data-hook=buttons]").removeClass('hidden_button');
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
$(document).ready(function() {
|
27
|
+
SpreeAlipayPayment.updateSaveAndContinueVisibility();
|
28
|
+
paymentMethods = $('div[data-hook="checkout_payment_step"] input[type="radio"]').click(function (e) {
|
29
|
+
SpreeAlipayPayment.updateSaveAndContinueVisibility();
|
30
|
+
});
|
31
|
+
})
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Spree
|
2
|
+
class AlipayController < StoreController
|
3
|
+
ssl_allowed
|
4
|
+
|
5
|
+
def partner_trade
|
6
|
+
order = current_order || raise(ActiveRecord::RecordNotFound)
|
7
|
+
order.line_items.each do |item|
|
8
|
+
@product_name=item.variant.product.name
|
9
|
+
end
|
10
|
+
payment = Spree::Payment.create({:order_id => order.id, :amount => order.amount, :payment_method_id=> payment_method.id})
|
11
|
+
payment.started_processing!
|
12
|
+
partner_trade = payment_method.set_partner_trade( payment.identifier , order, spree.order_url(order) , notify_alipay_url, {:subject=> "#{current_store.name} #{@product_name} #{order.number}"})
|
13
|
+
redirect_to partner_trade
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def payment_method
|
19
|
+
Spree::PaymentMethod.find(params[:payment_method_id])
|
20
|
+
end
|
21
|
+
|
22
|
+
def provider
|
23
|
+
payment_method.provider
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Spree
|
2
|
+
class AlipayNotifyController < ApplicationController
|
3
|
+
skip_before_action :verify_authenticity_token
|
4
|
+
|
5
|
+
def notify_web
|
6
|
+
# except :controller_name, :action_name, :host, etc.
|
7
|
+
# {"discount"=>"0.02", "logistics_type"=>"POST", "receive_zip"=>"999077", "payment_type"=>"1", "subject"=>"TalkGoal #R381807226", "logistics_fee"=>"0.03","trade_no"=>"2014111830597476", "buyer_email"=>"test@testing.com", "gmt_create"=>"2014-11-18 17:49:28", "notify_type"=>"trade_status_sync", "quantity"=>"1", "logistics_payment"=>"BUYER_PAY", "out_trade_no"=>"R381807226", "seller_id"=>"1111002381708888", "notify_time"=>"2014-11-18 17:49:52","trade_status"=>"WAIT_SELLER_SEND_GOODS", "is_total_fee_adjust"=>"N", "gmt_payment"=>"2014-11-18 17:49:52", "total_fee"=>"0.04", "seller_email"=>"seller@test.com", "price"=>"0.01", "buyer_id"=>"3333602021013333", "gmt_logistics_modify"=>"2014-11-18 17:49:40", "receive_phone"=>"999999999", "notify_id"=>"fe67a9a70e7372f11aa65985a556a11111", "receive_name"=>"Arthur CHAN", "use_coupon"=>"N", "sign_type"=>"MD5", "sign"=>"a9999ba0aac13a0ff511977b71b78888", "receive_address"=>"中国香港 九龍"}
|
8
|
+
notify_params = params.except(*request.path_parameters.keys)
|
9
|
+
|
10
|
+
if Alipay::Notify.verify?(notify_params)
|
11
|
+
logger.info notify_params.inspect
|
12
|
+
|
13
|
+
# Valid notify, code your business logic.
|
14
|
+
# trade_status is base on your payment type
|
15
|
+
# Example:
|
16
|
+
#
|
17
|
+
# case params[:trade_status]
|
18
|
+
# when 'WAIT_BUYER_PAY'
|
19
|
+
# when 'WAIT_SELLER_SEND_GOODS'
|
20
|
+
# when 'TRADE_FINISHED'
|
21
|
+
# when 'TRADE_CLOSED'
|
22
|
+
# end
|
23
|
+
# Alipay workflow
|
24
|
+
# WAIT_BUYER_PAY(等待买家付款)
|
25
|
+
# WAIT_SELLER_SEND_GOODS(买家已付款,等待卖家发货)
|
26
|
+
# WAIT_BUYER_CONFIRM_GOODS(卖家已发货,等待买家收货)
|
27
|
+
# TRADE_FINISHED(买家已收货,交易完成)
|
28
|
+
#
|
29
|
+
# Spree Order status
|
30
|
+
# payment - The store is ready to receive the payment information for the order.
|
31
|
+
# confirm - The order is ready for a final review by the customer before being processed.
|
32
|
+
# complete
|
33
|
+
if notify_params[:trade_status] == 'WAIT_SELLER_SEND_GOODS'
|
34
|
+
out_trade_no = notify_params[:out_trade_no]
|
35
|
+
payment = Spree::Payment.find_by_identifier(out_trade_no) || raise(ActiveRecord::RecordNotFound)
|
36
|
+
|
37
|
+
#payment.update_columns( :response_code => notify_params[:trade_no])
|
38
|
+
|
39
|
+
payment.complete!
|
40
|
+
|
41
|
+
# o.next!
|
42
|
+
payment.order.next!
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
return render :text => 'success'
|
48
|
+
end
|
49
|
+
return render :text => 'error'
|
50
|
+
end
|
51
|
+
|
52
|
+
# Alipay status
|
53
|
+
# 1、已收货情况
|
54
|
+
# WAIT_SELLER_AGRE(等待卖家同意退款)
|
55
|
+
# WAIT_BUYER_RETURN_GOOD(卖家同意退款,等待买家退货)
|
56
|
+
# WAIT_SELLER_CONFIRM_GOODS(买家退货,等待卖家收到退货)
|
57
|
+
# REFUND_SUCCESS(买家收到退货,退款成功,交易关闭)
|
58
|
+
# 2、未收货情况
|
59
|
+
# WAIT_SELLER_AGREE(等待卖家同意退款)
|
60
|
+
# REFUND_SUCCESS(卖家同意退款,退款成功,交易关闭)
|
61
|
+
# 3、卖家未发货而退款成功,交易状态会变为TRADE_CLOSED
|
62
|
+
# 4、卖家发货而退款成功后,交易状态变为TRADE_FINISHED
|
63
|
+
def notify_refund
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
module Spree
|
3
|
+
CheckoutController.class_eval do
|
4
|
+
before_filter :checkout_to_pay_money, :only => [:update]
|
5
|
+
private
|
6
|
+
def checkout_to_pay_money
|
7
|
+
return unless current_order.next_step_complete?
|
8
|
+
return unless params[:order][:payments_attributes].present?
|
9
|
+
if pay_by_billing_integration?
|
10
|
+
if params["state"]=="payment"
|
11
|
+
redirect_to alipay_partner_trade_path(:payment_method_id => params[:order][:payments_attributes].first[:payment_method_id])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def pay_by_billing_integration?
|
17
|
+
if @order.next_step_complete?
|
18
|
+
payment_method_info=Spree::PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
|
19
|
+
if payment_method_info.type.include? "Alipay"
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'alipay'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
class Gateway::AlipayDirectPay < Gateway
|
5
|
+
|
6
|
+
|
7
|
+
preference :pid, :string
|
8
|
+
preference :key, :string
|
9
|
+
preference :seller_email, :string
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def supports?(source)
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def provider_class
|
18
|
+
::Alipay::Service
|
19
|
+
end
|
20
|
+
|
21
|
+
def provider
|
22
|
+
setup_alipay
|
23
|
+
::Alipay::Service
|
24
|
+
end
|
25
|
+
|
26
|
+
def auto_capture?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def source_required?
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_type
|
35
|
+
'alipay_direct_pay'
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def purchase(money, source, gateway_options)
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def set_partner_trade(out_trade_no, order, return_url, notify_url, gateway_options={})
|
45
|
+
raise unless preferred_pid && preferred_key && preferred_seller_email
|
46
|
+
amount = order.amount
|
47
|
+
tax_adjustments = order.all_adjustments.tax.additional
|
48
|
+
|
49
|
+
shipping_adjustments = order.all_adjustments.shipping
|
50
|
+
|
51
|
+
adjustment_label = []
|
52
|
+
adjustment_costs = 0.0
|
53
|
+
|
54
|
+
order.all_adjustments.nonzero.eligible.each do |adjustment|
|
55
|
+
next if (tax_adjustments + shipping_adjustments).include?(adjustment)
|
56
|
+
adjustment_label << adjustment.label
|
57
|
+
|
58
|
+
adjustment_costs += adjustment.amount # Spree::Currency.convert(adjustment.amount, order.currency, 'RMB')
|
59
|
+
end
|
60
|
+
|
61
|
+
subject = gateway_options[:subject] || order.number
|
62
|
+
subject += " #{adjustment_label.join(' | ')}"if adjustment_label.present?
|
63
|
+
shipping_cost = order.shipments.to_a.sum(&:cost)
|
64
|
+
options = {
|
65
|
+
:out_trade_no => out_trade_no, # 20130801000001
|
66
|
+
:subject => subject,
|
67
|
+
:logistics_type => 'EXPRESS', #EXPRESS、POST、EMS
|
68
|
+
:logistics_fee => shipping_cost,
|
69
|
+
:logistics_payment => 'BUYER_PAY',
|
70
|
+
:price => amount,
|
71
|
+
:quantity => 1,
|
72
|
+
:discount => adjustment_costs,
|
73
|
+
:return_url => return_url, # https://writings.io/orders/20130801000001
|
74
|
+
:notify_url => notify_url # https://writings.io/orders/20130801000001/alipay_notify
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
logger.debug "create_direct_pay: #{options}"
|
79
|
+
return provider.create_direct_pay_by_user_url(options)
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
# def refund(payment, amount)
|
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 => order.number, :amount => order.amount, :reason => 'WEBSITE_REFUND'}],
|
91
|
+
# notify_url: notify_url # https://writings.io/orders/20130801000001/alipay_refund_notify
|
92
|
+
# }
|
93
|
+
# logger.info options
|
94
|
+
# refund_transaction = provider.create_refund_url(options)
|
95
|
+
# end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def setup_alipay
|
100
|
+
|
101
|
+
Alipay.pid = preferred_pid
|
102
|
+
Alipay.key = preferred_key
|
103
|
+
Alipay.seller_email = preferred_seller_email
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# payment.state = 'completed'
|
109
|
+
# current_order.state = 'complete'
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'alipay'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
class Gateway::AlipayPartnerTrade < Gateway
|
5
|
+
|
6
|
+
|
7
|
+
preference :pid, :string
|
8
|
+
preference :key, :string
|
9
|
+
preference :seller_email, :string
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def supports?(source)
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def provider_class
|
18
|
+
::Alipay::Service
|
19
|
+
end
|
20
|
+
|
21
|
+
def provider
|
22
|
+
setup_alipay
|
23
|
+
::Alipay::Service
|
24
|
+
end
|
25
|
+
|
26
|
+
def auto_capture?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def source_required?
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_type
|
35
|
+
'alipay_partner_trade'
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def purchase(money, source, gateway_options)
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def set_partner_trade(out_trade_no, order, return_url, notify_url, gateway_options={})
|
45
|
+
raise unless preferred_pid && preferred_key && preferred_seller_email
|
46
|
+
amount = order.amount
|
47
|
+
tax_adjustments = order.all_adjustments.tax.additional
|
48
|
+
|
49
|
+
shipping_adjustments = order.all_adjustments.shipping
|
50
|
+
|
51
|
+
adjustment_label = []
|
52
|
+
adjustment_costs = 0.0
|
53
|
+
|
54
|
+
order.all_adjustments.nonzero.eligible.each do |adjustment|
|
55
|
+
next if (tax_adjustments + shipping_adjustments).include?(adjustment)
|
56
|
+
adjustment_label << adjustment.label
|
57
|
+
|
58
|
+
adjustment_costs += adjustment.amount # Spree::Currency.convert(adjustment.amount, order.currency, 'RMB')
|
59
|
+
end
|
60
|
+
|
61
|
+
subject = gateway_options[:subject] || order.number
|
62
|
+
subject += " #{adjustment_label.join(' | ')}"if adjustment_label.present?
|
63
|
+
shipping_cost = order.shipments.to_a.sum(&:cost)
|
64
|
+
options = {
|
65
|
+
:out_trade_no => out_trade_no, # 20130801000001
|
66
|
+
:subject => subject,
|
67
|
+
:logistics_type => 'POST', #EXPRESS、POST、EMS
|
68
|
+
:logistics_fee => shipping_cost,
|
69
|
+
:logistics_payment => 'BUYER_PAY',
|
70
|
+
:price => amount,
|
71
|
+
:quantity => 1,
|
72
|
+
:discount => adjustment_costs,
|
73
|
+
:return_url => return_url, # https://writings.io/orders/20130801000001
|
74
|
+
:notify_url => notify_url # https://writings.io/orders/20130801000001/alipay_notify
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
logger.debug "create_partner_trade_by_buyer_url: #{options}"
|
79
|
+
return provider.create_partner_trade_by_buyer_url(options)
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
# def refund(payment, amount)
|
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 => order.number, :amount => order.amount, :reason => 'WEBSITE_REFUND'}],
|
91
|
+
# notify_url: notify_url # https://writings.io/orders/20130801000001/alipay_refund_notify
|
92
|
+
# }
|
93
|
+
# logger.info options
|
94
|
+
# refund_transaction = provider.create_refund_url(options)
|
95
|
+
# end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def setup_alipay
|
100
|
+
|
101
|
+
Alipay.pid = preferred_pid
|
102
|
+
Alipay.key = preferred_key
|
103
|
+
Alipay.seller_email = preferred_seller_email
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# payment.state = 'completed'
|
109
|
+
# current_order.state = 'complete'
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'alipay'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
class Gateway::AlipayTradeDirect < Gateway
|
5
|
+
|
6
|
+
preference :pid, :string
|
7
|
+
preference :key, :string
|
8
|
+
preference :seller_email, :string
|
9
|
+
|
10
|
+
def supports?(source)
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def provider_class
|
15
|
+
::Alipay::Service
|
16
|
+
end
|
17
|
+
|
18
|
+
def provider
|
19
|
+
setup_alipay
|
20
|
+
::Alipay::Service
|
21
|
+
end
|
22
|
+
|
23
|
+
def auto_capture?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def source_required?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_type
|
32
|
+
'alipay_trade_direct'
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def purchase(money, source, gateway_options)
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_partner_trade(out_trade_no, order, return_url, notify_url, gateway_options={})
|
41
|
+
alipay_key= preferred_key
|
42
|
+
time = Time.now.strftime('%Y%m%d%H%M%S%L')
|
43
|
+
#https://mapi.alipay.com/gateway.do?service=trade_create_by_buyer&_input_charset=utf-8&partner=2088002627298374&seller_email=areq22%40aliyun.com&payment_type=1&out_trade_no=aquarius20141210165948670&subject=Iphone+6&logistics_type=DIRECT&logistics_fee=0&logistics_payment=SELLER_PAY&price=0.01&quantity=1&discount=0.00&return_url=http%3A%2F%2Flocalhost%3A3000%2Freturn¬ify_url=http%3A%2F%2Flocalhost%3A3000%2Fnotify&sign_type=MD5&sign=b74cdf8eea44cfe174c95a2e27c70a5a
|
44
|
+
url="https://mapi.alipay.com/gateway.do"
|
45
|
+
subject = gateway_options[:subject] || order.number
|
46
|
+
|
47
|
+
options={
|
48
|
+
:service=>"trade_create_by_buyer",
|
49
|
+
:_input_charset=>"utf-8",
|
50
|
+
:partner=>preferred_pid,
|
51
|
+
:seller_email=>preferred_seller_email,
|
52
|
+
:payment_type=>1,
|
53
|
+
:out_trade_no=>out_trade_no,
|
54
|
+
:subject=>subject,
|
55
|
+
:logistics_type=>"EXPRESS",
|
56
|
+
:logistics_fee=>0,
|
57
|
+
:logistics_payment=>"BUYER_PAY",
|
58
|
+
:price=>order.amount,
|
59
|
+
:quantity=>1,
|
60
|
+
:discount=>0.00,
|
61
|
+
:return_url=>return_url,
|
62
|
+
:notify_url=>notify_url
|
63
|
+
}
|
64
|
+
|
65
|
+
sign=""
|
66
|
+
paymentlink=url<<"?"
|
67
|
+
options.each do |key,value|
|
68
|
+
paymentlink<<"#{key}=#{value}&"
|
69
|
+
end
|
70
|
+
md5sign=_sign(options,alipay_key)
|
71
|
+
paymentlink<<"sign_type=MD5&sign=#{md5sign}"
|
72
|
+
return paymentlink
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def _sign(options,alipay_key)
|
78
|
+
|
79
|
+
sign_str=""
|
80
|
+
options.sort.map do |key,value|
|
81
|
+
if value
|
82
|
+
sign_str<<"#{key}=#{value}&"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
sign_str=sign_str[0, sign_str.length - 1]
|
86
|
+
|
87
|
+
sign_str<<"#{alipay_key}"
|
88
|
+
sign_str=Digest::MD5.hexdigest(sign_str)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
<% if @order.currency == 'CNY' || @order.currency == 'RMB' %>
|
3
|
+
<%=image_tag('alipay.png', :alt=> I18n.t('spree.checkout.payment.alipay.partner_trade'))%>
|
4
|
+
<br/>
|
5
|
+
<%= "#{I18n.t('spree.alipay.click_and_pay')} (#{I18n.t('spree.alipay.direct_pay')})"%>
|
6
|
+
<% else %>
|
7
|
+
<%= I18n.t('spree.alipay.error_non_rmb') %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<script>
|
11
|
+
SpreeAlipayPayment.paymentMethodID = "<%= payment_method.id %>"
|
12
|
+
</script>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
<% if @order.currency == 'CNY' || @order.currency == 'RMB' %>
|
3
|
+
<%=image_tag('alipay.png', :alt=> I18n.t('spree.checkout.payment.alipay.partner_trade'))%>
|
4
|
+
<br/>
|
5
|
+
<%= "#{I18n.t('spree.alipay.click_and_pay')} (#{I18n.t('spree.alipay.partner_trade')})"%>
|
6
|
+
<% else %>
|
7
|
+
<%= I18n.t('spree.alipay.error_non_rmb') %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<script>
|
11
|
+
SpreeAlipayPayment.paymentMethodID = "<%= payment_method.id %>"
|
12
|
+
</script>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
<% if @order.currency == 'CNY' || @order.currency == 'RMB' %>
|
3
|
+
<%=image_tag('alipay.png', :alt=> I18n.t('spree.checkout.payment.alipay.partner_trade'))%>
|
4
|
+
<br/>
|
5
|
+
<%= "#{I18n.t('spree.alipay.click_and_pay')} (#{I18n.t('spree.alipay.trade_direct')})"%>
|
6
|
+
<% else %>
|
7
|
+
<%= I18n.t('spree.alipay.error_non_rmb') %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<script>
|
11
|
+
SpreeAlipayPayment.paymentMethodID = "<%= payment_method.id %>"
|
12
|
+
</script>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
en:
|
2
|
+
spree:
|
3
|
+
alipay:
|
4
|
+
click_and_pay: Please click the Alipay button to complete the payment.
|
5
|
+
error_non_rmb: For Alipay payment, please change currency to RMB first.
|
6
|
+
partner_trade: Partner Trade
|
7
|
+
trade_direct: Partner Trade and Direct pay
|
8
|
+
direct_pay: Direct Pay
|
data/config/routes.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Spree::Core::Engine.add_routes do
|
2
|
+
# Add your extension routes here
|
3
|
+
#get '/alipay/confirm', :to => "alipay_notify#confirm", :as => :confirm_alipay
|
4
|
+
get '/alipay/partner_trade', :to => "alipay#partner_trade", :as => :alipay_partner_trade
|
5
|
+
post '/alipay/notify', :to => "alipay_notify#notify_web", :as => :notify_alipay
|
6
|
+
|
7
|
+
resources :orders do
|
8
|
+
resource :checkout, :controller => 'checkout' do
|
9
|
+
member do
|
10
|
+
get :alipay_checkout_payment
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SpreeAlipayPayment
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_alipay_payment'
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
# use rspec for tests
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.activate
|
15
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
16
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
config.to_prepare &method(:activate).to_proc
|
21
|
+
|
22
|
+
initializer "spree.alipay_payment.payment_methods", :after => "spree.register.payment_methods" do |app|
|
23
|
+
app.config.spree.payment_methods << Spree::Gateway::AlipayPartnerTrade
|
24
|
+
app.config.spree.payment_methods << Spree::Gateway::AlipayDirectPay
|
25
|
+
app.config.spree.payment_methods << Spree::Gateway::AlipayTradeDirect
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_alipay_payment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kevin obama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: spree_core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: alipay
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.0
|
41
|
+
description: Adds Alipay Payment as a Payment Method to Spree Commerce
|
42
|
+
email: w.zhou@aquarius-asia.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- app/assets/images/alipay.png
|
48
|
+
- app/assets/javascripts/spree/frontend/spree_alipay_payment.js
|
49
|
+
- app/assets/stylesheets/spree/frontend/spree_alipay_payment.css
|
50
|
+
- app/controllers/spree/alipay_controller.rb
|
51
|
+
- app/controllers/spree/alipay_notify_controller.rb
|
52
|
+
- app/controllers/spree/checkout_controller_decorator.rb
|
53
|
+
- app/models/spree/gateway/alipay_direct_pay.rb
|
54
|
+
- app/models/spree/gateway/alipay_partner_trade.rb
|
55
|
+
- app/models/spree/gateway/alipay_trade_direct.rb
|
56
|
+
- app/models/spree/order_decorator.rb
|
57
|
+
- app/views/spree/admin/payments/source_views/_alipay_partner_trade.erb
|
58
|
+
- app/views/spree/checkout/payment/_alipay_direct_pay.erb
|
59
|
+
- app/views/spree/checkout/payment/_alipay_partner_trade.erb
|
60
|
+
- app/views/spree/checkout/payment/_alipay_trade_direct.erb
|
61
|
+
- config/locales/en.yml
|
62
|
+
- config/locales/zh-CN.yml
|
63
|
+
- config/locales/zh-TW.yml
|
64
|
+
- config/routes.rb
|
65
|
+
- lib/spree_alipay_payment.rb
|
66
|
+
- lib/spree_alipay_payment/engine.rb
|
67
|
+
- lib/spree_alipay_payment/version.rb
|
68
|
+
homepage: http://g.uboxi.com/
|
69
|
+
licenses:
|
70
|
+
- BSD-3
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.9.3
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements:
|
87
|
+
- none
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.2.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Adds Alipay Payment as a Payment Method to Spree Commerce
|
93
|
+
test_files: []
|
94
|
+
has_rdoc:
|