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
- #build_headers ⇒ Object
-
#build_refund_request(money, identification, options) ⇒ Object
Note: ActiveMerchant is missing InvoiceID in RefundTransactionReq.
- #commit(action, request) ⇒ Object
- #original_successful? ⇒ Object
-
#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.”).
- #user_agent ⇒ Object
- #x_request_id ⇒ Object
Instance Method Details
#build_headers ⇒ Object
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
Note: ActiveMerchant is missing InvoiceID in RefundTransactionReq. See github.com/activemerchant/active_merchant/blob/v1.48.0/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb#L314
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, ) 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' => ([:currency] || currency(money)) if money.present? xml.tag! 'RefundType', ([:refund_type] || (money.present? ? 'Partial' : 'Full')) xml.tag! 'Memo', [:note] unless [:note].blank? xml.tag! 'InvoiceID', ([:order_id] || [:invoice_id]) unless ([:order_id] || [: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), (response), response, :test => test?, :authorization => (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.”)
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_agent ⇒ Object
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_id ⇒ Object
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 |