class Peperusha::CustomerPayViaPaybill

Public Instance Methods

call() click to toggle source
# File lib/peperusha/customer_pay_via_paybill.rb, line 18
def call
  path = 'mpesa/c2b/v1/simulate'
  response = Peperusha::Client.invoke_post_request(token, path, attributes)

  if response.status == 200
    data = JSON.parse(response.body)
    context.body = data
  else
    client_errors = Peperusha::Client.build_errors_collection(response)
    context.fail!(errors: client_errors)
  end
end

Private Instance Methods

attributes() click to toggle source
# File lib/peperusha/customer_pay_via_paybill.rb, line 42
def attributes
  {
    'Amount': amount,
    'BillRefNumber': account_number,
    'CommandID': 'CustomerPayBillOnline',
    'Msisdn': customer_number,
    'ShortCode': business_paybill_number
  }
end
check_if_params_missing() click to toggle source
# File lib/peperusha/customer_pay_via_paybill.rb, line 33
def check_if_params_missing
  errors = []
  errors << 'account_number.missing' if account_number.nil?
  errors << 'amount.missing' if amount.nil?
  errors << 'business_paybill_number.missing' if business_paybill_number.nil?
  errors << 'customer_number.missing' if customer_number.nil?
  errors
end