Class: Gemgento::API::SOAP::Globalcollect::SavedCc

Inherits:
Object
  • Object
show all
Defined in:
lib/gemgento/api/soap/globalcollect/saved_cc.rb

Class Method Summary collapse

Class Method Details

.fetch(user) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/gemgento/api/soap/globalcollect/saved_cc.rb', line 13

def self.fetch(user)
  saved_cards = []

  tokens(user.magento_id).each do |token|
    saved_cards << sync_magento_to_local(token, user.id)
  end

  # destroy saved cards that were not returned
  SavedCreditCard.where(user: user).where('id NOT IN (?)', saved_cards.collect(&:id)).delete_all
end

.fetch_allObject



7
8
9
10
11
# File 'lib/gemgento/api/soap/globalcollect/saved_cc.rb', line 7

def self.fetch_all
  User.all.each do |user|
    fetch(user)
  end
end

.tokens(customer_id) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gemgento/api/soap/globalcollect/saved_cc.rb', line 24

def self.tokens(customer_id)
  response = MagentoApi.create_call(:globalcollect_tokens, {customer_id: customer_id})

  if response.success?
    if response.body[:result][:item].nil?
      return []
    else
      response.body[:result][:item] = [response.body[:result][:item]] unless response.body[:result][:item].is_a? Array
      return response.body[:result][:item]
    end
  else
    return false
  end
end