class Payments::Payjunction::VaultService < ApplicationService
  include Payments::Payjunction::Httpable

  def initialize(school, action, customer_id, vault=nil)
    @school = school
    @action = action
    @path = "/customers/#{customer_id}/vaults"
    @vault = vault
  end

  def call
    return unless @school.payjunction_credential

    case @action
    when :index
      request('Get', @path, @school)['results']
    when :create
      request('Post', @path, @school, @vault)
    when :destroy
      @path += "/#{@vault['vaultId']}"
      request('Delete', @path, @school)
    end
  end
end
