lib/active_merchant/billing/gateways/paypal.rb in activemerchant-1.1.0 vs lib/active_merchant/billing/gateways/paypal.rb in activemerchant-1.2.0
- old
+ new
@@ -1,16 +1,19 @@
require File.dirname(__FILE__) + '/paypal/paypal_common_api'
+require File.dirname(__FILE__) + '/paypal_express'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaypalGateway < Gateway
include PaypalCommonAPI
- def self.supported_cardtypes
- [:visa, :master, :american_express, :discover]
- end
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
+ self.supported_countries = ['US']
+ self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_wp-pro-overview-outside'
+ self.display_name = 'PayPal Website Payments Pro (US)'
+
def authorize(money, credit_card, options = {})
requires!(options, :ip)
if result = test_result_from_cc_number(credit_card.number)
return result
@@ -34,21 +37,32 @@
end
private
def build_sale_or_authorization_request(action, money, credit_card, options)
shipping_address = options[:shipping_address] || options[:address]
+ currency_code = options[:currency] || currency(money)
xml = Builder::XmlMarkup.new :indent => 2
xml.tag! 'DoDirectPaymentReq', 'xmlns' => PAYPAL_NAMESPACE do
xml.tag! 'DoDirectPaymentRequest', 'xmlns:n2' => EBAY_NAMESPACE do
xml.tag! 'n2:Version', API_VERSION
xml.tag! 'n2:DoDirectPaymentRequestDetails' do
xml.tag! 'n2:PaymentAction', action
xml.tag! 'n2:PaymentDetails' do
- xml.tag! 'n2:OrderTotal', amount(money), 'currencyID' => currency(money)
+ xml.tag! 'n2:OrderTotal', amount(money), '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', amount(options[:subtotal]), 'currencyID' => currency_code
+ xml.tag! 'n2:ShippingTotal', amount(options[:shipping]),'currencyID' => currency_code
+ xml.tag! 'n2:HandlingTotal', amount(options[:handling]),'currencyID' => currency_code
+ xml.tag! 'n2:TaxTotal', amount(options[:tax]), 'currencyID' => currency_code
+ end
+
xml.tag! 'n2:NotifyURL', options[:notify_url]
xml.tag! 'n2:OrderDescription', options[:description]
xml.tag! 'n2:InvoiceID', options[:order_id]
+ xml.tag! 'n2:ButtonSource', application_id.to_s.slice(0,32) unless application_id.blank?
add_address(xml, 'n2:ShipToAddress', shipping_address)
end
add_credit_card(xml, credit_card, options[:billing_address] || shipping_address, options)
xml.tag! 'n2:IPAddress', options[:ip]