Skip to content

Commit 4001ccf

Browse files
committed
Add transactions service
1 parent d425498 commit 4001ccf

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

client.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ type Client struct {
2222
secretKey string
2323
baseURL string
2424

25-
Bills *billsService
26-
Payment *paymentsService
25+
Bills *billsService
26+
Payments *paymentsService
27+
Transactions *transactionsService
2728
}
2829

2930
// New creates and returns a new flutterwave.Client from a slice of flutterwave.ClientOption.
@@ -42,7 +43,8 @@ func New(options ...ClientOption) *Client {
4243

4344
client.common.client = client
4445
client.Bills = (*billsService)(&client.common)
45-
client.Payment = (*paymentsService)(&client.common)
46+
client.Payments = (*paymentsService)(&client.common)
47+
client.Transactions = (*transactionsService)(&client.common)
4648
return client
4749
}
4850

transactions.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package flutterwave
2+
3+
import "time"
4+
5+
// TransactionResponse is data returned when querying a transaction
6+
type TransactionResponse struct {
7+
Status string `json:"status"`
8+
Message string `json:"message"`
9+
Data struct {
10+
ID int64 `json:"id"`
11+
TxRef string `json:"tx_ref"`
12+
FlwRef string `json:"flw_ref"`
13+
DeviceFingerprint string `json:"device_fingerprint"`
14+
Amount int `json:"amount"`
15+
Currency string `json:"currency"`
16+
ChargedAmount int `json:"charged_amount"`
17+
AppFee float64 `json:"app_fee"`
18+
MerchantFee int `json:"merchant_fee"`
19+
ProcessorResponse string `json:"processor_response"`
20+
AuthModel string `json:"auth_model"`
21+
IP string `json:"ip"`
22+
Narration string `json:"narration"`
23+
Status string `json:"status"`
24+
PaymentType string `json:"payment_type"`
25+
CreatedAt time.Time `json:"created_at"`
26+
AccountID int `json:"account_id"`
27+
Card struct {
28+
First6Digits string `json:"first_6digits"`
29+
Last4Digits string `json:"last_4digits"`
30+
Issuer string `json:"issuer"`
31+
Country string `json:"country"`
32+
Type string `json:"type"`
33+
Token string `json:"token"`
34+
Expiry string `json:"expiry"`
35+
} `json:"card"`
36+
Meta interface{} `json:"meta"`
37+
AmountSettled float64 `json:"amount_settled"`
38+
Customer struct {
39+
ID int `json:"id"`
40+
Name string `json:"name"`
41+
PhoneNumber string `json:"phone_number"`
42+
Email string `json:"email"`
43+
CreatedAt time.Time `json:"created_at"`
44+
} `json:"customer"`
45+
} `json:"data"`
46+
}

transactions_service.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package flutterwave
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
8+
)
9+
10+
// transactionsService is the API client for the `/v3/transactions` endpoint
11+
type transactionsService service
12+
13+
// Verify the final status of a transaction
14+
//
15+
// API Docs: https://developer.flutterwave.com/reference/endpoints/transactions
16+
func (service *transactionsService) Verify(ctx context.Context, transactionID int64) (*TransactionResponse, *Response, error) {
17+
uri := fmt.Sprintf("/v3/transactions/%d/verify", transactionID)
18+
19+
request, err := service.client.newRequest(ctx, http.MethodGet, uri, nil)
20+
if err != nil {
21+
return nil, nil, err
22+
}
23+
24+
response, err := service.client.do(request)
25+
if err != nil {
26+
return nil, response, err
27+
}
28+
29+
var data TransactionResponse
30+
if err = json.Unmarshal(*response.Body, &data); err != nil {
31+
return nil, response, err
32+
}
33+
34+
return &data, response, nil
35+
}

0 commit comments

Comments
 (0)