Skip to content

Commit caf04b8

Browse files
committed
Make user credentials specific to product
1 parent e939569 commit caf04b8

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

lib/momoapi-ruby/client.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def get_auth_token(path, subscription_key)
4848
headers = {
4949
"Ocp-Apim-Subscription-Key": subscription_key
5050
}
51-
username = Momoapi.config.collection_user_id
52-
password = Momoapi.config.collection_api_secret
5351
url = Momoapi.config.base_url
5452
conn = Faraday.new(url: url)
5553
conn.headers = headers
56-
conn.basic_auth(username, password)
54+
product = path.split('/')[0]
55+
get_credentials(product)
56+
conn.basic_auth(@username, @password)
5757
response = conn.post(path)
5858
begin
5959
JSON.parse(response.body)
@@ -62,6 +62,20 @@ def get_auth_token(path, subscription_key)
6262
end
6363
end
6464

65+
def get_credentials(product)
66+
case product
67+
when 'collection'
68+
@username = Momoapi.config.collection_user_id
69+
@password = Momoapi.config.collection_api_secret
70+
when 'disbursement'
71+
@username = Momoapi.config.disbursement_user_id
72+
@password = Momoapi.config.disbursement_api_secret
73+
when 'remittance'
74+
@username = Momoapi.config.remittance_user_id
75+
@password = Momoapi.config.remittance_api_secret
76+
end
77+
end
78+
6579
def prepare_get_request(path, subscription_key)
6680
headers = {
6781
"X-Target-Environment": Momoapi.config.environment || 'sandbox',

0 commit comments

Comments
 (0)