[英]How can I use the Paypal Adaptive Payments SDK?
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. 我是rails的新手,我想尝试建立一个买家和卖家市场我想在这个实验中使用paypal ruby自适应支付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 => "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? 我在哪里可以将我的自定义版本的代码放在我的OrdersController,applicationController或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. 本着保持代码更易读的精神,您可以将上面的代码放在rails helper或lib文件夹中的类中,并从那里调用方法。
Though it's a pretty late answer. 虽然这是一个很晚的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.