-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1e3e6a
commit a09c0af
Showing
4 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package campay | ||
|
||
// Transaction contains details of an initiated transaction | ||
type Transaction struct { | ||
Reference string `json:"reference"` | ||
Status string `json:"status"` | ||
Amount float64 `json:"amount"` | ||
Currency string `json:"currency"` | ||
Operator string `json:"operator"` | ||
Code string `json:"code"` | ||
OperatorReference string `json:"operator_reference"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,34 @@ | ||
package campay | ||
|
||
// TransactionService is the API client for the `/gateway` endpoint | ||
type TransactionService service | ||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
// transactionService is the API client for the `/gateway` endpoint | ||
type transactionService service | ||
|
||
func (service *transactionService) Get(ctx context.Context, reference string) (*Transaction, *Response, error) { | ||
err := service.client.refreshToken(ctx) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
request, err := service.client.newRequest(ctx, http.MethodGet, "/transaction/"+reference, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
response, err := service.client.do(request) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
var transaction Transaction | ||
if err = json.Unmarshal(*response.Body, &transaction); err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return &transaction, response, nil | ||
} |