Passed
Push — main ( e1e3e6...a09c0a )
by Acho
01:15
created

campay.*transactionService.Get   A

Complexity

Conditions 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 14
nop 2
dl 0
loc 22
rs 9.2333
c 0
b 0
f 0
1
package campay
2
3
import (
4
	"context"
5
	"encoding/json"
6
	"net/http"
7
)
8
9
// transactionService is the API client for the `/gateway` endpoint
10
type transactionService service
11
12
func (service *transactionService) Get(ctx context.Context, reference string) (*Transaction, *Response, error) {
13
	err := service.client.refreshToken(ctx)
14
	if err != nil {
15
		return nil, nil, err
16
	}
17
18
	request, err := service.client.newRequest(ctx, http.MethodGet, "/transaction/"+reference, nil)
19
	if err != nil {
20
		return nil, nil, err
21
	}
22
23
	response, err := service.client.do(request)
24
	if err != nil {
25
		return nil, response, err
26
	}
27
28
	var transaction Transaction
29
	if err = json.Unmarshal(*response.Body, &transaction); err != nil {
30
		return nil, response, err
31
	}
32
33
	return &transaction, response, nil
34
}
35