Sha256: 21c55321b734c4c5a83d95f1a90c640f6f1f0b7c0aa667efea749810373cc80f

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

module Spree
  class Gateway::KomojuCreditCard < KomojuGateway
    def auto_capture?
      true
    end

    def purchase(money, source, options)
      options = change_options_to_dollar(options) if options[:currency] == "JPY"
      if profile_id = source.gateway_payment_profile_id || source.gateway_customer_profile_id
        payment_details = profile_id
      else
        payment_details = source.to_active_merchant
      end
      super(money - options[:tax], payment_details, options)
    end

    # enable either token-based profiles or customer-based profiles
    def create_profile(payment)
      return unless payment.source.number.present?

      if SpreeKomoju.enable_customer_profiles
        profile_id_name = :gateway_customer_profile_id
        options = { email: payment.order.email, customer_profile: true }
      else
        profile_id_name = :gateway_payment_profile_id
        options = {}
      end

      profile_id = payment.source.public_send(profile_id_name)
      if profile_id.nil?
        response = provider.store(payment.source.to_active_merchant, options)

        if response.success?
          payment.source.update_attributes!(profile_id_name => response.params['id'])
        else
          payment.send(:gateway_error, response.message)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_komoju-0.0.4 app/models/spree/gateway/komoju_credit_card.rb