Module: ActiveMerchant::Billing::PaypalCommonAPI
- Includes:
- Empty
- Included in:
- PaypalExpressGateway, PaypalGateway
- Defined in:
- lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb
Overview
This module is included in both PaypalGateway and PaypalExpressGateway
Constant Summary collapse
- API_VERSION =
'72'
- URLS =
{ :test => { :certificate => 'https://api.sandbox.paypal.com/2.0/', :signature => 'https://api-3t.sandbox.paypal.com/2.0/' }, :live => { :certificate => 'https://api.paypal.com/2.0/', :signature => 'https://api-3t.paypal.com/2.0/' } }
- PAYPAL_NAMESPACE =
'urn:ebay:api:PayPalAPI'
- EBAY_NAMESPACE =
'urn:ebay:apis:eBLBaseComponents'
- ENVELOPE_NAMESPACES =
{ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns:env' => 'http://schemas.xmlsoap.org/soap/envelope/', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' }
- CREDENTIALS_NAMESPACES =
{ 'xmlns' => PAYPAL_NAMESPACE, 'xmlns:n1' => EBAY_NAMESPACE, 'env:mustUnderstand' => '0' }
- AUSTRALIAN_STATES =
{ 'ACT' => 'Australian Capital Territory', 'NSW' => 'New South Wales', 'NT' => 'Northern Territory', 'QLD' => 'Queensland', 'SA' => 'South Australia', 'TAS' => 'Tasmania', 'VIC' => 'Victoria', 'WA' => 'Western Australia' }
- SUCCESS_CODES =
[ 'Success', 'SuccessWithWarning' ]
- FRAUD_REVIEW_CODE =
"11610"
Class Method Summary collapse
Instance Method Summary collapse
-
#authorize_transaction(transaction_id, money, options = {}) ⇒ Object
DoAuthorization takes the transaction_id returned when you call DoExpressCheckoutPayment with a PaymentAction of ‘Order’.
-
#balance(return_all_currencies = false) ⇒ Object
Parameters: *
:return_all_currencies
– Either ‘1’ or ‘0’ 0 – Return only the balance for the primary currency holding. - #capture(money, authorization, options = {}) ⇒ Object
- #credit(money, identification, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Object
The gateway must be configured with either your PayPal PEM file or your PayPal API Signature.
-
#manage_pending_transaction(transaction_id, action) ⇒ Object
The ManagePendingTransactionStatus API operation accepts or denies a pending transaction held by Fraud Management Filters.
- #reauthorize(money, authorization, options = {}) ⇒ Object
-
#reference_transaction(money, options = {}) ⇒ Object
For full documentation see Paypal API Reference: ==== Parameter: *
:money
– (Required) The amount of this new transaction, required fo the payment details portion of this request. -
#refund(money, identification, options = {}) ⇒ Object
Refunds a transaction.
- #transaction_details(transaction_id) ⇒ Object
-
#transaction_search(options) ⇒ Object
For full documentation see PayPal API Reference ==== Options: *
:payer
– (Optional) Search by the buyer’s email address. -
#transfer(*args) ⇒ Object
Transfer money to one or more recipients.
- #void(authorization, options = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 43 def self.included(base) base.default_currency = 'USD' base.cattr_accessor :pem_file base.cattr_accessor :signature base.live_url = URLS[:live][:signature] base.test_url = URLS[:test][:signature] end |
Instance Method Details
#authorize_transaction(transaction_id, money, options = {}) ⇒ Object
DoAuthorization takes the transaction_id returned when you call DoExpressCheckoutPayment with a PaymentAction of ‘Order’. When you did that, you created an order authorization subject to settlement with PayPal DoAuthorization and DoCapture
Parameters:
-
:transaction_id
– The ID returned by DoExpressCheckoutPayment with a PaymentAction of ‘Order’. -
:money
– The amount of money to be authorized for this purchase.
243 244 245 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 243 def (transaction_id, money, = {}) commit 'DoAuthorization', (transaction_id, money, ) end |
#balance(return_all_currencies = false) ⇒ Object
Parameters:
-
:return_all_currencies
– Either ‘1’ or ‘0’0 – Return only the balance for the primary currency holding. 1 – Return the balance for each currency holding.
225 226 227 228 229 230 231 232 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 225 def balance(return_all_currencies = false) clean_currency_argument = case return_all_currencies when 1, '1' , true; '1' else '0' end commit 'GetBalance', build_get_balance(clean_currency_argument) end |
#capture(money, authorization, options = {}) ⇒ Object
88 89 90 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 88 def capture(money, , = {}) commit 'DoCapture', build_capture_request(money, , ) end |
#credit(money, identification, options = {}) ⇒ Object
126 127 128 129 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 126 def credit(money, identification, = {}) ActiveMerchant.deprecated Gateway::CREDIT_DEPRECATION_MESSAGE refund(money, identification, ) end |
#initialize(options = {}) ⇒ Object
The gateway must be configured with either your PayPal PEM file or your PayPal API Signature. Only one is required.
:pem
The text of your PayPal PEM file. Note
this is not the path to file, but its
contents. If you are only using one PEM
file on your site you can declare it
globally and then you won't need to
include this option
:signature
The text of your PayPal signature.
If you are only using one API Signature
on your site you can declare it
globally and then you won't need to
include this option
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 66 def initialize( = {}) requires!(, :login, :password) headers = {'X-PP-AUTHORIZATION' => .delete(:auth_signature), 'X-PAYPAL-MESSAGE-PROTOCOL' => 'SOAP11'} if [:auth_signature] = { :pem => pem_file, :signature => signature, :headers => headers || {} }.update() if [:pem].blank? && [:signature].blank? raise ArgumentError, "An API Certificate or API Signature is required to make requests to PayPal" end super() end |
#manage_pending_transaction(transaction_id, action) ⇒ Object
The ManagePendingTransactionStatus API operation accepts or denies a pending transaction held by Fraud Management Filters.
Parameters:
-
:transaction_id
– The ID of the transaction held by Fraud Management Filters. -
:action
– Either ‘Accept’ or ‘Deny’
254 255 256 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 254 def manage_pending_transaction(transaction_id, action) commit 'ManagePendingTransactionStatus', build_manage_pending_transaction_status(transaction_id, action) end |
#reauthorize(money, authorization, options = {}) ⇒ Object
84 85 86 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 84 def (money, , = {}) commit 'DoReauthorization', (money, , ) end |
#reference_transaction(money, options = {}) ⇒ Object
For full documentation see Paypal API Reference:
Parameter:
-
:money
– (Required) The amount of this new transaction,
required fo the payment details portion of this request
Options:
-
:reference_id
– (Required) A transaction ID from a previous purchase, such as a credit card charge using the DoDirectPayment API, or a billing agreement ID. -
:payment_action
– (Optional) How you want to obtain payment. It is one of the following values:Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture. Sale – This is a final sale for which you are requesting payment.
-
:ip_address
– (Optional) IP address of the buyer’s browser.
Note: PayPal records this IP addresses as a means to detect possible fraud.
-
:req_confirm_shipping
– Whether you require that the buyer’s shipping address on file with PayPal be a confirmed address. You must have permission from PayPal to not require a confirmed address. It is one of the following values:0 – You do not require that the buyer’s shipping address be a confirmed address. 1 – You require that the buyer’s shipping address be a confirmed address.
-
:merchant_session_id
– (Optional) Your buyer session identification token. -
:return_fmf_details
– (Optional) Flag to indicate whether you want the results returned by Fraud Management Filters. By default, you do not receive this information. It is one of the following values:0 – Do not receive FMF details (default) 1 – Receive FMF details
-
:soft_descriptor
– (Optional) Per transaction description of the payment that is passed to the consumer’s credit card statement. If the API request provides a value for the soft descriptor field, the full descriptor displayed on the buyer’s statement has the following format:<PP * | PAYPAL *><Merchant descriptor as set in the Payment Receiving Preferences><1 space><soft descriptor> The soft descriptor can contain only the following characters: Alphanumeric characters - (dash) * (asterisk) . (period) {space}
167 168 169 170 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 167 def reference_transaction(money, = {}) requires!(, :reference_id) commit 'DoReferenceTransaction', build_reference_transaction_request(money, ) end |
#refund(money, identification, options = {}) ⇒ Object
Refunds a transaction.
For a full refund pass nil for the amount:
gateway.refund nil, 'G39883289DH238'
This will automatically make the :refund_type be “Full”.
For a partial refund just pass the amount as usual:
gateway.refund 100, 'UBU83983N920'
122 123 124 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 122 def refund(money, identification, = {}) commit 'RefundTransaction', build_refund_request(money, identification, ) end |
#transaction_details(transaction_id) ⇒ Object
172 173 174 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 172 def transaction_details(transaction_id) commit 'GetTransactionDetails', build_get_transaction_details(transaction_id) end |
#transaction_search(options) ⇒ Object
For full documentation see PayPal API Reference
Options:
-
:payer
– (Optional) Search by the buyer’s email address. -
:receipt_id
– (Optional) Search by the PayPal Account Optional receipt ID. -
:receiver
– (Optional) Search by the receiver’s email address. If the merchant account has only one email address, this is the primary email. It can also be a non-primary email address. -
:transaction_id
– (Optional) Search by the transaction ID. The returned results are from the merchant’s transaction records. -
:invoice_id
– (Optional) Search by invoice identification key, as set by you for the original transaction. This field searches the records for items the merchant sells, not the items purchased. -
:card_number
– (Optional) Search by credit card number, as set by you for the original transaction. This field searches the records for items the merchant sells, not the items purchased. -
:auction_item_number
– (Optional) Search by auction item number of the purchased goods. -
:transaction_class
– (Optional) Search by classification of transaction. Some kinds of possible classes of transactions are not searchable with this field. You cannot search for bank transfer withdrawals, for example. It is one of the following values:All – All transaction classifications Sent – Only payments sent Received – Only payments received MassPay – Only mass payments MoneyRequest – Only money requests FundsAdded – Only funds added to balance FundsWithdrawn – Only funds withdrawn from balance Referral – Only transactions involving referrals Fee – Only transactions involving fees Subscription – Only transactions involving subscriptions Dividend – Only transactions involving dividends Billpay – Only transactions involving BillPay Transactions Refund – Only transactions involving funds CurrencyConversions – Only transactions involving currency conversions BalanceTransfer – Only transactions involving balance transfers Reversal – Only transactions involving BillPay reversals Shipping – Only transactions involving UPS shipping fees BalanceAffecting – Only transactions that affect the account balance ECheck – Only transactions involving eCheck
-
:currency_code
– (Optional) Search by currency code. -
:status
– (Optional) Search by transaction status. It is one of the following values:One of: Pending – The payment is pending. The specific reason the payment is pending is returned by the GetTransactionDetails API PendingReason field. Processing – The payment is being processed. Success – The payment has been completed and the funds have been added successfully to your account balance. Denied – You denied the payment. This happens only if the payment was previously pending. Reversed – A payment was reversed due to a chargeback or other type of reversal. The funds have been removed from your account balance and returned to the buyer.
215 216 217 218 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 215 def transaction_search() requires!(, :start_date) commit 'TransactionSearch', build_transaction_search() end |
#transfer(*args) ⇒ Object
Transfer money to one or more recipients.
gateway.transfer 1000, '[email protected]',
:subject => "The money I owe you", :note => "Sorry it's so late"
gateway.transfer [1000, '[email protected]'],
[2450, '[email protected]', :note => 'You will receive another payment on 3/24'],
[2000, '[email protected]'],
:subject => "Your Earnings", :note => "Thanks for your business."
102 103 104 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 102 def transfer(*args) commit 'MassPay', build_mass_pay_request(*args) end |
#void(authorization, options = {}) ⇒ Object
106 107 108 |
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 106 def void(, = {}) commit 'DoVoid', build_void_request(, ) end |