-
Notifications
You must be signed in to change notification settings - Fork 1
/
transactions_controller.go
53 lines (46 loc) · 1.67 KB
/
transactions_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package pagarmeapisdk
import (
"context"
"fmt"
"github.com/apimatic/go-core-runtime/utilities"
"pagarmeapisdk/models"
)
// TransactionsController represents a controller struct.
type TransactionsController struct {
baseController
}
// NewTransactionsController creates a new instance of TransactionsController.
// It takes a baseController as a parameter and returns a pointer to the TransactionsController.
func NewTransactionsController(baseController baseController) *TransactionsController {
transactionsController := TransactionsController{baseController: baseController}
return &transactionsController
}
// GetTransaction takes context, transactionId as parameters and
// returns an models.ApiResponse with models.GetTransactionResponseInterface data and
// an error if there was an issue with the request or response.
func (t *TransactionsController) GetTransaction(
ctx context.Context,
transactionId string) (
models.ApiResponse[models.GetTransactionResponseInterface],
error) {
req := t.prepareRequest(
ctx,
"GET",
fmt.Sprintf("/transactions/%v", transactionId),
)
req.Authenticate(true)
var result models.GetTransactionResponseInterface
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
err = validateResponse(*resp)
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[*models.GetTransactionResponse](decoder)
if err != nil {
return models.NewApiResponse(result, resp), err
}
return models.NewApiResponse(result, resp), err
}