Permissions SDK
The PayPal Permission SDK provides Ruby APIs for developers to request and obtain permissions from merchants and consumers, to execute APIs on behalf of them. The permissions include variety of operations from processing payments to accessing account transaction history.
Support
Please contact PayPal Technical Support for any live or account issues.
Installation
Add this line to your application's Gemfile:
gem 'paypal-sdk-permissions'
And then execute:
$ bundle
Or install it yourself as:
$ gem install paypal-sdk-permissions
Configuration
For Rails application:
rails g paypal:sdk:install
For other ruby application, create a configuration file(config/paypal.yml
):
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:
<<: *default
mode: live
Load Configurations from specified file:
PayPal::SDK::Core::Config.load('config/paypal.yml', ENV['RACK_ENV'] || 'development')
Example
Request permission:
require 'paypal-sdk-permissions'
PayPal::SDK.configure({
:mode => "sandbox",
:app_id => "APP-80W284485P519543T",
:username => "jb-us-seller_api1.paypal.com",
:password => "WX4WTU3S8MY44S7F",
:signature => "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy" })
@api = PayPal::SDK::Permissions::API.new
@request_permissions = @api.build_request_permissions({
:scope => ["ACCESS_BASIC_PERSONAL_DATA","ACCESS_ADVANCED_PERSONAL_DATA"],
:callback => "http://localhost:3000/samples/permissions/get_access_token" })
@response = @api.request_permissions(@request_permissions)
if @response.success?
@response.token
redirect_to @api.grant_permission_url(@response)
else
@response.error
end
class PermissionsController < ApplicationController
include PayPal::SDK::Permissions
def get_access_token
api = PayPal::SDK::Permissions::API.new
request_access_token = api.build_get_access_token(
:token => params['request_token'],
:verifier => params['verification_code']
)
access_token_response = api.get_access_token(request_access_token)
if access_token_response.success?
token = access_token_response.token
token_secret = access_token_response.token_secret
else
@error = access_token_response.error
end
end
end
Make API call with token
and token_secret
:
@api = PayPal::SDK::Permissions::API.new({
:token => "3rMSi3kCmK1Q3.BKxkH29I53R0TRLrSuCO..l8AMOAFM6cQhPTTrfQ",
:token_secret => "RuE1j8RNRlSuL5T-PSSpVWLvOlI" })
@response = @api.get_basic_personal_data({
:attributeList => {
:attribute => [ "http://axschema.org/namePerson/first" ] } })