| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package campay |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "context" |
||
| 5 | "encoding/json" |
||
| 6 | "fmt" |
||
| 7 | "net/http" |
||
| 8 | ) |
||
| 9 | |||
| 10 | // transactionService is the API client for the `/transaction/` endpoint |
||
| 11 | type transactionService service |
||
| 12 | |||
| 13 | // Get the status of an initiated transaction. |
||
| 14 | // GET /transaction/{reference}/ |
||
| 15 | // API Doc: https://documenter.getpostman.com/view/2391374/T1LV8PVA#d9278e44-aa8a-4ed1-85f7-7e0184dc35db |
||
| 16 | func (service *transactionService) Get(ctx context.Context, reference string) (*Transaction, *Response, error) { |
||
| 17 | err := service.client.refreshToken(ctx) |
||
| 18 | if err != nil { |
||
| 19 | return nil, nil, err |
||
| 20 | } |
||
| 21 | |||
| 22 | request, err := service.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/transaction/%s/", reference), nil) |
||
| 23 | if err != nil { |
||
| 24 | return nil, nil, err |
||
| 25 | } |
||
| 26 | |||
| 27 | response, err := service.client.do(request) |
||
| 28 | if err != nil { |
||
| 29 | return nil, response, err |
||
| 30 | } |
||
| 31 | |||
| 32 | var transaction Transaction |
||
| 33 | if err = json.Unmarshal(*response.Body, &transaction); err != nil { |
||
| 34 | return nil, response, err |
||
| 35 | } |
||
| 36 | |||
| 37 | return &transaction, response, nil |
||
| 38 | } |
||
| 39 |