From b7b029f0c40d93eadba1826969c8eaa0d6edb9e7 Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Tue, 11 Jun 2024 17:00:58 +0200 Subject: [PATCH] Add transfer UUID field to airtime transfer --- flows/actions/testdata/transfer_airtime.json | 2 ++ flows/events/airtime_transferred.go | 15 +++++++++------ flows/events/base_test.go | 4 +++- flows/services.go | 5 ++++- services/airtime/dtone/service.go | 3 ++- services/airtime/dtone/service_test.go | 2 +- test/engine.go | 2 ++ .../runner/airtime.test_successful_transfer.json | 6 ++++-- 8 files changed, 27 insertions(+), 12 deletions(-) diff --git a/flows/actions/testdata/transfer_airtime.json b/flows/actions/testdata/transfer_airtime.json index 6f7d1b16d..0a9899ac1 100644 --- a/flows/actions/testdata/transfer_airtime.json +++ b/flows/actions/testdata/transfer_airtime.json @@ -194,6 +194,7 @@ "events": [ { "type": "airtime_transferred", + "transfer_uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", "created_on": "2018-10-18T14:20:30.000123456Z", "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "sender": "tel:+17036975131", @@ -292,6 +293,7 @@ "events": [ { "type": "airtime_transferred", + "transfer_uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", "created_on": "2018-10-18T14:20:30.000123456Z", "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "sender": "tel:+17036975131", diff --git a/flows/events/airtime_transferred.go b/flows/events/airtime_transferred.go index ebecc2dca..ab5355121 100644 --- a/flows/events/airtime_transferred.go +++ b/flows/events/airtime_transferred.go @@ -19,6 +19,7 @@ const TypeAirtimeTransferred string = "airtime_transferred" // { // "type": "airtime_transferred", // "created_on": "2006-01-02T15:04:05Z", +// "transfer_uuid": "552cd7ee-ccba-404d-9692-c1fe3b8d57c5", // "sender": "tel:4748", // "recipient": "tel:+1242563637", // "currency": "RWF", @@ -40,18 +41,20 @@ const TypeAirtimeTransferred string = "airtime_transferred" type AirtimeTransferredEvent struct { BaseEvent - Sender urns.URN `json:"sender"` - Recipient urns.URN `json:"recipient"` - Currency string `json:"currency"` - DesiredAmount decimal.Decimal `json:"desired_amount"` - ActualAmount decimal.Decimal `json:"actual_amount"` - HTTPLogs []*flows.HTTPLog `json:"http_logs"` + TransferUUID flows.AirtimeTransferUUID `json:"transfer_uuid"` + Sender urns.URN `json:"sender"` + Recipient urns.URN `json:"recipient"` + Currency string `json:"currency"` + DesiredAmount decimal.Decimal `json:"desired_amount"` + ActualAmount decimal.Decimal `json:"actual_amount"` + HTTPLogs []*flows.HTTPLog `json:"http_logs"` } // NewAirtimeTransferred creates a new airtime transferred event func NewAirtimeTransferred(t *flows.AirtimeTransfer, httpLogs []*flows.HTTPLog) *AirtimeTransferredEvent { return &AirtimeTransferredEvent{ BaseEvent: NewBaseEvent(TypeAirtimeTransferred), + TransferUUID: t.UUID, Sender: t.Sender, Recipient: t.Recipient, Currency: t.Currency, diff --git a/flows/events/base_test.go b/flows/events/base_test.go index 90159fe97..3bafc2946 100644 --- a/flows/events/base_test.go +++ b/flows/events/base_test.go @@ -57,6 +57,7 @@ func TestEventMarshaling(t *testing.T) { { events.NewAirtimeTransferred( &flows.AirtimeTransfer{ + UUID: flows.AirtimeTransferUUID("4c2d9b7a-e02c-4e6a-ab18-06df4cb5666d"), Sender: urns.URN("tel:+593979099111"), Recipient: urns.URN("tel:+593979099222"), Currency: "USD", @@ -98,7 +99,8 @@ func TestEventMarshaling(t *testing.T) { ], "recipient": "tel:+593979099222", "sender": "tel:+593979099111", - "type": "airtime_transferred" + "type": "airtime_transferred", + "transfer_uuid": "4c2d9b7a-e02c-4e6a-ab18-06df4cb5666d" }`, }, { diff --git a/flows/services.go b/flows/services.go index 02321fa40..07159f8e4 100644 --- a/flows/services.go +++ b/flows/services.go @@ -143,6 +143,9 @@ type TicketService interface { Open(env envs.Environment, contact *Contact, topic *Topic, body string, assignee *User, logHTTP HTTPLogCallback) (*Ticket, error) } +// AirtimeTransferUUID is the UUID of a airtime transfer +type AirtimeTransferUUID uuids.UUID + // AirtimeTransferStatus is a status of a airtime transfer type AirtimeTransferStatus string @@ -154,7 +157,7 @@ const ( // AirtimeTransfer is the result of an attempted airtime transfer type AirtimeTransfer struct { - UUID uuids.UUID + UUID AirtimeTransferUUID Sender urns.URN Recipient urns.URN Currency string diff --git a/services/airtime/dtone/service.go b/services/airtime/dtone/service.go index da0932c6d..c0d9450e8 100644 --- a/services/airtime/dtone/service.go +++ b/services/airtime/dtone/service.go @@ -29,9 +29,10 @@ func NewService(httpClient *http.Client, httpRetries *httpx.RetryConfig, key, se func (s *service) Transfer(sender urns.URN, recipient urns.URN, amounts map[string]decimal.Decimal, logHTTP flows.HTTPLogCallback) (*flows.AirtimeTransfer, error) { transfer := &flows.AirtimeTransfer{ - UUID: uuids.New(), + UUID: flows.AirtimeTransferUUID(uuids.New()), Sender: sender, Recipient: recipient, + Currency: "", DesiredAmount: decimal.Zero, ActualAmount: decimal.Zero, } diff --git a/services/airtime/dtone/service_test.go b/services/airtime/dtone/service_test.go index 09f34c59a..b95233fbf 100644 --- a/services/airtime/dtone/service_test.go +++ b/services/airtime/dtone/service_test.go @@ -58,7 +58,7 @@ func TestServiceWithSuccessfulTranfer(t *testing.T) { ) assert.NoError(t, err) assert.Equal(t, &flows.AirtimeTransfer{ - UUID: uuids.UUID("1ae96956-4b34-433e-8d1a-f05fe6923d6d"), + UUID: flows.AirtimeTransferUUID("1ae96956-4b34-433e-8d1a-f05fe6923d6d"), Sender: urns.URN("tel:+593979000000"), Recipient: urns.URN("tel:+593979123456"), Currency: "USD", diff --git a/test/engine.go b/test/engine.go index 02d4b01e5..4ba2b5987 100644 --- a/test/engine.go +++ b/test/engine.go @@ -7,6 +7,7 @@ import ( "github.com/nyaruka/gocommon/httpx" "github.com/nyaruka/gocommon/urns" + "github.com/nyaruka/gocommon/uuids" "github.com/nyaruka/goflow/envs" "github.com/nyaruka/goflow/flows" "github.com/nyaruka/goflow/flows/engine" @@ -120,6 +121,7 @@ func (s *airtimeService) Transfer(sender urns.URN, recipient urns.URN, amounts m } transfer := &flows.AirtimeTransfer{ + UUID: flows.AirtimeTransferUUID(uuids.New()), Sender: sender, Recipient: recipient, Currency: s.fixedCurrency, diff --git a/test/testdata/runner/airtime.test_successful_transfer.json b/test/testdata/runner/airtime.test_successful_transfer.json index b8b3b7800..364d9ba3b 100644 --- a/test/testdata/runner/airtime.test_successful_transfer.json +++ b/test/testdata/runner/airtime.test_successful_transfer.json @@ -167,7 +167,8 @@ "recipient": "tel:+12065551212", "sender": "", "step_uuid": "8720f157-ca1c-432f-9c0b-2014ddc77094", - "type": "airtime_transferred" + "type": "airtime_transferred", + "transfer_uuid": "c34b6c7d-fa06-4563-92a3-d648ab64bccb" }, { "category": "Success", @@ -251,7 +252,8 @@ "recipient": "tel:+12065551212", "sender": "", "step_uuid": "8720f157-ca1c-432f-9c0b-2014ddc77094", - "type": "airtime_transferred" + "type": "airtime_transferred", + "transfer_uuid": "c34b6c7d-fa06-4563-92a3-d648ab64bccb" }, { "category": "Success",