任何人都可以提供的任何帮助将不胜感激。
我正在尝试使用 PayPal 在成功付款时返回的 payKey 作为变量?这样我就可以使用 if else 语句将某物标记为已付款或未付款;告诉应用程序显示立即付款或下载选项...这是我的贝宝 lib 文件,其中定义了付费方法的模型和使用付费方法的控制器:
lib/pay_pal_api.rb
require "pp-adaptive"
class PayPalAPI
def self.payment_url(submission)
amount = submission.amount_in_cents.to_f / 100.0
recipient_cut = amount * 0.9
recipient_email = submission.submitter.paypal_email
client.execute(:Pay,
:action_type => "PAY",
:currency_code => "USD",
:cancel_url => "http://session-logix.herokuapp.com/my-studio",
:return_url => "http://session-logix.herokuapp.com/submissions/#{submission.id}",
:feesPayer => "PRIMARYRECEIVER",
:receivers => [
{ :email => "barrypas37@gmail.com", :amount => amount, :primary => true },
{ :email => recipient_email, :amount => recipient_cut, :primary => false }
]
) do |response|
if response.success?
puts "Pay key: #{response.pay_key}"
# send the user to PayPal to make the payment
# e.g. https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=abc
return client.payment_url(response)
else
puts "#{response.ack_code}: #{response.error_message}"
end
end
return nil
end
模型/提交.rb
class Submission < ActiveRecord::Base
belongs_to :submitter, :class_name => "User"
belongs_to :project
def price
sprintf "%.2f", (self.amount_in_cents.to_f/100.0)
end
def price=(val)
self.amount_in_cents = (val.to_f*100.0).to_i
end
def paid?
!!self.$payKey
end
end
提交控制器
def pay
@submission = Submission.find(params[:id])
if @submission.project.user_id == current_user.id
if !@submission.paid?
redirect_to PayPalAPI.payment_url(@submission)
return
end
flash[:notice] = "You have already paid for this submission"
else
flash[:error] = "You are not authorized to view this page"
end
end