1
|
|
|
package smobilpay |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"fmt" |
7
|
|
|
"net/http" |
8
|
|
|
"net/url" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
// subscriptionService is the API client for the `/subscription` endpoint |
12
|
|
|
type subscriptionService service |
13
|
|
|
|
14
|
|
|
// Get subscription payment handler |
15
|
|
|
// |
16
|
|
|
// https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html#APIReference-Specification |
17
|
|
|
func (service *subscriptionService) Get(ctx context.Context, params *SubscriptionGetParams, options ...RequestOption) ([]*Subscription, *Response, error) { |
18
|
|
|
q := url.Values{ |
19
|
|
|
"merchant": []string{params.Merchant}, |
20
|
|
|
"serviceid": []string{params.ServiceID}, |
21
|
|
|
} |
22
|
|
|
if params.ServiceNumber != "" { |
23
|
|
|
q.Set("serviceNumber", params.ServiceNumber) |
24
|
|
|
} |
25
|
|
|
if params.CustomerNumber != "" { |
26
|
|
|
q.Set("customerNumber", params.CustomerNumber) |
27
|
|
|
} |
28
|
|
|
request, err := service.client.newRequest(ctx, options, http.MethodGet, fmt.Sprintf("/subscription?%s", q.Encode()), nil) |
29
|
|
|
if err != nil { |
30
|
|
|
return nil, nil, err |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
response, err := service.client.do(request) |
34
|
|
|
if err != nil { |
35
|
|
|
return nil, response, err |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
var services []*Subscription |
39
|
|
|
if err = json.Unmarshal(*response.Body, &services); err != nil { |
40
|
|
|
return nil, response, err |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return services, response, nil |
44
|
|
|
} |
45
|
|
|
|