Class: MechanizeStore::Payment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/mechanize_store/payment.rb

Constant Summary collapse

STATUSES =

ids inseridos na base de dados

{
    1 => :accomplished,
    2 => :in_analisis,
    3 => :awaiting,
    4 => :canceled,
    5 => :unauthorized
}
TYPES =
{
    1 => :credit_card, 
    2 => :billet,
    3 => :cash
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.statuses_collectionObject



48
49
50
51
52
53
54
55
56
# File 'app/models/mechanize_store/payment.rb', line 48

def self.statuses_collection
    statuses_collection = []

    STATUSES.each_pair do |key, value|
        statuses_collection << [I18n.t(value, scope: "payment_statuses"), key]
    end

    return statuses_collection 
end

.types_collectionObject



58
59
60
61
62
63
64
65
66
# File 'app/models/mechanize_store/payment.rb', line 58

def self.types_collection
    types_collection = []

    TYPES.each_pair do |key, value|
        types_collection << [I18n.t(value, scope: "payment_types"), key]
    end

    return types_collection
end

Instance Method Details

#before_createObject



68
69
70
# File 'app/models/mechanize_store/payment.rb', line 68

def before_create
    self.payment_status = STATUSES.invert[:awaiting]
end

#confirm!Object



27
28
29
30
31
32
# File 'app/models/mechanize_store/payment.rb', line 27

def confirm!
    Payment.transaction do
        self.update_attributes(payment_status: STATUSES.invert[:accomplished], paid_in: Time.now)
        self.order.update_attribute(:order_status, Order::STATUSES.invert[:accomplished])
    end
end

#decline!Object



34
35
36
37
38
# File 'app/models/mechanize_store/payment.rb', line 34

def decline!
    Payment.transaction do
        self.update_attributes(payment_status: STATUSES.invert[:unauthorized])
    end 
end

#payment_status_labelObject



72
73
74
75
76
77
# File 'app/models/mechanize_store/payment.rb', line 72

def payment_status_label
    return "success" if self.payment_status == STATUSES.invert[:accomplished]
    return "warning" if self.payment_status == STATUSES.invert[:awaiting] or self.payment_status == STATUSES.invert[:in_analisis]
    return "info" if self.payment_status == STATUSES.invert[:canceled] 
    return "danger" if self.payment_status == STATUSES.invert[:unauthorized] or self.payment_status == STATUSES.invert[:need_authorization]
end

#payment_status_strObject



40
41
42
# File 'app/models/mechanize_store/payment.rb', line 40

def payment_status_str
    return I18n.t(STATUSES[self.payment_status], scope: "payment_statuses")
end

#payment_type_strObject



44
45
46
# File 'app/models/mechanize_store/payment.rb', line 44

def payment_type_str
    return I18n.t(TYPES[self.payment_type], scope: "payment_types")
end