ruby-on-rails - 在 Ruby On Rails 上使用 Express Checkout Paypal,返回空白页

标签 ruby-on-rails ruby paypal

我在我的应用程序中遇到了一些问题。 我正在关注 https://launchschool.com/blog/basic-paypal-checkout-processing-in-rails 的教程使用 Paypal 处理付款,但是当我的应用程序重定向到沙盒 paypal 时,它只显示一个空白页面。

这是我的代码

订单 Controller

def create
    @order = Order.new(order_params)
    @order.add_line_items_from_cart(@cart)
    respond_to do |format|
    if @order.save
      redirect_to @order.paypal_url(orders_path(@order))
    else
      render :new 
    end
  end

订单模型

protect_from_forgery except: [:hook]
  def hook
    params.permit! # Permit all Paypal input params
    status = params[:payment_status]
    if status == "Completed"
      @order = Order.find params[:invoice]
      @order.update_attributes notification_params: params, status: status, transaction_id: params[:txn_id], purchased_at: Time.now
    end
    render nothing: true
  end

secret .yml

development:
  secret_key_base: 0351c7e4eb70df5503d739c085d7a75dae662a55e95cf257b4a2e3edaa6985623372b7d20fc3ea59fe58d9ec94243e36a7250007ad2d9734b68cf29f90cca682
  paypal_host: https://www.sandbox.paypal.com
  app_host: http://0.0.0.0:3000

路线.rb

post "/hook" => "orders#hook"
post "/orders/:id" => "orders#show"

抱歉我的英语不好..

最佳答案

respond_to 要求你指定 Action 将响应的格式,比如

respond_to do |format|
    format.html { redirect_to .... }
end

format.any(:html, :js) { ... }

在你的情况下,你似乎不需要使用 respond_to

关于ruby-on-rails - 在 Ruby On Rails 上使用 Express Checkout Paypal,返回空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44782714/

相关文章:

ruby-on-rails - 在 devise_invitable 中覆盖邮件程序?

ruby-on-rails - ActiveRecord 未更新/保存,但显示该字段已在控制台中修改(db 另有说明)

ruby-on-rails - Rails GeoCoder,循环遍历现有数据库和 geocode_by :address, :city, :state

arrays - 将多维数组转换为散列而不覆盖值

ruby-on-rails - 改革 - 访问嵌套表单范围内的父表单参数

ruby-on-rails - Nokogiri 解析元词

javascript - 如何将 ENV 变量传递到脚本标记中

paypal - "Only single payment transaction currently supported"单笔交易

Paypal 自适应付款发票数据

javascript - 上下文结帐中的 Paypal - 防止页面重定向