Class: VenmoAPI::Payment

Inherits:
Object
  • Object
show all
Defined in:
lib/venmo/payment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Payment

Returns a new instance of Payment.



4
5
6
7
8
9
10
11
12
# File 'lib/venmo/payment.rb', line 4

def initialize(options = {})
  self.phone = options[:phone]
  self.email = options[:email]
  self.user_id = options[:user_id]
  self.note = options[:note]
  self.amount = options[:amount]
  self.audience = options[:audience] ? options[:audience] : 'friends'
  validate_properties
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



3
4
5
# File 'lib/venmo/payment.rb', line 3

def amount
  @amount
end

#audienceObject

Returns the value of attribute audience.



3
4
5
# File 'lib/venmo/payment.rb', line 3

def audience
  @audience
end

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/venmo/payment.rb', line 3

def data
  @data
end

#emailObject

Returns the value of attribute email.



3
4
5
# File 'lib/venmo/payment.rb', line 3

def email
  @email
end

#noteObject

Returns the value of attribute note.



3
4
5
# File 'lib/venmo/payment.rb', line 3

def note
  @note
end

#phoneObject

Returns the value of attribute phone.



3
4
5
# File 'lib/venmo/payment.rb', line 3

def phone
  @phone
end

#sentObject

Returns the value of attribute sent.



3
4
5
# File 'lib/venmo/payment.rb', line 3

def sent
  @sent
end

#user_idObject

Returns the value of attribute user_id.



3
4
5
# File 'lib/venmo/payment.rb', line 3

def user_id
  @user_id
end

Instance Method Details

#send(access_token) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/venmo/payment.rb', line 14

def send (access_token)
  uri = URI(VenmoAPI::Helper::VENMO_BASE_URL + 'payments')
  res = Net::HTTP.post_form(uri, 'access_token' => access_token,
                                 'phone' => self.phone,
                                 'email' => self.email,
                                 'user_id' => self.user_id,
                                 'note' => self.note,
                                 'amount' => self.amount,
                                 'audience' => self.audience)
  res_data = JSON.parse(res.body)
  if res_data["data"]
    self.data = VenmoAPI::Helper::recursive_symbolize_keys! res_data["data"]
  end
  return self
end