diff --git a/flows/actions/testdata/transfer_airtime.json b/flows/actions/testdata/transfer_airtime.json index 33a4f69f6..46a215a04 100644 --- a/flows/actions/testdata/transfer_airtime.json +++ b/flows/actions/testdata/transfer_airtime.json @@ -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", @@ -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" } ], @@ -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": "", diff --git a/flows/actions/transfer_airtime.go b/flows/actions/transfer_airtime.go index 79df5a195..4cc6318ae 100644 --- a/flows/actions/transfer_airtime.go +++ b/flows/actions/transfer_airtime.go @@ -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) { diff --git a/flows/events/airtime_transferred.go b/flows/events/airtime_transferred.go index ab5355121..f243c4ec6 100644 --- a/flows/events/airtime_transferred.go +++ b/flows/events/airtime_transferred.go @@ -3,7 +3,6 @@ package events import ( "github.com/nyaruka/gocommon/urns" "github.com/nyaruka/goflow/flows" - "github.com/shopspring/decimal" ) @@ -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", @@ -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"` @@ -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, diff --git a/flows/services.go b/flows/services.go index 07159f8e4..f8fa6844b 100644 --- a/flows/services.go +++ b/flows/services.go @@ -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 diff --git a/services/airtime/dtone/service.go b/services/airtime/dtone/service.go index c0d9450e8..44a279768 100644 --- a/services/airtime/dtone/service.go +++ b/services/airtime/dtone/service.go @@ -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)) @@ -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