我是Rails的新手,我想尝试建立一个买卖双方市场,我想在此实验中使用paypal ruby adaptive payment sdk gem.github页面提供了用于设置它的示例代码。

require 'paypal-sdk-adaptivepayments'
PayPal::SDK.configure(
  :mode      => "sandbox",  # Set "live" for production
  :app_id    => "APP-80W284485P519543T",
  :username  => "jb-us-seller_api1.paypal.com",
  :password  => "WX4WTU3S8MY44S7F",
  :signature => "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy" )

@api = PayPal::SDK::AdaptivePayments.new

# Build request object
@pay = @api.build_pay({
  :actionType => "PAY",
  :cancelUrl => "http://localhost:3000/samples/adaptive_payments/pay",
  :currencyCode => "USD",
  :feesPayer => "SENDER",
  :ipnNotificationUrl => "http://localhost:3000/samples/adaptive_payments/ipn_notify",
  :receiverList => {
    :receiver => [{
      :amount => 1.0,
      :email => "[email protected]" }] },
  :returnUrl => "http://localhost:3000/samples/adaptive_payments/pay" })

# Make API call & get response
@response = @api.pay(@pay)

# Access response
if @response.success?
  @response.payKey
  @api.payment_url(@response)  # Url to complete payment
else
  @response.error[0].message
end


我将该代码的自定义版本放在我的OrdersController,applicationController或UserController中的哪里?我只需要一点指导。

最佳答案

您可以将此代码放在订单控制器中,也可以放在包裹在类或实例方法中的订单模型中,该类或实例方法将必要的参数传递给它,这样就不会使控制器负担太多逻辑。

10-06 10:38