Sha256: c28026b822f713bbecf3a75132d5462808ea6923101da14c1154e3abc5bb9837

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

module ActiveMerchant
  module Billing
    class CyberSourceGateway

      # Add support for CreditCard objects
      def build_credit_request(money, creditcard_or_reference, options)
        xml = Builder::XmlMarkup.new :indent => 2

        setup_address_hash(options)

        add_payment_method_or_subscription(xml, money, creditcard_or_reference, options)
        add_credit_service(xml)

        xml.target!
      end

      # See https://github.com/killbill/killbill-cybersource-plugin/issues/4
      def commit(request, options)
        request = build_request(request, options)
        begin
          raw_response = ssl_post(test? ? self.test_url : self.live_url, request)
        rescue ResponseError => e
          raw_response = e.response.body
        end
        response = parse(raw_response)

        success = response[:decision] == 'ACCEPT'
        authorization = success ? [options[:order_id], response[:requestID], response[:requestToken]].compact.join(";") : nil

        if response[:faultcode] == 'wsse:FailedCheck'
          message = { :exception_message => response[:message], :payment_plugin_status => :CANCELED }.to_json
        else
          message = @@response_codes[('r' + response[:reasonCode]).to_sym] rescue response[:message]
        end

        Response.new(success, message, response,
                     :test => test?,
                     :authorization => authorization,
                     :avs_result => {:code => response[:avsCode]},
                     :cvv_result => response[:cvCode]
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
killbill-cybersource-4.0.2 lib/cybersource/ext/active_merchant/active_merchant.rb