How to integrate PayPal with Ruby on Rails

1. Gem file-ndaa uuniig nem
gem 'paypal-sdk-rest'
 
2. bundle install
 
3. rails g paypal:sdk:install 
Daraahi 2 file nemegdene:
      create  config/paypal.yml
      create  config/initializers/paypal.rb
4. config/paypal.yml neej uzvel, iimerhuu um baih buguud clien_id, client_secret-iig uuriim paypal
 business account ruugaa login hiij orood  MyApps -> Create Apps tohiruulj credentialsaa avna.
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: Platform.sdk.seller@gmail.com

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

development:
  <<: *default

production:
  <<: *default
  mode: live
 

6. Erunhiiduu ingeed boloo, hurdan turshij uzey gevel turshilt.rb file uusgeed dotor n:

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 => "4567516310777851",
        :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
 
7. ruby turshilt.rb gej ajiluulj uzeerei
 
Delgerenguid https://github.com/paypal/PayPal-Ruby-SDK 
https://devtools-paypal.com/guide/expresscheckout/ruby?env=sandbox 

Comments