How can I use Paypal Adaptive Payments SDK?

I am new to rails and I want to experiment with building a market for buyers and sellers. I want to use paypal ruby adaptive payment sdk gem for this experiment. The github page also provides sample code 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, be it in my OrdersController, applicationController or UserController? I just need some advice.

+3
source share
2 answers

, , , , .

0

, , rails lib .

.

0

All Articles