Module: ActiveMerchant::Billing::PaypalCommonAPI

Defined in:
lib/paypal_express/ext/active_merchant/active_merchant.rb

Constant Summary collapse

DUPLICATE_REQUEST_CODE =
'11607'

Instance Method Summary collapse

Instance Method Details

#build_headersObject



50
51
52
53
54
55
56
57
58
# File 'lib/paypal_express/ext/active_merchant/active_merchant.rb', line 50

def build_headers
  x_r_id = x_request_id

  headers = (@options[:headers] || {}).dup
  headers['Content-Type'] ||= 'text/xml'
  headers['User-Agent'] ||= user_agent
  headers['X-Request-Id'] ||= x_r_id unless x_r_id.blank?
  headers
end

#build_refund_request(money, identification, options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/paypal_express/ext/active_merchant/active_merchant.rb', line 22

def build_refund_request(money, identification, options)
  xml = Builder::XmlMarkup.new

  xml.tag! 'RefundTransactionReq', 'xmlns' => PAYPAL_NAMESPACE do
    xml.tag! 'RefundTransactionRequest', 'xmlns:n2' => EBAY_NAMESPACE do
      xml.tag! 'n2:Version', API_VERSION
      xml.tag! 'TransactionID', identification
      xml.tag! 'Amount', amount(money), 'currencyID' => (options[:currency] || currency(money)) if money.present?
      xml.tag! 'RefundType', (options[:refund_type] || (money.present? ? 'Partial' : 'Full'))
      xml.tag! 'Memo', options[:note] unless options[:note].blank?
      xml.tag! 'InvoiceID', (options[:order_id] || options[:invoice_id]) unless (options[:order_id] || options[:invoice_id]).blank?
    end
  end

  xml.target!
end

#commit(action, request) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/paypal_express/ext/active_merchant/active_merchant.rb', line 39

def commit(action, request)
  response = parse(action, ssl_post(endpoint_url, build_request(request), build_headers))

  build_response(successful?(response), message_from(response), response,
                 :test => test?,
                 :authorization => authorization_from(response),
                 :fraud_review => fraud_review?(response),
                 :avs_result => {:code => response[:avs_code]},
                 :cvv_result => response[:cvv2_code])
end

#original_successful?Object



10
# File 'lib/paypal_express/ext/active_merchant/active_merchant.rb', line 10

alias_method :original_successful?, :successful?

#successful?(response) ⇒ Boolean

Note: this may need more thoughts when/if we want to support MsgSubID See developer.paypal.com/docs/classic/express-checkout/integration-guide/ECRelatedAPIOps/#idempotency For now, we just want to correctly handle a subsequent payment using a one-time token (error “A successful transaction has already been completed for this token.”)

Returns:

  • (Boolean)


16
17
18
# File 'lib/paypal_express/ext/active_merchant/active_merchant.rb', line 16

def successful?(response)
  response[:error_codes] == DUPLICATE_REQUEST_CODE ? false : original_successful?(response)
end

#user_agentObject



60
61
62
63
64
65
66
67
68
# File 'lib/paypal_express/ext/active_merchant/active_merchant.rb', line 60

def user_agent
  @@ua ||= JSON.dump({
                         :bindings_version => KB_PLUGIN_VERSION,
                         :lang => 'ruby',
                         :lang_version => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
                         :platform => RUBY_PLATFORM,
                         :publisher => 'killbill'
                     })
end

#x_request_idObject



70
71
72
73
# File 'lib/paypal_express/ext/active_merchant/active_merchant.rb', line 70

def x_request_id
  # See KillbillMDCInsertingServletFilter
  org::slf4j::MDC::get('req.requestId') rescue nil
end