Skip to content

Commit

Permalink
feat: fx
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Aug 29, 2023
1 parent 6528561 commit 5227769
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Client interface {
TestClient
RateClient
StatementClient
FxClient
}

var _ Client = (*client)(nil)
Expand Down
60 changes: 60 additions & 0 deletions fx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package clearbank

import (
"context"
"fmt"
"net/http"
)

type FxClient interface {
InitiateFxOrder(context.Context, FXPayload) error
}

type FXAttestation string

const (
FXAttestationSameOwner FXAttestation = "Y"
FXAttestationDifferentOwner FXAttestation = "N"
)

type FXPayload struct {
CustomerInformation struct {
SellAccount struct {
Owner string `json:"owner"`
IBAN string `json:"iban"`
} `json:"sellAccount"`
BuyAccount struct {
Owner string `json:"owner"`
IBAN string `json:"iban"`
} `json:"buyAccount"`
Attestation FXAttestation `json:"attestation"`
} `json:"customerInformation"`
TradeInformation struct {
ValueDate string `json:"valueDate,omitempty"`
Details struct {
InstructedAmount float64 `json:"instructedAmount"`
FixedSide FixedSide `json:"fixedSide"`
SellCurrency string `json:"sellCurrency"`
BuyCurrency string `json:"buyCurrency"`
} `json:"details"`
Margin struct {
Amount float64 `json:"amount"`
Account struct {
Owner string `json:"owner"`
IBAN string `json:"iban"`
} `json:"account"`
} `json:"margin,omitempty"`
EndToEndID string `json:"endToEndId"`
UnstructuredInformation string `json:"unstructuredInformation,omitempty"`
} `json:"tradeInformation"`
}

func (c *client) InitiateFxOrder(ctx context.Context, payload FXPayload) error {
req, err := c.newRequest(ctx, http.MethodPost, "/fx/v1/order", payload)
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}

req.ExpectStatus(http.StatusAccepted)
return c.do(ctx, req)
}
28 changes: 28 additions & 0 deletions fx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package clearbank_test

import (
"bytes"
"context"
"io"
"net/http"
"testing"

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

func TestInitiateFxOrder(t *testing.T) {
mockSigner := signature.NewMockSigner(t)
mockHttpClient := clearbank.NewMockHttpClient(t)
client := clearbank.NewClient("token", mockSigner, clearbank.WithHTTPClient(mockHttpClient))

ctx := clearbank.RequestIdContext(context.TODO(), "123")
mockSigner.On("Sign", ctx, mock.Anything).Return([]byte("signed"), nil).Once()

resp := &http.Response{StatusCode: http.StatusAccepted, Body: io.NopCloser(bytes.NewReader(nil))}
mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(resp, nil).Once()

assert.NoError(t, client.InitiateFxOrder(ctx, clearbank.FXPayload{}))
}

0 comments on commit 5227769

Please sign in to comment.