Class: Pagseguro::Charge::PaymentMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/charge/payment_method.rb

Overview

Payment data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = Pagseguro::Charge::ChargeRequest::TYPE_CREDITCARD) ⇒ PaymentMethod

Returns a new instance of PaymentMethod.



20
21
22
# File 'lib/pagseguro/charge/payment_method.rb', line 20

def initialize(type = Pagseguro::Charge::ChargeRequest::TYPE_CREDITCARD)
  @type = type
end

Instance Attribute Details

#amountInteger

Gross amount of the charge, in cents.

Returns:

  • (Integer)

    the current value of amount



10
11
12
# File 'lib/pagseguro/charge/payment_method.rb', line 10

def amount
  @amount
end

#boletoObject

Returns the value of attribute boleto.



12
13
14
# File 'lib/pagseguro/charge/payment_method.rb', line 12

def boleto
  @boleto
end

#captureBoolean

Represents if the charge must be created and captured. For now, ‘TRUE’ is the only supported value.

Returns:

  • (Boolean)

    the current value of capture



10
11
12
# File 'lib/pagseguro/charge/payment_method.rb', line 10

def capture
  @capture
end

#capture_beforeObject

Returns the value of attribute capture_before.



12
13
14
# File 'lib/pagseguro/charge/payment_method.rb', line 12

def capture_before
  @capture_before
end

#cardObject

The Credit Card object

Returns:

  • (Object)

    the current value of card



10
11
12
# File 'lib/pagseguro/charge/payment_method.rb', line 10

def card
  @card
end

#installmentsInteger

The number of monthly installments the card will be charged. This must be an one or two-digit integer between 1 and 12.

Returns:

  • (Integer)

    the current value of installments



10
11
12
# File 'lib/pagseguro/charge/payment_method.rb', line 10

def installments
  @installments
end

#payment_methodString

States the payment method used in the charge. For now, we only support credit cards (“credit_card”) and boleto (“boleto”)

Returns:

  • (String)

    the current value of payment_method



10
11
12
# File 'lib/pagseguro/charge/payment_method.rb', line 10

def payment_method
  @payment_method
end

#typeObject

Returns the value of attribute type.



12
13
14
# File 'lib/pagseguro/charge/payment_method.rb', line 12

def type
  @type
end

Class Method Details

.fill_from_json(data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pagseguro/charge/payment_method.rb', line 30

def self.fill_from_json(data)
  return if data.nil?

  payment_method = new

  payment_method.type = data["type"]
  payment_method.card = CreditCard.fill_from_json(data["card"])
  payment_method.boleto = Boleto.fill_from_json(data["boleto"])
  payment_method.installments = data["installments"]
  payment_method.capture = data["capture"]
  payment_method.capture_before = data["capture_before"]
  payment_method
end

Instance Method Details

#as_json(options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/pagseguro/charge/payment_method.rb', line 45

def as_json(options={})
  {
    type: @type,
    installments: @installments,
    capture: @capture,
    capture_before: @capture_before,
    card: @card,
    boleto: @boleto,
  }
end

#to_json(*options) ⇒ Object



24
25
26
27
28
# File 'lib/pagseguro/charge/payment_method.rb', line 24

def to_json(*options)
  hash = as_json(*options)
  hash.reject! {|k,v| v.nil?}
  hash.to_json(*options)
end