Class: Trade::PaymentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Trade::PaymentsController
- Defined in:
- app/controllers/trade/payments_controller.rb
Instance Method Summary collapse
- #alipay_notify ⇒ Object
- #apple_notify ⇒ Object
- #notify ⇒ Object
- #result ⇒ Object
- #wxpay_notify ⇒ Object
Instance Method Details
#alipay_notify ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/trade/payments_controller.rb', line 5 def alipay_notify notify_params = params.permit!.except(*request.path_parameters.keys).to_h @order = Order.find_by(uuid: params[:out_trade_no]) result = nil if Alipay::Notify.verify?(notify_params) result = @order.change_to_paid! params: notify_params, payment_uuid: notify_params['trade_no'], type: 'AlipayPayment' end if result render plain: 'success' else render plain: 'failure', status: :bad_request end end |
#apple_notify ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/trade/payments_controller.rb', line 22 def apple_notify @order = Order.find_by(uuid: params[:order_uuid]) notify_params = params.permit! notify_params.merge! amount: @order.amount result = nil if ApplePay.verify? result = @order.changed_to_paid! params: notify_params, type: 'ApplePayment' end if result render json: { code: 200 } else render json: { }, status: :bad_request end end |
#notify ⇒ Object
57 58 59 |
# File 'app/controllers/trade/payments_controller.rb', line 57 def notify @notify_params = params.permit!.except(*request.path_parameters.keys).to_h end |
#result ⇒ Object
61 62 63 64 |
# File 'app/controllers/trade/payments_controller.rb', line 61 def result @order.change_to_paid! type: 'HandPayment' render json: @order.as_json(only: [:id, :amount, :received_amount, :currency, :payment_status]) end |
#wxpay_notify ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/trade/payments_controller.rb', line 39 def wxpay_notify notify_params = Hash.from_xml(request.body.read)['xml'] @order = Order.find_by(uuid: notify_params['out_trade_no']) wechat_app = WechatApp.find_by(appid: notify_params['appid']) result = nil if @order && WxPay::Sign.verify?(notify_params, key: wechat_app.key) result = @order.change_to_paid! params: notify_params, payment_uuid: notify_params['transaction_id'], type: 'WxpayPayment' end if result render xml: { return_code: 'SUCCESS' }.to_xml(root: 'xml', dasherize: false) else render xml: { return_code: 'FAIL', return_msg: '签名失败' }.to_xml(root: 'xml', dasherize: false), status: :bad_request end end |