lib/active_merchant/billing/gateways/paypal_express.rb in activemerchant-1.20.4 vs lib/active_merchant/billing/gateways/paypal_express.rb in activemerchant-1.21.0
- old
+ new
@@ -39,10 +39,16 @@
requires!(options, :token, :payer_id)
commit 'DoExpressCheckoutPayment', build_sale_or_authorization_request('Sale', money, options)
end
+ def reference_transaction(money, options = {})
+ requires!(options, :reference_id, :payment_type, :invoice_id, :description, :ip)
+
+ commit 'DoReferenceTransaction', build_reference_transaction_request('Sale', money, options)
+ end
+
private
def build_get_details_request(token)
xml = Builder::XmlMarkup.new :indent => 2
xml.tag! 'GetExpressCheckoutDetailsReq', 'xmlns' => PAYPAL_NAMESPACE do
xml.tag! 'GetExpressCheckoutDetailsRequest', 'xmlns:n2' => EBAY_NAMESPACE do
@@ -104,10 +110,11 @@
xml.tag! 'n2:MaxAmount', localized_amount(options[:max_amount], currency_code), 'currencyID' => currency_code
end
xml.tag! 'n2:NoShipping', options[:no_shipping] ? '1' : '0'
xml.tag! 'n2:AddressOverride', options[:address_override] ? '1' : '0'
xml.tag! 'n2:LocaleCode', options[:locale] unless options[:locale].blank?
+ xml.tag! 'n2:BrandName', options[:brand_name] unless options[:brand_name].blank?
# Customization of the payment page
xml.tag! 'n2:PageStyle', options[:page_style] unless options[:page_style].blank?
xml.tag! 'n2:cpp-header-image', options[:header_image] unless options[:header_image].blank?
xml.tag! 'n2:cpp-header-border-color', options[:header_border_color] unless options[:header_border_color].blank?
xml.tag! 'n2:cpp-header-back-color', options[:header_background_color] unless options[:header_background_color].blank?
@@ -147,10 +154,11 @@
add_address(xml, 'n2:ShipToAddress', options[:shipping_address] || options[:address])
add_items_xml(xml, options, currency_code) if options[:items]
xml.tag! 'n2:PaymentAction', action
+ xml.tag! 'n2:Custom', options[:custom] unless options[:custom].blank?
end
if options[:shipping_options]
options[:shipping_options].each do |shipping_option|
xml.tag! 'n2:FlatRateShippingOptions' do
@@ -168,10 +176,36 @@
end
xml.target!
end
+ def build_reference_transaction_request(action, money, options)
+ currency_code = options[:currency] || currency(money)
+
+ xml = Builder::XmlMarkup.new :indent => 2
+ xml.tag! 'DoReferenceTransactionReq', 'xmlns' => PAYPAL_NAMESPACE do
+ xml.tag! 'DoReferenceTransactionRequest', 'xmlns:n2' => EBAY_NAMESPACE do
+ xml.tag! 'n2:Version', API_VERSION
+ xml.tag! 'n2:DoReferenceTransactionRequestDetails' do
+ xml.tag! 'n2:ReferenceID', options[:reference_id]
+ xml.tag! 'n2:PaymentAction', action
+ xml.tag! 'n2:PaymentType', options[:payment_type] || 'Any'
+ xml.tag! 'n2:PaymentDetails' do
+ xml.tag! 'n2:OrderTotal', amount(money).to_f.zero? ? localized_amount(100, currency_code) : localized_amount(money, currency_code), 'currencyID' => currency_code
+ xml.tag! 'n2:OrderDescription', options[:description]
+ xml.tag! 'n2:InvoiceID', options[:invoice_id]
+ xml.tag! 'n2:ButtonSource', 'ActiveMerchant'
+ xml.tag! 'n2:NotifyURL', ''
+ end
+ xml.tag! 'n2:IPAddress', options[:ip]
+ end
+ end
+ end
+
+ xml.target!
+ end
+
def build_response(success, message, response, options = {})
PaypalExpressResponse.new(success, message, response, options)
end
private
@@ -185,11 +219,12 @@
if item[:amount]
xml.tag! 'n2:Amount', localized_amount(item[:amount], currency_code), 'currencyID' => currency_code
end
xml.tag! 'n2:Description', item[:description]
xml.tag! 'n2:ItemURL', item[:url]
+ xml.tag! 'n2:ItemCategory', item[:category] if item[:category]
end
end
end
end
end
-end
\ No newline at end of file
+end