Kelly
Kelly

Reputation: 469

PayPal Adaptive Payments Rails App Configuration

I'm in the middle of building my first rails app and I'm trying to integrate PayPal adaptive payments (chained) into the application. I'm terribly confused by their integration guides and I've searched google and SO to see if someone else's problem could help me figure out how to set it up but I'm more lost than when I started. I just need some basic guidance and hopefully someone at PayPal will read this and update their docs.

First, I installed this gem, https://github.com/paypal/PayPal-Ruby-SDK, which automatically installed this paypal.yml configuration file:

test: &default

  # Credentials for REST APIs
  client_id: EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
  client_secret: EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM

  # Mode can be 'live' or 'sandbox'
  mode: sandbox

  # Credentials for Classic APIs
  app_id: APP-80W284485P519543T
  username: jb-us-seller_api1.paypal.com
  password: WX4WTU3S8MY44S7F
  signature: AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy
  # # With Certificate
  # cert_path: "config/cert_key.pem"
  sandbox_email_address: [email protected]

  # # IP Address
  # ip_address: 127.0.0.1
  # # HTTP Proxy
  # http_proxy: http://proxy-ipaddress:3129/

  # verbose_logging: true

development:
  <<: *default

production:
  <<: *default
  mode: live

Question 1: Do I use these credentials or do I change them to my PayPal sandbox credentials?

Next the read.me file instructs you to load configurations from specified file:

PayPal::SDK::Core::Config.load('spec/config/paypal.yml',  ENV['RACK_ENV'] || 'development')

Or w/o the configuration file:

PayPal::SDK.configure(
  :mode => "sandbox", # "sandbox" or "live"
  :client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
  :client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM",
  :ssl_options => { } )

Question 2: Where do load these files to? I'm not sure where in the app this code goes.

Next it gives the following code to create the payment which leads to..

Question 3: Which file does this code go in? I would guess it goes in the model that has the PayPal payment button but I'm not sure.

require 'paypal-sdk-rest'
include PayPal::SDK::REST

PayPal::SDK::REST.set_config(
  :mode => "sandbox", # "sandbox" or "live"
  :client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
  :client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM")

# Build Payment object
@payment = Payment.new({
  :intent => "sale",
  :payer => {
    :payment_method => "credit_card",
    :funding_instruments => [{
      :credit_card => {
        :type => "visa",
        :number => "4417119669820331",
        :expire_month => "11",
        :expire_year => "2018",
        :cvv2 => "874",
        :first_name => "Joe",
        :last_name => "Shopper",
        :billing_address => {
          :line1 => "52 N Main ST",
          :city => "Johnstown",
          :state => "OH",
          :postal_code => "43210",
          :country_code => "US" }}}]},
  :transactions => [{
    :item_list => {
      :items => [{
        :name => "item",
        :sku => "item",
        :price => "1",
        :currency => "USD",
        :quantity => 1 }]},
    :amount => {
      :total => "1.00",
      :currency => "USD" },
    :description => "This is the payment transaction description." }]})

# Create Payment and return the status(true or false)
if @payment.create
  @payment.id     # Payment Id
else
  @payment.error  # Error Hash
end

Can anyone give me some basic guidance or advice? I've also found integration documentation from PayPal that doesn't mention the PayPal Ruby Gem at all so I'm wondering if it was a mistake to install it. Thank you for your time.

Upvotes: 1

Views: 1191

Answers (1)

PYPL_ORCN
PYPL_ORCN

Reputation: 91

Please note that our REST API doesn't have Adaptive payments functionality yet so you need to use the Adaptive Payments SDK for Ruby, which can be downloaded from here https://github.com/paypal/adaptivepayments-sdk-ruby

Question 1: Do I use these credentials or do I change them to my PayPal sandbox credentials?

You need to use your Sandbox account API credentials. You can view your Sandbox account API details on https://developer.paypal.com/webapps/developer/applications/accounts (Please login with your live PayPal account and you'll see a list of your Sandbox accounts. Click on the Sandbox account you would like to use, then click "Profile" and you'll see your API credentials under the "API Credentials" tab. You can use the app ID APP-80W284485P519543T in Sandbox. With Adaptive Payments, you need your API username, API password, API signature and app ID.

Question 2: Where do load these files to? I'm not sure where in the app this code goes.

I would suggest checking our samples on https://github.com/paypal/adaptivepayments-sdk-ruby/tree/master/samples

Question 3: Which file does this code go in? I would guess it goes in the model that has the PayPal payment button but I'm not sure.

The code you provided is for REST API only. For Adaptive Payments, please download the correct SDK I mentioned in answer 1 and have a look at the samples.

Upvotes: 1

Related Questions