Skip to content

Commit

Permalink
feat: inbound outbound
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Jun 27, 2024
1 parent 84499a4 commit 24b9eae
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
15 changes: 15 additions & 0 deletions webhook/testdata/InboundHeldTransaction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"TimestampCreated": "2019-03-01T00:00:00Z",
"Scheme": "Chaps",
"Account": {
"BBAN": "CUBK11223312345678",
"IBAN": "GB00CUBK11223312345678"
},
"CounterpartAccount": {
"BBAN": "CUBK44556687654321",
"IBAN": "GB00CUBK44556687654321"
},
"TransactionAmount": 88.52,
"PaymentReference": "ee9a790ea56c142c6b538916c8bd6bcc",
"EndToEndTransactionId": "5e30e0b4bfb0"
}
14 changes: 14 additions & 0 deletions webhook/testdata/OutboundHeldTransaction-no-time.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Scheme": "Chaps",
"CounterpartAccount": {
"BBAN": "CUBK44556687654321",
"IBAN": "GB00CUBK44556687654321"
},
"Account": {
"BBAN": "CUBK11223312345678",
"IBAN": "GB00CUBK11223312345678"
},
"TransactionAmount": 88.52,
"PaymentReference": "a6f3c732a6a0b2a8018a06e10c6ecae2",
"EndToEndTransactionId": "b0c50dc87f86"
}
15 changes: 15 additions & 0 deletions webhook/testdata/OutboundHeldTransaction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"TimestampCreated": "2019-03-01T00:00:00Z",
"Scheme": "Chaps",
"CounterpartAccount": {
"BBAN": "CUBK44556687654321",
"IBAN": "GB00CUBK44556687654321"
},
"Account": {
"BBAN": "CUBK11223312345678",
"IBAN": "GB00CUBK11223312345678"
},
"TransactionAmount": 88.52,
"PaymentReference": "a6f3c732a6a0b2a8018a06e10c6ecae2",
"EndToEndTransactionId": "b0c50dc87f86"
}
36 changes: 36 additions & 0 deletions webhook/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,39 @@ type PaymentMessageValidationFailedPayload struct {
} `json:"Creditors" validate:"required"`
} `json:"AccountIdentification" validate:"required"`
}

// InboundHeldTransactionPayload
// This webhook confirms the inbound transaction has been held
type InboundHeldTransactionPayload struct {
Scheme string `json:"Scheme" validate:"required"`
Account struct {
IBAN string `json:"IBAN" validate:"required"`
BBAN string `json:"BBAN" validate:"required"`
} `json:"Account" validate:"required"`
CounterpartAccount struct {
IBAN string `json:"IBAN" validate:"required"`
BBAN string `json:"BBAN" validate:"required"`
} `json:"CounterpartAccount" validate:"required"`
TransactionAmount float64 `json:"TransactionAmount"`
PaymentReference string `json:"PaymentReference"`
EndToEndTransactionID string `json:"EndToEndTransactionID"`
TimestampCreated clearbank.Time `json:"TimestampCreated"`
}

// OutboundHeldTransactionPayload
// This webhook confirms the outbound transaction has been held
type OutboundHeldTransactionPayload struct {
Scheme string `json:"Scheme" validate:"required"`
Account struct {
IBAN string `json:"IBAN" validate:"required"`
BBAN string `json:"BBAN" validate:"required"`
} `json:"Account" validate:"required"`
CounterpartAccount struct {
IBAN string `json:"IBAN" validate:"required"`
BBAN string `json:"BBAN" validate:"required"`
} `json:"CounterpartAccount" validate:"required"`
TransactionAmount float64 `json:"TransactionAmount"`
PaymentReference string `json:"PaymentReference"`
EndToEndTransactionID string `json:"EndToEndTransactionID"`
TimestampCreated clearbank.Time `json:"TimestampCreated"`
}
27 changes: 27 additions & 0 deletions webhook/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

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

//go:embed testdata/TransactionSettled-with-supplementary.json
Expand All @@ -15,6 +16,15 @@ var transactionSettledWithSupplementary []byte
//go:embed testdata/TransactionSettled-no-supplementary.json
var transactionSettledNoSupplementary []byte

//go:embed testdata/InboundHeldTransaction.json
var inboundHeldTransaction []byte

//go:embed testdata/OutboundHeldTransaction.json
var outboundHeldTransaction []byte

//go:embed testdata/OutboundHeldTransaction-no-time.json
var outboundHeldTransactionNoTime []byte

func TestTransactionSettledPayload(t *testing.T) {
var d1 webhook.TransactionSettledPayload
err := json.Unmarshal(transactionSettledWithSupplementary, &d1)
Expand All @@ -26,3 +36,20 @@ func TestTransactionSettledPayload(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, d2.SupplementaryData, 0)
}

func TestHeldTransaction(t *testing.T) {
var d1 webhook.InboundHeldTransactionPayload
err := json.Unmarshal(inboundHeldTransaction, &d1)
require.NoError(t, err)
assert.Equal(t, "GB00CUBK11223312345678", d1.Account.IBAN)

var d2 webhook.OutboundHeldTransactionPayload
err = json.Unmarshal(outboundHeldTransaction, &d2)
require.NoError(t, err)
assert.Equal(t, "GB00CUBK11223312345678", d2.Account.IBAN)

var d3 webhook.OutboundHeldTransactionPayload
err = json.Unmarshal(outboundHeldTransactionNoTime, &d3)
require.NoError(t, err)
assert.Equal(t, "GB00CUBK11223312345678", d3.Account.IBAN)
}
2 changes: 2 additions & 0 deletions webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
PaymentMessageAssesmentFailed = "PaymentMessageAssesmentFailed"
PaymentMessageValidationFailed = "PaymentMessageValidationFailed"
TransactionRejected = "TransactionRejected"
OutboundHeldTransaction = "OutboundHeldTransaction"
InboundHeldTransaction = "InboundHeldTransaction"
MCCYAccountCreated = "Accounts.AccountCreated"
MCCYAccountUpdated = "Accounts.AccountUpdated"
MCCYVirtualAccountCreated = "Accounts.VirtualAccountCreated"
Expand Down

0 comments on commit 24b9eae

Please sign in to comment.