Skip to content

Commit

Permalink
Merge pull request #128 from erply/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tarmo-randma authored Oct 11, 2024
2 parents e6d8b9b + 2a0e4b9 commit 8aa9a21
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.13

require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
7 changes: 5 additions & 2 deletions pkg/api/sales/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,19 @@ type (
AssignmentsManger
ReportsManager
GetCoupons(ctx context.Context, filters map[string]string) (*GetCouponsResponse, error)
//payment requests
// payment requests
SavePayment(ctx context.Context, filters map[string]string) (int64, error)
SavePaymentsBulk(ctx context.Context, bulkFilters []map[string]interface{}, baseFilters map[string]string) (SavePaymentsResponseBulk, error)
GetPayments(ctx context.Context, filters map[string]string) ([]PaymentInfo, error)
GetPaymentsBulk(ctx context.Context, bulkFilters []map[string]interface{}, baseFilters map[string]string) (GetPaymentsResponseBulk, error)
DeletePayment(ctx context.Context, filters map[string]string) error
DeletePaymentsBulk(ctx context.Context, bulkFilters []map[string]interface{}, baseFilters map[string]string) (DeleteResponseBulk, error)

//shopping cart
// shopping cart
CalculateShoppingCart(ctx context.Context, filters map[string]string) (*ShoppingCartTotals, error)
CalculateShoppingCartWithFullRowsResponse(ctx context.Context, filters map[string]string) (*ShoppingCartTotalsWithFullRows, error)

// ProcessRecurringBilling is Erply API call processRecurringBilling. https://learn-api.erply.com/requests/processrecurringbilling
ProcessRecurringBilling(ctx context.Context, filters map[string]string) ([]RecurringBillingProcessedInvoices, error)
}
)
18 changes: 18 additions & 0 deletions pkg/api/sales/recurringBillingModel.go
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"`
}
)
35 changes: 35 additions & 0 deletions pkg/api/sales/recurringBillingRequests.go
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
}
}
135 changes: 135 additions & 0 deletions pkg/api/sales/recurringBillingRequests_test.go
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))
})
}
62 changes: 62 additions & 0 deletions pkg/api/servicediscovery/models.go.bak
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"`
}

0 comments on commit 8aa9a21

Please sign in to comment.