From 969f18eaacb95e928d4bc37832f0151fb260930e Mon Sep 17 00:00:00 2001 From: Cody Fauser Date: Sun, 23 Nov 2008 00:08:32 -0500 Subject: [PATCH] Remove Payflow and PayPal NV gateways --- CHANGELOG | 1 + .../billing/gateways/payflow_express_nv.rb | 181 ---------- .../billing/gateways/payflow_nv.rb | 234 ------------- .../payflow_nv/payflow_express_nv_response.rb | 39 --- .../payflow_nv/payflow_nv_common_api.rb | 227 ------------ .../payflow_nv/payflow_nv_response.rb | 28 -- .../billing/gateways/paypal_express_nv.rb | 97 ------ .../billing/gateways/paypal_nv.rb | 59 ---- .../paypal_nv/paypal_express_nv_response.rb | 38 --- .../paypal_nv/paypal_nv_common_api.rb | 323 ------------------ .../remote_payflow_express_nv_test.rb | 51 --- .../remote/gateways/remote_payflow_nv_test.rb | 237 ------------- .../gateways/remote_paypal_express_nv_test.rb | 50 --- test/remote/gateways/remote_paypal_nv_test.rb | 228 ------------- test/unit/gateways/payflow_express_nv_test.rb | 156 --------- test/unit/gateways/payflow_nv_test.rb | 238 ------------- test/unit/gateways/paypal_express_nv_test.rb | 185 ---------- test/unit/gateways/paypal_nv_test.rb | 272 --------------- 18 files changed, 1 insertion(+), 2643 deletions(-) delete mode 100644 lib/active_merchant/billing/gateways/payflow_express_nv.rb delete mode 100644 lib/active_merchant/billing/gateways/payflow_nv.rb delete mode 100644 lib/active_merchant/billing/gateways/payflow_nv/payflow_express_nv_response.rb delete mode 100644 lib/active_merchant/billing/gateways/payflow_nv/payflow_nv_common_api.rb delete mode 100644 lib/active_merchant/billing/gateways/payflow_nv/payflow_nv_response.rb delete mode 100644 lib/active_merchant/billing/gateways/paypal_express_nv.rb delete mode 100644 lib/active_merchant/billing/gateways/paypal_nv.rb delete mode 100644 lib/active_merchant/billing/gateways/paypal_nv/paypal_express_nv_response.rb delete mode 100644 lib/active_merchant/billing/gateways/paypal_nv/paypal_nv_common_api.rb delete mode 100644 test/remote/gateways/remote_payflow_express_nv_test.rb delete mode 100644 test/remote/gateways/remote_payflow_nv_test.rb delete mode 100644 test/remote/gateways/remote_paypal_express_nv_test.rb delete mode 100644 test/remote/gateways/remote_paypal_nv_test.rb delete mode 100644 test/unit/gateways/payflow_express_nv_test.rb delete mode 100644 test/unit/gateways/payflow_nv_test.rb delete mode 100644 test/unit/gateways/paypal_express_nv_test.rb delete mode 100644 test/unit/gateways/paypal_nv_test.rb diff --git a/CHANGELOG b/CHANGELOG index 6a1f0eb004e..a9f883b9533 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = ActiveMerchant CHANGELOG +* Remove PayPal and Payflow Name-Value gateways. PayPal is no longer terminating the Payflow XML API. [cody] * Don't directly use the inflector in the action view helper [cody] * Work around Rails Inflector change [cody] * Add configurable timeouts to PostsData [Michael Koziarski] diff --git a/lib/active_merchant/billing/gateways/payflow_express_nv.rb b/lib/active_merchant/billing/gateways/payflow_express_nv.rb deleted file mode 100644 index 55f9fd7336b..00000000000 --- a/lib/active_merchant/billing/gateways/payflow_express_nv.rb +++ /dev/null @@ -1,181 +0,0 @@ -require File.dirname(__FILE__) + '/payflow_nv/payflow_nv_common_api' -require File.dirname(__FILE__) + '/payflow_nv/payflow_express_nv_response' -require File.dirname(__FILE__) + '/paypal_express_common' - -module ActiveMerchant #:nodoc: - module Billing #:nodoc: - class PayflowExpressNvGateway < Gateway - include PayflowNvCommonAPI - include PaypalExpressCommon - - self.test_redirect_url = 'https://test-expresscheckout.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' - self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=xpt/merchant/ExpressCheckoutIntro-outside' - self.display_name = 'PayPal Express Checkout' - - ACTIONS = { - :set_express_checkout => 'S', - :get_express_checkout => 'G', - :do_express_checkout => 'D' - } - - def authorize(money, options = {}) - requires!(options, :token, :payer_id) - - post = {} - add_transaction_details(post, :do_express_checkout) - - commit(:authorization, post) - end - - def purchase(money, options = {}) - requires!(options, :token, :payer_id) - - post = {} - add_transaction_details(post, :do_express_checkout) - - commit(:purchase, post) - end - - def credit(money, identification, options = {}) - request = build_reference_request(:credit, money, identification, options) - commit(request) - end - - def setup_authorization(money, options = {}) - requires!(options, :return_url, :cancel_return_url) - - post = {} - - add_transaction_details(post, :set_express_checkout) - add_return_urls(post, options) - add_addresses(post, options) - add_customer_data(post, options) - add_invoice(post, options) - add_amount(post, money, options) - - commit(:authorization, post) - end - - def setup_purchase(money, options = {}) - requires!(options, :return_url, :cancel_return_url) - - post = {} - - add_transaction_details(post, :set_express_checkout) - add_return_urls(post, options) - add_addresses(post, options) - add_customer_data(post, options) - add_invoice(post, options) - add_amount(post, money, options) - - commit(:purchase, post) - end - - # How to deal with this? - def details_for(token) - post = {} - - add_transaction_details(post, :get_express_checkout) - add_token(post, token) - - commit(:authorization, post) - end - - private - def add_paypal_action(post, action) - post[:action] = ACTIONS[action] - end - - def add_token(post, token) - post[:token] = token - end - - def add_transaction_details(post, action) - add_paypal_action(post, action) - post[:tender] = TENDERS[:paypal] - end - - def add_return_urls(post, options) - post[:returnurl] = options[:return_url] - post[:cancelurl] = options[:cancel_return_url] - end - - def add_buyer_details(post, options) - post[:token] = options[:token] - end - - #def build_setup_request(action, money, options) - # 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 - # xml.tag! 'n2:PaymentAction', action - # xml.tag! 'n2:OrderTotal', amount(money).to_f.zero? ? amount(100) : amount(money), 'currencyID' => options[:currency] || currency(money) - # if options[:max_amount] - # xml.tag! 'n2:MaxAmount', amount(options[:max_amount]), 'currencyID' => options[:currency] || currency(options[:max_amount]) - # end - # add_address(xml, 'n2:Address', options[:shipping_address] || options[:address]) - # xml.tag! 'n2:AddressOverride', options[:address_override] ? '1' : '0' - # xml.tag! 'n2:NoShipping', options[:no_shipping] ? '1' : '0' - # xml.tag! 'n2:ReturnURL', options[:return_url] - # xml.tag! 'n2:CancelURL', options[:cancel_return_url] - # xml.tag! 'n2:IPAddress', options[:ip] - # xml.tag! 'n2:OrderDescription', options[:description] - # xml.tag! 'n2:BuyerEmail', options[:email] unless options[:email].blank? - # xml.tag! 'n2:InvoiceID', options[:order_id] - # - # # Customization of the payment page - # xml.tag! 'n2:PageStyle', options[:page_style] unless options[:page_style].blank? - # xml.tag! 'n2:cpp-image-header', options[:header_image] unless options[:header_image].blank? - # xml.tag! 'n2:cpp-header-back-color', options[:header_background_color] unless options[:header_background_color].blank? - # xml.tag! 'n2:cpp-header-border-color', options[:header_border_color] unless options[:header_border_color].blank? - # xml.tag! 'n2:cpp-payflow-color', options[:background_color] unless options[:background_color].blank? - # - # xml.tag! 'n2:LocaleCode', options[:locale] unless options[:locale].blank? - # end - # end - # end - - # xml.target! - #end - - #def build_sale_or_authorization_request(action, money, options) - # currency_code = options[:currency] || currency(money) - # - # xml = Builder::XmlMarkup.new :indent => 2 - # xml.tag! 'DoExpressCheckoutPaymentReq', 'xmlns' => PAYPAL_NAMESPACE do - # xml.tag! 'DoExpressCheckoutPaymentRequest', 'xmlns:n2' => EBAY_NAMESPACE do - # 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', 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:ButtonSource', application_id.to_s.slice(0,32) unless application_id.blank? - # end - # end - # end - # end - - # xml.target! - #end - - def build_response(success, message, response, options = {}) - PayflowExpressNvResponse.new(success, message, response, options) - end - end - end -end - diff --git a/lib/active_merchant/billing/gateways/payflow_nv.rb b/lib/active_merchant/billing/gateways/payflow_nv.rb deleted file mode 100644 index f12054460d6..00000000000 --- a/lib/active_merchant/billing/gateways/payflow_nv.rb +++ /dev/null @@ -1,234 +0,0 @@ -require File.dirname(__FILE__) + '/payflow_nv/payflow_nv_common_api' -require File.dirname(__FILE__) + '/payflow_nv/payflow_nv_response' -require File.dirname(__FILE__) + '/payflow_express_nv' - -module ActiveMerchant #:nodoc: - module Billing #:nodoc: - class PayflowNvGateway < Gateway - include PayflowNvCommonAPI - - RECURRING_ACTIONS = Set.new([:add, :modify, :cancel, :inquiry, :reactivate, :payment]) - TERM_PERIOD = Set.new([:week, :biwk, :smmo, :frwk, :mont, :qter, :smyr, :year]) - - RECURRING_CODE = { - :add => "A", - :modify => "M", - :cancel => "C", - :inquiry => "I", - :reactivate => "R", - :payment => "P", - } - - self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :discover, :diners_club] - self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_payflow-pro-overview-outside' - self.display_name = 'PayPal Payflow Pro' - - def authorize(money, credit_card_or_reference, options = {}) - post = build_sale_or_authorization_request(money, credit_card_or_reference, options) - commit(:authorization, post) - end - - def purchase(money, credit_card_or_reference, options = {}) - if credit_card_or_reference.is_a?(String) - post = build_reference_sale_or_authorization_request(money, credit_card_or_reference, options) - else - post = build_sale_or_authorization_request(money, credit_card_or_reference, options) - end - commit(:purchase, post) - end - - def build_reference_sale_or_authorization_request(money, reference, options) - post = {} - add_reference(post, reference, options) - add_amount(post, money, options) - return post - end - - def build_sale_or_authorization_request(money, credit_card_or_reference, options) - post = {} - add_addresses(post, options) - add_customer_data(post, options) - add_invoice(post, options) - add_credit_card(post, credit_card_or_reference) - add_amount(post, money, options) - post - end - - public - - def credit(money, identification_or_credit_card, options = {}) - if identification_or_credit_card.is_a?(String) - # Perform referenced credit - post = build_reference_request(money, identification_or_credit_card, options) - else - # Perform non-referenced credit - post = build_credit_card_request(money, identification_or_credit_card, options) - end - - commit(:credit, post) - end - - # Adds or modifies a recurring Payflow profile. See the Payflow Pro Recurring Billing Guide for more details: - # https://www.paypal.com/en_US/pdf/PayflowPro_RecurringBilling_Guide.pdf - # - # Several options are available to customize the recurring profile: - # - # * profile_id - is only required for editing a recurring profile - # * starting_at - takes a Date, Time, or string in mmddyyyy format. The date must be in the future. - # * name - The name of the customer to be billed. If not specified, the name from the credit card is used. - # * periodicity - The frequency that the recurring payments will occur at. Can be one of - # :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily, :semimonthly, :quadweekly, :quarterly, :semiyearly - # * payments - The term, or number of payments that will be made - # * comment - A comment associated with the profile - def recurring(money, credit_card, options = {}) - options[:name] = credit_card.name if options[:name].blank? && credit_card - post = build_recurring_request(options[:profile_id] ? :modify : :add, money, options) - add_credit_card(post, credit_card) if credit_card - commit(:recurring, post) - end - - def cancel_recurring(profile_id) - post = build_recurring_request(:cancel, 0, :profile_id => profile_id) - commit(:recurring, post) - end - - def recurring_inquiry(profile_id, options = {}) - post = build_recurring_request(:inquiry, nil, options.update( :profile_id => profile_id )) - commit(:recurring, post) - end - - def express - @express ||= PayflowExpressNvGateway.new(@options) - end - - - private - def build_credit_card_request(money, credit_card, options) - post = {} - add_credit_card(post, credit_card) - add_amount(post, money, options) - return post - end - - def add_credit_card(post, credit_card) - post[:tender] = TENDERS[:credit_card] - post[:firstname] = credit_card.first_name - post[:lastname] = credit_card.last_name - post[:acct] = credit_card.number - post[:expdate] = format_date(credit_card.month, credit_card.year) - post[:cvv2] = credit_card.verification_value if credit_card.verification_value? - if [ 'switch', 'solo' ].include?(credit_card.type.to_s) - post[:cardstart] = format_date(credit_card.start_month, credit_card.start_year) unless credit_card.start_month.blank? || credit_card.start_year.blank? - post[:cardissue] = credit_card.issue_number unless credit_card.issue_number.blank? - end - end - - def format_date(month, year) - month = format(month, :two_digits) - year = format(year, :two_digits) - - "#{month}#{year}" - end - - def credit_card_type(credit_card) - return '' if card_brand(credit_card).blank? - - CARD_MAPPING[card_brand(credit_card).to_sym] - end - - def expdate(creditcard) - year = sprintf("%.4i", creditcard.year) - month = sprintf("%.2i", creditcard.month) - - "#{year}#{month}" - end - - def startdate(creditcard) - year = format(creditcard.start_year, :two_digits) - month = format(creditcard.start_month, :two_digits) - - "#{month}#{year}" - end - - - - # Number of payments to be made over the agreement - # 0 = payments made until profile deactivated - def add_term(post, options) - post[:term] = options[:term] || 0 - end - - def build_recurring_request(action, money, options) - unless RECURRING_ACTIONS.include?(action) - raise StandardError, "Invalid Recurring Profile Action: #{action}" - end - - - post = {} - add_pair(post, :action, RECURRING_CODE[action]) - unless [:cancel, :inquiry].include?(action) - # Requirements - #requires!(options, [:profilename]) - - - # Construct messages - add_amount(post, money, options) - add_pair(post, :profilename, (options[:profilename]||"foo")) - add_pair(post, :name, options[:name]) unless options[:name].nil? - add_amount(post, money, options) - add_pair(post, :payperiod, get_pay_period(options)) - add_term(post, options[:payments]) unless options[:payments].nil? - add_pair(post, :comment, options[:comment]) unless options[:payments].nil? - add_pair(post, :start, format_rp_date(options[:starting_at] || Date.today + 1 )) - add_pair(post, :email, options[:email]) unless options[:email].nil? - - if initial_tx = options[:initial_transaction] - requires!(initial_tx, [:type, :authorization, :purchase]) - requires!(initial_tx, :amount) if initial_tx[:type] == :purchase - - add_pair(post, 'OptionalTrans', TRANSACTIONS[initial_tx[:type]]) - add_pair(post, 'OptionalTransAmt', amount(initial_tx[:amount])) unless initial_tx[:amount].blank? - end - add_addresses(post, options) - end - - if action != :add - add_pair(post, :origprofileid, options[:profile_id]) - end - - if action == :inquiry - add_pair(post, :paymenthistory, options[:history] ? 'Y' : 'N' ) - end - return post - end - - - def get_pay_period(options) - requires!(options, [:periodicity, :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily, :semimonthly, :quadweekly, :quarterly, :semiyearly]) - case options[:periodicity] - when :weekly then 'WEEK' - when :biweekly then 'BIWK' - when :semimonthly then 'SMMO' - when :quadweekly then 'FRWK' - when :monthly then 'MONT' - when :quarterly then 'QTER' - when :semiyearly then 'SMYR' - when :yearly then 'YEAR' - end - end - - def format_rp_date(time) - case time - when Time, Date then time.strftime("%m%d%Y") - else - time.to_s - end - end - - def build_response(success, message, response, options = {}) - PayflowNvResponse.new(success, message, response, options) - end - end - end -end - diff --git a/lib/active_merchant/billing/gateways/payflow_nv/payflow_express_nv_response.rb b/lib/active_merchant/billing/gateways/payflow_nv/payflow_express_nv_response.rb deleted file mode 100644 index 85549cf0ae7..00000000000 --- a/lib/active_merchant/billing/gateways/payflow_nv/payflow_express_nv_response.rb +++ /dev/null @@ -1,39 +0,0 @@ -module ActiveMerchant #:nodoc: - module Billing #:nodoc: - class PayflowExpressNvResponse < Response - def email - @params['email'] - end - - def full_name - "#{@params['firstname']} #{@params['lastname']}" - end - - def token - @params['token'] - end - - def payer_id - @params['payerid'] - end - - # Really the shipping country, but it is all the information provided - def payer_country - address['country'] - end - - def address - { 'name' => full_name, - 'company' => @params['business'], - 'address1' => @params['shiptostreet'], - 'address2' => nil, - 'city' => @params['shiptocity'], - 'state' => @params['shiptostate'], - 'country' => @params['shiptocountry'], - 'zip' => @params['shiptozip'], - 'phone' => nil - } - end - end - end -end diff --git a/lib/active_merchant/billing/gateways/payflow_nv/payflow_nv_common_api.rb b/lib/active_merchant/billing/gateways/payflow_nv/payflow_nv_common_api.rb deleted file mode 100644 index 4ed2b19393e..00000000000 --- a/lib/active_merchant/billing/gateways/payflow_nv/payflow_nv_common_api.rb +++ /dev/null @@ -1,227 +0,0 @@ -module ActiveMerchant #:nodoc: - module Billing #:nodoc: - module PayflowNvCommonAPI - def self.included(base) - base.default_currency = 'USD' - - # The certification id requirement has been removed by Payflow - # This is no longer being sent in the requests to the gateway - base.class_inheritable_accessor :certification_id - - base.class_inheritable_accessor :partner - - # Set the default partner to PayPal - base.partner = 'PayPal' - - base.supported_countries = ['US', 'CA', 'SG', 'AU'] - - base.class_inheritable_accessor :timeout - base.timeout = 60 - - # Enable safe retry of failed connections - # Payflow is safe to retry because retried transactions use the same - # X-VPS-Request-ID header. If a transaction is detected as a duplicate - # only the original transaction data will be used by Payflow, and the - # subsequent Responses will have a :duplicate parameter set in the params - # hash. - base.retry_safe = true - end - - TEST_URL = 'https://pilot-payflowpro.paypal.com' - LIVE_URL = 'https://payflowpro.paypal.com' - - CARD_MAPPING = { - :visa => 'Visa', - :master => 'MasterCard', - :discover => 'Discover', - :american_express => 'Amex', - :jcb => 'JCB', - :diners_club => 'DinersClub', - :switch => 'Switch', - :solo => 'Solo' - } - - TRANSACTIONS = { :purchase => "S", - :authorization => "A", - :capture => "D", - :void => "V", - :credit => "C", - :inquiry => "I", - :duplicate => "N", - :recurring => "R", - } - - TENDERS = { - :credit_card => 'C', - :paypal => 'P', - :pinless => 'D', - :telecheck => 'K', - :auto_clearing_house => 'A', - } - - CVV_CODE = { - 'Match' => 'M', - 'No Match' => 'N', - 'Service Not Available' => 'U', - 'Service not Requested' => 'P' - } - - def initialize(options = {}) - requires!(options, :login, :password) - @options = { - :certification_id => self.class.certification_id, - :partner => self.class.partner - }.update(options) - super - end - - def test? - @options[:test] || super - end - - def capture(money, authorization, options = {}) - post = { :origid => authorization } - - add_amount(post, money, options) - commit(:capture, post) - end - - def void(authorization, options = {}) - post = { :origid => authorization } - commit(:void, post) - end - - - def test? - @options[:test] || Base.gateway_mode == :test - end - - - private - def add_pair(post, key, value, options = {}) - post[key] = value if not value.blank? || options[:allow_blank] - end - - def add_reference(post, reference, options) - post[:tender] = TENDERS[:credit_card] - add_pair(post, :origid, reference) - end - - def add_amount(post, money, options) - add_pair(post, :amt, amount(money), :allow_blank => false) - add_pair(post, :currency, currency(money)) - add_pair(post, :taxamt, amount(options[:tax])) - end - - def add_invoice(post, options) - add_pair(post, :invnum, options[:order_id]) - add_pair(post, :custref, options[:order_id]) - add_pair(post, :custcode, options[:order_id]) - add_pair(post, :desc, options[:description]) - end - - def add_customer_data(post, options) - add_pair(post, :custip, options[:ip]) - add_pair(post, :email, options[:email]) - end - - def add_addresses(post, options) - billing_address = options[:billing_address] || options[:address] - shipping_address = options[:shipping_address] || billing_address - - add_billing_address(post, billing_address) - add_shipping_address(post, shipping_address) - end - - - def add_shipping_address(post, address) - return if address.nil? - - add_pair(post, :shiptofirstname, address[:name]) - add_pair(post, :shiptostreet, address[:address1]) - add_pair(post, :shiptocity, address[:city]) - add_pair(post, :shiptostate, address[:state]) - add_pair(post, :shiptozip, address[:zip]) - add_pair(post, :shiptocountry, address[:country]) - end - - def add_billing_address(post, address) - return if address.nil? - - add_pair(post, :companyname, address[:company]) - add_pair(post, :street, address[:address1]) - add_pair(post, :city, address[:city]) - add_pair(post, :state, address[:state]) - add_pair(post, :zip, address[:zip]) - add_pair(post, :billtocountry, address[:country]) - add_pair(post, :phonenum, address[:phone]) - end - - def build_reference_request(money, authorization, options) - post = {} - add_reference(post, authorization, options) - post - end - - def post_headers(content_length) - { - "Content-Type" => "text/namevalue", - "Content-Length" => content_length.to_s, - "X-VPS-Timeout" => timeout.to_s, - "X-VPS-VIT-Integration-Product" => "ActiveMerchant", - "X-VPS-VIT-Runtime-Version" => RUBY_VERSION, - "X-VPS-Request-ID" => generate_unique_id - } - end - - def post_data(action, post) - post[:trxtype] = TRANSACTIONS[action] - post[:partner] = @options[:partner] - post[:vendor] = @options[:login] - post[:user] = @options[:login] - post[:pwd] = @options[:password] - post[:verbosity] = 'MEDIUM' - - request = post.collect do |key, value| - sanitized_data = value.to_s.gsub('"', '') - "#{key.to_s.upcase}[#{sanitized_data.size}]=#{sanitized_data}" - end.join("&") - - request - end - - def commit(action, post) - request = post_data(action, post) - headers = post_headers(request.size) - - url = test? ? TEST_URL : LIVE_URL - data = ssl_post(url, request, headers) - - response = parse(data) - - success = response[:result] == "0" - message = response[:respmsg] - - build_response(success, message, response, - :authorization => response[:pnref] || response[:rpref], - :cvv_result => response[:cvv2_match], - :avs_result => { - :street_match => response[:avsaddr], - :postal_match => response[:avszip], - :code => response[:procavs], - }, - :test => test? - ) - end - - def parse(data) - fields = {} - for line in data.split('&') - key, value = *line.scan( %r{^(\w+)\=(.*)$} ).flatten - fields[key.underscore.to_sym] = value - end - fields - end - end - end -end diff --git a/lib/active_merchant/billing/gateways/payflow_nv/payflow_nv_response.rb b/lib/active_merchant/billing/gateways/payflow_nv/payflow_nv_response.rb deleted file mode 100644 index e89cbaa06d5..00000000000 --- a/lib/active_merchant/billing/gateways/payflow_nv/payflow_nv_response.rb +++ /dev/null @@ -1,28 +0,0 @@ -module ActiveMerchant #:nodoc: - module Billing #:nodoc: - class PayflowNvResponse < Response - def profile_id - @params['profileid'] - end - - def payment_history - @payment_history ||= get_history - end - protected - def get_history - hist = [] - @params.reject {|key,val| key !~ /p_result/}.collect {|r| r[0].gsub(/p_result/, "")}.sort.each do |idx| - item = { - 'payment_num' => "#{idx}", - 'amt' => @params["p_amt#{idx}"], - 'transtime' => @params["p_transtime#{idx}"], - 'result' => @params["p_result#{idx}"], - 'state' => @params["p_transtate#{idx}"], - } - hist << item - end - return hist - end - end - end -end diff --git a/lib/active_merchant/billing/gateways/paypal_express_nv.rb b/lib/active_merchant/billing/gateways/paypal_express_nv.rb deleted file mode 100644 index 326c1168d7f..00000000000 --- a/lib/active_merchant/billing/gateways/paypal_express_nv.rb +++ /dev/null @@ -1,97 +0,0 @@ -require File.dirname(__FILE__) + '/paypal_nv/paypal_nv_common_api' -require File.dirname(__FILE__) + '/paypal_nv/paypal_express_nv_response' - -module ActiveMerchant #:nodoc: - module Billing #:nodoc: - class PaypalExpressNvGateway < Gateway - include PaypalNvCommonAPI - - self.supported_countries = ['US'] - - LIVE_REDIRECT_NV_URL = 'https://www.paypal.com/cgibin/webscr?cmd=_express-checkout&token=' - TEST_REDIRECT_NV_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' - - self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=xpt/merchant/ExpressCheckoutIntro-outside' - self.display_name = 'PayPal Express Checkout' - - def redirect_url - test? ? TEST_REDIRECT_NV_URL : LIVE_REDIRECT_NV_URL - end - - def redirect_url_for(token, options = {}) - options = {:review => true}.update(options) - options[:review] ? "#{redirect_url}#{token}" : "#{redirect_url}#{token}&useraction=commit" - end - - def setup_authorization(money, options = {}) - requires!(options, :return_url, :cancel_return_url) - commit 'SetExpressCheckout', build_setup_request('Authorization', money, options) - end - - def setup_purchase(money, options = {}) - requires!(options, :return_url, :cancel_return_url) - commit 'SetExpressCheckout', build_setup_request('Sale', money, options) - end - - def details_for(token) - commit 'GetExpressCheckoutDetails', build_get_details_request(token) - end - - def authorize(money, options = {}) - requires!(options, :token, :payer_id) - commit 'DoExpressCheckoutPayment', build_sale_or_authorization_request('Authorization', money, options) - end - - def purchase(money, options = {}) - requires!(options, :token, :payer_id) - commit 'DoExpressCheckoutPayment', build_sale_or_authorization_request('Sale', money, options) - end - - private - def build_setup_request(action, money, options) - post = {} - add_amount(post, money, options) - add_pair(post, :returnurl, options[:return_url]) - add_pair(post, :cancelurl, options[:cancel_return_url]) - add_pair(post, :ipaddress, options[:ip]) - add_pair(post, :noshipping, options[:no_shipping] ? '1' : '0') - add_pair(post, :maxamount, options[:max_amount]) if options[:max_amount] - add_pair(post, :paymentaction, action) - add_pair(post, :email, options[:email]) if options[:email] - add_pair(post, :custom, options[:custom_code]) if options[:custom_code] - add_pair(post, :reqconfirmshipping, options[:confirm_shipping] ? "1" : "0") if options[:confirm_shipping] - add_pair(post, :addressoverride, options[:address_override] ? "1" : "0") if options[:address_override] - add_pair(post, :token, options[:token]) if options[:token] - add_pair(post, :locale, options[:locale]) if options[:locale] - add_shipping_address(post, optioins[:shipping_address]) if options[:shipping_address] - post - end - - def build_get_details_request(token) - post = {} - add_pair(post, :token, token) - post - end - - def build_sale_or_authorization_request(action, money, options) - post = {} - #required - add_pair(post, :paymentaction, action) - add_pair(post, :payerid, options[:payer_id]) - add_pair(post, :token, options[:token]) - add_amount(post, money, options) - add_pair(post, :buttonsource, application_id) - - # optional - add_pair(post, :currencycode, options[:currency] || "USD") - add_pair(post, :token, options[:token]) if options[:token] - - post - end - - def build_response(success, message, response, options = {}) - PaypalExpressNvResponse.new(success, message, response, options) - end - end - end -end diff --git a/lib/active_merchant/billing/gateways/paypal_nv.rb b/lib/active_merchant/billing/gateways/paypal_nv.rb deleted file mode 100644 index 488353b75de..00000000000 --- a/lib/active_merchant/billing/gateways/paypal_nv.rb +++ /dev/null @@ -1,59 +0,0 @@ -require File.dirname(__FILE__) + '/paypal_nv/paypal_nv_common_api' -require File.dirname(__FILE__) + '/paypal_express_nv' - -module ActiveMerchant #:nodoc: - module Billing #:nodoc: - class PaypalNvGateway < Gateway - include PaypalNvCommonAPI - - 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) - commit 'DoDirectPayment', build_sale_or_authorization_request('Authorization', money, credit_card, options) - end - - def purchase(money, credit_card, options = {}) - requires!(options, :ip) - commit 'DoDirectPayment', build_sale_or_authorization_request('Sale', money, credit_card, options) - end - - def express - @express ||= PaypalExpressNvGateway.new(@options) - end - - private - - def build_sale_or_authorization_request(action, money, credit_card_or_reference, options) - post = {} - post[:paymentaction] = action - post[:buttonsource] = application_id.to_s.slice(0,32) unless application_id.blank? - add_addresses(post, options) - add_customer_data(post, options) - add_invoice(post, options) - add_credit_card(post, credit_card_or_reference) - add_amount(post, money, options) - add_subtotals(post, options) - post - end - - def credit_card_type(type) - case type - when 'visa' then 'Visa' - when 'master' then 'MasterCard' - when 'discover' then 'Discover' - when 'american_express' then 'Amex' - when 'switch' then 'Switch' - when 'solo' then 'Solo' - end - end - - def build_response(success, message, response, options = {}) - Response.new(success, message, response, options) - end - end - end -end diff --git a/lib/active_merchant/billing/gateways/paypal_nv/paypal_express_nv_response.rb b/lib/active_merchant/billing/gateways/paypal_nv/paypal_express_nv_response.rb deleted file mode 100644 index b41902cbfa9..00000000000 --- a/lib/active_merchant/billing/gateways/paypal_nv/paypal_express_nv_response.rb +++ /dev/null @@ -1,38 +0,0 @@ -module ActiveMerchant #:nodoc: - module Billing #:nodoc: - class PaypalExpressNvResponse < Response - def email - @params['email'] - end - - def name - [@params['firstname'], @params['middlename'], @params['lastname']].compact.join(' ') - end - - def token - @params['token'] - end - - def payer_id - @params['payerid'] - end - - def payer_country - @params['payer_country'] - end - - def address - { 'name' => self.name, - 'company' => @params['business'], - 'address1' => @params['shiptostreet'], - 'address2' => @params['shiptostreet2'], - 'city' => @params['shiptocity'], - 'state' => @params['shiptostate'], - 'country' => @params['shiptocountrycode'], - 'zip' => @params['shiptozip'], - 'phone' => @params['phonenum'], - } - end - end - end -end diff --git a/lib/active_merchant/billing/gateways/paypal_nv/paypal_nv_common_api.rb b/lib/active_merchant/billing/gateways/paypal_nv/paypal_nv_common_api.rb deleted file mode 100644 index 145c661634b..00000000000 --- a/lib/active_merchant/billing/gateways/paypal_nv/paypal_nv_common_api.rb +++ /dev/null @@ -1,323 +0,0 @@ -require 'cgi' -module ActiveMerchant #:nodoc: - module Billing #:nodoc: - # This module is included in both PaypalGateway and PaypalExpressGateway - module PaypalNvCommonAPI - def self.included(base) - base.default_currency = 'USD' - base.cattr_accessor :pem_file - base.cattr_accessor :signature - end - - API_VERSION = '50.0000' - - URLS = { - :test => { :certificate => 'https://api.sandbox.paypal.com/nvp/', - :signature => 'https://api-3t.sandbox.paypal.com/nvp/' }, - :live => { :certificate => 'https://api.paypal.com/nvp/', - :signature => 'https://api-3t.paypal.com/nvp/' } - } - - AUSTRALIAN_STATES = { - 'ACT' => 'Australian Capital Territory', - 'NSW' => 'New South Wales', - 'NT' => 'Northern Territory', - 'QLD' => 'Queensland', - 'SA' => 'South Australia', - 'TAS' => 'Tasmania', - 'VIC' => 'Victoria', - 'WA' => 'Western Australia' - } - - SUCCESS_CODES = [ 'Success', 'SuccessWithWarning' ] - - # The gateway must be configured with either your PayPal PEM file - # or your PayPal API Signature. Only one is required. - # - # :pem The text of your PayPal PEM file. Note - # this is not the path to file, but its - # contents. If you are only using one PEM - # file on your site you can declare it - # globally and then you won't need to - # include this option - # - # :signature The text of your PayPal signature. - # If you are only using one API Signature - # on your site you can declare it - # globally and then you won't need to - # include this option - - def initialize(options = {}) - requires!(options, :login, :password) - - @options = { - :pem => pem_file, - :signature => signature - }.update(options) - - if @options[:pem].blank? && @options[:signature].blank? - raise ArgumentError, "An API Certificate or API Signature is required to make requests to PayPal" - end - - super - end - - def test? - @options[:test] || super - end - - def reauthorize(money, authorization, options = {}) - commit 'DoReauthorization', build_reauthorize_request(money, authorization, options) - end - - def capture(money, authorization, options = {}) - commit 'DoCapture', build_capture_request(money, authorization, options) - end - - # Transfer money to one or more recipients. - # - # gateway.transfer 1000, 'bob@example.com', - # :subject => "The money I owe you", :note => "Sorry it's so late" - # - # gateway.transfer [1000, 'fred@example.com'], - # [2450, 'wilma@example.com', :note => 'You will receive another payment on 3/24'], - # [2000, 'barney@example.com'], - # :subject => "Your Earnings", :note => "Thanks for your business." - # - def transfer(*args) - commit 'MassPay', build_mass_pay_request(*args) - end - - def void(authorization, options = {}) - commit 'DoVoid', build_void_request(authorization, options) - end - - def credit(money, identification, options = {}) - commit 'RefundTransaction', build_credit_request(money, identification, options) - end - - private - def build_reauthorize_request(money, authorization, options) - post = {} - add_pair(post, :authorizationid, authorization) - add_amount(post, money, options) - post - end - - # - Softdescriptor - max len 22 - def build_capture_request(money, authorization, options) - post = {} - add_pair(post, :authorizationid, authorization) - add_amount(post, money, options) - add_pair(post, :completetype, (options[:complete] || "Complete")) - add_pair(post, :note, options[:description]) if options[:description] - add_pair(post, :softdescriptor, options[:soft_descriptor]) if options[:soft_descriptor] - post - end - - - def build_credit_request(money, identification, options) - post = {} - add_pair(post, :transactionid, identification) - add_pair(post, :refundtype, options[:refund_type] || "Partial") - add_pair(post, :note, options[:description]) if options[:description] - add_amount(post, money, options) - post - end - - def build_void_request(authorization, options) - post = {} - add_pair(post, :authorizationid, authorization) - add_pair(post, :note, options[:description]) if options[:description] - post - end - - # TODO: make transfer check for recipient or unique recipiend id - # They are not supposed to be mixed - def build_mass_pay_request(*args) - post = {} - default_options = args.last.is_a?(Hash) ? args.pop : {} - recipients = args.first.is_a?(Array) ? args : [args] - - if recipients.size > 250 - raise ArgumentError, "PayPal only supports transferring money to 250 recipients at a time" - end - - add_pair(post, :currencycode, default_options[:currency]) - add_pair(post, :emailsubject, default_options[:subject]) if default_options[:subject] - - recipients.each_with_index do |(money, recipient, options), index| - options ||= default_options - add_trans_item(post, index, :amt, amount(money)) - add_trans_item(post, index, :email, recipient) - add_trans_item(post, index, :note, options[:note]) if options[:note] - add_trans_item(post, index, :uniqueid, options[:unique_id]) if options[:unique_id] - end - post - end - - def add_trans_item(post, id, label, value) - add_pair(post, "l_#{label}#{id}", value) - end - - def parse(data) - fields = {} - for line in data.split('&') - key, value = *line.scan( %r{^(\w+)\=(.*)$} ).flatten - fields[key.underscore.to_sym] = CGI.unescape(value) - end - fields - end - - def post_data(action, post) - post[:method] = action - post[:user] = @options[:login] - post[:pwd] = @options[:password] - post[:signature] = @options[:signature] unless @options[:signature].blank? - post[:subject] = @options[:subject] unless @options[:subject].blank? - post[:version] = API_VERSION - - post.collect {|k,v| "#{k.to_s.upcase}=#{CGI.escape(v.to_s)}" }.join("&") - end - - def add_email(post, options) - add_pair(post, :email, options[:email]) if options[:email] - end - - def endpoint_url - URLS[test? ? :test : :live][@options[:signature].blank? ? :certificate : :signature] - end - - def commit(action, post) - response = parse(ssl_post(endpoint_url, post_data(action, post))) - - build_response(successful?(response), message_from(response), response, - :test => test?, - :authorization => authorization_from(response), - :avs_result => { :code => response[:avscode] }, - :cvv_result => response[:cvv2_match] - ) - end - - def authorization_from(response) - response[:transactionid] || response[:authorizationid] # latter one is from reauthorization - end - - def successful?(response) - SUCCESS_CODES.include?(response[:ack]) - end - - def message_from(response) - if successful?(response) - response[:message] - else - response[:l_longmessage0] || response[:ack] - end - end - - private - def add_pair(post, key, value, options = {}) - post[key] = value if not value.blank? || options[:allow_blank] - end - - def add_addresses(post, options) - billing_address = options[:billing_address] || options[:address] - unless options[:no_shipping] - shipping_address = options[:shipping_address] || billing_address - end - - add_billing_address(post, billing_address) - add_shipping_address(post, shipping_address) - end - - def format_date(month, year) - month = format(month, :two_digits) - year = format(year, :four_digits) - - "#{month}#{year}" - end - - def add_credit_card(post, credit_card) - post[:creditcardtype] = credit_card_type(card_brand(credit_card)) - post[:firstname] = credit_card.first_name - post[:lastname] = credit_card.last_name - post[:acct] = credit_card.number - post[:expdate] = format_date(credit_card.month, credit_card.year) - post[:cvv2] = credit_card.verification_value if credit_card.verification_value? - if requires_start_date_or_issue_number?(credit_card) - post[:cardstart] = format_date(credit_card.start_month, credit_card.start_year) unless credit_card.start_month.blank? || credit_card.start_year.blank? - post[:cardissue] = credit_card.issue_number unless credit_card.issue_number.blank? - end - end - - def add_customer_data(post, options) - add_pair(post, :ipaddress, options[:ip]) - add_pair(post, :email, options[:email]) - end - - def add_billing_address(post, address) - return if address.nil? - add_pair(post, :companyname, address[:company]) - add_pair(post, :street, address[:address1]) - add_pair(post, :street2, address[:address2]) - add_pair(post, :city, address[:city]) - add_pair(post, :state, address[:state]) - add_pair(post, :zip, address[:zip]) - add_pair(post, :countrycode, address[:country]) - add_pair(post, :phonenum, address[:phone]) - end - - def add_shipping_address(post, address) - return if address.nil? - add_pair(post, :shiptoname, address[:name]) - add_pair(post, :shiptostreet, address[:address1]) - add_pair(post, :shiptostreet2, address[:address2]) if address[:address2] - add_pair(post, :shiptocity, address[:city]) - add_pair(post, :shiptostate, address[:state]) - add_pair(post, :shiptozip, address[:zip]) - add_pair(post, :shiptocountrycode, address[:country]) - add_pair(post, :shiptophonenum, address[:phone]) - end - - def add_invoice(post, options) - add_pair(post, :invnum, options[:order_id]) if options[:order_id] - add_pair(post, :desc, options[:description]) if options[:description] - add_pair(post, :custom, options[:custom_code]) if options[:custom_code] - add_line_items(post, options[:line_items]) if options[:line_items] - end - - def add_line_items(post, line_items) - line_items.each_with_index do |line_item, index| - add_line_item(post, line_item, index) - end - end - - def add_line_item(post, line_item, index) - add_line_item_pair(post, :name, line_item[:description], index) - add_line_item_pair(post, :number, line_item[:sku], index) - add_line_item_pair(post, :qty, line_item[:quantity], index) - add_line_item_pair(post, :taxamt, amount(line_item[:tax]), index) if line_item[:tax] - add_line_item_pair(post, :amt, amount(line_item[:amount]), index) if line_item[:amount] - end - - def add_line_item_pair(post, name, value, index) - add_pair(post, "l_#{name}#{index}", value) - end - - def add_amount(post, money, options) - add_pair(post, :currencycode, options[:currency] || currency(money)) - add_pair(post, :amt, amount(money), :allow_blank => false) - end - - def add_subtotals(post, options) - # All of the values must be included together and add up to the order total - if options[:subtotal] - add_pair(post, :itemamt, amount(options[:subtotal])) - add_pair(post, :shippingamt, amount(options[:shipping] || 0)) - add_pair(post, :handlingamt, amount(options[:handling] || 0)) - add_pair(post, :taxamt, amount(options[:tax] || 0)) - end - end - end - end -end diff --git a/test/remote/gateways/remote_payflow_express_nv_test.rb b/test/remote/gateways/remote_payflow_express_nv_test.rb deleted file mode 100644 index 164901944a7..00000000000 --- a/test/remote/gateways/remote_payflow_express_nv_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require File.dirname(__FILE__) + '/../../test_helper' - -class RemotePayflowNvTest < Test::Unit::TestCase - def setup - Base.gateway_mode = :test - - @gateway = PayflowExpressNvGateway.new(fixtures(:payflow)) - - @options = { :billing_address => { - :name => 'Cody Fauser', - :address1 => '1234 Shady Brook Lane', - :city => 'Ottawa', - :state => 'ON', - :country => 'CA', - :zip => '90210', - :phone => '555-555-5555' - }, - :email => 'cody@example.com' - } - end - - # Only works with a Payflow 2.0 account or by requesting the addition - # of Express checkout to an existing Payflow Pro account. This can be done - # by contacting Payflow sales. The PayPal account used must be a business - # account and the Payflow Pro account must be in Live mode in order for - # the tests to work correctly - def test_set_express_authorization - @options.update( - :return_url => 'http://example.com', - :cancel_return_url => 'http://example.com', - :email => 'Buyer1@paypal.com' - ) - response = @gateway.setup_authorization(500, @options) - puts response.inspect - assert response.success?, response.message - assert response.test? - assert !response.params['token'].blank? - end - - def test_set_express_purchase - @options.update( - :return_url => 'http://example.com', - :cancel_return_url => 'http://example.com', - :email => 'Buyer1@paypal.com' - ) - response = @gateway.setup_purchase(500, @options) - assert response.success?, response.message - assert response.test? - assert !response.params['token'].blank? - end -end diff --git a/test/remote/gateways/remote_payflow_nv_test.rb b/test/remote/gateways/remote_payflow_nv_test.rb deleted file mode 100644 index d2304f3f4bb..00000000000 --- a/test/remote/gateways/remote_payflow_nv_test.rb +++ /dev/null @@ -1,237 +0,0 @@ -require File.dirname(__FILE__) + '/../../test_helper' - -class RemotePayflowNvTest < Test::Unit::TestCase - def setup - Base.gateway_mode = :test - - @gateway = PayflowNvGateway.new(fixtures(:payflow)) - - @credit_card = credit_card('5105105105105100', - :type => 'master' - ) - - @options = { :billing_address => address, - :email => 'cody@example.com', - :customer => 'codyexample' - } - end - - def test_successful_purchase - assert response = @gateway.purchase(100000, @credit_card, @options) - assert_equal "Approved", response.message - assert_success response - assert response.test? - assert_not_nil response.authorization - end - - def test_declined_purchase - assert response = @gateway.purchase(210000, @credit_card, @options) - assert_equal 'Declined', response.message - assert_failure response - assert response.test? - end - - def test_successful_authorization - assert response = @gateway.authorize(100, @credit_card, @options) - assert_equal "Approved", response.message - assert_success response - assert response.test? - assert_not_nil response.authorization - end - - def test_authorize_and_capture - assert auth = @gateway.authorize(100, @credit_card, @options) - assert_success auth - assert_equal 'Approved', auth.message - assert auth.authorization - assert capture = @gateway.capture(100, auth.authorization) - assert_success capture - end - - def test_authorize_and_partial_capture - assert auth = @gateway.authorize(100 * 2, @credit_card, @options) - assert_success auth - assert_equal 'Approved', auth.message - assert auth.authorization - - assert capture = @gateway.capture(100, auth.authorization) - assert_success capture - end - - def test_failed_capture - assert response = @gateway.capture(100, '999') - assert_failure response - assert_equal 'Invalid tender', response.message - end - - def test_authorize_and_void - assert auth = @gateway.authorize(100, @credit_card, @options) - assert_success auth - assert_equal 'Approved', auth.message - assert auth.authorization - assert void = @gateway.void(auth.authorization) - assert_success void - end - - def test_invalid_login - gateway = PayflowNvGateway.new( - :login => '', - :password => '' - ) - assert response = gateway.purchase(100, @credit_card, @options) - assert_equal 'Invalid vendor account', response.message - assert_failure response - end - - def test_duplicate_request_id - request_id = Digest::MD5.hexdigest(rand.to_s) - @gateway.expects(:generate_unique_id).times(2).returns(request_id) - - response1 = @gateway.purchase(100, @credit_card, @options) - assert response1.success? - assert_nil response1.params['duplicate'] - - response2 = @gateway.purchase(100, @credit_card, @options) - assert response2.success? - assert response2.params['duplicate'], "Transaction was not marked duplicate." - end - - def test_create_recurring_profile - response = @gateway.recurring(1000, @credit_card, :periodicity => :monthly) - assert_success response - assert !response.params['profileid'].blank? - assert response.test? - end - - def test_create_recurring_profile_with_invalid_date - response = @gateway.recurring(1000, @credit_card, :periodicity => :monthly, :starting_at => Time.now) - assert_failure response - assert_equal 'Field format error: Start or next payment date must be a valid future date', response.message - assert response.params['profileid'].blank? - assert response.test? - end - - def test_create_and_cancel_recurring_profile - response = @gateway.recurring(1000, @credit_card, :periodicity => :monthly) - assert_success response - assert !response.params['profileid'].blank? - assert response.test? - - response = @gateway.cancel_recurring(response.params['profileid']) - assert_success response - assert response.test? - end - - def test_full_feature_set_for_recurring_profiles - # Test add - @options.update( - :periodicity => :weekly, - :payments => '12', - :starting_at => Time.now + 1.day, - :comment => "Test Profile" - ) - response = @gateway.recurring(100, @credit_card, @options) - assert_success response - assert_equal "Approved", response.params['respmsg'] - assert_equal "0", response.params['result'] - assert response.test? - assert !response.params['profileid'].blank? - @recurring_profile_id = response.params['profileid'] - - # Test modify - @options.update( - :periodicity => :monthly, - :starting_at => Time.now + 1.day, - :payments => '4', - :profileid => @recurring_profile_id - ) - response = @gateway.recurring(400, @credit_card, @options) - assert_equal "Approved", response.params['respmsg'] - assert_equal "0", response.params['result'] - assert_success response - assert response.test? - - # Test inquiry - response = @gateway.recurring_inquiry(@recurring_profile_id) - assert_equal "0", response.params['result'] - assert_success response - assert response.test? - - # Test payment history inquiry - response = @gateway.recurring_inquiry(@recurring_profile_id, :history => true) - assert_equal '0', response.params['result'] - assert_success response - assert response.test? - - # Test cancel - response = @gateway.cancel_recurring(@recurring_profile_id) - assert_equal "Approved", response.params['respmsg'] - assert_equal "0", response.params['result'] - assert_success response - assert response.test? - end - - # Note that this test will only work if you enable reference transactions!! - def test_reference_purchase - assert response = @gateway.purchase(10000, @credit_card, @options) - assert_equal "Approved", response.message - assert_success response - assert response.test? - assert_not_nil pn_ref = response.authorization - - # now another purchase, by reference - assert response = @gateway.purchase(10000, pn_ref) - assert_equal "Approved", response.message - assert_success response - assert response.test? - end - - def test_recurring_with_initial_authorization - response = @gateway.recurring(1000, @credit_card, - :periodicity => :monthly, - :initial_transaction => { - :type => :authorization - } - ) - - assert_success response, "Missing response" - assert !response.params['profileid'].blank?, "Profile id is not present" - assert response.test? - end - - def test_recurring_with_initial_authorization - response = @gateway.recurring(1000, @credit_card, - :periodicity => :monthly, - :initial_transaction => { - :type => :purchase, - :amount => 500 - } - ) - - assert_success response - assert !response.params['profileid'].blank?, "Profile id is blank." - assert response.test? - end - - def test_purchase_and_referenced_credit - amount = 100 - - assert purchase = @gateway.purchase(amount, @credit_card, @options) - assert_success purchase - assert_equal 'Approved', purchase.message - assert !purchase.authorization.blank? - - assert credit = @gateway.credit(amount, purchase.authorization) - assert_success credit - end - - # The default security setting for Payflow Pro accounts is Allow - # non-referenced credits = No. - # - # Non-referenced credits will fail with Result code 117 (failed the security - # check) unless Allow non-referenced credits = Yes in PayPal manager - def test_purchase_and_non_referenced_credit - assert credit = @gateway.credit(100, @credit_card, @options) - assert_success credit - end -end diff --git a/test/remote/gateways/remote_paypal_express_nv_test.rb b/test/remote/gateways/remote_paypal_express_nv_test.rb deleted file mode 100644 index 11fab897171..00000000000 --- a/test/remote/gateways/remote_paypal_express_nv_test.rb +++ /dev/null @@ -1,50 +0,0 @@ -require File.dirname(__FILE__) + '/../../test_helper' - -class PaypalExpressNvTest < Test::Unit::TestCase - def setup - Base.gateway_mode = :test - - @gateway = PaypalExpressNvGateway.new(fixtures(:paypal_signature)) - - @options = { - :order_id => '230000', - :email => 'buyer@jadedpallet.com', - :billing_address => { :name => 'Fred Brooks', - :address1 => '1234 Penny Lane', - :city => 'Jonsetown', - :state => 'NC', - :country => 'US', - :zip => '23456' - } , - :description => 'Stuff that you purchased, yo!', - :ip => '10.0.0.1', - :return_url => 'http://example.com/return', - :cancel_return_url => 'http://example.com/cancel' - } - end - - def test_set_express_authorization - @options.update( - :return_url => 'http://example.com', - :cancel_return_url => 'http://example.com', - :email => 'Buyer1@paypal.com' - ) - response = @gateway.setup_authorization(500, @options) - assert response.success? - assert response.test? - assert !response.params['token'].blank? - end - - def test_set_express_purchase - @options.update( - :return_url => 'http://example.com', - :cancel_return_url => 'http://example.com', - :email => 'Buyer1@paypal.com' - ) - response = @gateway.setup_purchase(500, @options) - assert response.success? - assert response.test? - assert !response.params['token'].blank? - end - -end diff --git a/test/remote/gateways/remote_paypal_nv_test.rb b/test/remote/gateways/remote_paypal_nv_test.rb deleted file mode 100644 index aa72120b780..00000000000 --- a/test/remote/gateways/remote_paypal_nv_test.rb +++ /dev/null @@ -1,228 +0,0 @@ -require File.dirname(__FILE__) + '/../../test_helper' - -class PaypalNvTest < Test::Unit::TestCase - def setup - Base.gateway_mode = :test - - @gateway = PaypalNvGateway.new(fixtures(:paypal_certificate)) - - @credit_card = credit_card("4683075410516684") - - @options = { - :order_id => generate_unique_id, - :email => 'tester@esdlc.com', - :billing_address => { - :name => 'Fred Brooks', - :address1 => '1234 Penny Lane', - :city => 'Jonsetown', - :state => 'NC', - :country => 'US', - :zip => '23456', - } , - :description => 'Stuff that you purchased, yo!', - :ip => '10.0.0.1' - } - - @line_items = [ - { :sku => 1, :description => "foo", :quantity => 3, :amount => 500 }, - { :sku => 2, :description => "bar", :quantity => 2, :tax => 20, :amount => 500 } - ] - - - @subtotal = @line_items.inject(0){ |sum, item| sum += (item[:quantity] * item[:amount]) } - @tax = @line_items.inject(0){ |sum, item| sum += (item[:quantity] * item[:tax].to_i) } - @amount = @subtotal + @tax - - # test re-authorization, auth-id must be more than 3 days old. - # each auth-id can only be reauthorized and tested once. - # leave it commented if you don't want to test reauthorization. - # - #@three_days_old_auth_id = "9J780651TU4465545" - #@three_days_old_auth_id2 = "62503445A3738160X" - end - - def test_successful_purchase - response = @gateway.purchase(@amount, @credit_card, @options) - assert_success response - assert_false response.authorization.blank? - assert_equal '25.40', response.params['amt'] - assert_equal 'X', response.avs_result['code'] - assert_equal 'M', response.cvv_result['code'] - assert_equal 'USD', response.params['currencycode'] - end - - def test_successful_purchase_in_cad - @options[:currency] = 'CAD' - - response = @gateway.purchase(@amount, @credit_card, @options) - assert_success response - assert_false response.authorization.blank? - assert_equal '25.40', response.params['amt'] - assert_equal 'X', response.avs_result['code'] - assert_equal 'M', response.cvv_result['code'] - assert_equal 'CAD', response.params['currencycode'] - end - - def test_successful_authorization - response = @gateway.purchase(@amount, @credit_card, @options) - assert_success response - assert_false response.authorization.blank? - assert_equal '25.40', response.params['amt'] - assert_equal 'X', response.avs_result['code'] - assert_equal 'M', response.cvv_result['code'] - assert_equal 'USD', response.params['currencycode'] - end - - def test_successful_purchase_with_line_items - add_line_items(@options) - response = @gateway.purchase(@amount, @credit_card, @options) - assert_success response - assert_false response.authorization.blank? - end - - def test_successful_purchase_details_with_line_items_shipping_and_handling - add_line_items(@options) - - @shipping = 100 - @handling = 200 - @amount += (@shipping + @handling) - - @options[:subtotal] = @subtotal - @options[:shipping] = @shipping - @options[:handling] = @handling - - response = @gateway.purchase(@amount, @credit_card, @options) - assert_success response - assert_false response.authorization.blank? - end - - def test_successful_purchase_no_shipping - @options[:no_shipping] = true - response = @gateway.purchase(@amount, @credit_card, @options) - assert_success response - assert_false response.authorization.blank? - end - - def test_successful_purchase_with_api_signature - gateway = PaypalNvGateway.new(fixtures(:paypal_signature)) - response = gateway.purchase(@amount, @credit_card, @options) - assert_success response - assert_false response.authorization.blank? - end - - def test_failed_purchase - @credit_card.number = '234234234234' - response = @gateway.purchase(@amount, @credit_card, @options) - assert_failure response - assert_nil response.authorization - assert_equal "This transaction cannot be processed. Please enter a valid credit card number and type.", response.message - end - - def test_failed_authorization - @credit_card.number = '234234234234' - response = @gateway.authorize(@amount, @credit_card, @options) - assert_failure response - assert_nil response.authorization - end - - def test_successful_authorization_and_capture - auth = @gateway.authorize(@amount, @credit_card, @options) - assert_success auth - - capture = @gateway.capture(@amount, auth.authorization) - assert_success capture - assert_false capture.authorization.blank? - assert_equal "25.40", capture.params["amt"] - end - - def test_failed_capture - response = @gateway.capture(@amount, 'invalid') - assert_failure response - assert_nil response.authorization - assert_equal "The transaction id is not valid", response.message - end - - def test_successful_voiding - auth = @gateway.authorize(@amount, @credit_card, @options) - assert_success auth - - void = @gateway.void(auth.authorization, :description => 'Cancelled') - assert_success void - assert_false void.authorization.blank? - end - - def test_purchase_and_full_credit - purchase = @gateway.purchase(@amount, @credit_card, @options) - assert_success purchase - - credit = @gateway.credit(@amount, purchase.authorization, :description => 'Sorry') - assert_success credit - assert_equal '25.40', credit.params['grossrefundamt'] - end - - def test_failed_voiding - response = @gateway.void('foo') - assert_failure response - end - - def test_successful_transfer - response = @gateway.purchase(@amount, @credit_card, @options) - assert_success response - - response = @gateway.transfer(@amount, 'joe@example.com', :subject => 'Your money', :note => 'Thanks for taking care of that') - assert_success response - end - - def test_failed_transfer - # paypal allows a max transfer of $10,000 - response = @gateway.transfer(1000001, 'joe@example.com') - assert_failure response - end - - def test_successful_multiple_transfer - response = @gateway.purchase(900, @credit_card, @options) - assert_success response - - response = @gateway.transfer([@amount, 'joe@example.com'], - [600, 'jane@example.com', {:note => 'Thanks for taking care of that'}], - :subject => 'Your money') - assert_success response - end - - def test_maximum_multiple_transfer - response = @gateway.purchase(25100, @credit_card, @options) - assert_success response - - # You can only include up to 250 recipients - recipients = (1..250).collect {|i| [100, "person#{i}@example.com"]} - response = @gateway.transfer(*recipients) - assert_success response - end - - def test_successful_reauthorization - return unless @three_days_old_auth_id - auth = @gateway.reauthorize(1000, @three_days_old_auth_id) - assert_success auth - assert auth.authorization - - response = @gateway.capture(1000, auth.authorization) - assert_success response - assert response.params['transactionid'] - assert_equal '10.00', response.params['gross_amount'] - assert_equal 'USD', response.params['gross_amount_currency_id'] - end - - def test_failed_reauthorization - return unless @three_days_old_auth_id2 # was authed for $10, attempt $20 - auth = @gateway.reauthorize(2000, @three_days_old_auth_id2) - assert_false auth? - assert !auth.authorization - end - - private - def add_line_items(options) - options[:line_items] = @line_items - options[:tax] = @tax - options[:subtotal] = @subtotal - end -end diff --git a/test/unit/gateways/payflow_express_nv_test.rb b/test/unit/gateways/payflow_express_nv_test.rb deleted file mode 100644 index 5b4912098bb..00000000000 --- a/test/unit/gateways/payflow_express_nv_test.rb +++ /dev/null @@ -1,156 +0,0 @@ -require File.dirname(__FILE__) + '/../../test_helper' - -class PayflowExpressNvTest < Test::Unit::TestCase - TEST_REDIRECT_URL = 'https://test-expresscheckout.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=1234567890' - LIVE_REDIRECT_URL = 'https://www.paypal.com/cgibin/webscr?cmd=_express-checkout&token=1234567890' - - TEST_REDIRECT_URL_WITHOUT_REVIEW = "#{TEST_REDIRECT_URL}&useraction=commit" - LIVE_REDIRECT_URL_WITHOUT_REVIEW = "#{LIVE_REDIRECT_URL}&useraction=commit" - - def setup - Base.gateway_mode = :test - - @gateway = PayflowExpressNvGateway.new( - :login => 'LOGIN', - :password => 'PASSWORD' - ) - - @address = { :address1 => '1234 My Street', - :address2 => 'Apt 1', - :company => 'Widgets Inc', - :city => 'Ottawa', - :state => 'ON', - :zip => 'K1C2N6', - :country => 'Canada', - :phone => '(555)555-5555' - } - end - - def teardown - Base.gateway_mode = :test - end - - def test_using_test_mode - assert @gateway.test? - end - - def test_overriding_test_mode - Base.gateway_mode = :production - - gateway = PayflowExpressGateway.new( - :login => 'LOGIN', - :password => 'PASSWORD', - :test => true - ) - - assert gateway.test? - end - - def test_using_production_mode - Base.gateway_mode = :production - - gateway = PayflowExpressGateway.new( - :login => 'LOGIN', - :password => 'PASSWORD' - ) - - assert !gateway.test? - end - - def test_live_redirect_url - Base.gateway_mode = :production - assert_equal LIVE_REDIRECT_URL, @gateway.redirect_url_for('1234567890') - end - - def test_test_redirect_url - assert_equal TEST_REDIRECT_URL, @gateway.redirect_url_for('1234567890') - end - - def test_live_redirect_url_without_review - Base.gateway_mode = :production - assert_equal LIVE_REDIRECT_URL_WITHOUT_REVIEW, @gateway.redirect_url_for('1234567890', :review => false) - end - - def test_test_redirect_url_without_review - assert_equal :test, Base.gateway_mode - assert_equal TEST_REDIRECT_URL_WITHOUT_REVIEW, @gateway.redirect_url_for('1234567890', :review => false) - end - - def test_invalid_get_express_details_request - @gateway.expects(:ssl_post).returns(invalid_get_express_details_response) - response = @gateway.details_for('EC-2OPN7UJGFWK9OYFV') - assert_failure response - assert response.test? - assert_equal 'Field format error: Invalid Token', response.message - end - - def test_get_express_details - @gateway.expects(:ssl_post).returns(successful_get_express_details_response) - response = @gateway.details_for('EC-C02HPKS9A2FF46QN') - - assert_instance_of PayflowExpressNvResponse, response - assert_success response - assert response.test? - - assert_equal 'EC-C02HPKS9A2FF46QN', response.token - assert_equal '12345678901234567', response.payer_id - assert_equal 'Buyer1@paypal.com', response.email - assert_equal 'Joe Smith', response.full_name, "Full name not valid." - assert_equal 'US', response.payer_country - - assert address = response.address - assert_equal 'Joe Smith', address['name'] - assert_nil address['company'] - assert_equal '111 Main St.', address['address1'] - assert_nil address['address2'] - assert_equal 'San Jose', address['city'] - assert_equal 'CA', address['state'] - assert_equal '95100', address['zip'] - assert_equal 'US', address['country'] - assert_nil address['phone'] - end - - def test_set_express_checkout - @gateway.expects(:ssl_post).returns(successful_set_express) - options = {} - options[:return_url] = "http://www.example.com/confirm" - options[:cancel_return_url] = "http://www.example.com/cancel" - - response = @gateway.setup_authorization(4000, options) - assert_instance_of PayflowExpressNvResponse, response - assert_equal "0", response.params["result"] - assert_equal "Approved", response.params["respmsg"] - assert_equal "EC-17C76533PL706494P", response.params["token"] - end - - def test_set_express_checkout_missing_return_url - options = {} - assert_raise ArgumentError do - response = @gateway.setup_authorization(4000, options) - end - end - - - - #def test_button_source - # xml = Builder::XmlMarkup.new - # @gateway.send(:add_paypal_details, xml, {}) - # xml_doc = REXML::Document.new(xml.target!) - # assert_equal 'ActiveMerchant', REXML::XPath.first(xml_doc, '/PayPal/ButtonSource').text - #end - - private - - def successful_get_express_details_response - 'RESULT=0&RESPMSG=Approved&TOKEN=EC-C02HPKS9A2FF46QN&PAYERID=12345678901234567&CORRELATIONID=9c3706997455e&EMAIL=Buyer1@paypal.com&PAYERSTATUS=verified&FIRSTNAME=Joe&LASTNAME=Smith&SHIPTOSTREET=111 Main St.&SHIPTOCITY=San Jose&SHIPTOSTATE=CA&SHIPTOZIP=95100&SHIPTOCOUNTRY=US' - end - - def invalid_get_express_details_response - 'RESULT=7&RESPMSG=Field format error: Invalid Token' - end - - def successful_set_express - "RESULT=0&RESPMSG=Approved&TOKEN=EC-17C76533PL706494P" - end - -end diff --git a/test/unit/gateways/payflow_nv_test.rb b/test/unit/gateways/payflow_nv_test.rb deleted file mode 100644 index eb57c46f189..00000000000 --- a/test/unit/gateways/payflow_nv_test.rb +++ /dev/null @@ -1,238 +0,0 @@ -require File.dirname(__FILE__) + '/../../test_helper' - -class PayflowNvTest < Test::Unit::TestCase - def setup - Base.mode = :test - - @gateway = PayflowNvGateway.new( - :login => 'LOGIN', - :password => 'PASSWORD' - ) - - @amount = 100 - @credit_card = credit_card('4242424242424242') - @options = { :billing_address => address } - end - - def test_successful_authorization - @gateway.stubs(:ssl_post).returns(successful_authorization_response) - - assert response = @gateway.authorize(@amount, @credit_card, @options) - assert_equal "Approved", response.message - assert_success response - assert response.test? - assert_equal "VUJN1A6E11D9", response.authorization - end - - def test_failed_authorization - @gateway.stubs(:ssl_post).returns(failed_authorization_response) - - assert response = @gateway.authorize(@amount, @credit_card, @options) - assert_equal "Declined", response.message - assert_failure response - assert response.test? - end - - def test_avs_result - @gateway.expects(:ssl_post).returns(successful_authorization_response) - - response = @gateway.purchase(@amount, @credit_card, @options) - assert_equal 'Y', response.avs_result['postal_match'] - assert_equal 'Y', response.avs_result['street_match'] - assert_equal 'Y', response.avs_result['code'] - end - - def test_partial_avs_match - @gateway.expects(:ssl_post).returns(successful_duplicate_response) - - response = @gateway.purchase(@amount, @credit_card, @options) - assert_equal 'Y', response.avs_result['street_match'] - assert_equal 'N', response.avs_result['postal_match'] - assert_equal 'A', response.avs_result['code'] - end - - def test_cvv_result - @gateway.expects(:ssl_post).returns(successful_authorization_response) - - response = @gateway.purchase(@amount, @credit_card, @options) - assert_equal 'Y', response.cvv_result['code'] - end - - def test_using_test_mode - assert @gateway.test? - end - - def test_overriding_test_mode - Base.gateway_mode = :production - - gateway = PayflowNvGateway.new( - :login => 'LOGIN', - :password => 'PASSWORD', - :test => true - ) - - assert gateway.test? - end - - def test_using_production_mode - Base.gateway_mode = :production - - gateway = PayflowNvGateway.new( - :login => 'LOGIN', - :password => 'PASSWORD' - ) - - assert !gateway.test? - end - - def test_partner_class_accessor - assert_equal 'PayPal', PayflowNvGateway.partner - gateway = PayflowNvGateway.new(:login => 'test', :password => 'test') - assert_equal 'PayPal', gateway.options[:partner] - end - - def test_passed_in_partner_overrides_class_accessor - assert_equal 'PayPal', PayflowNvGateway.partner - gateway = PayflowNvGateway.new(:login => 'test', :password => 'test', :partner => 'PayPalUk') - assert_equal 'PayPalUk', gateway.options[:partner] - end - - def test_express_instance - PayflowNvGateway.certification_id = '123456' - gateway = PayflowNvGateway.new( - :login => 'test', - :password => 'password' - ) - express = gateway.express - assert_instance_of PayflowExpressNvGateway, express - assert_equal '123456', express.options[:certification_id] - assert_equal 'PayPal', express.options[:partner] - assert_equal 'test', express.options[:login] - assert_equal 'password', express.options[:password] - end - - def test_default_currency - assert_equal 'USD', PayflowNvGateway.default_currency - end - - def test_supported_countries - assert_equal ['US', 'CA', 'SG', 'AU'], PayflowNvGateway.supported_countries - end - - def test_supported_card_types - assert_equal [:visa, :master, :american_express, :jcb, :discover, :diners_club], PayflowNvGateway.supported_cardtypes - end - - def test_initial_recurring_transaction_missing_parameters - assert_raises ArgumentError do - response = @gateway.recurring(@amount, @credit_card, - :periodicity => :monthly, - :initial_transaction => { } - ) - end - end - - def test_initial_purchase_missing_amount - assert_raises ArgumentError do - response = @gateway.recurring(@amount, @credit_card, - :periodicity => :monthly, - :initial_transaction => { :amount => :purchase } - ) - end - end - - def test_successful_recurring_action - @gateway.stubs(:ssl_post).returns(successful_recurring_add_response) - - response = @gateway.recurring(@amount, @credit_card, :periodicity => :monthly) - - assert_instance_of PayflowNvResponse, response - assert_success response - assert response.test? - assert_equal "RWY504915344", response.authorization - assert_equal 'RP000000001234', response.profile_id - end - - def test_recurring_profile_payment_history_inquiry - @gateway.stubs(:ssl_post).returns(successful_payment_history_recurring_response) - - response = @gateway.recurring_inquiry('RT0000000009', :history => true) - assert_equal 6, response.payment_history.size - assert_equal '1', response.payment_history.first['payment_num'] - assert_equal '1.00', response.payment_history.first['amt'] - end - - def test_recurring_profile_payment_history_inquiry_contains_the_proper_xml - request = @gateway.send( :build_recurring_request, :inquiry, nil, :profile_id => 'RT0000000009', :history => true) - assert_equal "Y", request[:paymenthistory] - end - - #def test_format_issue_number - # xml = Builder::XmlMarkup.new - # credit_card = credit_card("5641820000000005", - # :type => "switch", - # :issue_number => 1 - # ) - # - # @gateway.send(:add_credit_card, xml, credit_card) - # doc = REXML::Document.new(xml.target!) - # node = REXML::XPath.first(doc, '/Card/ExtData') - # assert_equal '01', node.attributes['Value'] - #end - - def test_duplicate_response_flag - @gateway.expects(:ssl_post).returns(successful_duplicate_response) - - response = @gateway.authorize(@amount, @credit_card, @options) - assert_success response - assert response.params['duplicate'] - end - - def test_ensure_gateway_uses_safe_retry - assert @gateway.retry_safe - end - - # This test fails because we don't yet parse the XML from the response - # def test_response_under_review_by_fraud_service - # @gateway.expects(:ssl_post).returns(fraud_review_response) - # - # response = @gateway.purchase(@amount, @credit_card) - # assert_failure response - # assert response.fraud_review? - # assert_equal "", response.message - # end - - private - - def successful_recurring_add_response - "RESULT=0&RPREF=RWY504915344&PROFILEID=RP000000001234&RESPMSG=Approved&TRXRESULT=0&TRXPNREF=VWYA04915345&TRXRESPMSG=Approved&AUTHCODE=489PNI" - end - - def successful_payment_history_recurring_response - res = "RESULT=0&RPREF=RKM500141021&PROFILEID=RT0000000100&" - res << "P_PNREF1=VWYA06156256&P_TRANSTIME1=21-May-04 04:47PM&P_RESULT1=0&P_TENDER1=C&P_AMT1=1.00&P_TRANSTATE1=8&" - res << "P_PNREF2=VWYA06156269&P_TRANSTIME2=27-May-04 01:19PM&P_RESULT2=0&P_TENDER2=C&P_AMT2=1.00&P_TRANSTATE2=8&" - res << "P_PNREF3=VWYA06157650&P_TRANSTIME3=03-Jun-04 04:47PM&P_RESULT3=0&P_TENDER3=C&P_AMT3=1.00&P_TRANSTATE3=8&" - res << "P_PNREF4=VWYA06157668&P_TRANSTIME4=10-Jun-04 04:47PM&P_RESULT4=0&P_TENDER4=C&P_AMT4=1.00&P_TRANSTATE4=8&" - res << "P_PNREF5=VWYA06158795&P_TRANSTIME5=17-Jun-04 04:47PM&P_RESULT5=0&P_TENDER5=C&P_AMT5=1.00&P_TRANSTATE5=8&" - res << "P_PNREF6=VJLA00000060&P_TRANSTIME6=05-Aug-04 05:54PM&P_RESULT6=0&P_TENDER6=C&P_AMT6=1.00&P_TRANSTATE6=1" - res - end - - def successful_authorization_response - "RESULT=0&PNREF=VUJN1A6E11D9&RESPMSG=Approved&AUTHCODE=123456&AVSADDR=Y&AVSZIP=Y&CVV2MATCH=Y&IAVS=Y&PROCAVS=Y" - end - - def failed_authorization_response - "RESULT=12&PNREF=VXYZ01234567&RESPMSG=Declined&BALANCE=99.00&AVSADDR=Y&AVSZIP=N" - end - - def successful_duplicate_response - "RESULT=0&PNREF=VUJN1A6E11D9&RESPMSG=Approved&AUTHCODE=123456&AVSADDR=Y&AVSZIP=N&CVV2MATCH=Y&HOSTCODE=A&PROCAVS=A&PROCCVV2=M&DATE_TO_SETTLE=2008-02-27 17:40:30&IAVS=N&DUPLICATE=1" - end - - def fraud_review_response - 'RESULT=126&PNREF=V79A0D0CA828&RESPMSG=Under review by Fraud Service&AUTHCODE=505PNI&AVSADDR=Y&AVSZIP=Y&CVV2MATCH=Y&HOSTCODE=A&PROCAVS=Y&PROCCVV2=M&IAVS=N&PREFPSMSG=Review: More than one rule was triggered for Review&FPS_PREXMLDATA[2830]=1818InternationalOrderInternational Shipping/Billing AddressRInternational billing and shipping addresses4646AccountNumberVelocityAccount Number VelocityRThe card used in this transaction has been used at least 6 times recentlyCardVelocityTrigger6FPSID10586727TRANS_DATE3/3/2008 8:20:18PNREFIDV70A0D0CA828FPSID10586664TRANS_DATE3/3/2008 8:18:16PNREFIDV78A0D0CA6B8FPSID10586617TRANS_DATE3/3/2008 8:15:30PNREFIDV79A0D0CA4FBFPSID10586594TRANS_DATE3/3/2008 8:14:45PNREFIDV19A0D9FAE53FPSID10586552TRANS_DATE3/3/2008 8:12:29PNREFIDV18A0D9FAE41FPSID10585793TRANS_DATE3/3/2008 7:34:20PNREFIDV19A0D9FADAC&POSTFPSMSG=Review' - end - -end diff --git a/test/unit/gateways/paypal_express_nv_test.rb b/test/unit/gateways/paypal_express_nv_test.rb deleted file mode 100644 index a356b04e3b9..00000000000 --- a/test/unit/gateways/paypal_express_nv_test.rb +++ /dev/null @@ -1,185 +0,0 @@ -require File.dirname(__FILE__) + '/../../test_helper' - -class PaypalExpressNvTest < Test::Unit::TestCase - API_VER = 50.0000 - BUILD_NUM = 1 - DEBUG_TOKEN = 1 - - TEST_REDIRECT_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=1234567890' - LIVE_REDIRECT_URL = 'https://www.paypal.com/cgibin/webscr?cmd=_express-checkout&token=1234567890' - TEST_REDIRECT_URL_WITHOUT_REVIEW = "#{TEST_REDIRECT_URL}&useraction=commit" - LIVE_REDIRECT_URL_WITHOUT_REVIEW = "#{LIVE_REDIRECT_URL}&useraction=commit" - - def setup - @gateway = PaypalExpressNvGateway.new( - :login => 'cody', - :password => 'test', - :pem => 'PEM' - ) - - @address = { :address1 => '1234 My Street', - :address2 => 'Apt 1', - :company => 'Widgets Inc', - :city => 'Ottawa', - :state => 'ON', - :zip => 'K1C2N6', - :country => 'Canada', - :phone => '(555)555-5555' - } - - Base.gateway_mode = :test - end - - def teardown - Base.gateway_mode = :test - end - - def test_live_redirect_url - Base.gateway_mode = :production - assert_equal LIVE_REDIRECT_URL, @gateway.redirect_url_for('1234567890') - end - - def test_force_sandbox_redirect_url - Base.gateway_mode = :production - - gateway = PaypalExpressNvGateway.new( - :login => 'cody', - :password => 'test', - :pem => 'PEM', - :test => true - ) - - assert gateway.test? - assert_equal TEST_REDIRECT_URL, gateway.redirect_url_for('1234567890') - end - - def test_test_redirect_url - assert_equal :test, Base.gateway_mode - assert_equal TEST_REDIRECT_URL, @gateway.redirect_url_for('1234567890') - end - - def test_live_redirect_url_without_review - Base.gateway_mode = :production - assert_equal LIVE_REDIRECT_URL_WITHOUT_REVIEW, @gateway.redirect_url_for('1234567890', :review => false) - end - - def test_test_redirect_url_without_review - assert_equal :test, Base.gateway_mode - assert_equal TEST_REDIRECT_URL_WITHOUT_REVIEW, @gateway.redirect_url_for('1234567890', :review => false) - end - - def test_get_express_details - @gateway.expects(:ssl_post).returns(successful_details_response) - response = @gateway.details_for('EC-3DJ78083ES565113B') - - assert_instance_of PaypalExpressNvResponse, response - assert response.success? - assert response.test? - - assert_equal 'EC-3DJ78083ES565113B', response.token - assert_equal '95HR9CM6D56Q2', response.payer_id - assert_equal 'abcdef@anyemail.com', response.email - - assert address = response.address - assert_equal 'John Smith', address['name'] - assert_equal 'foo inc.', address['company'] - assert_equal '144 Main St.', address['address1'] - assert_nil address['address2'] - assert_equal 'San Jose', address['city'] - assert_equal 'CA', address['state'] - assert_equal '99221', address['zip'] - assert_equal 'US', address['country'] - assert_nil address['phone'] - end - - def test_authorization - @gateway.expects(:ssl_post).returns(successful_authorization_response) - response = @gateway.authorize(300, :token => 'EC-6WS104951Y388951L', :payer_id => 'FWRVKNRRZ3WUC') - assert response.success? - assert_not_nil response.authorization - assert response.test? - end - - def test_default_payflow_currency - assert_equal 'USD', PayflowExpressNvGateway.default_currency - end - - def test_default_partner - assert_equal 'PayPal', PayflowExpressNvGateway.partner - end - - def test_uk_partner - assert_equal 'PayPalUk', PayflowExpressUkGateway.partner - end - - def test_handle_non_zero_amount - data = @gateway.send(:build_setup_request, 'SetExpressCheckout', 50, {}) - assert_equal '0.50', data[:amt] - end - - def test_handles_zero_amount - data = @gateway.send(:build_setup_request, 'SetExpressCheckout', 0, {}) - assert_equal '0.00', data[:amt] - end - - def test_handle_locale_code - data = @gateway.send(:build_setup_request, 'SetExpressCheckout', 0, { :locale => 'GB' }) - assert_equal 'GB', data[:locale] - end - - def test_supported_countries - assert_equal ['US'], PaypalExpressNvGateway.supported_countries - end - - def test_button_source - PaypalExpressNvGateway.application_id = 'ActiveMerchant_EC' - - data = @gateway.send(:build_sale_or_authorization_request, 'Test', 100, {}) - assert_equal 'ActiveMerchant_EC', data[:buttonsource] - end - - private - def timestamp - Time.new.strftime("%Y-%m-%dT%H:%M:%SZ") - end - - def successful_response_fields - resp = "ACK=Success&TIMESTAMP=#{timestamp}&" - resp << "CORRELATIONID=#{DEBUG_TOKEN}&" - resp << "VERSION=#{API_VER}&BUILD=#{BUILD_NUM}" - end - - def successful_setup_response - resp = successful_response_fields - resp << "&TOKEN=EC-3DJ78083ES565113B" - end - - def successful_details_response - resp = successful_response_fields - resp << "&TOKEN=EC-3DJ78083ES565113B&EMAIL=abcdef@anyemail.com" - resp << "&PAYERID=95HR9CM6D56Q2&PAYERSTATUS=verified&FIRSTNAME=John" - resp << "&LASTNAME=Smith&COUNTRYCODE=US" - resp << "&SHIPTONAME=John Smith&SHIPTOSTREET=144+Main+St." - resp << "&SHIPTOCITY=San+Jose&SHIPTOSTATE=CA&SHIPTOCOUNTRYCODE=US" - resp << "&SHIPTOZIP=99221&ADDRESSID=PayPal" - resp << "&ADDRESSSTATUS=Confirmed&BUSINESS=foo inc." - end - - def successful_authorization_response - resp = successful_response_fields - resp << "&TOKEN=EC-30P862430W113011F" - resp << "&TRANSACTIONID=4D479374VP578364Y&TRANSACTIONTYPE=expresscheckout" - resp << "&PAYMENTTYPE=instant&ORDERTIME=2006-08-22T22:02:42Z&AMT=10.00" - resp << "&CURRENCYCODE=USD&TAXAMT=0.00&PAYMENTSTATUS=Pending" - resp << "&PENDINGREASON=authorization&REASONCODE=None" - end - - def successful_sale_response - resp = successful_response_fields - resp << "&TOKEN=EC-0E881823PA052770A" - resp << "&TRANSACTIONID=8SC56973LM923823H&TRANSACTIONTYPE=expresscheckout" - resp << "&PAYMENTTYPE=instant&ORDERTIME=2006-08-22T20:16:05Z&AMT=10.00" - resp << "&CURRENCYCODE=USD&FEEAMT=0.59&TAXAMT=0.00" - resp << "&PAYMENTSTATUS=Completed&PENDINGREASON=None&REASONCODE=None" - end -end diff --git a/test/unit/gateways/paypal_nv_test.rb b/test/unit/gateways/paypal_nv_test.rb deleted file mode 100644 index bfa0e154934..00000000000 --- a/test/unit/gateways/paypal_nv_test.rb +++ /dev/null @@ -1,272 +0,0 @@ -require File.dirname(__FILE__) + '/../../test_helper' - -class PaypalNvTest < Test::Unit::TestCase - API_VER = 50.0000 - BUILD_NUM = 1 - DEBUG_TOKEN = 1 - def setup - Base.mode = :test - PaypalNvGateway.pem_file = nil - - @amount = 100 - @gateway = PaypalNvGateway.new( - :login => 'cody', - :password => 'test', - :pem => 'PEM' - ) - - @credit_card = credit_card('4242424242424242') - @options = { :billing_address => address, :ip => '127.0.0.1' } - end - - def test_no_ip_address - assert_raise(ArgumentError){ @gateway.purchase(@amount, @credit_card, :billing_address => address)} - end - - def test_successful_purchase - @gateway.expects(:ssl_post).returns(successful_purchase_response) - - assert response = @gateway.purchase(@amount, @credit_card, @options) - assert_instance_of Response, response - assert_success response - assert_equal '9CX07910UV614511L', response.authorization - assert response.test? - end - - def test_failed_purchase - @gateway.expects(:ssl_post).returns(failed_purchase_response) - - assert response = @gateway.purchase(@amount, @credit_card, @options) - assert_instance_of Response, response - assert_failure response - assert response.test? - end - - def test_reauthorization - @gateway.expects(:ssl_post).returns(successful_reauthorization_response) - response = @gateway.reauthorize(@amount, '32J876265E528623B') - assert response.success? - assert_equal('1TX27389GX108740X', response.authorization) - assert response.test? - end - - def test_amount_style - assert_equal '10.34', @gateway.send(:amount, 1034) - - assert_raise(ArgumentError) do - @gateway.send(:amount, '10.34') - end - end - - def test_paypal_timeout_error - @gateway.stubs(:ssl_post).returns(paypal_timeout_error_response) - response = @gateway.purchase(@amount, @credit_card, @options) - assert_equal "Internal Error.", response.params['l_shortmessage0'] - assert_equal "Timeout processing request.", response.params['l_longmessage0'] - assert_equal "Timeout processing request.", response.message - end - - def test_pem_file_accessor - PaypalNvGateway.pem_file = '123456' - gateway = PaypalNvGateway.new(:login => 'test', :password => 'test') - assert_equal '123456', gateway.options[:pem] - end - - def test_passed_in_pem_overrides_class_accessor - PaypalNvGateway.pem_file = '123456' - gateway = PaypalNvGateway.new(:login => 'test', :password => 'test', :pem => 'Clobber') - assert_equal 'Clobber', gateway.options[:pem] - end - - def test_ensure_options_are_transferred_to_express_instance - PaypalNvGateway.pem_file = '123456' - gateway = PaypalNvGateway.new(:login => 'test', :password => 'password') - express = gateway.express - assert_instance_of PaypalExpressNvGateway, express - assert_equal 'test', express.options[:login] - assert_equal 'password', express.options[:password] - assert_equal '123456', express.options[:pem] - end - - def test_supported_countries - assert_equal ['US'], PaypalNvGateway.supported_countries - end - - def test_supported_card_types - assert_equal [:visa, :master, :american_express, :discover], PaypalNvGateway.supported_cardtypes - end - - def test_button_source - PaypalNvGateway.application_id = 'ActiveMerchant_DC' - - data = @gateway.send(:build_sale_or_authorization_request, 'Test', @amount, @credit_card, {}) - assert_equal 'ActiveMerchant_DC', data[:buttonsource] - end - - def test_tax_shipping_handling_not_added_without_subtotal - data = @gateway.send(:build_sale_or_authorization_request, 'Authorization', @amount, @credit_card, {}) - - assert_nil data[:itemamt] - assert_nil data[:taxamt] - assert_nil data[:shippingamt] - assert_nil data[:handlingamt] - end - - def test_adding_subtotal_adds_tax_shipping_handling - data = @gateway.send(:build_sale_or_authorization_request, 'Authorization', @amount, @credit_card, :subtotal => 100) - - assert_equal '1.00', data[:itemamt] - assert_equal '0.00', data[:taxamt] - assert_equal '0.00', data[:shippingamt] - assert_equal '0.00', data[:handlingamt] - end - - def test_item_total_shipping_handling_and_tax - data = @gateway.send(:build_sale_or_authorization_request, 'Authorization', @amount, @credit_card, - :tax => @amount, - :shipping => @amount, - :handling => @amount, - :subtotal => 200 - ) - - assert_equal "2.00", data[:itemamt] - assert_equal "1.00", data[:taxamt] - assert_equal "1.00", data[:shippingamt] - assert_equal "1.00", data[:handlingamt] - end - - def test_should_use_test_certificate_endpoint - gateway = PaypalNvGateway.new( - :login => 'cody', - :password => 'test', - :pem => 'PEM' - ) - assert_equal PaypalNvGateway::URLS[:test][:certificate], gateway.send(:endpoint_url) - end - - def test_should_use_live_certificate_endpoint - gateway = PaypalNvGateway.new( - :login => 'cody', - :password => 'test', - :pem => 'PEM' - ) - gateway.expects(:test?).returns(false) - - assert_equal PaypalNvGateway::URLS[:live][:certificate], gateway.send(:endpoint_url) - end - - def test_should_use_test_signature_endpoint - gateway = PaypalNvGateway.new( - :login => 'cody', - :password => 'test', - :signature => 'SIG' - ) - - assert_equal PaypalNvGateway::URLS[:test][:signature], gateway.send(:endpoint_url) - end - - def test_should_use_live_signature_endpoint - gateway = PaypalNvGateway.new( - :login => 'cody', - :password => 'test', - :signature => 'SIG' - ) - gateway.expects(:test?).returns(false) - - assert_equal PaypalNvGateway::URLS[:live][:signature], gateway.send(:endpoint_url) - end - - def test_should_raise_argument_when_credentials_not_present - assert_raises(ArgumentError) do - PaypalNvGateway.new(:login => 'cody', :password => 'test') - end - end - - def test_avs_result - @gateway.expects(:ssl_post).returns(successful_purchase_response) - - response = @gateway.purchase(@amount, @credit_card, @options) - assert_equal 'X', response.avs_result['code'] - end - - def test_cvv_result - @gateway.expects(:ssl_post).returns(successful_purchase_response) - - response = @gateway.purchase(@amount, @credit_card, @options) - assert_equal 'M', response.cvv_result['code'] - end - - def test_void - @gateway.expects(:ssl_post).returns(successful_void_response) - - response = @gateway.purchase(@amount, @credit_card, @options) - assert_equal '1TX27389GX108740X', response.authorization - end - - def test_raise_when_greater_than_250_payment_recipients - assert_raise(ArgumentError) do - # You can only include up to 250 recipients - recipients = (1..251).collect {|i| [100, "person#{i}@example.com"]} - @gateway.transfer(*recipients) - end - end - - private - def timestamp - Time.new.strftime("%Y-%m-%dT%H:%M:%SZ") - end - - def successful_response_fields - resp = "ACK=Success&TIMESTAMP=#{timestamp}&" - resp << "CORRELATIONID=#{DEBUG_TOKEN}&" - resp << "VERSION=#{API_VER}&BUILD=#{BUILD_NUM}" - end - - def error_msg(id, code, shor, long, options = {} ) - srv_code = options[:service_code] || "000" - err = "&L_ERRORCODE#{id}=#{code}" - err << "&L_SHORTMESSAGE#{id}=#{shor}" - err << "&L_LONGMESSAGE#{id}=#{long}" - err << "&L_SEVERITYCODE#{id}=#{srv_code}" - end - - def error_response_fields() - - err = "ACK=Error&TIMESTAMP=#{timestamp}" - err << "&CORRELATIONID=#{DEBUG_TOKEN}" - err << "&VERSION=#{API_VER}&BUILD=#{BUILD_NUM}" - end - - def successful_purchase_response - resp = successful_response_fields - resp << "&AVSCODE=X&TRANSACTIONID=9CX07910UV614511L&AMT=212.95&CVV2MATCH=M" - end - - def failed_purchase_response - resp = error_response_fields - resp << error_msg(0, 10418, - "Transaction refused because of an invalid argument. See additional error messages for details.", - "The currencies of the shopping cart amounts must be the same.") - end - - - def paypal_timeout_error_response - resp = error_response_fields - resp << error_msg(0, 10001, - "Internal Error.", - "Timeout processing request.") - end - - def successful_reauthorization_response - resp = successful_response_fields - resp << "&AUTHORIZATIONID=1TX27389GX108740X" - end - - def successful_void_response - resp = successful_response_fields - resp << "&AUTHORIZATIONID=1TX27389GX108740X" - end - - - -end