Module: ActiveMerchant::Billing::PaypalCommonAPI

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-aa.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

Class Method Details

.included(base) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 41

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.



245
246
247
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 245

def authorize_transaction(transaction_id, money, options = {})
  commit 'DoAuthorization', build_do_authorize(transaction_id, money, options)
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.
    


227
228
229
230
231
232
233
234
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 227

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



90
91
92
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 90

def capture(money, authorization, options = {})
  commit 'DoCapture', build_capture_request(money, authorization, options)
end

#credit(money, identification, options = {}) ⇒ Object



128
129
130
131
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 128

def credit(money, identification, options = {})
  deprecated Gateway::CREDIT_DEPRECATION_MESSAGE
  refund(money, identification, options)
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


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 64

def initialize(options = {})
  requires!(options, :login, :password)

  headers = {'X-PP-AUTHORIZATION' => options.delete(:auth_signature), 'X-PAYPAL-MESSAGE-PROTOCOL' => 'SOAP11'} if options[:auth_signature]
  @options = {
    :pem => pem_file,
    :signature => signature,
    :headers => headers || {}
  }.update(options)


  if @options[:pem].blank? && @options[: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 denys 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’



256
257
258
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 256

def manage_pending_transaction(transaction_id, action)
  commit 'ManagePendingTransactionStatus', build_manage_pending_transaction_status(transaction_id, action)
end

#reauthorize(money, authorization, options = {}) ⇒ Object



86
87
88
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 86

def reauthorize(money, authorization, options = {})
  commit 'DoReauthorization', build_reauthorize_request(money, authorization, options)
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}
    


169
170
171
172
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 169

def reference_transaction(money, options = {})
  requires!(options, :reference_id)
  commit 'DoReferenceTransaction', build_reference_transaction_request(money, options)
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'


124
125
126
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 124

def refund(money, identification, options = {})
  commit 'RefundTransaction', build_refund_request(money, identification, options)
end

#test?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 82

def test?
  @options[:test] || Base.gateway_mode == :test
end

#transaction_details(transaction_id) ⇒ Object



174
175
176
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 174

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  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.
    


217
218
219
220
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 217

def transaction_search(options)
  requires!(options, :start_date)
  commit 'TransactionSearch', build_transaction_search(options)
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."


104
105
106
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 104

def transfer(*args)
  commit 'MassPay', build_mass_pay_request(*args)
end

#void(authorization, options = {}) ⇒ Object



108
109
110
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 108

def void(authorization, options = {})
  commit 'DoVoid', build_void_request(authorization, options)
end