
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
paypal-sdk-rest-pmrb
Advanced tools
The PayPal REST SDK provides Ruby APIs to create, process and manage payment.
PayPal has deprecated their REST SDK and archived the corresponding GitHub repos. The Payments API v1/payments remains active but merchants are left to maintain their own integration until equivalent v2/payments functionality becomes available. Lenny Markus at PayPal has confirmed there are no plans to continue support, feel free to fork it.
We recommend that you integrate with API v2/checkout/orders and v2/payments whenever possible. Please refer to the Checkout Ruby SDK to continue with the integration.
Add this line to your application's Gemfile:
gem 'paypal-sdk-rest-pmrb'
And then execute:
$ bundle
For Rails application:
rails g paypal:sdk:install
For other ruby application, create a configuration file(config/paypal.yml
):
development: &default
mode: sandbox
client_id: EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
client_secret: EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
# # with Proxy
# http_proxy: http://proxy-ipaddress:3129/
# # with CA File
# ssl_options:
# ca_file: config/cacert.pem
# # Override Endpoint
# rest_endpoint: https://api.sandbox.paypal.com
test:
<<: *default
production:
mode: live
client_id: CLIENT_ID
client_secret: CLIENT_SECRET
Load Configurations from specified file:
PayPal::SDK::Core::Config.load('spec/config/paypal.yml', ENV['RACK_ENV'] || 'development')
Without configuration file:
PayPal::SDK.configure(
:mode => "sandbox", # "sandbox" or "live"
:client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
:client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM",
:ssl_options => { } )
Logger configuration:
PayPal::SDK.logger = Logger.new(STDERR)
# change log level to INFO
PayPal::SDK.logger.level = Logger::INFO
NOTE: At DEBUG
level, all requests/responses are logged except when mode
is set to live
. In order to disable request/response printing, set the log level to INFO
or less verbose ones.
require 'paypal-sdk-rest'
# 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
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 => "paypal" },
:redirect_urls => {
:return_url => "http://localhost:3000/payment/execute",
:cancel_url => "http://localhost:3000/" },
:transactions => [{
:item_list => {
:items => [{
:name => "item",
:sku => "item",
:price => "5",
:currency => "USD",
:quantity => 1 }]},
:amount => {
:total => "5",
:currency => "USD" },
:description => "This is the payment transaction description." }]})
if @payment.create
@payment.id # Payment Id
else
@payment.error # Error Hash
end
# Fetch Payment
payment = Payment.find("PAY-57363176S1057143SKE2HO3A")
# Get List of Payments
payment_history = Payment.all( :count => 10 )
payment_history.payments
payment = Payment.find("PAY-57363176S1057143SKE2HO3A")
if payment.execute( :payer_id => "DUFRQ8GWYMJXC" )
# Success Message
# Note that you'll need to `Payment.find` the payment again to access user info like shipping address
else
payment.error # Error Hash
end
Future Payments sample is available here
See webhook event validation code sample and webhook event validation docs
# 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 authorize URL to Get Authorize code
puts Tokeninfo.authorize_url( :scope => "openid profile" )
# Create tokeninfo by using Authorize Code from redirect_uri
tokeninfo = Tokeninfo.create("Replace with Authorize Code received on redirect_uri")
# Refresh tokeninfo object
tokeninfo.refresh
# Create tokeninfo by using refresh token
tokeninfo = Tokeninfo.refresh("Replace with refresh_token")
# Get Userinfo
userinfo = tokeninfo.userinfo
# Get Userinfo by using access token
userinfo = Userinfo.get("Replace with access_token")
# Get logout url
logout_url = tokeninfo.logout_url
To make Payouts, you should enable this option in your account at http://developer.paypal.com.
@payout = Payout.new(
{
:sender_batch_header => {
:sender_batch_id => SecureRandom.hex(8),
:email_subject => 'You have a Payout!',
},
:items => [
{
:recipient_type => 'EMAIL',
:amount => {
:value => '1.0',
:currency => 'USD'
},
:note => 'Thanks for your patronage!',
:receiver => 'shirt-supplier-one@mail.com',
:sender_item_id => "2014031400023",
}
]
}
)
begin
@payout_batch = @payout.create
logger.info "Created Payout with [#{@payout_batch.batch_header.payout_batch_id}]"
rescue ResourceNotFound => err
logger.error @payout.error.inspect
end
Code released under SDK LICENSE
Pull requests and new issues are welcome. See CONTRIBUTING.md for details.
FAQs
Unknown package
We found that paypal-sdk-rest-pmrb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.