Permalink
Browse files

close #402, rename payment partner column to email.

  • Loading branch information...
1 parent 3aa6b67 commit f65edf0041e8850c8e84e359a715ec3a904d865b @saberma saberma committed Feb 6, 2012
@@ -9,11 +9,11 @@ App.Models.Payment = Backbone.Model.extend
validate: (attrs) ->
errors = {}
if attrs.payment_type_id is 1 # 支付宝
- errors["合作者身份ID"] = "不能为空." if attrs.partner is ''
- errors["帐号"] = "不能为空." if attrs.account is ''
+ errors["合作者身份ID"] = "不能为空." if attrs.account is ''
errors["交易安全校验码"] = "不能为空." if !@id? and (!attrs.key? or attrs.key is '') # 新增时才校验
+ errors["帐号"] = "不能为空." if attrs.email is ''
if attrs.payment_type_id is 2 # 财付通
- errors["商户号"] = "不能为空." if attrs.partner is ''
+ errors["商户号"] = "不能为空." if attrs.account is ''
errors["交易安全校验码"] = "不能为空." if !@id? and (!attrs.key? or attrs.key is '') # 新增时才校验
else # 自定义支付方式
errors["方式"] = "不能为空." if attrs.name is ''
@@ -34,10 +34,10 @@ App.Views.Payment.Online = Backbone.View.extend # 在线支付
save: ->
self = this
@model.save {
- partner: self.$("input[name='partner']").val(),
account: self.$("input[name='account']").val(),
key: self.$("input[name='key']").val(),
service: self.$("select[name='service']").val(),
+ email: self.$("input[name='email']").val(), # 支付宝才有
payment_type_id: self.$("input[name='payment_type_id']").val()
},
success: (model, resp) ->
@@ -142,7 +142,7 @@ def commit
def notify # 此action只供支付网关(支付宝)服务器的外部通知接口使用,通知我们订单支付状态(notify_url)
notification = ActiveMerchant::Billing::Integrations::Alipay::Notification.new(request.raw_post)
@order = Order.find_by_token(notification.out_trade_no)
- if @order and notification.acknowledge(@order.payment.key) and valid?(notification, @order.payment.partner)
+ if @order and notification.acknowledge(@order.payment.key) and valid?(notification, @order.payment.account)
@order.pay!(notification.total_fee) if notification.complete? and @order.financial_status_pending? # 要支持重复请求
render text: "success"
else
@@ -168,7 +168,7 @@ def done # 支付后从浏览器前台直接返回(return_url)
def tenpay_notify # 此action只供支付网关(财付通)服务器的外部通知接口使用,通知我们订单支付状态(return_url)
notification = ActiveMerchant::Billing::Integrations::Tenpay::Return.new(request.raw_post)
@order = Order.find_by_token(notification.order)
- if @order and notification.success?(@order.payment.key, @order.payment.partner)
+ if @order and notification.success?(@order.payment.key, @order.payment.account)
@order.pay!(notification.total_fee) if @order.financial_status_pending? # 要支持重复请求
render
else
@@ -221,9 +221,9 @@ def verify_customer!(cart)
end
end
- def valid?(notification, partner) # 注意:支付宝的notify_id只在一分钟内才有效
+ def valid?(notification, account) # 注意:支付宝的notify_id只在一分钟内才有效
url = "https://www.alipay.com/cooperate/gateway.do?service=notify_verify"
- result = HTTParty.get(url, query: {partner: partner, notify_id: notification.notify_id}).body
+ result = HTTParty.get(url, query: {partner: account, notify_id: notification.notify_id}).body
result == 'true'
end
View
@@ -1,7 +1,7 @@
class Payment < ActiveRecord::Base
belongs_to :shop
- validates_presence_of :partner, :key, :service, if: Proc.new{|p| p.payment_type_id?}
- validates_presence_of :account, if: Proc.new{|p| p.is_alipay?} # 支付宝才需要account
+ validates_presence_of :account, :key, :service, if: Proc.new{|p| p.payment_type_id?}
+ validates_presence_of :email, if: Proc.new{|p| p.is_alipay?} # 支付宝才需要email
validates_presence_of :name, if: Proc.new{|p| !p.payment_type_id?}
#default_scope order('created_at')
@@ -36,7 +36,7 @@
%strong
请提供您
%a(href="http://www.alipay.com" target="gateway") 支付宝
- 账户的合作者身份ID(partner)、交易安全校验码(key)以及账户,若没有,则请您登陆到
+ 账户的合作者身份ID(account)、交易安全校验码(key)以及账户(email),若没有,则请您登陆到
%a(href="https://b.alipay.com/order/productDetail.htm?productId=2011060800327555" target="gateway") 支付宝商家服务
进行申请
/ .group-fields
@@ -48,18 +48,18 @@
%script(type="text/x-handlebars-template")
.sb
- %label(for="payment_alipay_partner") 合作者身份ID
- %p.credential
- %input#payment_alipay_partner(autocomplete="off" name="partner" size="30" type="text" value="{{partner}}")
- .sb
- %label(for="payment_alipay_account") 帐号
+ %label(for="payment_alipay_account") 合作者身份ID
%p.credential
%input#payment_alipay_account(autocomplete="off" name="account" size="30" type="text" value="{{account}}")
.sb
%label(for="payment_alipay_key") 交易安全校验码
%p.credential
%input#payment_alipay_key(autocomplete="off" name="key" size="30" type="password" value="{{key}}")
.sb
+ %label(for="payment_alipay_email") 帐号
+ %p.credential
+ %input#payment_alipay_email(autocomplete="off" name="email" size="30" type="text" value="{{email}}")
+ .sb
%label(for="payment_alipay_service") 接口类型
%p.credential
%select#payment_alipay_service(name="service")=options_for_select alipay_service_types
@@ -48,9 +48,9 @@
%script(type="text/x-handlebars-template")
.sb
- %label(for="payment_tenpay_partner") 商户号
+ %label(for="payment_tenpay_account") 商户号
%p.credential
- %input#payment_tenpay_partner(autocomplete="off" name="partner" size="30" type="text" value="{{partner}}")
+ %input#payment_tenpay_account(autocomplete="off" name="account" size="30" type="text" value="{{account}}")
.sb
%label(for="payment_tenpay_key") 商户密钥
%p.credential
@@ -2,17 +2,17 @@
-address = order.shipping_address
%p==您选择的付款方式为: #{payment.payment_type.name}
%p==点击确认支付,将前往支付中心进行付款操作!
-- payment_service_for order.token, payment.partner, service: :alipay, html: { id: 'payment-form', method: :get } do |service|
+- payment_service_for order.token, payment.account, service: :alipay, html: { id: 'payment-form', method: :get } do |service|
- if payment.direct? # 即时到帐
- service.total_fee order.total_price
- else # 担保交易或者双功能
- service.price order.total_price
- service.quantity 1
- service.discount 0
- - service.agent payment.partner
+ - service.agent payment.account
- service.logistics type: 'EXPRESS', fee: 0, payment: 'BUYER_PAY'
-# service.receive name: address.name, address: address.info, zip: address.zip, phone: address.phone
- - service.seller email: payment.account
+ - service.seller email: payment.email
- service.notify_url notify_order_url
- service.return_url done_order_url
- service.charset "utf-8"
@@ -2,11 +2,11 @@
-address = order.shipping_address
%p==您选择的付款方式为: #{payment.payment_type.name}
%p==点击确认支付,将前往支付中心进行付款操作!
-- payment_service_for order.token, payment.partner, service: :tenpay, html: { id: 'payment-form', method: :get } do |service|
+- payment_service_for order.token, payment.account, service: :tenpay, html: { id: 'payment-form', method: :get } do |service|
- service.cmdno 1
- service.date Date.today.to_s(:number)
- service.amount (order.total_price*100).to_i # 以分为单位
- - service.transaction_id "#{payment.partner}#{Date.today.to_s(:number)}#{order.number.to_s.rjust(10, '0')}"
+ - service.transaction_id "#{payment.account}#{Date.today.to_s(:number)}#{order.number.to_s.rjust(10, '0')}"
- service.currency '1' # 人民币
- service.return_url tenpay_notify_order_url
- service.charset "utf-8"
View
@@ -32,11 +32,11 @@ cn:
name: 名称
price: 运费
payment:
- partner: 合作者身份ID
payment_type: 支付类型
remark: 备注
key: 交易安全校验码
- account: 账号
+ account: 账号(合作者身份ID或者商户号)
+ email: 支付宝登录帐号(email地址或者手机号)
service: 接口类型
number: 序号
apply: 申请
@@ -0,0 +1,7 @@
+class RenamePaymentPartnerToEmail < ActiveRecord::Migration
+
+ def change # 402
+ rename_column :payments, :partner, :email
+ end
+
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120113091629) do
+ActiveRecord::Schema.define(:version => 20120206135658) do
create_table "active_admin_comments", :force => true do |t|
t.integer "resource_id", :null => false
@@ -449,7 +449,7 @@
create_table "payments", :force => true do |t|
t.integer "shop_id"
- t.string "partner"
+ t.string "email"
t.integer "payment_type_id"
t.string "key"
t.string "account"
@@ -21,13 +21,13 @@
it "should be success" do
attrs = payment_alipay.attributes.clone
service = ActiveMerchant::Billing::Integrations::Alipay::Helper::TRADE_CREATE_BY_BUYER # 改为担保交易
- attrs.merge! key: 'abcdef', partner: '123456', account: 'admin@shopqi.com', service: service
+ attrs.merge! key: 'abcdef', account: '123456', email: 'admin@shopqi.com', service: service
post :update, id: payment_alipay.id, payment: attrs
payment_alipay.reload
- payment_alipay.account.should eql 'admin@shopqi.com'
payment_alipay.service.should eql service
payment_alipay.key.should eql 'abcdef'
- payment_alipay.partner.should eql '123456'
+ payment_alipay.account.should eql '123456'
+ payment_alipay.email.should eql 'admin@shopqi.com'
end
it "should support empty key" do # 更新时不输入key
@@ -214,7 +214,7 @@
let(:date) { Date.today.to_s(:number) }
- let(:transaction_id) { "#{order.payment.partner}#{date}0000000001" }
+ let(:transaction_id) { "#{order.payment.account}#{date}0000000001" }
let(:attrs) { { cmdno: '1', pay_result: '0', date: Date.today.to_s(:number), transaction_id: transaction_id, sp_billno: order.token, total_fee: (order.total_price*100).to_i, fee_type: '1', attach: 'ShopQi' } }
@@ -230,7 +230,7 @@
it 'should change order financial_status to paid' do
order.financial_status_pending?.should be_true
expect do
- post :tenpay_notify, attrs.merge(bargainor_id: order.payment.partner, sign: tenpay_sign(attrs, order.payment.key))
+ post :tenpay_notify, attrs.merge(bargainor_id: order.payment.account, sign: tenpay_sign(attrs, order.payment.key))
response.body.should_not eql 'fail'
order.reload.financial_status_paid?.should be_true
end.should change(OrderTransaction, :count).by(1)
@@ -241,9 +241,9 @@
order.reload
order.financial_status = :abandoned
order.save
- post :tenpay_notify, attrs.merge(bargainor_id: order.payment.partner, sign: tenpay_sign(attrs, order.payment.key))
+ post :tenpay_notify, attrs.merge(bargainor_id: order.payment.account, sign: tenpay_sign(attrs, order.payment.key))
response.body.should_not eql 'fail'
- post :tenpay_notify, attrs.merge(bargainor_id: order.payment.partner, sign: tenpay_sign(attrs, order.payment.key))
+ post :tenpay_notify, attrs.merge(bargainor_id: order.payment.account, sign: tenpay_sign(attrs, order.payment.key))
response.body.should_not eql 'fail'
order.reload.financial_status.to_sym.should eql :abandoned # 不能再次被修改为paid
end
@@ -10,9 +10,9 @@
message ""
name ''
payment_type_id 1 # KeyValues::PaymentType 支付宝
+ account '2398072190767748'
key UUID.generate(:compact)
- partner '2398072190767748'
- account 'mahb45@gmail.com'
+ email 'mahb45@gmail.com'
service ActiveMerchant::Billing::Integrations::Alipay::Helper::CREATE_DIRECT_PAY_BY_USER # 即时到帐
end
end
@@ -25,8 +25,8 @@
select '使用支付宝'
fill_in '合作者身份ID', with: '2398072190767748'
- fill_in '帐号', with: 'mahb45@gmail.com'
fill_in '交易安全校验码', with: '1111'
+ fill_in '帐号', with: 'mahb45@gmail.com'
select '担保交易'
click_on '保存'
end
@@ -47,7 +47,7 @@
select '使用支付宝'
click_on '保存'
end
- page.should have_content('合作者身份ID 不能为空. 帐号 不能为空. 交易安全校验码 不能为空.')
+ page.should have_content('合作者身份ID 不能为空. 交易安全校验码 不能为空. 帐号 不能为空.')
end
end
@@ -72,16 +72,16 @@
click_on '编辑'
fill_in '合作者身份ID', with: '2398072190768888'
- fill_in '帐号', with: 'mahb45@example.com'
fill_in '交易安全校验码', with: '2222'
+ fill_in '帐号', with: 'mahb45@example.com'
select '担保交易'
click_on '保存'
end
page.should have_content('修改成功!')
alipay = shop.payments.alipay
- alipay.partner.should eql '2398072190768888'
- alipay.account.should eql 'mahb45@example.com'
+ alipay.account.should eql '2398072190768888'
+ alipay.email.should eql 'mahb45@example.com'
alipay.key.should eql '2222'
visit payments_path # 回显

0 comments on commit f65edf0

Please sign in to comment.