Paypal
Another ruby wrapper for Paypal
Install / Use
/learn @dwilkie/PaypalREADME
paypal
A simple ruby wrapper for paypal.
Features
Currently paypal supports the following:
- Verifying Paypal IPN's
- MassPay Requests
- Permissions Service
- Authentication Service
Configuration
Paypal.setup do |config|
config.environment = "sandbox" # replace with "live" in production
config.api_username = "Replace me with your api username"
config.api_password = "Replace me with your api password"
config.api_signature = "Replace me with your api signature"
end
Usage
IPN Modules
Paypal::Ipn
class PaypalIpn
include Paypal::Ipn
attr_accessor :params
end
Note: Your class must respond to params and return a hash of paypal ipn parameters
Public methods
payment_completed?payment_statustxn_id
Private methods
verifyVerifies the IPN with paypal and returns true or falsereceiver_emailself.txn_type(params)self.masspay_transaction?(params)
Paypal::Ipn::Buyer
class BuyerPaypalIpn
include Paypal::Ipn::Buyer
attr_accessor :params
end
Public methods
customer_addressConvienence method. e.g. John Smith, 5 Some Street, Some City, Some State, Australia 1234customer_address_namecustomer_address_streetcustomer_address_citycustomer_address_statecustomer_address_zipcustomer_address_country
Paypal::Ipn::Item
class ItemPaypalIpn
include Paypal::Ipn::Item
attr_accessor :params
end
Public methods
item_name(index = nil)If index is supplied it will return item_name#index otherwise simply item_nameitem_number(index = nil)item_quantity(index = nil)number_of_cart_items
Paypal::Ipn::Masspay
class MasspayPaypalIpn
include Paypal::Ipn::Masspay
attr_accessor :params
end
Note: Currently Masspay IPN's only support a single transaction
Public methods
payment_statusReturns the payment status for the 1st transactiontxn_idReturns the transaction id for the 1st transactionpayment_unclaimed?Returns whether the payment status for the 1st transaction was unclaimed or not
Private methods
unique_idReturns the unique_id for the 1st transaction
Masspay
class Masspay
include Paypal::Masspay
attr_accessor :payment_response
end
Note: Your class must respond to payment_response and return the payment response as a hash
Public methods
successful_payment?Returns whether the masspay request was successful or not. Note: This only tells you if the request was successful or not. You should wait for an IPN to verify the receiver has been paid.
Private methods
-
masspay(payer_email, receiver_email, amount, currency, note, unique_id)Sends a mass pay request from payer_email to receiver_email for amount in currency. The note will appear on the receivers paypal account and the unique_id will be passed back in the Paypal IPN. Returns the response from paypal. -
payment_error_typeReturns :unauthorized or :insufficient_funds for these types of errors otherwise returns :unknown -
payment_error_messageReturns the paypal long error message
Note: Currently Masspay payments only support a single recipient
Permissions Service
class Permissions
include Paypal::Permissions
end
Usage
-
Make a call to
set_paypal_permissions_urlsetting the return_url to your application's callback url and with your required_permissions -
Redirect the user to that url
-
When Paypal redirects the user back to your application at return_url make a call to
get_paypal_permissionswith the token parameter
See below for further details:
Private methods
set_paypal_permissions_url(return_url, required_permissions = {})
Returns a url where the user can sign in to Paypal and authorize the requested permissions. Paypal will then redirect the user to the return_url. Specify required_permissions by supplying a hash in the following format:
{
:mass_pay => true,
:refund_transaction => true,
:get_transaction_details => true
}
First name, Last name and email are always required permissions so you never have to specify these manually.
get_paypal_permissions(token)
Returns a hash of user information and permission details for the given token in the following format:
{
:email => "joe@example.com",
:first_name => "Joe",
:last_name => "Bloggs",
:payer_id => "VK7XZU4BDY79",
:permissions => {
:mass_pay => true,
:refund_transaction => true,
:get_transaction_details => true
}
}
Installation
gem install paypal-ipn
Rails
Place the following in your Gemfile:
gem 'paypal-ipn', :require => 'paypal'
To generate a stub initializer under config/initializers run:
rails g paypal:initializer
Copyright (c) 2010 David Wilkie, released under the MIT license
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
