Skip to content

Latest commit

 

History

History
114 lines (85 loc) · 2.57 KB

DEV.md

File metadata and controls

114 lines (85 loc) · 2.57 KB

Installation

Add this line to your application's Gemfile:

gem 'paypal-sdk-core', :git => "https://github.com/paypal/sdk-core-ruby.git"

Or install it yourself as:

$ gem install paypal-sdk-core

Configuration

To generate configuration in Rails application:

rails g paypal:sdk:install

The Core library will try to load the configuration from default location config/paypal.yml and environment development

Example configuration:

development: &default
  username: jb-us-seller_api1.paypal.com
  password: WX4WTU3S8MY44S7F
  signature: AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy
  app_id: APP-80W284485P519543T
  http_timeout: 30
  mode: sandbox
test:
  <<: *default
production:
  mode: live
  ...

Load Configurations from specified file:

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

Logger configuration:

PayPal::SDK.logger = Logger.new(STDERR)

Usage API services

# To make Merchant API call
client   = PayPal::SDK::Core::API::Merchant.new
response = client.request("TransactionSearch", {
    "StartDate" => "2012-09-30T00:00:00+0530", "EndDate" => "2012-10-01T00:00:00+0530" })
if response["Ack"] == "Success"
  # ...
end

# To make Platform API call
client    = PayPal::SDK::Core::API::Platform.new("AdaptivePayments")
response  = client.request("ConvertCurrency", {
    "baseAmountList"        => { "currency" => [ { "code" => "USD", "amount" => "2.0"} ]},
    "convertToCurrencyList" => { "currencyCode" => ["GBP"] } })
if response["responseEnvelope"]["ack"] == "Success"
  # ...
end

# To Verify IPN message
PayPal::SDK::Core::IPN.verify?(request.raw_post) # return true or false

OpenIDConnect Samples

require 'paypal-sdk-core'

# Update client_id, client_secret and redirect_uri
PayPal::SDK.configure({
  :openid_client_id     => "client_id",
  :openid_client_secret => "client_secret",
  :openid_redirect_uri  => "http://google.com"
})
include PayPal::SDK::OpenIDConnect

# Generate URL to Get Authorize code
puts Tokeninfo.authorize_url( :scope => "openid profile" )

# Create tokeninfo by using AuthorizeCode from redirect_uri
tokeninfo = Tokeninfo.create("Replace with Authorize Code received on redirect_uri")
puts tokeninfo.to_hash

# Refresh tokeninfo object
tokeninfo = tokeninfo.refresh
puts tokeninfo.to_hash

# Create tokeninfo by using refresh token
tokeninfo = Tokeninfo.refresh("Replace with refresh_token")
puts tokeninfo.to_hash

# Get Userinfo
userinfo = tokeninfo.userinfo
puts userinfo.to_hash

# Get logout url
put tokeninfo.logout_url