lib/active_merchant/billing/gateways/paypal_express.rb in activemerchant-1.21.0 vs lib/active_merchant/billing/gateways/paypal_express.rb in activemerchant-1.22.0
- old
+ new
@@ -69,38 +69,24 @@
xml.tag! 'n2:Version', API_VERSION
xml.tag! 'n2:DoExpressCheckoutPaymentRequestDetails' do
xml.tag! 'n2:PaymentAction', action
xml.tag! 'n2:Token', options[:token]
xml.tag! 'n2:PayerID', options[:payer_id]
- xml.tag! 'n2:PaymentDetails' do
- xml.tag! 'n2:OrderTotal', localized_amount(money, currency_code), 'currencyID' => currency_code
-
- # All of the values must be included together and add up to the order total
- if [:subtotal, :shipping, :handling, :tax].all?{ |o| options.has_key?(o) }
- xml.tag! 'n2:ItemTotal', localized_amount(options[:subtotal], currency_code), 'currencyID' => currency_code
- xml.tag! 'n2:ShippingTotal', localized_amount(options[:shipping], currency_code),'currencyID' => currency_code
- xml.tag! 'n2:HandlingTotal', localized_amount(options[:handling], currency_code),'currencyID' => currency_code
- xml.tag! 'n2:TaxTotal', localized_amount(options[:tax], currency_code), 'currencyID' => currency_code
- end
-
- xml.tag! 'n2:NotifyURL', options[:notify_url]
- xml.tag! 'n2:ButtonSource', application_id.to_s.slice(0,32) unless application_id.blank?
- xml.tag! 'n2:InvoiceID', options[:order_id]
- xml.tag! 'n2:OrderDescription', options[:description]
-
- add_items_xml(xml, options, currency_code) if options[:items]
- end
+ add_payment_details(xml, money, currency_code, options)
end
end
end
xml.target!
end
def build_setup_request(action, money, options)
currency_code = options[:currency] || currency(money)
-
+ options[:payment_action] = action
+ options[:express_request] = true
+ options[:shipping_address] ||= options[:address]
+
xml = Builder::XmlMarkup.new :indent => 2
xml.tag! 'SetExpressCheckoutReq', 'xmlns' => PAYPAL_NAMESPACE do
xml.tag! 'SetExpressCheckoutRequest', 'xmlns:n2' => EBAY_NAMESPACE do
xml.tag! 'n2:Version', API_VERSION
xml.tag! 'n2:SetExpressCheckoutRequestDetails' do
@@ -119,11 +105,11 @@
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?
xml.tag! 'n2:cpp-payflow-color', options[:background_color] unless options[:background_color].blank?
if options[:allow_guest_checkout]
xml.tag! 'n2:SolutionType', 'Sole'
- xml.tag! 'n2:LandingPage', 'Billing'
+ xml.tag! 'n2:LandingPage', options[:landing_page] || 'Billing'
end
xml.tag! 'n2:BuyerEmail', options[:email] unless options[:email].blank?
if options[:billing_agreement]
xml.tag! 'n2:BillingAgreementDetails' do
@@ -135,32 +121,12 @@
if !options[:allow_note].nil?
xml.tag! 'n2:AllowNote', options[:allow_note] ? '1' : '0'
end
xml.tag! 'n2:CallbackURL', options[:callback_url] unless options[:callback_url].blank?
-
- 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
- # All of the values must be included together and add up to the order total
- if [:subtotal, :shipping, :handling, :tax].all? { |o| options.has_key?(o) }
- xml.tag! 'n2:ItemTotal', localized_amount(options[:subtotal], currency_code), 'currencyID' => currency_code
- xml.tag! 'n2:ShippingTotal', localized_amount(options[:shipping], currency_code), 'currencyID' => currency_code
- xml.tag! 'n2:HandlingTotal', localized_amount(options[:handling], currency_code), 'currencyID' => currency_code
- xml.tag! 'n2:TaxTotal', localized_amount(options[:tax], currency_code), 'currencyID' => currency_code
- end
-
- xml.tag! 'n2:OrderDescription', options[:description]
- xml.tag! 'n2:InvoiceID', options[:order_id]
-
- 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
-
+
+ add_payment_details(xml, with_money_default(money), currency_code, options)
if options[:shipping_options]
options[:shipping_options].each do |shipping_option|
xml.tag! 'n2:FlatRateShippingOptions' do
xml.tag! 'n2:ShippingOptionIsDefault', shipping_option[:default]
xml.tag! 'n2:ShippingOptionAmount', localized_amount(shipping_option[:amount], currency_code), 'currencyID' => currency_code
@@ -178,26 +144,22 @@
xml.target!
end
def build_reference_transaction_request(action, money, options)
currency_code = options[:currency] || currency(money)
-
+
+ # I am not sure why it's set like this for express gateway
+ # but I don't want to break the existing behavior
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
+ add_payment_details(xml, with_money_default(money), currency_code, options)
xml.tag! 'n2:IPAddress', options[:ip]
end
end
end
@@ -206,25 +168,11 @@
def build_response(success, message, response, options = {})
PaypalExpressResponse.new(success, message, response, options)
end
- private
-
- def add_items_xml(xml, options, currency_code)
- options[:items].each do |item|
- xml.tag! 'n2:PaymentDetailsItem' do
- xml.tag! 'n2:Name', item[:name]
- xml.tag! 'n2:Number', item[:number]
- xml.tag! 'n2:Quantity', item[:quantity]
- 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
+ def with_money_default(money)
+ amount(money).to_f.zero? ? 100 : money
end
end
end
end