add wechat pay support

dev_trainings
p31729568 6 years ago
parent d8e3214a16
commit e8f40b9430

@ -13,6 +13,20 @@ class TrainingsController < ApplicationController
before_filter :check_training_type, only: [:enroll] before_filter :check_training_type, only: [:enroll]
before_filter :check_current_training, only: [:show, :update, :pay, :pay_js, :update_payinfo, :result] before_filter :check_current_training, only: [:show, :update, :pay, :pay_js, :update_payinfo, :result]
# TODO: 测试完成后删除
ALLOW_OPENID_LIST = [
'o5fSc08-NDxC2564k9USCuiuC9cY',
'o5fSc097mQbwhYVLK9DAIa3uz_ug',
'o5fSc0607iR3rp4-h_VnuBTp8CiM',
'o5fSc0-nX6bUGQNQt3FrRhUKVNIw',
'o5fSc0607iR3rp4-h_VnuBTp8CiM'
]
before_filter :check_openid, only: [:update_payinfo]
def check_openid
return if ALLOW_OPENID_LIST.include?(session[:wechat_open_id])
render plain: '暂未开放'
end
layout 'base_trainings' layout 'base_trainings'
def show def show
@ -23,6 +37,9 @@ class TrainingsController < ApplicationController
return return
end end
# TODO: 测试完成后删除
@test_wxpay = ALLOW_OPENID_LIST.include?(session[:wechat_open_id])
render 'trainingsInfo' render 'trainingsInfo'
end end
@ -43,6 +60,9 @@ class TrainingsController < ApplicationController
@training.training_payinfo.fee = @training.registration_fee @training.training_payinfo.fee = @training.registration_fee
@training.training_payinfo.pay_type = params[:pay_type].presence || 3 @training.training_payinfo.pay_type = params[:pay_type].presence || 3
end end
# TODO: 测试完成后删除
@test_wxpay = ALLOW_OPENID_LIST.include?(session[:wechat_open_id])
end end
def pay_callback def pay_callback
@ -148,9 +168,13 @@ class TrainingsController < ApplicationController
training_info.save! training_info.save!
# TODO: 测试完成后删除
@test_wxpay = ALLOW_OPENID_LIST.include?(session[:wechat_open_id])
if params[:js] == 'true' && training_info.not_payed? if params[:js] == 'true' && training_info.not_payed?
Rails.logger.info("### start wechat pay => fee: #{training_info.fee}") Rails.logger.info("### start wechat pay => fee: #{training_info.fee}")
_pay_js(training_info.fee) # TODO: 测试完成后删除
_pay_js(@test_wxpay ? 0.01 : training_info.fee)
else else
redirect_to result_training_path(id: friendly_id) redirect_to result_training_path(id: friendly_id)
end end

@ -1,5 +1,5 @@
<% disabled ||= false %> <% disabled ||= false %>
<div id="sendPhoto" class="<%= training.training_payinfo.pay_type.to_i == 3 ? "" : "none" %>" style="padding-bottom: 10px;"> <div id="sendPhoto" style="padding-bottom: 10px;">
<div class="weui-uploader__bd"> <div class="weui-uploader__bd">
<% if training.training_payinfo.attachment_url.present? %> <% if training.training_payinfo.attachment_url.present? %>
<li id="uploaderFiles" class="weui-uploader__file" <li id="uploaderFiles" class="weui-uploader__file"

