Skip to content

Commit

Permalink
Update DT One requests
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Jun 10, 2024
1 parent b6e3b34 commit d3113b0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 35 deletions.
18 changes: 9 additions & 9 deletions flows/actions/testdata/transfer_airtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -137,7 +137,7 @@
]
}
],
"https://dvs-api.dtone.com/v1/sync/transactions": [
"https://dvs-api.dtone.com/v1/async/transactions": [
{
"status": 200,
"body": {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions services/airtime/dtone/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions services/airtime/dtone/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
})
Expand Down Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion services/airtime/dtone/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
8 changes: 4 additions & 4 deletions services/airtime/dtone/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
})
Expand Down Expand Up @@ -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
Expand All @@ -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)),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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"}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit d3113b0

Please sign in to comment.