Sha256: 4cdf6be89d8a5abcf3e84edb5649cd8debb04a4029364fe2325c5c08ae17d35d

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

# For STK Push/Receive MPESA Payments from merchant's customers
class K2Stk < K2Entity
  # Receive payments from M-PESA users.
  def receive_mpesa_payments(params)
    # Validation
    params = validate_input(params, @exception_array += %w[payment_channel till_number first_name last_name phone_number email currency value metadata callback_url])
    # The Request Body Parameters
    k2_request_subscriber = {
      first_name: params[:first_name],
      middle_name: params[:middle_name],
      last_name: params[:last_name],
      phone_number: validate_phone(params[:phone_number]),
      email: validate_email(params[:email])
    }
    k2_request_amount = {
      currency: 'KES',
      value: params[:value]
    }
    k2_request_metadata = params[:metadata]
    k2_request_links = {
        callback_url: params[:callback_url]
    }
    receive_body = {
      payment_channel: params[:payment_channel],
      till_number: validate_till_number_prefix(params[:till_number]),
      subscriber: k2_request_subscriber,
      amount: k2_request_amount,
      meta_data: k2_request_metadata,
      _links: k2_request_links
    }
    receive_hash = make_hash(K2Config.path_url('incoming_payments'), 'post', @access_token, 'STK', receive_body)
    @threads << Thread.new do
      sleep 0.25
      @location_url = K2Connect.make_request(receive_hash)
    end
    @threads.each(&:join)
  end

  # Query/Check STK Payment Request Status
  def query_status
    super('STK', path_url=@location_url)
  end

  # Query Location URL
  def query_resource(url)
    super('STK', url)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
k2-connect-ruby-2.0.0 lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk.rb
k2-connect-ruby-1.0.0 lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk.rb
k2-connect-ruby-0.0.3 lib/k2-connect-ruby/k2_financial_entity/entities/k2_stk.rb
k2-connect-ruby-0.0.2 lib/k2-connect-ruby/k2_financial_entity/entities/k2_stk.rb
k2-connect-ruby-0.0.1 lib/k2-connect-ruby/k2_financial_entity/entities/k2_stk.rb