Class: Momoapi::Collection

Inherits:
Client
  • Object
show all
Defined in:
lib/momoapi-ruby/collection.rb

Instance Method Summary collapse

Methods inherited from Client

#get_credentials, #handle_error, #interpret_response, #prepare_get_request, #send_request

Instance Method Details

#get_auth_tokenObject



13
14
15
16
# File 'lib/momoapi-ruby/collection.rb', line 13

def get_auth_token
  path = 'collection/token/'
  super(path, Momoapi.config.collection_primary_key)
end

#get_balanceObject



18
19
20
21
# File 'lib/momoapi-ruby/collection.rb', line 18

def get_balance
  path = '/collection/v1_0/account/balance'
  super(path, Momoapi.config.collection_primary_key)
end

#get_transaction_status(transaction_id) ⇒ Object



23
24
25
26
# File 'lib/momoapi-ruby/collection.rb', line 23

def get_transaction_status(transaction_id)
  path = "/collection/v1_0/requesttopay/#{transaction_id}"
  super(path, Momoapi.config.collection_primary_key)
end

#is_user_active(phone_number) ⇒ Object



63
64
65
66
# File 'lib/momoapi-ruby/collection.rb', line 63

def is_user_active(phone_number)
  path = "/collection/v1_0/accountholder/msisdn/#{phone_number}/active"
  super(path, Momoapi.config.collection_primary_key)
end

#request_to_pay(phone_number, amount, external_id, payee_note = '', payer_message = '', currency = 'EUR', callback_url = '') ⇒ Object

This method is used to request a payment from a consumer (Payer). The payer will be asked to authorize the payment. The transaction will be executed once the payer has authorized the payment. The requesttopay will be in status PENDING until the transaction is authorized or declined by the payer or it is timed out by the system. The status of the transaction can be validated by using ‘get_transation_status`



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/momoapi-ruby/collection.rb', line 35

def request_to_pay(phone_number, amount, external_id,
                   payee_note = '', payer_message = '',
                   currency = 'EUR', callback_url = '')
  Momoapi::Validate.new.validate(phone_number, amount, currency)
  uuid = SecureRandom.uuid
  headers = {
    "X-Target-Environment": Momoapi.config.environment || 'sandbox',
    "Content-Type": 'application/json',
    "X-Reference-Id": uuid,
    "Ocp-Apim-Subscription-Key": Momoapi.config.collection_primary_key
  }
  headers['X-Callback-Url'] = callback_url unless callback_url.empty?
  body = {
    "payer": {
      "partyIdType": 'MSISDN',
      "partyId": phone_number
    },
    "payeeNote": payee_note,
    "payerMessage": payer_message,
    "externalId": external_id,
    "currency": currency,
    "amount": amount.to_s
  }
  path = '/collection/v1_0/requesttopay'
  send_request('post', path, headers, body)
  { transaction_reference: uuid }
end