我看着ryan bates rails在条纹集成上施展.一切都差不多顺利到最后.我觉得他的演员有点过时了,也许条纹更新了api.我收到此错误
SubscriptionsController中的Stripe :: InvalidRequestError.
它突出显示了我的订阅模型页面,特别是客户创建部分
class Subscription < ActiveRecord::Base
belongs_to :plan
belongs_to :user
validates_presence_of :plan_id
validates_presence_of :email
attr_accessor :stripe_card_token
def save_with_payment
if valid?
customer = Stripe::Customer.create(description: email, plan: plan_id, card: stripe_card_token)
self.stripe_customer_token = customer.id
save!
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我的订阅控制器
class SubscriptionsController < ApplicationController
before_action :authenticate_user!
def new
plan = Plan.find(params[:plan_id])
@subscription = plan.subscriptions.build
@useremail = current_user.email
end
def create
@subscription = current_user.build_subscription(subscription_params)
if @subscription.save_with_payment
redirect_to @subscription, :notice => "Thank you for subscribing!"
else
render :new
end
end
def …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用 Stripe 设置我的第一个 webhook。我找到了一篇看起来像正确的方法的文章,但 2 岁了。我认为它已经过时了。
到目前为止,这是我的控制器。
class StripewebhooksController < ApplicationController
# Set your secret key: remember to change this to your live secret key in production
# See your keys here https://manage.stripe.com/account
Stripe.api_key = "mytestapikey"
require 'json'
post '/stripewebhooks' do
data = JSON.parse request.body.read, :symbolize_names => true
p data
puts "Received event with ID: #{data[:id]} Type: #{data[:type]}"
# Retrieving the event from the Stripe API guarantees its authenticity
event = Stripe::Event.retrieve(data[:id])
# This will send …Run Code Online (Sandbox Code Playgroud) 我真的一直在摸不着头脑,非常感谢帮助.我有一个商店设置,人们可以在那里上课.我有一个课程模型,订单模型和优惠券模型.以下是模型中的关联
class Course < ActiveRecord::Base
belongs_to :category
has_many :orders
has_many :coupons
end
class Order < ActiveRecord::Base
belongs_to :course
belongs_to :user
belongs_to :coupon
end
class Coupon < ActiveRecord::Base
belongs_to :course
has_many :orders
end
Run Code Online (Sandbox Code Playgroud)
我有一个非常简单的优惠券模型设置,包含代码和newprice列.我希望有人能够在新订单页面上填写优惠券表格并更新价格.
在我对新订单的看法中,我有两个表单用于新订单,一个用于优惠券.如果用户输入了正确的优惠券代码,如何检查我的控制器?如何更新要显示的优惠券价格而不是课程价格?
这是我的订单管理员
class OrdersController < ApplicationController
before_action :set_order, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!
def index
@orders = Order.all
end
def show
end
def new
course = Course.find(params[:course_id])
@course = Course.find(params[:course_id])
@order = course.orders.build
@coupon = Coupon.new
@user = current_user.id
@useremail = current_user.email
end
def discount …Run Code Online (Sandbox Code Playgroud)