Skip to content

Commit

Permalink
feat: common trx info
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Sep 17, 2023
1 parent c8a94aa commit 226b473
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 1 deletion.
120 changes: 120 additions & 0 deletions webhook/mccy_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type WebhookMCTransactionCreatedPayload struct {
AdditionalProperties []AdditionalProperty `json:"AdditionalProperties" validate:"required"`
}

var _ Transaction = (*WebhookMCTransactionSettledPayload)(nil)

// WebhookMCTransactionSettledPayload
// This webhook confirms that a multicurrency transaction has been settled
type WebhookMCTransactionSettledPayload struct {
Expand All @@ -52,6 +54,66 @@ type WebhookMCTransactionSettledPayload struct {
AdditionalProperties []AdditionalProperty `json:"AdditionalProperties" validate:"required"`
}

func (w WebhookMCTransactionSettledPayload) GetID() uuid.UUID {
return w.TransactionID
}

func (w WebhookMCTransactionSettledPayload) GetEndToEndID() string {
return w.EndToEndID
}

func (w WebhookMCTransactionSettledPayload) GetCurrency() string {
return w.InstructedCurrency
}

func (w WebhookMCTransactionSettledPayload) GetAmount() float64 {
return w.InstructedAmount
}

func (w WebhookMCTransactionSettledPayload) IsReturn() bool {
return false
}

func (w WebhookMCTransactionSettledPayload) GetReference() string {
return w.Reference
}

func (w WebhookMCTransactionSettledPayload) GetAccountIdentifier() string {
if len(w.UltimateCreditorAccountIdentifiers) == 0 {
return ""
}
if w.InstructedAmount > 0 {
return w.UltimateCreditorAccountIdentifiers[0].Identifier
}
return w.UltimateDebtorAccountIdentifiers[0].Identifier
}

func (w WebhookMCTransactionSettledPayload) GetAccountOwner() string {
if w.InstructedAmount > 0 {
return w.UltimateCreditorName
}
return w.UltimateDebtorName
}

func (w WebhookMCTransactionSettledPayload) GetCounterpartAccountIdentifier() string {
if len(w.UltimateCreditorAccountIdentifiers) == 0 {
return ""
}
if w.InstructedAmount > 0 {
return w.UltimateDebtorAccountIdentifiers[0].Identifier
}
return w.UltimateCreditorAccountIdentifiers[0].Identifier
}

func (w WebhookMCTransactionSettledPayload) GetCounterpartAccountOwner() string {
if w.InstructedAmount > 0 {
return w.UltimateDebtorName
}
return w.UltimateCreditorName
}

var _ Transaction = (*WebhookMCTransactionCancelledPayload)(nil)

// WebhookMCTransactionCancelledPayload
// This webhook confirms that a multicurrency transaction has been canceled
type WebhookMCTransactionCancelledPayload struct {
Expand All @@ -74,6 +136,64 @@ type WebhookMCTransactionCancelledPayload struct {
CancellationReason string `json:"CancellationReason" validate:"required"`
}

func (w WebhookMCTransactionCancelledPayload) GetID() uuid.UUID {
return w.TransactionID
}

func (w WebhookMCTransactionCancelledPayload) GetEndToEndID() string {
return w.EndToEndID
}

func (w WebhookMCTransactionCancelledPayload) GetCurrency() string {
return w.InstructedCurrency
}

func (w WebhookMCTransactionCancelledPayload) GetAmount() float64 {
return w.InstructedAmount
}

func (w WebhookMCTransactionCancelledPayload) IsReturn() bool {
return false
}

func (w WebhookMCTransactionCancelledPayload) GetReference() string {
return w.Reference
}

func (w WebhookMCTransactionCancelledPayload) GetAccountIdentifier() string {
if len(w.UltimateCreditorAccountIdentifiers) == 0 {
return ""
}
if w.InstructedAmount > 0 {
return w.UltimateCreditorAccountIdentifiers[0].Identifier
}
return w.UltimateDebtorAccountIdentifiers[0].Identifier
}

func (w WebhookMCTransactionCancelledPayload) GetAccountOwner() string {
if w.InstructedAmount > 0 {
return w.UltimateCreditorName
}
return w.UltimateDebtorName
}

func (w WebhookMCTransactionCancelledPayload) GetCounterpartAccountIdentifier() string {
if len(w.UltimateCreditorAccountIdentifiers) == 0 {
return ""
}
if w.InstructedAmount > 0 {
return w.UltimateDebtorAccountIdentifiers[0].Identifier
}
return w.UltimateCreditorAccountIdentifiers[0].Identifier
}

func (w WebhookMCTransactionCancelledPayload) GetCounterpartAccountOwner() string {
if w.InstructedAmount > 0 {
return w.UltimateDebtorName
}
return w.UltimateCreditorName
}

// WebhookMCPayloadAssessmentFailedPayload
// This webhook confirms that a multicurrency payment has failed assessment
type WebhookMCPayloadAssessmentFailedPayload struct {
Expand Down
90 changes: 90 additions & 0 deletions webhook/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type TransactionAccount struct {
InstitutionName string `json:"InstitutionName"`
}

var _ Transaction = (*WebhookTransactionSettledPayload)(nil)

// WebhookTransactionSettledPayload
// This sends a webhook notification confirming the transaction has settled
type WebhookTransactionSettledPayload struct {
Expand Down Expand Up @@ -66,6 +68,51 @@ type WebhookTransactionSettledPayload struct {
} `json:"SupplementaryData"`
}

func (w WebhookTransactionSettledPayload) GetID() uuid.UUID {
return w.TransactionID
}

func (w WebhookTransactionSettledPayload) GetEndToEndID() string {
return w.EndToEndTransactionID
}

func (w WebhookTransactionSettledPayload) GetCurrency() string {
return w.CurrencyCode
}

func (w WebhookTransactionSettledPayload) GetAmount() float64 {
if w.DebitCreditCode == DebitCreditCodeDebit {
return -w.Amount
}
return w.Amount
}

func (w WebhookTransactionSettledPayload) IsReturn() bool {
return w.Return
}

func (w WebhookTransactionSettledPayload) GetReference() string {
return w.Reference
}

func (w WebhookTransactionSettledPayload) GetAccountIdentifier() string {
return w.Account.IBAN
}

func (w WebhookTransactionSettledPayload) GetAccountOwner() string {
return w.Account.OwnerName
}

func (w WebhookTransactionSettledPayload) GetCounterpartAccountIdentifier() string {
return w.CounterpartAccount.IBAN
}

func (w WebhookTransactionSettledPayload) GetCounterpartAccountOwner() string {
return w.CounterpartAccount.TransactionOwnerName
}

var _ Transaction = (*WebhookTransactionRejectedPayload)(nil)

// WebhookTransactionRejectedPayload
// This webhook confirms the payment has been rejected
type WebhookTransactionRejectedPayload struct {
Expand All @@ -85,6 +132,49 @@ type WebhookTransactionRejectedPayload struct {
CounterpartAccount TransactionAccount `json:"CounterpartAccount" validate:"required"`
}

func (w WebhookTransactionRejectedPayload) GetID() uuid.UUID {
return w.TransactionID
}

func (w WebhookTransactionRejectedPayload) GetEndToEndID() string {
return w.EndToEndTransactionID
}

func (w WebhookTransactionRejectedPayload) GetCurrency() string {
return w.CurrencyCode
}

func (w WebhookTransactionRejectedPayload) GetAmount() float64 {
if w.DebitCreditCode == DebitCreditCodeDebit {
return -w.Amount
}
return w.Amount
}

func (w WebhookTransactionRejectedPayload) IsReturn() bool {
return w.Return
}

func (w WebhookTransactionRejectedPayload) GetReference() string {
return w.Reference
}

func (w WebhookTransactionRejectedPayload) GetAccountIdentifier() string {
return w.Account.IBAN
}

func (w WebhookTransactionRejectedPayload) GetAccountOwner() string {
return w.Account.OwnerName
}

func (w WebhookTransactionRejectedPayload) GetCounterpartAccountIdentifier() string {
return w.CounterpartAccount.IBAN
}

func (w WebhookTransactionRejectedPayload) GetCounterpartAccountOwner() string {
return w.CounterpartAccount.TransactionOwnerName
}

// WebhookPaymentMessageAssesmentFailedPayload
// This webhook confirms the payment assessment has failed
type WebhookPaymentMessageAssesmentFailedPayload struct {
Expand Down
20 changes: 19 additions & 1 deletion webhook/webhook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package webhook

import "encoding/json"
import (
"encoding/json"

"github.com/google/uuid"
)

const (
Test = "FITestEvent"
Expand Down Expand Up @@ -41,3 +45,17 @@ type WebhookResponse struct {
// The value that you receive in the webhook request.
Nonce int `json:"Nonce"`
}

// Transaction is a common interface for the transaction related webhooks.
type Transaction interface {
GetID() uuid.UUID
GetEndToEndID() string
GetCurrency() string
GetAmount() float64
IsReturn() bool
GetReference() string
GetAccountIdentifier() string
GetAccountOwner() string
GetCounterpartAccountIdentifier() string
GetCounterpartAccountOwner() string
}

0 comments on commit 226b473

Please sign in to comment.