diff --git a/flows/actions/testdata/transfer_airtime.json b/flows/actions/testdata/transfer_airtime.json index 2c74b89b2..1a065712e 100644 --- a/flows/actions/testdata/transfer_airtime.json +++ b/flows/actions/testdata/transfer_airtime.json @@ -58,7 +58,7 @@ { "description": "Transfer and set result events if transfer made", "http_mocks": { - "https://dvs-api.dtone.com/v1/lookup/mobile-number/+12065551212": [ + "https://dvs-api.dtone.com/v1/lookup/mobile-number": [ { "status": 200, "body": [ @@ -137,7 +137,7 @@ ] } ], - "https://dvs-api.dtone.com/v1/sync/transactions": [ + "https://dvs-api.dtone.com/v1/async/transactions": [ { "status": 200, "body": { @@ -203,9 +203,9 @@ "actual_amount": 3, "http_logs": [ { - "url": "https://dvs-api.dtone.com/v1/lookup/mobile-number/+12065551212", + "url": "https://dvs-api.dtone.com/v1/lookup/mobile-number", "status_code": 200, - "request": "GET /v1/lookup/mobile-number/+12065551212 HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nAccept-Encoding: gzip\r\n\r\n", + "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: 215\r\n\r\n[\n {\n \"id\": 1596,\n \"name\": \"Claro Ecuador\",\n \"identified\": true\n }\n ]", "elapsed_ms": 0, "retries": 0, @@ -223,9 +223,9 @@ "created_on": "2018-10-18T14:20:30.000123456Z" }, { - "url": "https://dvs-api.dtone.com/v1/sync/transactions", + "url": "https://dvs-api.dtone.com/v1/async/transactions", "status_code": 200, - "request": "POST /v1/sync/transactions HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nContent-Length: 151\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n{\"external_id\":\"9688d21d-95aa-4bed-afc7-f31b35731a3d\",\"product_id\":6035,\"auto_confirm\":true,\"credit_party_identifier\":{\"mobile_number\":\"+12065551212\"}}", + "request": "POST /v1/async/transactions HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nContent-Length: 151\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n{\"external_id\":\"9688d21d-95aa-4bed-afc7-f31b35731a3d\",\"product_id\":6035,\"auto_confirm\":true,\"credit_party_identifier\":{\"mobile_number\":\"+12065551212\"}}", "response": "HTTP/1.0 200 OK\r\nContent-Length: 1746\r\n\r\n{\n \"confirmation_date\": \"2021-03-24T20:05:06.111631000Z\",\n \"confirmation_expiration_date\": \"2021-03-24T21:05:05.883561000Z\",\n \"creation_date\": \"2021-03-24T20:05:05.883561000Z\",\n \"credit_party_identifier\": {\n \"mobile_number\": \"+593979123456\"\n },\n \"external_id\": \"EX12345\",\n \"id\": 2237512891,\n \"product\": {\n \"description\": \"\",\n \"id\": 6035,\n \"name\": \"3 USD\",\n \"operator\": {\n \"country\": {\n \"iso_code\": \"ECU\",\n \"name\": \"Ecuador\",\n \"regions\": null\n },\n \"id\": 1596,\n \"name\": \"Claro Ecuador\",\n \"regions\": null\n },\n \"regions\": null,\n \"service\": {\n \"id\": 1,\n \"name\": \"Mobile\"\n },\n \"type\": \"FIXED_VALUE_RECHARGE\"\n },\n \"status\": {\n \"class\": {\n \"id\": 2,\n \"message\": \"CONFIRMED\"\n },\n \"id\": 20000,\n \"message\": \"CONFIRMED\"\n }\n }", "elapsed_ms": 0, "retries": 0, @@ -266,7 +266,7 @@ { "description": "Transfer failed if lookup number API request returns error response", "http_mocks": { - "https://dvs-api.dtone.com/v1/lookup/mobile-number/+12065551212": [ + "https://dvs-api.dtone.com/v1/lookup/mobile-number": [ { "status": 400, "body": { @@ -301,9 +301,9 @@ "actual_amount": 0, "http_logs": [ { - "url": "https://dvs-api.dtone.com/v1/lookup/mobile-number/+12065551212", + "url": "https://dvs-api.dtone.com/v1/lookup/mobile-number", "status_code": 400, - "request": "GET /v1/lookup/mobile-number/+12065551212 HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nAccept-Encoding: gzip\r\n\r\n", + "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 400 Bad Request\r\nContent-Length: 254\r\n\r\n{\n \"errors\": [\n {\n \"code\": 50000,\n \"message\": \"that didn't work\"\n }\n ]\n }", "elapsed_ms": 0, "retries": 0, diff --git a/services/airtime/dtone/client.go b/services/airtime/dtone/client.go index da24f378e..a5acd27d2 100644 --- a/services/airtime/dtone/client.go +++ b/services/airtime/dtone/client.go @@ -74,10 +74,16 @@ type Operator struct { } // LookupMobileNumber see https://dvs-api-doc.dtone.com/#tag/Mobile-Number -func (c *Client) LookupMobileNumber(tel string) ([]*Operator, *httpx.Trace, error) { +func (c *Client) LookupMobileNumber(phoneNumber string) ([]*Operator, *httpx.Trace, error) { var response []*Operator - trace, err := c.request("GET", fmt.Sprintf("lookup/mobile-number/%s", tel), nil, &response) + payload := &struct { + MobileNumber string `json:"mobile_number"` + }{ + MobileNumber: phoneNumber, + } + + trace, err := c.request("POST", "lookup/mobile-number", payload, &response) if err != nil { return nil, trace, err } @@ -142,8 +148,8 @@ type Transaction struct { } `json:"status"` } -// TransactionSync see https://dvs-api-doc.dtone.com/#tag/Transactions -func (c *Client) TransactionSync(externalID string, productID int, mobileNumber string) (*Transaction, *httpx.Trace, error) { +// TransactionAsync see https://dvs-api-doc.dtone.com/#tag/Transactions +func (c *Client) TransactionAsync(externalID string, productID int, mobileNumber string) (*Transaction, *httpx.Trace, error) { var response *Transaction type creditPartyIdentifier struct { @@ -164,7 +170,7 @@ func (c *Client) TransactionSync(externalID string, productID int, mobileNumber }, } - trace, err := c.request("POST", "sync/transactions", payload, &response) + trace, err := c.request("POST", "async/transactions", payload, &response) if err != nil { return nil, trace, err } diff --git a/services/airtime/dtone/client_test.go b/services/airtime/dtone/client_test.go index 8a4c75b93..9cea31273 100644 --- a/services/airtime/dtone/client_test.go +++ b/services/airtime/dtone/client_test.go @@ -344,14 +344,14 @@ func TestClient(t *testing.T) { defer dates.SetNowSource(dates.DefaultNowSource) mocks := httpx.NewMockRequestor(map[string][]*httpx.MockResponse{ - "https://dvs-api.dtone.com/v1/lookup/mobile-number/+593979123456": { + "https://dvs-api.dtone.com/v1/lookup/mobile-number": { httpx.NewMockResponse(200, nil, []byte(lookupNumberResponse)), // successful mobile number lookup httpx.MockConnectionError, // timeout }, "https://dvs-api.dtone.com/v1/products?type=FIXED_VALUE_RECHARGE&operator_id=1596&per_page=100": { httpx.NewMockResponse(200, nil, []byte(productsResponse)), }, - "https://dvs-api.dtone.com/v1/sync/transactions": { + "https://dvs-api.dtone.com/v1/async/transactions": { httpx.NewMockResponse(200, nil, []byte(transactionRejectedResponse)), }, }) @@ -385,10 +385,10 @@ func TestClient(t *testing.T) { test.AssertSnapshot(t, "products", string(trace.RequestTrace)) // create a synchronous transaction - tx, trace, err := cl.TransactionSync("EX12345", 6035, "+593979123456") + tx, trace, err := cl.TransactionAsync("EX12345", 6035, "+593979123456") assert.NoError(t, err) assert.Equal(t, int64(2237512891), tx.ID) assert.Equal(t, "EX12345", tx.ExternalID) assert.Equal(t, "REJECTED-OPERATOR-CURRENTLY-UNAVAILABLE", tx.Status.Message) - test.AssertSnapshot(t, "transaction_sync", string(trace.RequestTrace)) + test.AssertSnapshot(t, "transaction_async", string(trace.RequestTrace)) } diff --git a/services/airtime/dtone/service.go b/services/airtime/dtone/service.go index 805363f8e..cfc3ea5e9 100644 --- a/services/airtime/dtone/service.go +++ b/services/airtime/dtone/service.go @@ -94,7 +94,7 @@ func (s *service) Transfer(sender urns.URN, recipient urns.URN, amounts map[stri transfer.DesiredAmount = amounts[transfer.Currency] // request synchronous confirmed transaction for this product - tx, trace, err := s.client.TransactionSync(string(transfer.UUID), product.ID, recipient.Path()) + tx, trace, err := s.client.TransactionAsync(string(transfer.UUID), product.ID, recipient.Path()) if trace != nil { logHTTP(flows.NewHTTPLog(trace, flows.HTTPStatusFromCode, s.redactor)) } diff --git a/services/airtime/dtone/service_test.go b/services/airtime/dtone/service_test.go index d0744d604..09f34c59a 100644 --- a/services/airtime/dtone/service_test.go +++ b/services/airtime/dtone/service_test.go @@ -27,13 +27,13 @@ func TestServiceWithSuccessfulTranfer(t *testing.T) { defer httpx.SetRequestor(httpx.DefaultRequestor) mocks := httpx.NewMockRequestor(map[string][]*httpx.MockResponse{ - "https://dvs-api.dtone.com/v1/lookup/mobile-number/+593979123456": { + "https://dvs-api.dtone.com/v1/lookup/mobile-number": { httpx.NewMockResponse(200, nil, []byte(lookupNumberResponse)), // successful mobile number lookup }, "https://dvs-api.dtone.com/v1/products?type=FIXED_VALUE_RECHARGE&operator_id=1596&per_page=100": { httpx.NewMockResponse(200, nil, []byte(productsResponse)), }, - "https://dvs-api.dtone.com/v1/sync/transactions": { + "https://dvs-api.dtone.com/v1/async/transactions": { httpx.NewMockResponse(200, nil, []byte(transactionConfirmedResponse)), }, }) @@ -77,7 +77,7 @@ func TestServiceFailedTransfers(t *testing.T) { defer httpx.SetRequestor(httpx.DefaultRequestor) mocks := httpx.NewMockRequestor(map[string][]*httpx.MockResponse{ - "https://dvs-api.dtone.com/v1/lookup/mobile-number/+593979123456": { + "https://dvs-api.dtone.com/v1/lookup/mobile-number": { httpx.MockConnectionError, // timeout httpx.NewMockResponse(400, nil, errorResp(1005003, "Credit party mobile number is invalid")), httpx.NewMockResponse(200, nil, []byte(`[]`)), // no matches @@ -92,7 +92,7 @@ func TestServiceFailedTransfers(t *testing.T) { httpx.NewMockResponse(200, nil, []byte(productsResponse)), httpx.NewMockResponse(200, nil, []byte(productsResponse)), }, - "https://dvs-api.dtone.com/v1/sync/transactions": { + "https://dvs-api.dtone.com/v1/async/transactions": { httpx.NewMockResponse(400, nil, errorResp(1003001, "Something went wrong")), httpx.NewMockResponse(200, nil, []byte(transactionRejectedResponse)), }, diff --git a/services/airtime/dtone/testdata/TestClient_lookup_mobile_number.snap b/services/airtime/dtone/testdata/TestClient_lookup_mobile_number.snap index 5291a696c..fb78bb65c 100644 --- a/services/airtime/dtone/testdata/TestClient_lookup_mobile_number.snap +++ b/services/airtime/dtone/testdata/TestClient_lookup_mobile_number.snap @@ -1,6 +1,9 @@ -GET /v1/lookup/mobile-number/+593979123456 HTTP/1.1 +POST /v1/lookup/mobile-number HTTP/1.1 Host: dvs-api.dtone.com User-Agent: Go-http-client/1.1 +Content-Length: 33 Authorization: Basic a2V5MTIzOnNlc2FtZQ== +Content-Type: application/json Accept-Encoding: gzip +{"mobile_number":"+593979123456"} \ No newline at end of file diff --git a/services/airtime/dtone/testdata/TestClient_transaction_sync.snap b/services/airtime/dtone/testdata/TestClient_transaction_async.snap similarity index 86% rename from services/airtime/dtone/testdata/TestClient_transaction_sync.snap rename to services/airtime/dtone/testdata/TestClient_transaction_async.snap index bf6311c1b..f95002a34 100644 --- a/services/airtime/dtone/testdata/TestClient_transaction_sync.snap +++ b/services/airtime/dtone/testdata/TestClient_transaction_async.snap @@ -1,4 +1,4 @@ -POST /v1/sync/transactions HTTP/1.1 +POST /v1/async/transactions HTTP/1.1 Host: dvs-api.dtone.com User-Agent: Go-http-client/1.1 Content-Length: 123 diff --git a/test/testdata/runner/airtime.test_successful_transfer.json b/test/testdata/runner/airtime.test_successful_transfer.json index cb8e24943..b8b3b7800 100644 --- a/test/testdata/runner/airtime.test_successful_transfer.json +++ b/test/testdata/runner/airtime.test_successful_transfer.json @@ -1,6 +1,6 @@ { "http_mocks": { - "https://dvs-api.dtone.com/v1/lookup/mobile-number/+12065551212": [ + "https://dvs-api.dtone.com/v1/lookup/mobile-number": [ { "body": [ { @@ -79,7 +79,7 @@ "status": 200 } ], - "https://dvs-api.dtone.com/v1/sync/transactions": [ + "https://dvs-api.dtone.com/v1/async/transactions": [ { "body": { "confirmation_date": "2021-03-24T20:05:06.111631000Z", @@ -136,12 +136,12 @@ { "created_on": "2018-07-06T12:30:02.123456789Z", "elapsed_ms": 1000, - "request": "GET /v1/lookup/mobile-number/+12065551212 HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nAccept-Encoding: gzip\r\n\r\n", + "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", "status_code": 200, - "url": "https://dvs-api.dtone.com/v1/lookup/mobile-number/+12065551212" + "url": "https://dvs-api.dtone.com/v1/lookup/mobile-number" }, { "created_on": "2018-07-06T12:30:04.123456789Z", @@ -156,12 +156,12 @@ { "created_on": "2018-07-06T12:30:06.123456789Z", "elapsed_ms": 1000, - "request": "POST /v1/sync/transactions HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nContent-Length: 151\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n{\"external_id\":\"c34b6c7d-fa06-4563-92a3-d648ab64bccb\",\"product_id\":6035,\"auto_confirm\":true,\"credit_party_identifier\":{\"mobile_number\":\"+12065551212\"}}", + "request": "POST /v1/async/transactions HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nContent-Length: 151\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n{\"external_id\":\"c34b6c7d-fa06-4563-92a3-d648ab64bccb\",\"product_id\":6035,\"auto_confirm\":true,\"credit_party_identifier\":{\"mobile_number\":\"+12065551212\"}}", "response": "HTTP/1.0 200 OK\r\nContent-Length: 1594\r\n\r\n{\n \"confirmation_date\": \"2021-03-24T20:05:06.111631000Z\",\n \"confirmation_expiration_date\": \"2021-03-24T21:05:05.883561000Z\",\n \"creation_date\": \"2021-03-24T20:05:05.883561000Z\",\n \"credit_party_identifier\": {\n \"mobile_number\": \"+593979123456\"\n },\n \"external_id\": \"EX12345\",\n \"id\": 2237512891,\n \"product\": {\n \"description\": \"\",\n \"id\": 6035,\n \"name\": \"3 USD\",\n \"operator\": {\n \"country\": {\n \"iso_code\": \"ECU\",\n \"name\": \"Ecuador\",\n \"regions\": null\n },\n \"id\": 1596,\n \"name\": \"Claro Ecuador\",\n \"regions\": null\n },\n \"regions\": null,\n \"service\": {\n \"id\": 1,\n \"name\": \"Mobile\"\n },\n \"type\": \"FIXED_VALUE_RECHARGE\"\n },\n \"status\": {\n \"class\": {\n \"id\": 2,\n \"message\": \"CONFIRMED\"\n },\n \"id\": 20000,\n \"message\": \"CONFIRMED\"\n }\n }", "retries": 0, "status": "success", "status_code": 200, - "url": "https://dvs-api.dtone.com/v1/sync/transactions" + "url": "https://dvs-api.dtone.com/v1/async/transactions" } ], "recipient": "tel:+12065551212", @@ -220,12 +220,12 @@ { "created_on": "2018-07-06T12:30:02.123456789Z", "elapsed_ms": 1000, - "request": "GET /v1/lookup/mobile-number/+12065551212 HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nAccept-Encoding: gzip\r\n\r\n", + "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", "status_code": 200, - "url": "https://dvs-api.dtone.com/v1/lookup/mobile-number/+12065551212" + "url": "https://dvs-api.dtone.com/v1/lookup/mobile-number" }, { "created_on": "2018-07-06T12:30:04.123456789Z", @@ -240,12 +240,12 @@ { "created_on": "2018-07-06T12:30:06.123456789Z", "elapsed_ms": 1000, - "request": "POST /v1/sync/transactions HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nContent-Length: 151\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n{\"external_id\":\"c34b6c7d-fa06-4563-92a3-d648ab64bccb\",\"product_id\":6035,\"auto_confirm\":true,\"credit_party_identifier\":{\"mobile_number\":\"+12065551212\"}}", + "request": "POST /v1/async/transactions HTTP/1.1\r\nHost: dvs-api.dtone.com\r\nUser-Agent: Go-http-client/1.1\r\nContent-Length: 151\r\nAuthorization: Basic bnlhcnVrYToxMjM0NTY3ODk=\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n{\"external_id\":\"c34b6c7d-fa06-4563-92a3-d648ab64bccb\",\"product_id\":6035,\"auto_confirm\":true,\"credit_party_identifier\":{\"mobile_number\":\"+12065551212\"}}", "response": "HTTP/1.0 200 OK\r\nContent-Length: 1594\r\n\r\n{\n \"confirmation_date\": \"2021-03-24T20:05:06.111631000Z\",\n \"confirmation_expiration_date\": \"2021-03-24T21:05:05.883561000Z\",\n \"creation_date\": \"2021-03-24T20:05:05.883561000Z\",\n \"credit_party_identifier\": {\n \"mobile_number\": \"+593979123456\"\n },\n \"external_id\": \"EX12345\",\n \"id\": 2237512891,\n \"product\": {\n \"description\": \"\",\n \"id\": 6035,\n \"name\": \"3 USD\",\n \"operator\": {\n \"country\": {\n \"iso_code\": \"ECU\",\n \"name\": \"Ecuador\",\n \"regions\": null\n },\n \"id\": 1596,\n \"name\": \"Claro Ecuador\",\n \"regions\": null\n },\n \"regions\": null,\n \"service\": {\n \"id\": 1,\n \"name\": \"Mobile\"\n },\n \"type\": \"FIXED_VALUE_RECHARGE\"\n },\n \"status\": {\n \"class\": {\n \"id\": 2,\n \"message\": \"CONFIRMED\"\n },\n \"id\": 20000,\n \"message\": \"CONFIRMED\"\n }\n }", "retries": 0, "status": "success", "status_code": 200, - "url": "https://dvs-api.dtone.com/v1/sync/transactions" + "url": "https://dvs-api.dtone.com/v1/async/transactions" } ], "recipient": "tel:+12065551212",