generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ea7d30
commit 2fb5ac1
Showing
18 changed files
with
596 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: gomod | ||
directory: / | ||
schedule: | ||
interval: daily |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package smobilpay | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// cashinService is the API client for the `/cashin` endpoint | ||
type cashinService service | ||
|
||
// Get returns a list of all available cashout packages. | ||
// | ||
// https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html | ||
func (service *cashinService) Get(ctx context.Context, serviceID string, options ...RequestOption) ([]*PayItem, *Response, error) { | ||
request, err := service.client.newRequest(ctx, options, http.MethodGet, fmt.Sprintf("/cashin?serviceid=%s", serviceID), nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
response, err := service.client.do(request) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
var packages []*PayItem | ||
if err = json.Unmarshal(*response.Body, &packages); err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return packages, response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package smobilpay | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/NdoleStudio/smobilpay-go/internal/helpers" | ||
"github.com/NdoleStudio/smobilpay-go/internal/stubs" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCashinService_Get(t *testing.T) { | ||
// Setup | ||
t.Parallel() | ||
|
||
// Arrange | ||
server := helpers.MakeTestServer(http.StatusOK, stubs.CashinGetOk()) | ||
accessToken := "6B352110-4716-11ED-963F-0800200C9A66" | ||
client := New( | ||
WithBaseURL(server.URL), | ||
WithAccessToken(accessToken), | ||
WithAccessSecret("1B875FB0-4717-11ED-963F-0800200C9A66"), | ||
) | ||
nonce := "95cdf110-4614-4d95-b6c2-f14fe01c4995" | ||
serviceID := "30052" | ||
|
||
// Act | ||
payItems, response, err := client.Cashout.Get( | ||
context.Background(), | ||
serviceID, | ||
WithRequestNonce(nonce), | ||
) | ||
|
||
// Assert | ||
assert.Nil(t, err) | ||
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) | ||
assert.Equal(t, 1, len(payItems)) | ||
assert.Equal(t, serviceID, payItems[0].ServiceID) | ||
|
||
// Teardown | ||
server.Close() | ||
} | ||
|
||
func TestCashinService_GetError(t *testing.T) { | ||
// Setup | ||
t.Parallel() | ||
|
||
// Arrange | ||
server := helpers.MakeTestServer(http.StatusBadRequest, stubs.CashinGetError()) | ||
accessToken := "6B352110-4716-11ED-963F-0800200C9A66" | ||
client := New( | ||
WithBaseURL(server.URL), | ||
WithAccessToken(accessToken), | ||
WithAccessSecret("1B875FB0-4717-11ED-963F-0800200C9A66"), | ||
) | ||
nonce := "95cdf110-4614-4d95-b6c2-f14fe01c4995" | ||
serviceID := "30052" | ||
|
||
// Act | ||
payItems, response, err := client.Cashout.Get( | ||
context.Background(), | ||
serviceID, | ||
WithRequestNonce(nonce), | ||
) | ||
|
||
// Assert | ||
assert.NotNil(t, err) | ||
assert.Equal(t, http.StatusBadRequest, response.HTTPResponse.StatusCode) | ||
assert.Equal(t, 0, len(payItems)) | ||
|
||
// Teardown | ||
server.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package smobilpay | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// cashoutService is the API client for the `/cashout` endpoint | ||
type cashoutService service | ||
|
||
// Get returns a list of all available cashout packages. | ||
// | ||
// https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html | ||
func (service *cashoutService) Get(ctx context.Context, serviceID string, options ...RequestOption) ([]*PayItem, *Response, error) { | ||
request, err := service.client.newRequest(ctx, options, http.MethodGet, fmt.Sprintf("/cashout?serviceid=%s", serviceID), nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
response, err := service.client.do(request) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
var packages []*PayItem | ||
if err = json.Unmarshal(*response.Body, &packages); err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return packages, response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package smobilpay | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/NdoleStudio/smobilpay-go/internal/helpers" | ||
"github.com/NdoleStudio/smobilpay-go/internal/stubs" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCashoutService_Get(t *testing.T) { | ||
// Setup | ||
t.Parallel() | ||
|
||
// Arrange | ||
server := helpers.MakeTestServer(http.StatusOK, stubs.CashoutGetOk()) | ||
accessToken := "6B352110-4716-11ED-963F-0800200C9A66" | ||
client := New( | ||
WithBaseURL(server.URL), | ||
WithAccessToken(accessToken), | ||
WithAccessSecret("1B875FB0-4717-11ED-963F-0800200C9A66"), | ||
) | ||
nonce := "95cdf110-4614-4d95-b6c2-f14fe01c4995" | ||
serviceID := "20053" | ||
|
||
// Act | ||
payItems, response, err := client.Cashout.Get( | ||
context.Background(), | ||
serviceID, | ||
WithRequestNonce(nonce), | ||
) | ||
|
||
// Assert | ||
assert.Nil(t, err) | ||
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) | ||
assert.Equal(t, 1, len(payItems)) | ||
assert.Equal(t, serviceID, payItems[0].ServiceID) | ||
|
||
// Teardown | ||
server.Close() | ||
} | ||
|
||
func TestCashoutService_GetError(t *testing.T) { | ||
// Setup | ||
t.Parallel() | ||
|
||
// Arrange | ||
server := helpers.MakeTestServer(http.StatusBadRequest, stubs.CashoutGetError()) | ||
accessToken := "6B352110-4716-11ED-963F-0800200C9A66" | ||
client := New( | ||
WithBaseURL(server.URL), | ||
WithAccessToken(accessToken), | ||
WithAccessSecret("1B875FB0-4717-11ED-963F-0800200C9A66"), | ||
) | ||
nonce := "95cdf110-4614-4d95-b6c2-f14fe01c4995" | ||
serviceID := "30052" | ||
|
||
// Act | ||
payItems, response, err := client.Cashout.Get( | ||
context.Background(), | ||
serviceID, | ||
WithRequestNonce(nonce), | ||
) | ||
|
||
// Assert | ||
assert.NotNil(t, err) | ||
assert.Equal(t, http.StatusBadRequest, response.HTTPResponse.StatusCode) | ||
assert.Equal(t, 0, len(payItems)) | ||
|
||
// Teardown | ||
server.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
package smobilpay | ||
|
||
import "net/http" | ||
import ( | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type clientConfig struct { | ||
httpClient *http.Client | ||
baseURL string | ||
accessToken string | ||
accessSecret string | ||
httpClient *http.Client | ||
collectSyncVerifyInterval time.Duration | ||
collectSyncVerifyRetryCount uint | ||
baseURL string | ||
accessToken string | ||
accessSecret string | ||
} | ||
|
||
func defaultClientConfig() *clientConfig { | ||
return &clientConfig{ | ||
httpClient: http.DefaultClient, | ||
baseURL: "https://s3p.smobilpay.staging.maviance.info/v2", | ||
httpClient: http.DefaultClient, | ||
collectSyncVerifyInterval: 20 * time.Second, | ||
collectSyncVerifyRetryCount: 15, | ||
baseURL: "https://s3p.smobilpay.staging.maviance.info/v2", | ||
} | ||
} |
Oops, something went wrong.