Class: MpesaStk::PushPayment

Inherits:
Object
  • Object
show all
Defined in:
lib/mpesa_stk/push_payment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount, phone_number) ⇒ PushPayment

Returns a new instance of PushPayment.



13
14
15
16
17
# File 'lib/mpesa_stk/push_payment.rb', line 13

def initialize(amount, phone_number)
  @token = MpesaStk::AccessToken.call
  @amount = amount
  @phone_number = phone_number
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



11
12
13
# File 'lib/mpesa_stk/push_payment.rb', line 11

def amount
  @amount
end

#phone_numberObject (readonly)

Returns the value of attribute phone_number.



11
12
13
# File 'lib/mpesa_stk/push_payment.rb', line 11

def phone_number
  @phone_number
end

#tokenObject (readonly)

Returns the value of attribute token.



11
12
13
# File 'lib/mpesa_stk/push_payment.rb', line 11

def token
  @token
end

Class Method Details

.call(amount, phone_number) ⇒ Object



6
7
8
# File 'lib/mpesa_stk/push_payment.rb', line 6

def call(amount, phone_number)
  new(amount, phone_number).push_payment
end

Instance Method Details

#push_paymentObject



19
20
21
22
# File 'lib/mpesa_stk/push_payment.rb', line 19

def push_payment
  response = HTTParty.post(url, headers: headers, body: body)
  JSON.parse(response.body)
end