Skip to content

Commit

Permalink
Save airtime transfer transaction id as result and on event as extern…
Browse files Browse the repository at this point in the history
…al_id
  • Loading branch information
rowanseymour committed Jun 12, 2024
1 parent 797a567 commit bdbbac6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion flows/actions/testdata/transfer_airtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"transfer_uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d",
"external_id": "2237512891",
"sender": "tel:+17036975131",
"recipient": "tel:+12065551212?channel=57f1078f-88aa-46f4-a59a-948a5739c03d&id=123",
"currency": "USD",
Expand Down Expand Up @@ -240,7 +241,7 @@
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"name": "Reward Transfer",
"value": "3",
"value": "2237512891",
"category": "Success"
}
],
Expand Down Expand Up @@ -296,6 +297,7 @@
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"transfer_uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d",
"external_id": "",
"sender": "tel:+17036975131",
"recipient": "tel:+12065551212?channel=57f1078f-88aa-46f4-a59a-948a5739c03d&id=123",
"currency": "",
Expand Down
2 changes: 1 addition & 1 deletion flows/actions/transfer_airtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (a *TransferAirtimeAction) transfer(run flows.Run, logEvent flows.EventCall
}

func (a *TransferAirtimeAction) saveSuccess(run flows.Run, step flows.Step, transfer *flows.AirtimeTransfer, logEvent flows.EventCallback) {
a.saveResult(run, step, a.ResultName, transfer.ActualAmount.String(), CategorySuccess, "", "", nil, logEvent)
a.saveResult(run, step, a.ResultName, transfer.ExternalID, CategorySuccess, "", "", nil, logEvent)
}

func (a *TransferAirtimeAction) saveFailure(run flows.Run, step flows.Step, logEvent flows.EventCallback) {
Expand Down
4 changes: 3 additions & 1 deletion flows/events/airtime_transferred.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package events
import (
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/flows"

"github.com/shopspring/decimal"
)

Expand All @@ -20,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",
// "external_id": "12345678",
// "sender": "tel:4748",
// "recipient": "tel:+1242563637",
// "currency": "RWF",
Expand All @@ -42,6 +42,7 @@ type AirtimeTransferredEvent struct {
BaseEvent

TransferUUID flows.AirtimeTransferUUID `json:"transfer_uuid"`
ExternalID string `json:"external_id"`
Sender urns.URN `json:"sender"`
Recipient urns.URN `json:"recipient"`
Currency string `json:"currency"`
Expand All @@ -55,6 +56,7 @@ func NewAirtimeTransferred(t *flows.AirtimeTransfer, httpLogs []*flows.HTTPLog)
return &AirtimeTransferredEvent{
BaseEvent: NewBaseEvent(TypeAirtimeTransferred),
TransferUUID: t.UUID,
ExternalID: t.ExternalID,
Sender: t.Sender,
Recipient: t.Recipient,
Currency: t.Currency,
Expand Down
1 change: 1 addition & 0 deletions flows/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const (
// AirtimeTransfer is the result of an attempted airtime transfer
type AirtimeTransfer struct {
UUID AirtimeTransferUUID
ExternalID string
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 @@ -99,7 +99,7 @@ func (s *service) Transfer(sender urns.URN, recipient urns.URN, amounts map[stri
transfer.Currency = product.Destination.Unit
transfer.DesiredAmount = amounts[transfer.Currency]

// request synchronous confirmed transaction for this product
// request asynchronous confirmed transaction for this product
tx, trace, err := s.client.TransactionAsync(string(transfer.UUID), product.ID, recipientPhoneNumber)
if trace != nil {
logHTTP(flows.NewHTTPLog(trace, flows.HTTPStatusFromCode, s.redactor))
Expand All @@ -112,6 +112,7 @@ func (s *service) Transfer(sender urns.URN, recipient urns.URN, amounts map[stri
return transfer, fmt.Errorf("transaction to send product %d on operator %d ended with status %s", product.ID, operator.ID, tx.Status.Message)
}

transfer.ExternalID = fmt.Sprintf("%d", tx.ID)
transfer.ActualAmount = product.Destination.Amount

return transfer, nil
Expand Down

0 comments on commit bdbbac6

Please sign in to comment.