Class: Tipjoy::Payment

Inherits:
Object
  • Object
show all
Includes:
Requestor
Defined in:
lib/tipjoy/payment.rb

Constant Summary collapse

NOTIFY_PATH =
"/api/tweetpayment/notify/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Requestor

included

Constructor Details

#initialize(client, to_account, amount, message = "") ⇒ Payment

Returns a new instance of Payment.



9
10
11
# File 'lib/tipjoy/payment.rb', line 9

def initialize(client, , amount, message="")
  self., self.amount, self.client, self.message = , amount, client, message
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



7
8
9
# File 'lib/tipjoy/payment.rb', line 7

def amount
  @amount
end

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/tipjoy/payment.rb', line 7

def client
  @client
end

#errorsObject

Returns the value of attribute errors.



7
8
9
# File 'lib/tipjoy/payment.rb', line 7

def errors
  @errors
end

#messageObject

Returns the value of attribute message.



7
8
9
# File 'lib/tipjoy/payment.rb', line 7

def message
  @message
end

#to_accountObject

Returns the value of attribute to_account.



7
8
9
# File 'lib/tipjoy/payment.rb', line 7

def 
  @to_account
end

#transaction_idObject

Returns the value of attribute transaction_id.



7
8
9
# File 'lib/tipjoy/payment.rb', line 7

def transaction_id
  @transaction_id
end

#tweet_idObject

Returns the value of attribute tweet_id.



7
8
9
# File 'lib/tipjoy/payment.rb', line 7

def tweet_id
  @tweet_id
end

Instance Method Details

#payObject



13
14
15
16
17
18
# File 'lib/tipjoy/payment.rb', line 13

def pay
  raise Tipjoy::InvalidPaymentError.new(errors.join(", ")) unless valid?

  tweet_payment
  notify_tipjoy
end

#valid?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
# File 'lib/tipjoy/payment.rb', line 20

def valid?
  self.errors = []

  self.errors << "amount required" unless amount
  self.errors << "to_account required" unless    
  self.errors << "no client" unless client
  self.errors << "amount not > 0 " unless amount.to_f > 0

  self.errors.empty?
end