Permalink
Browse files

config tenpay, #308.

  • Loading branch information...
1 parent 560e1a6 commit 3e3c6be8508e5a635bf249fb975052926f997142 @saberma saberma committed Feb 5, 2012
@@ -7,7 +7,8 @@ App.Views.Payment.Index = Backbone.View.extend
'submit form#new_custom_payment' : 'save'
initialize: ->
- new App.Views.Payment.Alipay model: App.payment_alipay # 支付宝
+ new App.Views.Payment.Online el: '#payment_alipay', model: App.payment_alipay # 支付宝
+ new App.Views.Payment.Online el: '#payment_tenpay', model: App.payment_tenpay # 财付通
self = this
@collection.view = this
_.bindAll this, 'render'
@@ -1,5 +1,4 @@
-App.Views.Payment.Alipay = Backbone.View.extend
- el: '#payment_alipay'
+App.Views.Payment.Online = Backbone.View.extend # 在线支付
events:
'change .gateway-id' : 'select'
@@ -25,7 +24,7 @@ App.Views.Payment.Alipay = Backbone.View.extend
edit: -> # 编辑
self = this
- template = Handlebars.compile $('#payment-alipay-form-item').html()
+ template = Handlebars.compile @$('script').html()
@$('.payment-gateway-form').html template @model.attributes
@$('.account_payment_provider form select').each -> $(this).val self.model.get($(this).attr('name')) # 显示下拉框
@$('.account_payment_provider').show()
@@ -39,7 +38,7 @@ App.Views.Payment.Alipay = Backbone.View.extend
account: self.$("input[name='account']").val(),
key: self.$("input[name='key']").val(),
service: self.$("select[name='service']").val(),
- payment_type_id: 1,
+ payment_type_id: self.$("input[name='payment_type_id']").val()
},
success: (model, resp) ->
msg '修改成功!'
@@ -5,6 +5,7 @@ class Admin::PaymentsController < Admin::AppController
expose(:shop){ current_user.shop }
expose(:payments){ shop.payments }
expose(:payment_alipay_json){ shop.payments.alipay.to_json(except: [:created_at, :updated_at], methods: [:service_name]) }
+ expose(:payment_tenpay_json){ shop.payments.tenpay.to_json(except: [:created_at, :updated_at], methods: [:service_name]) }
expose(:payment)
expose(:payment_json){ payment.to_json(except: [:created_at, :updated_at], methods: [:service_name]) }
expose(:policy_types){ KeyValues::PolicyType.all }
@@ -13,7 +14,8 @@ class Admin::PaymentsController < Admin::AppController
expose(:custom_payments){ shop.payments.where(payment_type_id: nil).all }
expose(:selected_custom_types){ custom_payments.map{|c|[c.name,c.name]} }
expose(:custom_types){ all_custom_types - selected_custom_types }
- expose(:service_types){ KeyValues::Payment::Alipay::Service.options }
+ expose(:alipay_service_types){ KeyValues::Payment::Alipay::Service.options }
+ expose(:tenpay_service_types){ KeyValues::Payment::Tenpay::Service.options }
def index
if shop.policies.empty?
View
@@ -163,6 +163,17 @@ class Service < KeyValues::Base # 支付接口
end
+ module Tenpay
+
+ class Service < KeyValues::Base # 支付接口
+ self.data = [
+ {id: 1, name: '即时到帐交易' , code: 'direct' },
+ {id: 2, name: '中价担保交易' , code: 'protect'}
+ ]
+ end
+
+ end
+
end
module Plan
View
@@ -1,6 +1,7 @@
class Payment < ActiveRecord::Base
belongs_to :shop
- validates_presence_of :partner, :account, :key, :service, if: Proc.new{|p| p.payment_type_id?}
+ 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 :name, if: Proc.new{|p| !p.payment_type_id?}
#default_scope order('created_at')
@@ -12,26 +13,42 @@ def payment_type
KeyValues::PaymentType.find(self.payment_type_id)
end
- begin 'alipay' # 支付宝
+ begin 'online' # 支付宝、财付通等
def self.alipay
where(payment_type_id: 1).first
end
+ def self.tenpay
+ where(payment_type_id: 2).first
+ end
+
def service_name # 支付接口类型
- KeyValues::Payment::Alipay::Service.find_by_code(self.service).name
+ if self.is_alipay?
+ KeyValues::Payment::Alipay::Service.find_by_code(self.service).name
+ elsif self.is_tenpay?
+ KeyValues::Payment::Tenpay::Service.find_by_code(self.service).name
+ end
end
def direct? # 即时到帐
- self.service == ActiveMerchant::Billing::Integrations::Alipay::Helper::CREATE_DIRECT_PAY_BY_USER
+ (self.is_alipay? and self.service == ActiveMerchant::Billing::Integrations::Alipay::Helper::CREATE_DIRECT_PAY_BY_USER) or (self.is_tenpay? and self.service == 'direct')
end
def escrow? # 担保交易
- self.service == ActiveMerchant::Billing::Integrations::Alipay::Helper::CREATE_PARTNER_TRADE_BY_BUYER
+ (self.is_alipay? and self.service == ActiveMerchant::Billing::Integrations::Alipay::Helper::CREATE_PARTNER_TRADE_BY_BUYER) or (self.is_tenpay? and self.service == 'protect')
end
def dualfun? # 双功能收款
- self.service == ActiveMerchant::Billing::Integrations::Alipay::Helper::TRADE_CREATE_BY_BUYER
+ (is_alipay? and self.service == ActiveMerchant::Billing::Integrations::Alipay::Helper::TRADE_CREATE_BY_BUYER)
+ end
+
+ def is_alipay?
+ self.payment_type_id == 1
+ end
+
+ def is_tenpay?
+ self.payment_type_id == 2
end
end
@@ -24,7 +24,7 @@
当前正在使用:
%strong 支付宝即时到帐服务
%span.warn=link_to w('edit'), '#', class: :payment_edit
- %dd.account_payment_provider.nsb.alipay-properties(style="display:none;border-top: 1px solid #ddd;")
+ %dd.account_payment_provider.nsb(style="display:none;border-top: 1px solid #ddd;")
%form(action="#" onsubmit="return false")
.group-fields
%table
@@ -46,20 +46,21 @@
=link_to w('cancel'), '#', class: 'cancel'
/ .group-actions
-%script(id="payment-alipay-form-item" 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") 帐号
- %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_service") 接口类型
- %p.credential
- %select#payment_alipay_service(name="service")=options_for_select service_types
+ %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") 帐号
+ %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_service") 接口类型
+ %p.credential
+ %select#payment_alipay_service(name="service")=options_for_select alipay_service_types
+ %input(name="payment_type_id" type="hidden" value="1")
@@ -0,0 +1,62 @@
+#payment_tenpay.payment-service-provider
+ %table
+ %tr
+ %td.fl(style="padding:20px 10px 20px 20px;width:225px")
+ =link_to image_tag('admin/payments/tenpay.png'), 'http://union.tenpay.com/mch/mch_register_1.shtml', title: '申请', target: '_blank'
+ %td
+ %table.desc
+ %tr
+ %td.r 支付方式:
+ %td.meta
+ %strong 在线支付-财付通
+ %tr
+ %td.r 描述:
+ %td.meta==#{link_to '财付通', 'http://www.tenpay.com'}是腾讯公司创办的在线支付平台。按交易额来算,财付通排名第二,份额为20%,仅次于支付宝。
+ %dl.cl.sst(style="padding:0px; margin-bottom: 0; border-top: 1px solid #ddd")
+ %dd.payment_select.hide(style="margin:0; padding-bottom: 10px")
+ %p.gateway-select(style="padding-top:10px; padding-left:10px")
+ %select.gateway-id(name="enabled_gateway")
+ %option(value="0") 不使用财付通
+ %option(value="1") 使用财付通
+ %dd.hide.activate_payment_provider(style="padding: 10px 10px 5px 10px")
+ .fr
+ %a.destroy(href="#")=image_tag 'admin/icons/trash.gif'
+ 当前正在使用:
+ %strong 财付通即时到帐服务
+ %span.warn=link_to w('edit'), '#', class: :payment_edit
+ %dd.account_payment_provider.nsb(style="display:none;border-top: 1px solid #ddd;")
+ %form(action="#" onsubmit="return false")
+ .group-fields
+ %table
+ %tr
+ %td.payment-gateway-form(style="vertical-align: top; padding: 20px 20px 20px 0px; width: 180px")
+ %td.provider-info
+ %div
+ %p.note
+ %strong
+ 请提供您
+ %a(href="http://www.tenpay.com" target="gateway") 财付通
+ 账户的商户号、初始密钥,若没有,则请您登陆到
+ %a(href="http://mch.tenpay.com/market/index.shtml" target="gateway") 财付通商家服务
+ 进行申请
+ / .group-fields
+ .group-actions
+ %input.btn(name="commit" type="submit" value="保存")
+ =w('or')
+ =link_to w('cancel'), '#', class: 'cancel'
+ / .group-actions
+
+ %script(type="text/x-handlebars-template")
+ .sb
+ %label(for="payment_tenpay_partner") 商户号
+ %p.credential
+ %input#payment_tenpay_partner(autocomplete="off" name="partner" size="30" type="text" value="{{partner}}")
+ .sb
+ %label(for="payment_tenpay_key") 商户密钥
+ %p.credential
+ %input#payment_tenpay_key(autocomplete="off" name="key" size="30" type="password" value="{{key}}")
+ .sb
+ %label(for="payment_tenpay_service") 接口类型
+ %p.credential
+ %select#payment_tenpay_service(name="service")=options_for_select tenpay_service_types
+ %input(name="payment_type_id" type="hidden" value="2")
@@ -10,6 +10,7 @@
=link_to '请点击这里',faq_path
.pgroup
=render 'alipay'
+ =render 'tenpay'
#custom-payment-methods.payment-service-provider
%table
%tr
@@ -86,6 +87,7 @@
App.custom_payments.refresh(#{custom_payments.to_json(except: [:created_at,:updated_at])})
App.payment_alipay = new App.Models.Payment(#{payment_alipay_json});
+ App.payment_tenpay = new App.Models.Payment(#{payment_tenpay_json});
new App.Views.Payment.Index({collection: App.custom_payments})

0 comments on commit 3e3c6be

Please sign in to comment.