@ -2,16 +2,21 @@
<div style="padding-top: 10px"> <div style="padding-top: 10px">
<%= hidden_field_tag(:friendly_id, @friendly_id) %> <%= hidden_field_tag(:friendly_id, @friendly_id) %>
<!-- <div class="showPanel" id="payTypeLine" NavShow>--> <% if @test_wxpay %>
<div class="showPanel" id="payTypeLine" NavShow>
<% else %>
<div class="showPanel" id="payTypeLine"> <div class="showPanel" id="payTypeLine">
<!-- <p class="clearfix pr">--> <% end %>
<!-- <label>支付方式</label>--> <p class="clearfix pr">
<!-- <span class="mr5" style="margin-right: 24px;" id="payTypeName"><%#= @training.training_payinfo.pay_type.to_i == 3 ? "线下支付" : "微信支付" %></span>--> <label>支付方式</label>
<!-- <span class="mr5" style="margin-right: 24px;">线下支付</span>--> <% if @test_wxpay %>
<!-- <i class="iconfont icon-gengduo1 rightArrow" style="color: #323232;right: 4px"></i>--> <span class="mr5" style="margin-right: 24px;" id="payTypeName"><%= @training.training_payinfo.pay_type.to_i == 3 ? "线下支付" : "微信支付" %></span>
<!-- </p>--> <% else %>
<!-- <div class="<%#= @training.training_payinfo.pay_type.to_i == 3 ? "" : "none" %> mt5" id="payInfos">--> <span class="mr5" style="margin-right: 24px;">线下支付</span>
<div class="mt5" id="payInfos"> <% end %>
<i class="iconfont icon-gengduo1 rightArrow" style="color: #323232;right: 4px"></i>
</p>
<div class="<%= @training.training_payinfo.pay_type.to_i == 3 ? "" : "none" %> mt5" id="payInfos">
<div class="payInfo df"> <div class="payInfo df">
<span class="fl accountIcon"> <span class="fl accountIcon">
<i class="iconfont icon-yinhangqia blue"></i> <i class="iconfont icon-yinhangqia blue"></i>
@ -60,10 +65,13 @@
<div class="infoBar mb10"> <div class="infoBar mb10">
<p>备注</p> <p>备注</p>
<textarea class="remarkAccount" name="info" id="info" placeholder="请您在此输入您的留言"><%= @training.training_payinfo.info %></textarea> <textarea class="remarkAccount" name="info" id="info" placeholder="请您在此输入您的留言"><%= @training.training_payinfo.info %></textarea>
</div>
<div class="infoBar mb10 pay-image <%= @training.training_payinfo.pay_type.to_i == 3 ? "" : "none" %>">
<p>上传转账凭证</p> <p>上传转账凭证</p>
<!--图片上传--> <!--图片上传-->
<%= render :partial => 'upload_img', :locals => {:training => @training} %> <%= render :partial => 'upload_img', :locals => {:training => @training} %>
</div> </div>
<div class="infoBar mb10"> <div class="infoBar mb10">
<p>费用明细 <p>费用明细
<% if @training.training_type == 3 %> <% if @training.training_type == 3 %>
@ -196,7 +204,7 @@
}) })
//立即支付 //立即支付
$('#payBtn').on('click', function () { $('#payBtn').on('click', function () {
if(!checkBillInfo()){ return } if(!checkBillInfo()){ return }
var postData = $('form').serialize(); var postData = $('form').serialize();
postData += '&js=true' postData += '&js=true'
@ -228,7 +236,7 @@
// 使用以上方式判断前端返回,微信团队郑重提示: // 使用以上方式判断前端返回,微信团队郑重提示:
//res.err_msg将在用户支付成功后返回ok但并不保证它绝对可靠。 //res.err_msg将在用户支付成功后返回ok但并不保证它绝对可靠。
setTimeout(function () { setTimeout(function () {
window.location.href = "/trainings/<%= @tag_id %>/result"; window.location.href = "/trainings/<%= @friendly_id %>/result";
}, 500); }, 500);
} else if (res.err_msg == 'get_brand_wcpay_request:cancel') { } else if (res.err_msg == 'get_brand_wcpay_request:cancel') {
@ -358,14 +366,14 @@
$("#payTypeName").html($(this).html().trim()); $("#payTypeName").html($(this).html().trim());
console.log($(this).index()); console.log($(this).index());
if ($(this).index() == 0) { //微信支付 if ($(this).index() == 0) { //微信支付
$("#payInfos,#sendPhoto").addClass("none"); $("#payInfos,.pay-image").addClass("none");
//切换显示按钮 //切换显示按钮
$("#offlinePaySubmitBtn").addClass("none"); $("#offlinePaySubmitBtn").addClass("none");
$("#paySubmitBtn").removeClass("none"); $("#paySubmitBtn").removeClass("none");
$('#pay_type').val("1"); $('#pay_type').val("1");
} else { //线下支付 } else { //线下支付
$("#payInfos,#sendPhoto").removeClass("none"); $("#payInfos,.pay-image").removeClass("none");
//切换显示按钮 //切换显示按钮
$("#offlinePaySubmitBtn").removeClass("none"); $("#offlinePaySubmitBtn").removeClass("none");
$("#paySubmitBtn").addClass("none"); $("#paySubmitBtn").addClass("none");

@ -41,8 +41,12 @@
<% if @training.training_payinfo.blank? || @training.training_payinfo.not_payed? %> <% if @training.training_payinfo.blank? || @training.training_payinfo.not_payed? %>
<div class="bottomBtn"> <div class="bottomBtn">
<%= link_to '转账支付', pay_training_path(id: @friendly_id, pay_type: 3), class: 'leftbtn' %> <%= link_to '转账支付', pay_training_path(id: @friendly_id, pay_type: 3), class: 'leftbtn' %>
<%#= link_to '微信支付', pay_training_path(id: @friendly_id, pay_type: 1), class: 'rightbtn' %> <!-- TODO:: 测试微信支付,待删除 -->
<a href="javascript:void(0)" onclick="alert('即将开通');" class="rightbtn">微信支付</a> <% if @test_wxpay %>
<%= link_to '微信支付', pay_training_path(id: @friendly_id, pay_type: 1), class: 'rightbtn' %>
<% else %>
<a href="javascript:void(0)" onclick="alert('即将开通');" class="rightbtn">微信支付</a>
<% end %>
</div> </div>
<% else %> <% else %>
<div class="bottomBtn"> <div class="bottomBtn">

@ -203,7 +203,7 @@ input[type='text'].right_input{
line-height: 20px;margin-top: 3px; line-height: 20px;margin-top: 3px;
} }
.remarkAccount{ .remarkAccount{
width: 100%;resize: none;height: 80px;border: 1px solid #eee;padding: 5px;box-sizing: border-box; width: 100%;resize: none;height: 80px;border: 1px solid #eee;padding: 5px;box-sizing: border-box;margin-bottom: 1rem;
} }
.moneyDetail{ .moneyDetail{
line-height: 20px;color: #4B4B4B; line-height: 20px;color: #4B4B4B;

Loading…
Cancel
Save