Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transfer UUID field to airtime transfer #1266

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flows/actions/testdata/transfer_airtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 9 additions & 6 deletions flows/events/airtime_transferred.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion flows/events/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}`,
},
{
Expand Down
5 changes: 4 additions & 1 deletion flows/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion services/airtime/dtone/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion services/airtime/dtone/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions test/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions test/testdata/runner/airtime.test_successful_transfer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading