Class: Sendly::CreditTransaction

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/types.rb

Overview

Represents a credit transaction

Constant Summary collapse

TYPES =

Transaction type constants

%w[purchase usage refund adjustment bonus].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CreditTransaction

Returns a new instance of CreditTransaction.



436
437
438
439
440
441
442
443
444
# File 'lib/sendly/types.rb', line 436

def initialize(data)
  @id = data["id"]
  @type = data["type"]
  @amount = data["amount"] || 0
  @balance_after = data["balance_after"] || data["balanceAfter"] || 0
  @description = data["description"]
  @message_id = data["message_id"] || data["messageId"]
  @created_at = parse_time(data["created_at"] || data["createdAt"])
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



431
432
433
# File 'lib/sendly/types.rb', line 431

def amount
  @amount
end

#balance_afterObject (readonly)

Returns the value of attribute balance_after.



431
432
433
# File 'lib/sendly/types.rb', line 431

def balance_after
  @balance_after
end

#created_atObject (readonly)

Returns the value of attribute created_at.



431
432
433
# File 'lib/sendly/types.rb', line 431

def created_at
  @created_at
end

#descriptionObject (readonly)

Returns the value of attribute description.



431
432
433
# File 'lib/sendly/types.rb', line 431

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



431
432
433
# File 'lib/sendly/types.rb', line 431

def id
  @id
end

#message_idObject (readonly)

Returns the value of attribute message_id.



431
432
433
# File 'lib/sendly/types.rb', line 431

def message_id
  @message_id
end

#typeObject (readonly)

Returns the value of attribute type.



431
432
433
# File 'lib/sendly/types.rb', line 431

def type
  @type
end

Instance Method Details

#credit?Boolean

Returns:

  • (Boolean)


446
447
448
# File 'lib/sendly/types.rb', line 446

def credit?
  amount > 0
end

#debit?Boolean

Returns:

  • (Boolean)


450
451
452
# File 'lib/sendly/types.rb', line 450

def debit?
  amount < 0
end