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 =
'124'
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"
STANDARD_ERROR_CODE_MAPPING =
{
  '15005' => :card_declined,
  '10754' => :card_declined,
  '10752' => :card_declined,
  '10759' => :card_declined,
  '10761' => :card_declined,
  '15002' => :card_declined,
  '11084' => :card_declined,
  '15004' => :incorrect_cvc,
  '10762' => :invalid_cvc,
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


57
58
59
60
61
62
63
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 57

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.


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

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 

239
240
241
242
243
244
245
246
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 239

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


102
103
104
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 102

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

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


140
141
142
143
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 140

def credit(money, identification, options = {})
  ActiveMerchant.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

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 80

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(options)
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'


268
269
270
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 268

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

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


98
99
100
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 98

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 
  • :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 
  • :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 
  • :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}
    

181
182
183
184
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 181

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'

136
137
138
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 136

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

#transaction_details(transaction_id) ⇒ Object


186
187
188
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 186

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 
  • :currency_code – (Optional) Search by currency code.

  • :status – (Optional) Search by transaction status. It is one of the following values:

    One of:
    Pending 

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

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

116
117
118
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 116

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

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


120
121
122
# File 'lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb', line 120

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