diff --git a/.idea/.gitignore b/.idea/.gitignore index 13566b8..a9d7db9 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -6,3 +6,5 @@ # Datasource local storage ignored files /dataSources/ /dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/business.go b/business.go index 25f0a71..0705bc0 100644 --- a/business.go +++ b/business.go @@ -1,3 +1,4 @@ +// Package swervpay provides a set of APIs to interact with the Swervpay service. package swervpay import ( @@ -5,43 +6,55 @@ import ( "net/http" ) +// Business represents a business entity in the Swervpay system. +// It includes various properties like address, name, country, etc. type Business struct { - Address string `json:"address"` - Name string `json:"name"` - Country string `json:"country"` - CreatedAt string `json:"created_at"` - Email string `json:"email"` - ID string `json:"id"` - Logo string `json:"logo"` - Slug string `json:"slug"` - Type string `json:"type"` - UpdatedAt string `json:"updated_at"` + Address string `json:"address"` // Address of the business + Name string `json:"name"` // Name of the business + Country string `json:"country"` // Country where the business is located + CreatedAt string `json:"created_at"` // Time when the business was created + Email string `json:"email"` // Email of the business + ID string `json:"id"` // Unique identifier of the business + Logo string `json:"logo"` // Logo of the business + Slug string `json:"slug"` // Slug of the business + Type string `json:"type"` // Type of the business + UpdatedAt string `json:"updated_at"` // Time when the business was last updated } +// BusinessInt is an interface that defines the methods a Business must have. type BusinessInt interface { + // Get retrieves the Business information from the Swervpay system. Get(ctx context.Context) (*Business, error) } +// BusinessIntImpl is a concrete implementation of the BusinessInt interface. type BusinessIntImpl struct { - client *SwervpayClient + client *SwervpayClient // Client used to make requests to the Swervpay system } +// Ensure BusinessIntImpl implements BusinessInt interface var _ BusinessInt = &BusinessIntImpl{} +// Get is a method on BusinessIntImpl that retrieves the Business information from the Swervpay system. +// https://docs.swervpay.co/api-reference/business/get func (b *BusinessIntImpl) Get(ctx context.Context) (*Business, error) { - // Prepare request + + // Create a new request to get the business information req, err := b.client.NewRequest(ctx, http.MethodGet, "business", nil) if err != nil { return nil, err } + // Response will hold the business information response := new(Business) + // Perform the request and populate the response _, err = b.client.Perform(req, response) if err != nil { return nil, err } + // Return the business information return response, nil } diff --git a/business_test.go b/business_test.go index 7a65f5c..b820c44 100644 --- a/business_test.go +++ b/business_test.go @@ -5,33 +5,9 @@ import ( "encoding/json" "github.com/stretchr/testify/assert" "net/http" - "net/http/httptest" - "net/url" "testing" ) -var ( - mux *http.ServeMux - client *SwervpayClient - server *httptest.Server -) - -func setup() { - mux = http.NewServeMux() - server = httptest.NewServer(mux) - client = NewSwervpayClient(&SwervpayClientOption{ - BusinessID: "", - SecretKey: "", - BaseURL: "", - }) - url, _ := url.Parse(server.URL) - client.BaseURL = url -} - -func teardown() { - server.Close() -} - func TestGetBusiness(t *testing.T) { setup() defer teardown() @@ -58,9 +34,3 @@ func TestGetBusiness(t *testing.T) { } assert.Equal(t, resp.ID, "bus_123456789") } - -func testMethod(t *testing.T, r *http.Request, expected string) { - if expected != r.Method { - t.Errorf("Request method = %v, expected %v", r.Method, expected) - } -} diff --git a/card.go b/card.go index 4254a9e..b427876 100644 --- a/card.go +++ b/card.go @@ -5,91 +5,100 @@ import ( "net/http" ) +// Card represents a card with its details. type Card struct { - AddressCity string `json:"address_city"` - AddressCountry string `json:"address_country"` - AddressPostalCode string `json:"address_postal_code"` - AddressState string `json:"address_state"` - AddressStreet string `json:"address_street"` - Balance int64 `json:"balance"` - CardNumber string `json:"card_number"` - CreatedAt string `json:"created_at"` - Currency string `json:"currency"` - Cvv string `json:"cvv"` - Expiry string `json:"expiry"` - Freeze bool `json:"freeze"` - ID string `json:"id"` - Issuer string `json:"issuer"` - MaskedPan string `json:"masked_pan"` - NameOnCard string `json:"name_on_card"` - Status string `json:"status"` - TotalFunded int64 `json:"total_funded"` - Type string `json:"type"` - UpdatedAt string `json:"updated_at"` + AddressCity string `json:"address_city"` // City of the card holder's address. + AddressCountry string `json:"address_country"` // Country of the card holder's address. + AddressPostalCode string `json:"address_postal_code"` // Postal code of the card holder's address. + AddressState string `json:"address_state"` // State of the card holder's address. + AddressStreet string `json:"address_street"` // Street of the card holder's address. + Balance int64 `json:"balance"` // Balance on the card. + CardNumber string `json:"card_number"` // Card number. + CreatedAt string `json:"created_at"` // Creation date of the card. + Currency string `json:"currency"` // Currency of the card. + Cvv string `json:"cvv"` // CVV of the card. + Expiry string `json:"expiry"` // Expiry date of the card. + Freeze bool `json:"freeze"` // Freeze status of the card. + ID string `json:"id"` // ID of the card. + Issuer string `json:"issuer"` // Issuer of the card. + MaskedPan string `json:"masked_pan"` // Masked PAN of the card. + NameOnCard string `json:"name_on_card"` // Name on the card. + Status string `json:"status"` // Status of the card. + TotalFunded int64 `json:"total_funded"` // Total funded amount on the card. + Type string `json:"type"` // Type of the card. + UpdatedAt string `json:"updated_at"` // Last update date of the card. } +// CardTransactionHistory represents a card's transaction history. type CardTransactionHistory struct { - Amount int64 `json:"amount"` - Category string `json:"category"` - Charges int64 `json:"charges"` - CreatedAt string `json:"created_at"` - Currency string `json:"currency"` - ID string `json:"id"` - MerchantCity string `json:"merchant_city"` - MerchantCountry string `json:"merchant_country"` - MerchantMcc string `json:"merchant_mcc"` - MerchantMid string `json:"merchant_mid"` - MerchantName string `json:"merchant_name"` - MerchantPostalCode string `json:"merchant_postal_code"` - MerchantState string `json:"merchant_state"` - Reference string `json:"reference"` - Report bool `json:"report"` - ReportMessage string `json:"report_message"` - Status string `json:"status"` - Type string `json:"type"` - UpdatedAt string `json:"updated_at"` + Amount int64 `json:"amount"` // Transaction amount. + Category string `json:"category"` // Category of the transaction. + Charges int64 `json:"charges"` // Charges of the transaction. + CreatedAt string `json:"created_at"` // Creation date of the transaction. + Currency string `json:"currency"` // Currency of the transaction. + ID string `json:"id"` // ID of the transaction. + MerchantCity string `json:"merchant_city"` // City of the merchant. + MerchantCountry string `json:"merchant_country"` // Country of the merchant. + MerchantMcc string `json:"merchant_mcc"` // MCC of the merchant. + MerchantMid string `json:"merchant_mid"` // MID of the merchant. + MerchantName string `json:"merchant_name"` // Name of the merchant. + MerchantPostalCode string `json:"merchant_postal_code"` // Postal code of the merchant. + MerchantState string `json:"merchant_state"` // State of the merchant. + Reference string `json:"reference"` // Reference of the transaction. + Report bool `json:"report"` // Report status of the transaction. + ReportMessage string `json:"report_message"` // Report message of the transaction. + Status string `json:"status"` // Status of the transaction. + Type string `json:"type"` // Type of the transaction. + UpdatedAt string `json:"updated_at"` // Last update date of the transaction. } +// CreateCardBody represents the body of a card creation request. type CreateCardBody struct { - Amount float64 `json:"amount"` - CustomerId string `json:"customer_id"` - Provider string `json:"provider"` - NameOnCard string `json:"name_on_card"` - Currency string `json:"currency"` - Type string `json:"type"` + Amount float64 `json:"amount"` // Amount to be loaded on the card. + CustomerId string `json:"customer_id"` // ID of the customer. + Provider string `json:"provider"` // Provider of the card. + NameOnCard string `json:"name_on_card"` // Name to be printed on the card. + Currency string `json:"currency"` // Currency of the card. + Type string `json:"type"` // Type of the card. } +// CardCreationResponse represents the response of a card creation request. type CardCreationResponse struct { - CardID string `json:"card_id"` - Message string `json:"message"` + CardID string `json:"card_id"` // ID of the created card. + Message string `json:"message"` // Message of the response. } +// FundOrWithdrawCardBody represents the body of a fund or withdraw request. type FundOrWithdrawCardBody struct { - Amount float64 `json:"amount"` + Amount float64 `json:"amount"` // Amount to be funded or withdrawn. } +// CardInt is the interface for card operations. type CardInt interface { - Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Card, error) - Get(ctx context.Context, id string) (*Card, error) - Create(ctx context.Context, body *CreateCardBody) (*CardCreationResponse, error) - Fund(ctx context.Context, id string, body *FundOrWithdrawCardBody) (*DefaultResponse, error) - Withdraw(ctx context.Context, id string, body *FundOrWithdrawCardBody) (*DefaultResponse, error) - Terminate(ctx context.Context, id string) (*DefaultResponse, error) - Freeze(ctx context.Context, id string) (*DefaultResponse, error) - Transactions(ctx context.Context, id string, query *PageAndLimitQuery) (*[]CardTransactionHistory, error) - Transaction(ctx context.Context, id string, transactionId string) (*CardTransactionHistory, error) + Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Card, error) // Gets multiple cards. + Get(ctx context.Context, id string) (*Card, error) // Gets a single card. + Create(ctx context.Context, body *CreateCardBody) (*CardCreationResponse, error) // Creates a card. + Fund(ctx context.Context, id string, body *FundOrWithdrawCardBody) (*DefaultResponse, error) // Funds a card. + Withdraw(ctx context.Context, id string, body *FundOrWithdrawCardBody) (*DefaultResponse, error) // Withdraws from a card. + Terminate(ctx context.Context, id string) (*DefaultResponse, error) // Terminates a card. + Freeze(ctx context.Context, id string) (*DefaultResponse, error) // Freezes a card. + Transactions(ctx context.Context, id string, query *PageAndLimitQuery) (*[]CardTransactionHistory, error) // Gets multiple transactions of a card. + Transaction(ctx context.Context, id string, transactionId string) (*CardTransactionHistory, error) // Gets a single transaction of a card. } +// CardIntImpl is the implementation of the CardInt interface. type CardIntImpl struct { - client *SwervpayClient + client *SwervpayClient // Client to perform the requests. } +// Verify that CardIntImpl implements CardInt. var _ CardInt = &CardIntImpl{} +// Gets gets multiple cards. +// https://docs.swervpay.co/api-reference/cards/get-all-cards func (c CardIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Card, error) { path := GenerateURLPath("cards", query) - // Prepare request req, err := c.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, err @@ -106,6 +115,8 @@ func (c CardIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Car return response, nil } +// Get gets a single card. +// https://docs.swervpay.co/api-reference/cards/get func (c CardIntImpl) Get(ctx context.Context, id string) (*Card, error) { req, err := c.client.NewRequest(ctx, http.MethodGet, "cards/"+id, nil) if err != nil { @@ -123,6 +134,8 @@ func (c CardIntImpl) Get(ctx context.Context, id string) (*Card, error) { return response, nil } +// Create creates a card. +// https://docs.swervpay.co/api-reference/cards/create func (c CardIntImpl) Create(ctx context.Context, body *CreateCardBody) (*CardCreationResponse, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "cards", body) if err != nil { @@ -140,6 +153,8 @@ func (c CardIntImpl) Create(ctx context.Context, body *CreateCardBody) (*CardCre return response, nil } +// Fund funds a card. +// https://docs.swervpay.co/api-reference/cards/fund-card func (c CardIntImpl) Fund(ctx context.Context, id string, body *FundOrWithdrawCardBody) (*DefaultResponse, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "cards/"+id+"/fund", body) if err != nil { @@ -157,6 +172,8 @@ func (c CardIntImpl) Fund(ctx context.Context, id string, body *FundOrWithdrawCa return response, nil } +// Withdraw withdraws from a card. +// https://docs.swervpay.co/api-reference/cards/withdraw-from-card func (c CardIntImpl) Withdraw(ctx context.Context, id string, body *FundOrWithdrawCardBody) (*DefaultResponse, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "cards/"+id+"/withdraw", body) if err != nil { @@ -174,6 +191,8 @@ func (c CardIntImpl) Withdraw(ctx context.Context, id string, body *FundOrWithdr return response, nil } +// Terminate terminates a card. +// https://docs.swervpay.co/api-reference/cards/terminate func (c CardIntImpl) Terminate(ctx context.Context, id string) (*DefaultResponse, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "cards/"+id+"/terminate", nil) if err != nil { @@ -191,6 +210,8 @@ func (c CardIntImpl) Terminate(ctx context.Context, id string) (*DefaultResponse return response, nil } +// Freeze freezes a card. +// https://docs.swervpay.co/api-reference/cards/freeze func (c CardIntImpl) Freeze(ctx context.Context, id string) (*DefaultResponse, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "cards/"+id+"/freeze", nil) if err != nil { @@ -208,10 +229,11 @@ func (c CardIntImpl) Freeze(ctx context.Context, id string) (*DefaultResponse, e return response, nil } +// Transactions gets multiple transactions of a card. +// https://docs.swervpay.co/api-reference/cards/transactions func (c CardIntImpl) Transactions(ctx context.Context, id string, query *PageAndLimitQuery) (*[]CardTransactionHistory, error) { path := GenerateURLPath("cards/"+id+"/transactions", query) - // Prepare request req, err := c.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, err @@ -228,9 +250,10 @@ func (c CardIntImpl) Transactions(ctx context.Context, id string, query *PageAnd return response, nil } +// Transaction get transactions of a card. +// https://docs.swervpay.co/api-reference/cards/get-transaction func (c CardIntImpl) Transaction(ctx context.Context, id string, transactionId string) (*CardTransactionHistory, error) { - // Prepare request req, err := c.client.NewRequest(ctx, http.MethodGet, "cards/"+id+"/transactions/"+transactionId, nil) if err != nil { return nil, err diff --git a/card_test.go b/card_test.go index 6f298f0..cc30237 100644 --- a/card_test.go +++ b/card_test.go @@ -12,7 +12,9 @@ func TestFundCard(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/cards/card_12345678/fund", func(w http.ResponseWriter, r *http.Request) { + cardId := "card_12345678" + + mux.HandleFunc("/cards/"+cardId+"/fund", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodPost) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) @@ -30,7 +32,7 @@ func TestFundCard(t *testing.T) { Amount: 1000, } - resp, err := client.Card.Fund(context.Background(), "card_12345678", req) + resp, err := client.Card.Fund(context.Background(), cardId, req) if err != nil { t.Errorf("Unable to fund card: %v", err) } diff --git a/client.go b/client.go index c47cd58..93927bc 100644 --- a/client.go +++ b/client.go @@ -68,6 +68,7 @@ func NewSwervpayClient(config *SwervpayClientOption) *SwervpayClient { return s } +// NewRequest creates a new request to the Swervpay API. func (c *SwervpayClient) NewRequest(ctx context.Context, method, path string, params interface{}) (*http.Request, error) { u, err := c.BaseURL.Parse(path) if err != nil { @@ -76,6 +77,9 @@ func (c *SwervpayClient) NewRequest(ctx context.Context, method, path string, pa var req *http.Request req, err = http.NewRequestWithContext(ctx, method, u.String(), nil) + if err != nil { + return nil, err + } if params != nil { buf := new(bytes.Buffer) err = json.NewEncoder(buf).Encode(params) @@ -107,7 +111,7 @@ func (c *SwervpayClient) Perform(req *http.Request, ret interface{}) (*http.Resp defer func(Body io.ReadCloser) { err := Body.Close() if err != nil { - + return } }(resp.Body) @@ -160,12 +164,14 @@ func handleError(resp *http.Response) error { } } +// InvalidRequestError represents an error caused by the client. type InvalidRequestError struct { StatusCode int `json:"statusCode"` Name string `json:"name"` Message string `json:"message"` } +// DefaultResponse represents the default response from the Swervpay API. type DefaultResponse struct { Message string `json:"message"` } diff --git a/client_test.go b/client_test.go index dd0d803..d189890 100644 --- a/client_test.go +++ b/client_test.go @@ -1,7 +1,36 @@ package swervpay -import "testing" +import ( + "net/http" + "net/http/httptest" + "net/url" + "testing" +) -func TestSwyftpayClient_PrintOptions(t *testing.T) { +var ( + mux *http.ServeMux + client *SwervpayClient + server *httptest.Server +) +func setup() { + mux = http.NewServeMux() + server = httptest.NewServer(mux) + client = NewSwervpayClient(&SwervpayClientOption{ + BusinessID: "", + SecretKey: "", + BaseURL: "", + }) + url, _ := url.Parse(server.URL) + client.BaseURL = url +} + +func teardown() { + server.Close() +} + +func testMethod(t *testing.T, r *http.Request, expected string) { + if expected != r.Method { + t.Errorf("Request method = %v, expected %v", r.Method, expected) + } } diff --git a/collection.go b/collection.go index eb001e6..ab44d6f 100644 --- a/collection.go +++ b/collection.go @@ -5,42 +5,48 @@ import ( "net/http" ) +// CollectionHistory represents the history of a collection. type CollectionHistory struct { - Amount int64 `json:"amount"` - Charges int64 `json:"charges"` - CreatedAt string `json:"created_at"` - Currency string `json:"currency"` - ID string `json:"id"` - PaymentMethod string `json:"payment_method"` - Reference string `json:"reference"` - UpdatedAt string `json:"updated_at"` + Amount int64 `json:"amount"` // The amount of the collection. + Charges int64 `json:"charges"` // The charges associated with the collection. + CreatedAt string `json:"created_at"` // The creation date of the collection. + Currency string `json:"currency"` // The currency of the collection. + ID string `json:"id"` // The ID of the collection. + PaymentMethod string `json:"payment_method"` // The payment method used for the collection. + Reference string `json:"reference"` // The reference of the collection. + UpdatedAt string `json:"updated_at"` // The last update date of the collection. } +// CreateCollectionBody represents the body of a create collection request. type CreateCollectionBody struct { - CustomerID string `json:"customer_id"` - Currency string `json:"currency"` - MerchantName string `json:"merchant_name"` - Amount int64 `json:"amount"` - Type string `json:"type"` + CustomerID string `json:"customer_id"` // The ID of the customer. + Currency string `json:"currency"` // The currency of the collection. + MerchantName string `json:"merchant_name"` // The name of the merchant. + Amount int64 `json:"amount"` // The amount of the collection. + Type string `json:"type"` // The type of the collection. } +// CollectionInt is an interface that defines the operations that can be performed on collections. type CollectionInt interface { - Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Wallet, error) - Get(ctx context.Context, id string) (*Wallet, error) - Create(ctx context.Context, body *CreateCollectionBody) (*Wallet, error) - Transactions(ctx context.Context, id string, query *PageAndLimitQuery) (*[]CollectionHistory, error) + Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Wallet, error) // Gets a list of wallets. + Get(ctx context.Context, id string) (*Wallet, error) // Gets a specific wallet. + Create(ctx context.Context, body *CreateCollectionBody) (*Wallet, error) // Creates a new wallet. + Transactions(ctx context.Context, id string, query *PageAndLimitQuery) (*[]CollectionHistory, error) // Gets the transactions of a specific wallet. } +// CollectionIntImpl is an implementation of the CollectionInt interface. type CollectionIntImpl struct { - client *SwervpayClient + client *SwervpayClient // The client used to interact with the Swervpay API. } +// Verify that CollectionIntImpl implements CollectionInt. var _ CollectionInt = &CollectionIntImpl{} +// Gets retrieves a list of wallets. +// https://docs.swervpay.co/api-reference/collections/get-all-collections func (c CollectionIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Wallet, error) { path := GenerateURLPath("collections", query) - // Prepare request req, err := c.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, err @@ -57,6 +63,8 @@ func (c CollectionIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) ( return response, nil } +// Get retrieves a specific wallet. +// https://docs.swervpay.co/api-reference/collections/get func (c CollectionIntImpl) Get(ctx context.Context, id string) (*Wallet, error) { req, err := c.client.NewRequest(ctx, http.MethodGet, "collections/"+id, nil) if err != nil { @@ -74,6 +82,8 @@ func (c CollectionIntImpl) Get(ctx context.Context, id string) (*Wallet, error) return response, nil } +// Create creates a new wallet. +// https://docs.swervpay.co/api-reference/collections/create func (c CollectionIntImpl) Create(ctx context.Context, body *CreateCollectionBody) (*Wallet, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "collections", body) if err != nil { @@ -91,10 +101,11 @@ func (c CollectionIntImpl) Create(ctx context.Context, body *CreateCollectionBod return response, nil } +// Transactions retrieves the transactions of a specific wallet. +// https://docs.swervpay.co/api-reference/collections/transaction func (c CollectionIntImpl) Transactions(ctx context.Context, id string, query *PageAndLimitQuery) (*[]CollectionHistory, error) { path := GenerateURLPath("collections/"+id+"/transactions", query) - // Prepare request req, err := c.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, err diff --git a/collection_test.go b/collection_test.go new file mode 100644 index 0000000..d00a93e --- /dev/null +++ b/collection_test.go @@ -0,0 +1 @@ +package swervpay diff --git a/customer.go b/customer.go index c17c871..d842a1a 100644 --- a/customer.go +++ b/customer.go @@ -5,74 +5,84 @@ import ( "net/http" ) +// Customer represents a customer in the Swervpay system. type Customer struct { - Country string `json:"country"` - CreatedAt string `json:"created_at"` - Email string `json:"email"` - FirstName string `json:"first_name"` - ID string `json:"id"` - IsBlacklisted bool `json:"is_blacklisted"` - LastName string `json:"last_name"` - MiddleName string `json:"middle_name"` - PhoneNumber string `json:"phone_number"` - Status string `json:"status"` - UpdatedAt string `json:"updated_at"` + Country string `json:"country"` // The country of the customer. + CreatedAt string `json:"created_at"` // The creation date of the customer. + Email string `json:"email"` // The email of the customer. + FirstName string `json:"first_name"` // The first name of the customer. + ID string `json:"id"` // The ID of the customer. + IsBlacklisted bool `json:"is_blacklisted"` // Whether the customer is blacklisted. + LastName string `json:"last_name"` // The last name of the customer. + MiddleName string `json:"middle_name"` // The middle name of the customer. + PhoneNumber string `json:"phone_number"` // The phone number of the customer. + Status string `json:"status"` // The status of the customer. + UpdatedAt string `json:"updated_at"` // The last update date of the customer. } +// CreateCustomerBody represents the body of a request to create a new customer. type CreateCustomerBody struct { - Country string `json:"country"` - Email string `json:"email"` - Firstname string `json:"firstname"` - Lastname string `json:"lastname"` - Middlename string `json:"middlename"` + Country string `json:"country"` // The country of the new customer. + Email string `json:"email"` // The email of the new customer. + Firstname string `json:"firstname"` // The first name of the new customer. + Lastname string `json:"lastname"` // The last name of the new customer. + Middlename string `json:"middlename"` // The middle name of the new customer. } +// UpdateustomerBody represents the body of a request to update a customer. type UpdateustomerBody struct { - Email string `json:"email"` - PhoneNumber string `json:"phone_number"` + Email string `json:"email"` // The new email of the customer. + PhoneNumber string `json:"phone_number"` // The new phone number of the customer. } +// CustomerKycBody represents the body of a request to update a customer's KYC information. type CustomerKycBody struct { - Tier string `json:"tier"` - Tier1 Tier1KycInput `json:"information"` - Tier2 Tier2KycInput `json:"document"` + Tier string `json:"tier"` // The tier of the KYC information. + Tier1 Tier1KycInput `json:"information"` // The tier 1 KYC information. + Tier2 Tier2KycInput `json:"document"` // The tier 2 KYC information. } +// Tier1KycInput represents the tier 1 KYC information of a customer. type Tier1KycInput struct { - Bvn string `json:"bvn"` - State string `json:"state"` - City string `json:"city"` - Country string `json:"country"` - Address string `json:"address"` - PostalCode string `json:"postal_code"` + Bvn string `json:"bvn"` // The BVN of the customer. + State string `json:"state"` // The state of the customer. + City string `json:"city"` // The city of the customer. + Country string `json:"country"` // The country of the customer. + Address string `json:"address"` // The address of the customer. + PostalCode string `json:"postal_code"` // The postal code of the customer. } +// Tier2KycInput represents the tier 2 KYC information of a customer. type Tier2KycInput struct { - DocumentType string `json:"document_type"` - Document string `json:"document"` - Passport string `json:"passport"` - DocumentNumber string `json:"document_number"` + DocumentType string `json:"document_type"` // The type of the document. + Document string `json:"document"` // The document. + Passport string `json:"passport"` // The passport of the customer. + DocumentNumber string `json:"document_number"` // The document number. } +// CustomerInt is an interface that defines the methods for interacting with customers in the Swervpay system. type CustomerInt interface { - Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Customer, error) - Get(ctx context.Context, id string) (*Customer, error) - Create(ctx context.Context, body *CreateCustomerBody) (*Customer, error) - Update(ctx context.Context, id string, body *UpdateustomerBody) (*Customer, error) - Kyc(ctx context.Context, id string, body *CustomerKycBody) (*DefaultResponse, error) - Blacklist(ctx context.Context, id string) (*DefaultResponse, error) + Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Customer, error) // Gets a list of customers. + Get(ctx context.Context, id string) (*Customer, error) // Gets a specific customer. + Create(ctx context.Context, body *CreateCustomerBody) (*Customer, error) // Creates a new customer. + Update(ctx context.Context, id string, body *UpdateustomerBody) (*Customer, error) // Updates a specific customer. + Kyc(ctx context.Context, id string, body *CustomerKycBody) (*DefaultResponse, error) // Updates the KYC information of a specific customer. + Blacklist(ctx context.Context, id string) (*DefaultResponse, error) // Blacklists a specific customer. } +// CustomerIntImpl is an implementation of the CustomerInt interface. type CustomerIntImpl struct { - client *SwervpayClient + client *SwervpayClient // The Swervpay client. } +// Verify that CustomerIntImpl implements the CustomerInt interface. var _ CustomerInt = &CustomerIntImpl{} +// Gets retrieves a list of customers. +// https://docs.swervpay.co/api-reference/customers/get-all-customers func (c CustomerIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Customer, error) { path := GenerateURLPath("customers", query) - // Prepare request req, err := c.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, err @@ -89,6 +99,8 @@ func (c CustomerIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) (*[ return response, nil } +// Get retrieves a specific customer. +// https://docs.swervpay.co/api-reference/customers/get func (c CustomerIntImpl) Get(ctx context.Context, id string) (*Customer, error) { req, err := c.client.NewRequest(ctx, http.MethodGet, "customers/"+id, nil) if err != nil { @@ -106,6 +118,8 @@ func (c CustomerIntImpl) Get(ctx context.Context, id string) (*Customer, error) return response, nil } +// Create creates a new customer. +// https://docs.swervpay.co/api-reference/customers/create func (c CustomerIntImpl) Create(ctx context.Context, body *CreateCustomerBody) (*Customer, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "customers", body) if err != nil { @@ -123,6 +137,8 @@ func (c CustomerIntImpl) Create(ctx context.Context, body *CreateCustomerBody) ( return response, nil } +// Update updates a specific customer. +// https://docs.swervpay.co/api-reference/customers/update func (c CustomerIntImpl) Update(ctx context.Context, id string, body *UpdateustomerBody) (*Customer, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "customers/"+id+"/update", body) if err != nil { @@ -140,6 +156,8 @@ func (c CustomerIntImpl) Update(ctx context.Context, id string, body *Updateusto return response, nil } +// Kyc updates the KYC information of a specific customer. +// https://docs.swervpay.co/api-reference/customers/kyc func (c CustomerIntImpl) Kyc(ctx context.Context, id string, body *CustomerKycBody) (*DefaultResponse, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "customers/"+id+"/kyc", body) if err != nil { @@ -157,6 +175,8 @@ func (c CustomerIntImpl) Kyc(ctx context.Context, id string, body *CustomerKycBo return response, nil } +// Blacklist blacklists a specific customer. +// https://docs.swervpay.co/api-reference/customers/blacklist func (c CustomerIntImpl) Blacklist(ctx context.Context, id string) (*DefaultResponse, error) { req, err := c.client.NewRequest(ctx, http.MethodPost, "customers/"+id+"/blacklist", nil) if err != nil { diff --git a/fx.go b/fx.go index d8c0fd7..e589391 100644 --- a/fx.go +++ b/fx.go @@ -5,34 +5,44 @@ import ( "net/http" ) +// FxBody represents the body of a foreign exchange request. type FxBody struct { - Amount float64 `json:"amount"` - From string `json:"from"` - To string `json:"to"` + Amount float64 `json:"amount"` // Amount is the amount to be converted. + From string `json:"from"` // From is the currency to convert from. + To string `json:"to"` // To is the currency to convert to. } +// FxRateResponse represents the response from a foreign exchange rate request. type FxRateResponse struct { - Rate float64 `json:"rate"` - From FromOrTo `json:"from"` - To FromOrTo `json:"to"` + Rate float64 `json:"rate"` // Rate is the conversion rate. + From FromOrTo `json:"from"` // From represents the original currency and amount. + To FromOrTo `json:"to"` // To represents the converted currency and amount. } +// FromOrTo represents a currency and amount in a foreign exchange operation. type FromOrTo struct { - Amount string `json:"amount"` - Currency string `json:"currency"` + Amount string `json:"amount"` // Amount is the amount in the currency. + Currency string `json:"currency"` // Currency is the currency code. } +// FxInt is an interface for foreign exchange operations. type FxInt interface { + // Rate gets the conversion rate for a foreign exchange operation. Rate(ctx context.Context, body FxBody) (*FxRateResponse, error) + // Exchange performs a foreign exchange operation. Exchange(ctx context.Context, body FxBody) (*Transaction, error) } +// FxIntImpl is an implementation of the FxInt interface. type FxIntImpl struct { - client *SwervpayClient + client *SwervpayClient // client is the Swervpay client. } +// Verify that FxIntImpl implements FxInt. var _ FxInt = &FxIntImpl{} +// Rate gets the conversion rate for a foreign exchange operation. +// https://docs.swervpay.co/api-reference/fx/get func (f FxIntImpl) Rate(ctx context.Context, body FxBody) (*FxRateResponse, error) { req, err := f.client.NewRequest(ctx, http.MethodPost, "fx/rate", body) if err != nil { @@ -50,6 +60,8 @@ func (f FxIntImpl) Rate(ctx context.Context, body FxBody) (*FxRateResponse, erro return response, nil } +// Exchange performs a foreign exchange operation. +// https://docs.swervpay.co/api-reference/fx/create func (f FxIntImpl) Exchange(ctx context.Context, body FxBody) (*Transaction, error) { req, err := f.client.NewRequest(ctx, http.MethodPost, "fx/exchange", body) if err != nil { diff --git a/other.go b/other.go index e6d6b1d..c7c6bdd 100644 --- a/other.go +++ b/other.go @@ -5,36 +5,46 @@ import ( "net/http" ) +// Bank represents a bank in the Swervpay system. type Bank struct { - Code string `json:"code"` - Name string `json:"name"` + Code string `json:"code"` // Code is the unique identifier for the bank. + Name string `json:"name"` // Name is the name of the bank. } +// ResolveAccountNumber represents the response from the Swervpay API when resolving an account number. type ResolveAccountNumber struct { - AccountNumber string `json:"account_number"` - BankCode string `json:"bank_code"` - BankName string `json:"bank_name"` - AccountName string `json:"account_name"` + AccountNumber string `json:"account_number"` // AccountNumber is the account number that was resolved. + BankCode string `json:"bank_code"` // BankCode is the code of the bank the account belongs to. + BankName string `json:"bank_name"` // BankName is the name of the bank the account belongs to. + AccountName string `json:"account_name"` // AccountName is the name of the account holder. } +// ResolveAccountNumberBody represents the request body when resolving an account number. type ResolveAccountNumberBody struct { - AccountNumber string `json:"account_number"` - BankCode string `json:"bank_code"` + AccountNumber string `json:"account_number"` // AccountNumber is the account number to resolve. + BankCode string `json:"bank_code"` // BankCode is the code of the bank the account belongs to. } +// OtherInt is an interface for interacting with the Swervpay API. type OtherInt interface { + // Banks retrieves a list of all banks in the Swervpay system. Banks(ctx context.Context) (*[]Bank, error) + // ResolveAccountNumber resolves an account number in the Swervpay system. ResolveAccountNumber(ctx context.Context, body ResolveAccountNumberBody) (*ResolveAccountNumber, error) } +// OtherIntImpl is an implementation of the OtherInt interface. type OtherIntImpl struct { - client *SwervpayClient + client *SwervpayClient // client is the Swervpay client used to interact with the API. } +// Verify that OtherIntImpl implements the OtherInt interface. var _ OtherInt = &OtherIntImpl{} +// Banks retrieves a list of all banks in the Swervpay system. +// https://docs.swervpay.co/api-reference/others/get-banks func (o OtherIntImpl) Banks(ctx context.Context) (*[]Bank, error) { - // Prepare request + req, err := o.client.NewRequest(ctx, http.MethodGet, "banks", nil) if err != nil { return nil, err @@ -51,8 +61,10 @@ func (o OtherIntImpl) Banks(ctx context.Context) (*[]Bank, error) { return response, nil } +// ResolveAccountNumber resolves an account number in the Swervpay system. +// https://docs.swervpay.co/api-reference/others/resolve-account-number func (o OtherIntImpl) ResolveAccountNumber(ctx context.Context, body ResolveAccountNumberBody) (*ResolveAccountNumber, error) { - // Prepare request + req, err := o.client.NewRequest(ctx, http.MethodPost, "resolve-account-number", body) if err != nil { return nil, err diff --git a/payout.go b/payout.go index 27b4a5c..cdcb507 100644 --- a/payout.go +++ b/payout.go @@ -5,32 +5,42 @@ import ( "net/http" ) +// CreatePayoutBody represents the request body for creating a payout. type CreatePayoutBody struct { - Reference string `json:"reference"` - AccountNumber string `json:"account_number"` - Narration string `json:"narration"` - BankCode string `json:"bank_code"` - Currency string `json:"currency"` - Amount int64 `json:"amount"` + Reference string `json:"reference"` // Unique reference for the payout + AccountNumber string `json:"account_number"` // Account number to send the payout to + Narration string `json:"narration"` // Description of the payout + BankCode string `json:"bank_code"` // Code of the bank for the account + Currency string `json:"currency"` // Currency of the payout + Amount int64 `json:"amount"` // Amount of the payout } +// CreatePayoutResponse represents the response from creating a payout. type CreatePayoutResponse struct { - Reference string `json:"reference"` - Message string `json:"message"` + Reference string `json:"reference"` // Unique reference for the payout + Message string `json:"message"` // Message indicating the status of the payout } +// PayoutInt is an interface for managing payouts. type PayoutInt interface { + // Get retrieves a payout by its ID. Get(ctx context.Context, id string) (*Transaction, error) + // Create creates a new payout with the provided body. Create(ctx context.Context, body *CreatePayoutBody) (*CreatePayoutResponse, error) } +// PayoutIntImpl is an implementation of the PayoutInt interface. type PayoutIntImpl struct { - client *SwervpayClient + client *SwervpayClient // Client used to make requests } +// Verify that PayoutIntImpl implements PayoutInt. var _ PayoutInt = &PayoutIntImpl{} +// Get retrieves a payout by its ID. +// https://docs.swervpay.co/api-reference/payouts/get func (p PayoutIntImpl) Get(ctx context.Context, id string) (*Transaction, error) { + // Create a new request to get a payout. req, err := p.client.NewRequest(ctx, http.MethodGet, "payouts/"+id, nil) if err != nil { return nil, err @@ -38,16 +48,21 @@ func (p PayoutIntImpl) Get(ctx context.Context, id string) (*Transaction, error) response := new(Transaction) + // Perform the request and populate the response. _, err = p.client.Perform(req, response) if err != nil { return nil, err } + // Return the retrieved payout. return response, nil } +// Create creates a new payout with the provided body. +// https://docs.swervpay.co/api-reference/payouts/create func (p PayoutIntImpl) Create(ctx context.Context, body *CreatePayoutBody) (*CreatePayoutResponse, error) { + // Create a new request to create a payout. req, err := p.client.NewRequest(ctx, http.MethodPost, "payouts", body) if err != nil { return nil, err @@ -55,11 +70,13 @@ func (p PayoutIntImpl) Create(ctx context.Context, body *CreatePayoutBody) (*Cre response := new(CreatePayoutResponse) + // Perform the request and populate the response. _, err = p.client.Perform(req, response) if err != nil { return nil, err } + // Return the response from creating the payout. return response, nil } diff --git a/transaction.go b/transaction.go index 419e361..43b7279 100644 --- a/transaction.go +++ b/transaction.go @@ -5,42 +5,47 @@ import ( "net/http" ) +// Transaction represents a transaction with all its details. type Transaction struct { - AccountName string `json:"account_name"` - AccountNumber string `json:"account_number"` - Amount int64 `json:"amount"` - BankCode string `json:"bank_code"` - BankName string `json:"bank_name"` - Category string `json:"category"` - Charges int64 `json:"charges"` - CreatedAt string `json:"created_at"` - Detail string `json:"detail"` - FiatRate int64 `json:"fiat_rate"` - ID string `json:"id"` - Reference string `json:"reference"` - Report bool `json:"report"` - ReportMessage string `json:"report_message"` - SessionID string `json:"session_id"` - Status string `json:"status"` - Type string `json:"type"` - UpdatedAt string `json:"updated_at"` + AccountName string `json:"account_name"` // The name of the account + AccountNumber string `json:"account_number"` // The number of the account + Amount int64 `json:"amount"` // The amount of the transaction + BankCode string `json:"bank_code"` // The code of the bank + BankName string `json:"bank_name"` // The name of the bank + Category string `json:"category"` // The category of the transaction + Charges int64 `json:"charges"` // The charges of the transaction + CreatedAt string `json:"created_at"` // The creation date of the transaction + Detail string `json:"detail"` // The detail of the transaction + FiatRate int64 `json:"fiat_rate"` // The fiat rate of the transaction + ID string `json:"id"` // The ID of the transaction + Reference string `json:"reference"` // The reference of the transaction + Report bool `json:"report"` // The report status of the transaction + ReportMessage string `json:"report_message"` // The report message of the transaction + SessionID string `json:"session_id"` // The session ID of the transaction + Status string `json:"status"` // The status of the transaction + Type string `json:"type"` // The type of the transaction + UpdatedAt string `json:"updated_at"` // The update date of the transaction } +// TransactionInt is an interface that defines the methods for transactions. type TransactionInt interface { - Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Transaction, error) - Get(ctx context.Context, id string) (*Transaction, error) + Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Transaction, error) // Gets a list of transactions + Get(ctx context.Context, id string) (*Transaction, error) // Gets a single transaction } +// TransactionIntImpl is the implementation of the TransactionInt interface. type TransactionIntImpl struct { - client *SwervpayClient + client *SwervpayClient // The client used to make requests } +// Verify that TransactionIntImpl implements TransactionInt. var _ TransactionInt = &TransactionIntImpl{} +// Gets retrieves a list of transactions. +// https://docs.swervpay.co/api-reference/transactions/get-all-transactions func (t TransactionIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Transaction, error) { path := GenerateURLPath("transactions", query) - // Prepare request req, err := t.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, err @@ -57,6 +62,8 @@ func (t TransactionIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) return response, nil } +// Get retrieves a single transaction. +// https://docs.swervpay.co/api-reference/transactions/get func (t TransactionIntImpl) Get(ctx context.Context, id string) (*Transaction, error) { req, err := t.client.NewRequest(ctx, http.MethodGet, "transactions/"+id, nil) if err != nil { diff --git a/wallet.go b/wallet.go index cd64bfa..eb5d3b3 100644 --- a/wallet.go +++ b/wallet.go @@ -5,41 +5,47 @@ import ( "net/http" ) +// Wallet represents a user's wallet in the system. type Wallet struct { - AccountName string `json:"account_name"` - AccountNumber string `json:"account_number"` - AccountType string `json:"account_type"` - Balance int64 `json:"balance"` - BankAddress string `json:"bank_address"` - BankCode string `json:"bank_code"` - BankName string `json:"bank_name"` - CreatedAt string `json:"created_at"` - ID string `json:"id"` - IsBlocked bool `json:"is_blocked"` - Label string `json:"label"` - PendingBalance int64 `json:"pending_balance"` - Reference string `json:"reference"` - RoutingNumber string `json:"routing_number"` - TotalReceived int64 `json:"total_received"` - UpdatedAt string `json:"updated_at"` + AccountName string `json:"account_name"` // The name of the account. + AccountNumber string `json:"account_number"` // The number of the account. + AccountType string `json:"account_type"` // The type of the account. + Balance int64 `json:"balance"` // The current balance of the wallet. + BankAddress string `json:"bank_address"` // The address of the bank. + BankCode string `json:"bank_code"` // The code of the bank. + BankName string `json:"bank_name"` // The name of the bank. + CreatedAt string `json:"created_at"` // The creation date of the wallet. + ID string `json:"id"` // The unique identifier of the wallet. + IsBlocked bool `json:"is_blocked"` // Indicates if the wallet is blocked. + Label string `json:"label"` // The label of the wallet. + PendingBalance int64 `json:"pending_balance"` // The pending balance of the wallet. + Reference string `json:"reference"` // The reference of the wallet. + RoutingNumber string `json:"routing_number"` // The routing number of the bank. + TotalReceived int64 `json:"total_received"` // The total amount received in the wallet. + UpdatedAt string `json:"updated_at"` // The last update date of the wallet. } +// WalletInt is an interface that defines the methods for managing wallets. type WalletInt interface { - Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Wallet, error) - Get(ctx context.Context, id string) (*Wallet, error) + Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Wallet, error) // Gets a list of wallets. + Get(ctx context.Context, id string) (*Wallet, error) // Gets a specific wallet by its ID. } +// WalletIntImpl is an implementation of the WalletInt interface. type WalletIntImpl struct { - client *SwervpayClient + client *SwervpayClient // The client used to make requests. } +// Verify that WalletIntImpl implements WalletInt. var _ WalletInt = &WalletIntImpl{} +// Gets retrieves a list of wallets. +// https://docs.swervpay.co/api-reference/wallets/get-all-wallets func (w WalletIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) (*[]Wallet, error) { path := GenerateURLPath("wallets", query) - // Prepare request + // Prepare the request. req, err := w.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, err @@ -47,17 +53,21 @@ func (w WalletIntImpl) Gets(ctx context.Context, query *PageAndLimitQuery) (*[]W response := new([]Wallet) + // Perform the request and get the response. _, err = w.client.Perform(req, response) if err != nil { return nil, err } + // Return the response. return response, nil } +// Get retrieves a specific wallet by its ID. +// https://docs.swervpay.co/api-reference/wallets/get func (w WalletIntImpl) Get(ctx context.Context, id string) (*Wallet, error) { - // Prepare request + // Prepare the request. req, err := w.client.NewRequest(ctx, http.MethodGet, "wallets/"+id, nil) if err != nil { return nil, err @@ -65,11 +75,13 @@ func (w WalletIntImpl) Get(ctx context.Context, id string) (*Wallet, error) { response := new(Wallet) + // Perform the request and get the response. _, err = w.client.Perform(req, response) if err != nil { return nil, err } + // Return the response. return response, nil } diff --git a/webhook.go b/webhook.go index 0cf7977..4d0bb24 100644 --- a/webhook.go +++ b/webhook.go @@ -5,19 +5,34 @@ import ( "net/http" ) +// WebhookInt is an interface that defines two methods: Test and Retry. type WebhookInt interface { + // Test sends a test webhook request. + // It takes a context and an id as parameters. + // It returns a pointer to a DefaultResponse and an error. Test(ctx context.Context, id string) (*DefaultResponse, error) + + // Retry retries a failed webhook request. + // It takes a context and a logId as parameters. + // It returns a pointer to a DefaultResponse and an error. Retry(ctx context.Context, logId string) (*DefaultResponse, error) } +// WebhookIntImpl is a struct that implements the WebhookInt interface. +// It contains a client of type *SwervpayClient. type WebhookIntImpl struct { client *SwervpayClient } +// Assert that WebhookIntImpl implements the WebhookInt interface. var _ WebhookInt = &WebhookIntImpl{} +// Test is a method of WebhookIntImpl that sends a test webhook request. +// It prepares a new request and performs it. +// If there is an error during these operations, it returns the error. +// Otherwise, it returns the response and nil. +// https://docs.swervpay.co/api-reference/webhook/test func (w WebhookIntImpl) Test(ctx context.Context, id string) (*DefaultResponse, error) { - // Prepare request req, err := w.client.NewRequest(ctx, http.MethodPost, "webhook/"+id+"/test", nil) if err != nil { return nil, err @@ -34,8 +49,12 @@ func (w WebhookIntImpl) Test(ctx context.Context, id string) (*DefaultResponse, return response, nil } +// Retry is a method of WebhookIntImpl that retries a failed webhook request. +// It prepares a new request and performs it. +// If there is an error during these operations, it returns the error. +// Otherwise, it returns the response and nil. +// https://docs.swervpay.co/api-reference/webhook/retry func (w WebhookIntImpl) Retry(ctx context.Context, logId string) (*DefaultResponse, error) { - // Prepare request req, err := w.client.NewRequest(ctx, http.MethodPost, "webhook/"+logId+"/retry", nil) if err != nil { return nil, err diff --git a/webhook_test.go b/webhook_test.go index d00a93e..4b5ede5 100644 --- a/webhook_test.go +++ b/webhook_test.go @@ -1 +1,63 @@ package swervpay + +import ( + "context" + "encoding/json" + "github.com/stretchr/testify/assert" + "net/http" + "testing" +) + +func TestTestWebhook(t *testing.T) { + setup() + defer teardown() + + webhookId := "wbh_123456789" + + mux.HandleFunc("/webhook/"+webhookId+"/test", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodPost) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + ret := &DefaultResponse{ + Message: "Test webhook sent successfully", + } + err := json.NewEncoder(w).Encode(&ret) + if err != nil { + panic(err) + } + }) + + resp, err := client.Webhook.Test(context.Background(), webhookId) + if err != nil { + t.Errorf("Err retrying webhook: %v", err) + } + assert.Equal(t, resp.Message, "Test webhook sent successfully") +} + +func TestRetryWebhook(t *testing.T) { + setup() + defer teardown() + + logId := "tri_123456789" + + mux.HandleFunc("/webhook/"+logId+"/retry", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodPost) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + ret := &DefaultResponse{ + Message: "Retry webhook sent successfully", + } + err := json.NewEncoder(w).Encode(&ret) + if err != nil { + panic(err) + } + }) + + resp, err := client.Webhook.Retry(context.Background(), logId) + if err != nil { + t.Errorf("Err retrying webhook: %v", err) + } + assert.Equal(t, resp.Message, "Retry webhook sent successfully") +}