1
|
|
|
package mtnmomo |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"net/http" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
// apiUserService is the API client for the `/` endpoint |
10
|
|
|
type apiUserService service |
11
|
|
|
|
12
|
|
|
// CreateAPIUser Used to create an API user in the sandbox target environment. |
13
|
|
|
// |
14
|
|
|
// API Docs: https://momodeveloper.mtn.com/docs/services/sandbox-provisioning-api/operations/post-v1_0-apiuser |
15
|
|
|
func (service *apiUserService) CreateAPIUser(ctx context.Context, userID string, providerCallbackHost string) (string, *Response, error) { |
16
|
|
|
payload := map[string]string{ |
17
|
|
|
"providerCallbackHost": providerCallbackHost, |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
request, err := service.client.newRequest(ctx, http.MethodPost, "/v1_0/apiuser", payload) |
21
|
|
|
if err != nil { |
22
|
|
|
return userID, nil, err |
23
|
|
|
} |
24
|
|
|
request.Header.Set("X-Reference-Id", userID) |
25
|
|
|
|
26
|
|
|
response, err := service.client.do(request) |
27
|
|
|
return userID, response, err |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// CreateAPIKey Used to create an API user in the sandbox target environment. |
31
|
|
|
// |
32
|
|
|
// API Docs: https://momodeveloper.mtn.com/docs/services/sandbox-provisioning-api/operations/post-v1_0-apiuser |
33
|
|
|
func (service *apiUserService) CreateAPIKey(ctx context.Context, userID string) (string, *Response, error) { |
34
|
|
|
request, err := service.client.newRequest(ctx, http.MethodPost, "/v1_0/apiuser/"+userID+"/apikey ", nil) |
35
|
|
|
if err != nil { |
36
|
|
|
return "", nil, err |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
response, err := service.client.do(request) |
40
|
|
|
if err != nil { |
41
|
|
|
return "", response, err |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
body := struct { |
45
|
|
|
APIKey string `json:"apiKey"` |
46
|
|
|
}{} |
47
|
|
|
|
48
|
|
|
if err = json.Unmarshal(*response.Body, &body); err != nil { |
49
|
|
|
return "", response, err |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return body.APIKey, response, err |
53
|
|
|
} |
54
|
|
|
|