Skip to content

Commit

Permalink
Merge pull request #1269 from nyaruka/transfer_external_id
Browse files Browse the repository at this point in the history
Save airtime transfer transaction id as result and on event as external_id
  • Loading branch information
rowanseymour authored Jun 12, 2024
2 parents 797a567 + 1180684 commit 543063b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 58 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
4 changes: 3 additions & 1 deletion flows/events/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func TestEventMarshaling(t *testing.T) {
{
events.NewAirtimeTransferred(
&flows.AirtimeTransfer{
UUID: flows.AirtimeTransferUUID("4c2d9b7a-e02c-4e6a-ab18-06df4cb5666d"),
UUID: "4c2d9b7a-e02c-4e6a-ab18-06df4cb5666d",
ExternalID: "98765432",
Sender: urns.URN("tel:+593979099111"),
Recipient: urns.URN("tel:+593979099222"),
Currency: "USD",
Expand Down Expand Up @@ -85,6 +86,7 @@ func TestEventMarshaling(t *testing.T) {
"created_on": "2018-10-18T14:20:30.000123456Z",
"currency": "USD",
"desired_amount": 1.2,
"external_id": "98765432",
"http_logs": [
{
"url": "https://send.money.com/topup",
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
3 changes: 2 additions & 1 deletion services/airtime/dtone/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func TestServiceWithSuccessfulTranfer(t *testing.T) {
)
assert.NoError(t, err)
assert.Equal(t, &flows.AirtimeTransfer{
UUID: flows.AirtimeTransferUUID("1ae96956-4b34-433e-8d1a-f05fe6923d6d"),
UUID: "1ae96956-4b34-433e-8d1a-f05fe6923d6d",
ExternalID: "2237512891",
Sender: urns.URN("tel:+593979000000"),
Recipient: urns.URN("tel:+593979123456"),
Currency: "USD",
Expand Down
106 changes: 54 additions & 52 deletions test/testdata/runner/airtime.test_successful_transfer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
{
"http_mocks": {
"https://dvs-api.dtone.com/v1/async/transactions": [
{
"body": {
"confirmation_date": "2021-03-24T20:05:06.111631000Z",
"confirmation_expiration_date": "2021-03-24T21:05:05.883561000Z",
"creation_date": "2021-03-24T20:05:05.883561000Z",
"credit_party_identifier": {
"mobile_number": "+593979123456"
},
"external_id": "EX12345",
"id": 2237512891,
"product": {
"description": "",
"id": 6035,
"name": "3 USD",
"operator": {
"country": {
"iso_code": "ECU",
"name": "Ecuador",
"regions": null
},
"id": 1596,
"name": "Claro Ecuador",
"regions": null
},
"regions": null,
"service": {
"id": 1,
"name": "Mobile"
},
"type": "FIXED_VALUE_RECHARGE"
},
"status": {
"class": {
"id": 2,
"message": "CONFIRMED"
},
"id": 20000,
"message": "CONFIRMED"
}
},
"status": 200
}
],
"https://dvs-api.dtone.com/v1/lookup/mobile-number": [
{
"body": [
Expand Down Expand Up @@ -78,50 +122,6 @@
],
"status": 200
}
],
"https://dvs-api.dtone.com/v1/async/transactions": [
{
"body": {
"confirmation_date": "2021-03-24T20:05:06.111631000Z",
"confirmation_expiration_date": "2021-03-24T21:05:05.883561000Z",
"creation_date": "2021-03-24T20:05:05.883561000Z",
"credit_party_identifier": {
"mobile_number": "+593979123456"
},
"external_id": "EX12345",
"id": 2237512891,
"product": {
"description": "",
"id": 6035,
"name": "3 USD",
"operator": {
"country": {
"iso_code": "ECU",
"name": "Ecuador",
"regions": null
},
"id": 1596,
"name": "Claro Ecuador",
"regions": null
},
"regions": null,
"service": {
"id": 1,
"name": "Mobile"
},
"type": "FIXED_VALUE_RECHARGE"
},
"status": {
"class": {
"id": 2,
"message": "CONFIRMED"
},
"id": 20000,
"message": "CONFIRMED"
}
},
"status": 200
}
]
},
"outputs": [
Expand All @@ -132,6 +132,7 @@
"created_on": "2018-07-06T12:30:08.123456789Z",
"currency": "USD",
"desired_amount": 3.5,
"external_id": "2237512891",
"http_logs": [
{
"created_on": "2018-07-06T12:30:02.123456789Z",
Expand Down Expand Up @@ -167,16 +168,16 @@
"recipient": "tel:+12065551212",
"sender": "",
"step_uuid": "8720f157-ca1c-432f-9c0b-2014ddc77094",
"type": "airtime_transferred",
"transfer_uuid": "c34b6c7d-fa06-4563-92a3-d648ab64bccb"
"transfer_uuid": "c34b6c7d-fa06-4563-92a3-d648ab64bccb",
"type": "airtime_transferred"
},
{
"category": "Success",
"created_on": "2018-07-06T12:30:12.123456789Z",
"name": "Transfer",
"step_uuid": "8720f157-ca1c-432f-9c0b-2014ddc77094",
"type": "run_result_changed",
"value": "3"
"value": "2237512891"
}
],
"segments": [],
Expand Down Expand Up @@ -217,11 +218,12 @@
"created_on": "2018-07-06T12:30:08.123456789Z",
"currency": "USD",
"desired_amount": 3.5,
"external_id": "2237512891",
"http_logs": [
{
"created_on": "2018-07-06T12:30:02.123456789Z",
"elapsed_ms": 1000,
"request": "POST /v1/lookup/mobile-number HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nContent-Length: 32\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n{\"mobile_number\":\"+12065551212\"}",
"request": "POST /v1/lookup/mobile-number HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nContent-Length: 32\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n{\"mobile_number\":\"+12065551212\"}",
"response": "HTTP/1.0 200 OK\r\nContent-Length: 191\r\n\r\n[\n {\n \"id\": 1596,\n \"identified\": true,\n \"name\": \"Claro Ecuador\"\n }\n ]",
"retries": 0,
"status": "success",
Expand Down Expand Up @@ -252,16 +254,16 @@
"recipient": "tel:+12065551212",
"sender": "",
"step_uuid": "8720f157-ca1c-432f-9c0b-2014ddc77094",
"type": "airtime_transferred",
"transfer_uuid": "c34b6c7d-fa06-4563-92a3-d648ab64bccb"
"transfer_uuid": "c34b6c7d-fa06-4563-92a3-d648ab64bccb",
"type": "airtime_transferred"
},
{
"category": "Success",
"created_on": "2018-07-06T12:30:12.123456789Z",
"name": "Transfer",
"step_uuid": "8720f157-ca1c-432f-9c0b-2014ddc77094",
"type": "run_result_changed",
"value": "3"
"value": "2237512891"
}
],
"exited_on": "2018-07-06T12:30:14.123456789Z",
Expand All @@ -284,7 +286,7 @@
"created_on": "2018-07-06T12:30:10.123456789Z",
"name": "Transfer",
"node_uuid": "75656148-9e8b-4611-82c0-7ff4b55fb44a",
"value": "3"
"value": "2237512891"
}
},
"status": "completed",
Expand Down

0 comments on commit 543063b

Please sign in to comment.