<commit_before>require "nokogiri"

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    class IppGateway < Gateway
      self.live_url = 'https://www.ippayments.com.au/interface/api'
      self.test_url = 'https://demo.ippayments.com.au/interface/api'

      self.supported_countries = ['AU']
      self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]

      self.homepage_url = 'http://www.ippayments.com.au/'
      self.display_name = 'IPP'

      self.money_format = :cents

      self.default_currency = 'AUD'

      STANDARD_ERROR_CODE_MAPPING = {
        "05" => STANDARD_ERROR_CODE[:card_declined],
        "06" => STANDARD_ERROR_CODE[:processing_error],
        "14" => STANDARD_ERROR_CODE[:invalid_number],
        "54" => STANDARD_ERROR_CODE[:expired_card],
      }

      def initialize(options={})
        requires!(options, :username, :password)
        super
      end

      def purchase(money, payment, options={})
        commit("SubmitSinglePayment") do |xml|
          xml.Transaction do
            xml.CustRef options[:order_id]
            add_amount(xml, money)
            xml.TrnType "1"
            add_credit_card(xml, payment)
            add_credentials(xml)
            xml.TrnSource options[:ip]
          end
        end
      end

      def authorize(money, payment, options={})
        commit("SubmitSinglePayment") do |xml|
          xml.Transaction do
            xml.CustRef options[:order_id]
            add_amount(xml, money)
            xml.TrnType "2"
            add_credit_card(xml, payment)
            add_credentials(xml)
            xml.TrnSource options[:ip]
          end
        end
      end

      def capture(money, authorization, options={})
        commit("SubmitSingleCapture") do |xml|
          xml.Capture do
            xml.Receipt authorization
            add_amount(xml, money)
            add_credentials(xml)
          end
        end
      end

      def void(money, authorization, options={})
        commit("SubmitSingleVOID") do |xml|
          xml.Void do
            xml.Receipt authorization
            add_amount(xml, money)
            add_credentials(xml)
          end
        end
      end

      def refund(money, authorization, options={})
        commit("SubmitSingleRefund") do |xml|
          xml.Refund do
            xml.Receipt authorization
            add_amount(xml, money)
            add_credentials(xml)
          end
        end
      end

      def store(payment, options={})
        commit("TokeniseCreditCard", "sipp", "tokeniseCreditCardXML") do |xml|
          xml.TokeniseCreditCard do
            xml.UserName @options[:username]
            xml.Password @options[:password]
            xml.CardNumber payment.number
            xml.ExpM format(payment.month, :two_digits)
            xml.ExpY format(payment.year, :four_digits)
            xml.TokeniseAlgorithmID "2"<commit_msg>Fix capitalization typo<commit_after>require "nokogiri"

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    class IppGateway < Gateway
      self.live_url = 'https://www.ippayments.com.au/interface/api'
      self.test_url = 'https://demo.ippayments.com.au/interface/api'

      self.supported_countries = ['AU']
      self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]

      self.homepage_url = 'http://www.ippayments.com.au/'
      self.display_name = 'IPP'

      self.money_format = :cents

      self.default_currency = 'AUD'

      STANDARD_ERROR_CODE_MAPPING = {
        "05" => STANDARD_ERROR_CODE[:card_declined],
        "06" => STANDARD_ERROR_CODE[:processing_error],
        "14" => STANDARD_ERROR_CODE[:invalid_number],
        "54" => STANDARD_ERROR_CODE[:expired_card],
      }

      def initialize(options={})
        requires!(options, :username, :password)
        super
      end

      def purchase(money, payment, options={})
        commit("SubmitSinglePayment") do |xml|
          xml.Transaction do
            xml.CustRef options[:order_id]
            add_amount(xml, money)
            xml.TrnType "1"
            add_credit_card(xml, payment)
            add_credentials(xml)
            xml.TrnSource options[:ip]
          end
        end
      end

      def authorize(money, payment, options={})
        commit("SubmitSinglePayment") do |xml|
          xml.Transaction do
            xml.CustRef options[:order_id]
            add_amount(xml, money)
            xml.TrnType "2"
            add_credit_card(xml, payment)
            add_credentials(xml)
            xml.TrnSource options[:ip]
          end
        end
      end

      def capture(money, authorization, options={})
        commit("SubmitSingleCapture") do |xml|
          xml.Capture do
            xml.Receipt authorization
            add_amount(xml, money)
            add_credentials(xml)
          end
        end
      end

      def void(money, authorization, options={})
        commit("SubmitSingleVoid") do |xml|
          xml.Void do
            xml.Receipt authorization
            add_amount(xml, money)
            add_credentials(xml)
          end
        end
      end

      def refund(money, authorization, options={})
        commit("SubmitSingleRefund") do |xml|
          xml.Refund do
            xml.Receipt authorization
            add_amount(xml, money)
            add_credentials(xml)
          end
        end
      end

      def store(payment, options={})
        commit("TokeniseCreditCard", "sipp", "tokeniseCreditCardXML") do |xml|
          xml.TokeniseCreditCard do
            xml.UserName @options[:username]
            xml.Password @options[:password]
            xml.CardNumber payment.number
            xml.ExpM format(payment.month, :two_digits)
            xml.ExpY format(payment.year, :four_digits)
            xml.TokeniseAlgorithmID "2"
{'fraction_non_alphanumeric': 0.1012311901504788, 'fraction_numerical': 0.003761969904240766, 'mean_word_length': 2.0352880124545925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 78}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3389764', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1680, 'n_words': 337}