Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update May 2, 2024 #89

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 65 additions & 8 deletions ozon/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,43 @@ type CreateUpdateProformaLinkParams struct {
// Shipment number
PostingNumber string `json:"posting_number"`

// Proforma invoice link
// Invoice link. Use the `v1/invoice/file/upload` method to create a link
URL string `json:"url"`

// Invoice HS-code. Pass a number up to 12 characters long
HSCode string `json:"hs_code"`
// Product HS-codes
HSCodes []CreateUpdateProformaLinkHSCode `json:"hs_codes"`

// Invoice date
Date time.Time `json:"date"`

// Invoice number. The number can contain letters and digits, maximum length is 50 characters
Number string `json:"number"`

// Cost stated in the invoice. The fractional part is separated by decimal point, up to two digits after the decimal poin
// Cost stated in the invoice. The fractional part is separated by decimal point, up to two digits after the decimal point
Price float64 `json:"price"`

// Invoice currency
PriceCurrency InvoiceCurrency `json:"price_currency" default:"USD"`
}

type CreateUpdateProformaLinkHSCode struct {
// Product HS code
Code string `json:"code"`

// Product identifier in the Ozon system, SKU
SKU string `json:"sku"`
}

type CreateUpdateProformaLinkResponse struct {
core.CommonResponse

// Method result
Result bool `json:"result"`
}

// Create or edit proforma invoice link for VAT refund to Turkey sellers
// Create or edit an invoice for VAT refund to Turkey sellers
func (c Invoices) CreateUpdate(ctx context.Context, params *CreateUpdateProformaLinkParams) (*CreateUpdateProformaLinkResponse, error) {
url := "/v1/invoice/create-or-update"
url := "/v2/invoice/create-or-update"

resp := &CreateUpdateProformaLinkResponse{}

Expand All @@ -70,13 +78,32 @@ type GetProformaLinkResponse struct {
}

type GetProformaLinkResult struct {
// Proforma invoice link
// Invoice uploading date
Date time.Time `json:"date"`

// Invoice link
FileURL string `json:"file_url"`

// Product HS-codes
HSCodes []CreateUpdateProformaLinkHSCode `json:"hs_codes"`

// Invoice number
Number string `json:"number"`

// Cost stated in the invoice.
// The fractional part is separated by decimal point,
// up to two digits after the decimal point.
//
// Example: 199.99
Price float64 `json:"price"`

// Invoice currency
PriceCurrency InvoiceCurrency `json:"price_currency"`
}

// Get a proforma invoice link
func (c Invoices) Get(ctx context.Context, params *GetProformaLinkParams) (*GetProformaLinkResponse, error) {
url := "/v1/invoice/get"
url := "/v2/invoice/get"

resp := &GetProformaLinkResponse{}

Expand Down Expand Up @@ -114,3 +141,33 @@ func (c Invoices) Delete(ctx context.Context, params *DeleteProformaLinkParams)

return resp, nil
}

type UploadInvoiceParams struct {
// Base64 encoded invoice
Content string `json:"base64_content"`

// Shipment number
PostingNumber string `json:"posting_number"`
}

type UploadInvoiceResponse struct {
core.CommonResponse

// Link to invoice
URL string `json:"url"`
}

// Available file types: JPEG and PDF. Maximum file size: 10 MB
func (c Invoices) Upload(ctx context.Context, params *UploadInvoiceParams) (*UploadInvoiceResponse, error) {
url := "/v1/invoice/file/upload"

resp := &UploadInvoiceResponse{}

response, err := c.client.Request(ctx, http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)

return resp, nil
}
74 changes: 72 additions & 2 deletions ozon/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ func TestCreateUpdateProformaLink(t *testing.T) {
&CreateUpdateProformaLinkParams{
PostingNumber: "33920146-0252-1",
URL: "https://cdn.ozone.ru/s3/ozon-disk-api/techdoc/seller-api/earsivfatura_1690960445.pdf",
HSCode: "2134322",
HSCodes: []CreateUpdateProformaLinkHSCode{
{
Code: "534758761999",
SKU: "SKU123",
},
{
Code: "534758761000",
SKU: "SKU456",
},
},
Date: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2023-08-01T12:08:44.342Z"),
Number: "424fdsf234",
Price: 234.34,
Expand Down Expand Up @@ -82,7 +91,17 @@ func TestGetProformaLink(t *testing.T) {
},
`{
"result": {
"file_url": "string"
"date": "2019-08-24T14:15:22Z",
"file_url": "string",
"hs_codes": [
{
"code": "string",
"sku": "string"
}
],
"number": "string",
"price": 0,
"price_currency": "string"
}
}`,
},
Expand Down Expand Up @@ -165,3 +184,54 @@ func TestDeleteProformaLink(t *testing.T) {
}
}
}

func TestUploadInvoice(t *testing.T) {
t.Parallel()

tests := []struct {
statusCode int
headers map[string]string
params *UploadInvoiceParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&UploadInvoiceParams{
PostingNumber: "posting number",
Content: "content",
},
`{
"url": "string"
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&UploadInvoiceParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}

for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))

ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Invoices().Upload(ctx, test.params)
if err != nil {
t.Error(err)
continue
}

compareJsonResponse(t, test.response, &UploadInvoiceResponse{})

if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
Loading