-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from erply/develop
Develop
- Loading branch information
Showing
7 changed files
with
259 additions
and
4 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
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
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,18 @@ | ||
package sales | ||
|
||
import common2 "github.com/erply/api-go-wrapper/pkg/api/common" | ||
|
||
type ( | ||
RecurringBillingResponse struct { | ||
Status common2.Status | ||
Records []RecurringBillingRecord `json:"records"` | ||
} | ||
RecurringBillingRecord struct { | ||
ProcessedInvoices []RecurringBillingProcessedInvoices `json:"processedInvoices"` | ||
} | ||
RecurringBillingProcessedInvoices struct { | ||
ID int `json:"id"` | ||
Created bool `json:"created"` | ||
Updated bool `json:"updated"` | ||
} | ||
) |
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,35 @@ | ||
package sales | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/erply/api-go-wrapper/internal/common" | ||
sharedCommon "github.com/erply/api-go-wrapper/pkg/api/common" | ||
"github.com/pkg/errors" | ||
"net/http" | ||
) | ||
|
||
// ProcessRecurringBilling is Erply API call processRecurringBilling. https://learn-api.erply.com/requests/processrecurringbilling | ||
func (cli *Client) ProcessRecurringBilling(ctx context.Context, filters map[string]string) ([]RecurringBillingProcessedInvoices, error) { | ||
resp, err := cli.SendRequest(ctx, "processRecurringBilling", filters) | ||
if err != nil { | ||
return nil, sharedCommon.NewFromError("ProcessRecurringBilling: error sending request", err, 0) | ||
} | ||
if resp.StatusCode != http.StatusOK { | ||
return nil, sharedCommon.NewFromError(fmt.Sprintf("ProcessRecurringBilling: bad response status code: %d", resp.StatusCode), nil, 0) | ||
} | ||
|
||
respData := RecurringBillingResponse{} | ||
if err := json.NewDecoder(resp.Body).Decode(&respData); err != nil { | ||
return nil, errors.Wrap(err, "failed to decode processRecurringBilling response") | ||
} | ||
if !common.IsJSONResponseOK(&respData.Status) { | ||
return nil, sharedCommon.NewFromResponseStatus(&respData.Status) | ||
} | ||
if len(respData.Records) > 0 { | ||
return respData.Records[0].ProcessedInvoices, nil | ||
} else { | ||
return make([]RecurringBillingProcessedInvoices, 0), 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,135 @@ | ||
package sales | ||
|
||
import ( | ||
"context" | ||
"github.com/erply/api-go-wrapper/internal/common" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestRecurringBilling(t *testing.T) { | ||
|
||
t.Run("success", func(t *testing.T) { | ||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
common.AssertFormValues(t, r, map[string]interface{}{ | ||
"clientCode": "someclient", | ||
"sessionKey": "somesess", | ||
}) | ||
_, err := w.Write([]byte(`{ | ||
"status": { | ||
"request": "processRecurringBilling", | ||
"requestUnixTime": 1728482531, | ||
"responseStatus": "ok", | ||
"errorCode": 0, | ||
"generationTime": 0.3931558132171630859375, | ||
"recordsTotal": 0, | ||
"recordsInResponse": 0 | ||
}, | ||
"records": [ | ||
{ | ||
"processedInvoices": [ | ||
{ | ||
"id": 89, | ||
"created": true, | ||
"updated": true | ||
} | ||
] | ||
} | ||
] | ||
}`)) | ||
assert.NoError(t, err) | ||
})) | ||
defer srv.Close() | ||
|
||
cli := common.NewClient("somesess", "someclient", "", nil, nil) | ||
cli.Url = srv.URL | ||
cl := NewClient(cli) | ||
bulkResp, err := cl.ProcessRecurringBilling( | ||
context.Background(), | ||
map[string]string{ | ||
"billingStatementIDs": "1,2", | ||
}, | ||
) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(bulkResp)) | ||
assert.Equal(t, 89, bulkResp[0].ID) | ||
assert.Equal(t, true, bulkResp[0].Created) | ||
assert.Equal(t, true, bulkResp[0].Updated) | ||
}) | ||
t.Run("empty", func(t *testing.T) { | ||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
common.AssertFormValues(t, r, map[string]interface{}{ | ||
"clientCode": "someclient", | ||
"sessionKey": "somesess", | ||
}) | ||
_, err := w.Write([]byte(`{ | ||
"status": { | ||
"request": "processRecurringBilling", | ||
"requestUnixTime": 1728485864, | ||
"responseStatus": "ok", | ||
"errorCode": 0, | ||
"generationTime": 0.1155679225921630859375, | ||
"recordsTotal": 0, | ||
"recordsInResponse": 0 | ||
}, | ||
"records": [ | ||
{ | ||
"processedInvoices": [] | ||
} | ||
] | ||
}`)) | ||
assert.NoError(t, err) | ||
})) | ||
defer srv.Close() | ||
|
||
cli := common.NewClient("somesess", "someclient", "", nil, nil) | ||
cli.Url = srv.URL | ||
cl := NewClient(cli) | ||
bulkResp, err := cl.ProcessRecurringBilling( | ||
context.Background(), | ||
map[string]string{ | ||
"billingStatementIDs": "1,2", | ||
}, | ||
) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, len(bulkResp)) | ||
}) | ||
t.Run("error", func(t *testing.T) { | ||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
common.AssertFormValues(t, r, map[string]interface{}{ | ||
"clientCode": "someclient", | ||
"sessionKey": "somesess", | ||
}) | ||
_, err := w.Write([]byte(`{ | ||
"status": { | ||
"request": "processRecurringBilling", | ||
"requestUnixTime": 1728489814, | ||
"responseStatus": "error", | ||
"errorCode": 1016, | ||
"errorField": "billingStatementIDs", | ||
"generationTime": 0.0900490283966064453125, | ||
"recordsTotal": 0, | ||
"recordsInResponse": 0 | ||
}, | ||
"records": [] | ||
}`)) | ||
assert.NoError(t, err) | ||
})) | ||
defer srv.Close() | ||
|
||
cli := common.NewClient("somesess", "someclient", "", nil, nil) | ||
cli.Url = srv.URL | ||
cl := NewClient(cli) | ||
bulkResp, err := cl.ProcessRecurringBilling( | ||
context.Background(), | ||
map[string]string{ | ||
"billingStatementIDs": "a", | ||
}, | ||
) | ||
assert.Error(t, err) | ||
assert.Equal(t, "ERPLY API: processRecurringBilling: error, status: [1016] Invalid value.(Attribute \"errorField\" indicates the field that contains an invalid value.), error field: billingStatementIDs, code: 1016", err.Error()) | ||
assert.Equal(t, 0, len(bulkResp)) | ||
}) | ||
} |
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,62 @@ | ||
package servicediscovery | ||
|
||
import ( | ||
common2 "github.com/erply/api-go-wrapper/pkg/api/common" | ||
) | ||
|
||
type getServiceEndpointsResponse struct { | ||
Status common2.Status | ||
Records []ServiceEndpoints `json:"records"` | ||
} | ||
type Endpoint struct { | ||
IsSandbox bool `json:"isSandbox"` | ||
Url string `json:"url"` | ||
Documentation string `json:"documentation"` | ||
} | ||
|
||
type ServiceEndpoints struct { | ||
Cafa Endpoint `json:"cafa"` | ||
Pim Endpoint `json:"pim"` | ||
Wms Endpoint `json:"wms"` | ||
Promotion Endpoint `json:"promotion"` | ||
Reports Endpoint `json:"reports"` | ||
JSON Endpoint `json:"json"` | ||
Assignments Endpoint `json:"assignments"` | ||
AccountAdmin Endpoint `json:"account-admin"` | ||
VisitorQueue Endpoint `json:"visitor-queue"` | ||
Loyalty Endpoint `json:"loyalty"` | ||
Cdn Endpoint `json:"cdn"` | ||
Tasks Endpoint `json:"tasks"` | ||
Webhook Endpoint `json:"webhook"` | ||
User Endpoint `json:"user"` | ||
Import Endpoint `json:"import"` | ||
Ems Endpoint `json:"ems"` | ||
Clockin Endpoint `json:"clockin"` | ||
Ledger Endpoint `json:"ledger"` | ||
Auth Endpoint `json:"auth"` | ||
Crm Endpoint `json:"crm"` | ||
Buum Endpoint `json:"buum"` | ||
Sales Endpoint `json:"sales"` | ||
Pricing Endpoint `json:"pricing"` | ||
Inventory Endpoint `json:"inventory"` | ||
Chair Endpoint `json:"chair"` | ||
PosAPI Endpoint `json:"pos-api"` | ||
Vin Endpoint `json:"vin"` | ||
IntegrationLogs Endpoint `json:"integration-logs"` | ||
InventoryTransaction Endpoint `json:"inventory-transaction"` | ||
InventoryDocuments Endpoint `json:"inventory-documents"` | ||
EInvoice Endpoint `json:"e-invoice"` | ||
Memberships Endpoint `json:"memberships"` | ||
CustomData Endpoint `json:"custom-data"` | ||
Stripe Endpoint `json:"stripe"` | ||
GoERP Endpoint `json:"goerp"` | ||
Logfiles Endpoint `json:"logfiles"` | ||
CommandBroker Endpoint `json:"command-broker"` | ||
EcomShopify Endpoint `json:"ecom-shopify"` | ||
Automation Endpoint `json:"automation"` | ||
WooCommerce Endpoint `json:"woocommerce"` | ||
Billing Endpoint `json:"billing"` | ||
Erply Endpoint `json:"erply"` | ||
InventoryDocument Endpoint `json:"inventory-document"` | ||
InventoryTransaction Endpoint `json:"inventory-transaction"` | ||
} |