Am new to rails and I want to experiment with building a buyer and seller marketplace I want to use the paypal ruby adaptive payment sdk gem for this experiment.The github page gives and example code to use for setting it up.
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 => "platfo_1255612361_per@gmail.com" }] },
: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
Where would I put my customized version of this code in would it be in my OrdersController, applicationController or the UserController? I Just need a bit of guidance please.
您可以将此代码放在订单控制器中,也可以放在包含在类或实例方法中的订单模型中,并将必要的参数传递给它,这样可以使控制器不会充满逻辑。
In the spirit of keeping your code more readable, you could place the above code in a class in a rails helper or lib folder and invoke the methods from there.
Though it's a pretty late answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.