-
-
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
6528561
commit 5227769
Showing
3 changed files
with
89 additions
and
0 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
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) | ||
} |
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,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{})) | ||
} |