Class: Braspag::Billet

Inherits:
Object
  • Object
show all
Includes:
ActiveAttr::Model
Defined in:
lib/cbraspag/payment/billet.rb

Defined Under Namespace

Classes: DueDateValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#accountObject

Returns the value of attribute account.



32
33
34
# File 'lib/cbraspag/payment/billet.rb', line 32

def 
  @account
end

#agencyObject

Returns the value of attribute agency.



32
33
34
# File 'lib/cbraspag/payment/billet.rb', line 32

def agency
  @agency
end

#amountObject

Returns the value of attribute amount.



32
33
34
# File 'lib/cbraspag/payment/billet.rb', line 32

def amount
  @amount
end

#amount_paidObject

Returns the value of attribute amount_paid.



32
33
34
# File 'lib/cbraspag/payment/billet.rb', line 32

def amount_paid
  @amount_paid
end

#bankObject

Returns the value of attribute bank.



32
33
34
# File 'lib/cbraspag/payment/billet.rb', line 32

def bank
  @bank
end

#codeObject

Returns the value of attribute code.



31
32
33
# File 'lib/cbraspag/payment/billet.rb', line 31

def code
  @code
end

#created_atObject

Returns the value of attribute created_at.



31
32
33
# File 'lib/cbraspag/payment/billet.rb', line 31

def created_at
  @created_at
end

#due_date_onObject

Returns the value of attribute due_date_on.



31
32
33
# File 'lib/cbraspag/payment/billet.rb', line 31

def due_date_on
  @due_date_on
end

#idObject

Returns the value of attribute id.



31
32
33
# File 'lib/cbraspag/payment/billet.rb', line 31

def id
  @id
end

#instructionsObject

Returns the value of attribute instructions.



31
32
33
# File 'lib/cbraspag/payment/billet.rb', line 31

def instructions
  @instructions
end

Returns the value of attribute paid_at.



32
33
34
# File 'lib/cbraspag/payment/billet.rb', line 32

def paid_at
  @paid_at
end

#receiverObject

Returns the value of attribute receiver.



32
33
34
# File 'lib/cbraspag/payment/billet.rb', line 32

def receiver
  @receiver
end

#urlObject

Returns the value of attribute url.



31
32
33
# File 'lib/cbraspag/payment/billet.rb', line 31

def url
  @url
end

#walletObject

Returns the value of attribute wallet.



32
33
34
# File 'lib/cbraspag/payment/billet.rb', line 32

def wallet
  @wallet
end

Class Method Details

.from_generate_billet(connection, order, billet, params) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cbraspag/payment/billet.rb', line 54

def self.from_generate_billet(connection, order, billet, params)
  response = Braspag::Converter::hash_from_xml(params.body, {
    :url => nil,
    :amount => nil,
    :number => "boletoNumber",
    :expiration_date => Proc.new { |document|
      begin
        Date.parse(document.search("expirationDate").first.to_s)
      rescue
        nil
      end
    },
    :return_code => "returnCode",
    :status => nil,
    :message => nil
  })
  
  order.gateway_return_code = response[:return_code]
  order.gateway_status = response[:status]
  order.gateway_amount = BigDecimal.new(response[:amount].to_s) if response[:amount]
  billet.url = response[:url]
  
  response
end

.to_generate_billet(connection, order, billet) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cbraspag/payment/billet.rb', line 39

def self.to_generate_billet(connection, order, billet)
  {
    "merchantId"       => connection.merchant_id,
    "boletoNumber"     => billet.id.to_s,
    "instructions"     => billet.instructions.to_s,
    "expirationDate"   => billet.due_date_on.strftime("%d/%m/%y"),
    "customerName"     => order.customer.name.to_s,
    "customerIdNumber" => order.customer.document.to_s,
    "emails"           => order.customer.email.to_s,
    "orderId"          => order.id.to_s,
    "amount"           => Braspag::Converter::decimal_to_string(order.amount),
    "paymentMethod"    => order.payment_method
  }
end