Skip to content

Commit

Permalink
Merge pull request #10 from brokeyourbike/missing
Browse files Browse the repository at this point in the history
Implement missing API method
  • Loading branch information
brokeyourbike authored Oct 22, 2023
2 parents 5a89131 + d2a0a68 commit 9d6f93f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
12 changes: 12 additions & 0 deletions transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type TransactionsClient interface {
InitiateCHAPSTransactions(context.Context, CreateTransactionsPayload) (TransactionsCreatedResponse, error)
InitiateFPSPaymentOriginatedOverseas(context.Context, CreateFPSPaymentOriginatedOverseasPayload) (TransactionsCreatedResponse, error)
FetchTransactions(ctx context.Context, params FetchTransactionsParams) (TransactionsResponse, error)
FetchTransactionForAccount(ctx context.Context, accountID uuid.UUID, trxID uuid.UUID) (TransactionResponse, error)
FetchTransactionsForAccount(ctx context.Context, accountID uuid.UUID, params FetchTransactionsParams) (TransactionsResponse, error)
FetchTransactionsForVirtualAccount(ctx context.Context, accountID, virtualAccountID uuid.UUID, params FetchTransactionsParams) (TransactionsResponse, error)
}
Expand Down Expand Up @@ -352,6 +353,17 @@ func (c *client) FetchTransactions(ctx context.Context, params FetchTransactions
return data, c.do(ctx, req)
}

func (c *client) FetchTransactionForAccount(ctx context.Context, accountID uuid.UUID, trxID uuid.UUID) (data TransactionResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, fmt.Sprintf("/v2/Accounts/%s/Transactions/%s", accountID.String(), trxID.String()), nil)
if err != nil {
return data, fmt.Errorf("failed to create request: %w", err)
}

req.ExpectStatus(http.StatusOK)
req.DecodeTo(&data)
return data, c.do(ctx, req)
}

func (c *client) FetchTransactionsForAccount(ctx context.Context, accountID uuid.UUID, params FetchTransactionsParams) (data TransactionsResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, fmt.Sprintf("/v2/Accounts/%s/Transactions", accountID.String()), nil)
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions webhook/mccy_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ type MCCYAccountCreatedPayload struct {
Type string `json:"Type" validate:"required"`
}

// GetIdentifier returns first identifier. If no identifiers are found, an empty string is returned.
func (w MCCYAccountCreatedPayload) GetIdentifier() string {
if len(w.Identifiers) > 0 {
return w.Identifiers[0].Identifier
}
return ""
}

// MCCYAccountUpdatedPayload
// This webhook confirms that the multicurrency account has been updated
type MCCYAccountUpdatedPayload struct {
Expand All @@ -56,6 +64,14 @@ type MCCYAccountUpdatedPayload struct {
Type string `json:"Type" validate:"required"`
}

// GetIdentifier returns first identifier. If no identifiers are found, an empty string is returned.
func (w MCCYAccountUpdatedPayload) GetIdentifier() string {
if len(w.Identifiers) > 0 {
return w.Identifiers[0].Identifier
}
return ""
}

// MCCYVirtualAccountCreatedPayload
// This webhook confirms that the multicurrency virtual account has been created
type MCCYVirtualAccountCreatedPayload struct {
Expand All @@ -68,6 +84,14 @@ type MCCYVirtualAccountCreatedPayload struct {
TimestampCreated clearbank.Time `json:"TimestampCreated" validate:"required"`
}

// GetIdentifier returns first identifier. If no identifiers are found, an empty string is returned.
func (w MCCYVirtualAccountCreatedPayload) GetIdentifier() string {
if len(w.Identifiers) > 0 {
return w.Identifiers[0].Identifier
}
return ""
}

// MCCYVirtualAccountUpdatedPayload
// This webhook confirms that the multicurrency virtual account has been updated
type MCCYVirtualAccountUpdatedPayload struct {
Expand All @@ -81,3 +105,11 @@ type MCCYVirtualAccountUpdatedPayload struct {
StatusReason string `json:"StatusReason"`
StatusInformation string `json:"StatusInformation"`
}

// GetIdentifier returns first identifier. If no identifiers are found, an empty string is returned.
func (w MCCYVirtualAccountUpdatedPayload) GetIdentifier() string {
if len(w.Identifiers) > 0 {
return w.Identifiers[0].Identifier
}
return ""
}
40 changes: 40 additions & 0 deletions webhook/mccy_accounts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package webhook_test

import (
"testing"

"github.com/brokeyourbike/clearbank-api-client-go/webhook"
"github.com/stretchr/testify/assert"
)

func TestMCCYAccountCreatedPayload_GetIdentifier(t *testing.T) {
p1 := webhook.MCCYAccountCreatedPayload{}
assert.Equal(t, "", p1.GetIdentifier())

p2 := webhook.MCCYAccountCreatedPayload{Identifiers: []webhook.MCCYIdentifier{{Identifier: "A"}, {Identifier: "B"}}}
assert.Equal(t, "A", p2.GetIdentifier())
}

func TestMCCYAccountUpdatedPayload_GetIdentifier(t *testing.T) {
p1 := webhook.MCCYAccountUpdatedPayload{}
assert.Equal(t, "", p1.GetIdentifier())

p2 := webhook.MCCYAccountUpdatedPayload{Identifiers: []webhook.MCCYIdentifier{{Identifier: "A"}, {Identifier: "B"}}}
assert.Equal(t, "A", p2.GetIdentifier())
}

func TestMCCYVirtualAccountCreatedPayload_GetIdentifier(t *testing.T) {
p1 := webhook.MCCYVirtualAccountCreatedPayload{}
assert.Equal(t, "", p1.GetIdentifier())

p2 := webhook.MCCYVirtualAccountCreatedPayload{Identifiers: []webhook.MCCYIdentifier{{Identifier: "A"}, {Identifier: "B"}}}
assert.Equal(t, "A", p2.GetIdentifier())
}

func TestMCCYVirtualAccountUpdatedPayload_GetIdentifier(t *testing.T) {
p1 := webhook.MCCYVirtualAccountUpdatedPayload{}
assert.Equal(t, "", p1.GetIdentifier())

p2 := webhook.MCCYVirtualAccountUpdatedPayload{Identifiers: []webhook.MCCYIdentifier{{Identifier: "A"}, {Identifier: "B"}}}
assert.Equal(t, "A", p2.GetIdentifier())
}

0 comments on commit 9d6f93f

Please sign in to comment.