complete structure revamp
This commit is contained in:
158
examples.go
Normal file
158
examples.go
Normal file
@@ -0,0 +1,158 @@
|
||||
package vchasno
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"gitea.jeezft.xyz/jeezft/go-vchasno-kassa/api"
|
||||
)
|
||||
|
||||
func ExampleBasicUsage() {
|
||||
client := NewClient(Config{
|
||||
Token: "your-token",
|
||||
Cashier: "Иванов",
|
||||
Source: "parking",
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
response, _ := client.QuickSell(ctx, 100.00)
|
||||
_ = response
|
||||
}
|
||||
|
||||
func ExampleWithDefaults() {
|
||||
client := NewClient(Config{
|
||||
Token: "your-token",
|
||||
Cashier: "Иванов",
|
||||
Defaults: &DefaultParams{
|
||||
ProductName: "Парковка",
|
||||
Comment: "Оплата парковки",
|
||||
Taxgrp: "1",
|
||||
PayType: api.PayTypeCash,
|
||||
DefaultTimeout: 30 * time.Second,
|
||||
},
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
response, _ := client.QuickSell(ctx, 50.00)
|
||||
_ = response
|
||||
}
|
||||
|
||||
func ExampleBuilderPattern() {
|
||||
client := NewClient(Config{
|
||||
Token: "your-token",
|
||||
Cashier: "Иванов",
|
||||
Defaults: &DefaultParams{
|
||||
ProductName: "Парковка",
|
||||
Taxgrp: "1",
|
||||
PayType: api.PayTypeCash,
|
||||
},
|
||||
})
|
||||
|
||||
response, _ := client.NewSellParams().
|
||||
Price(100.00).
|
||||
Cnt(2).
|
||||
Comment("Парковка на 2 часа").
|
||||
ExecuteDefault()
|
||||
|
||||
_ = response
|
||||
}
|
||||
|
||||
func ExampleBuilderWithCard() {
|
||||
client := NewClient(Config{
|
||||
Token: "your-token",
|
||||
})
|
||||
|
||||
response, _ := client.NewSellParams().
|
||||
Name("Услуга парковки").
|
||||
Price(150.00).
|
||||
PayCard("411111****1111", "305299", "123456789012", "123456").
|
||||
Userinfo("user@example.com", "+380501234567").
|
||||
ExecuteDefault()
|
||||
|
||||
_ = response
|
||||
}
|
||||
|
||||
func ExampleChangingDefaults() {
|
||||
client := NewClient(Config{
|
||||
Token: "your-token",
|
||||
})
|
||||
|
||||
client.SetDefaults(DefaultParams{
|
||||
ProductName: "VIP Парковка",
|
||||
Comment: "VIP зона",
|
||||
Taxgrp: "2",
|
||||
PayType: api.PayTypeCard,
|
||||
DefaultTimeout: 60 * time.Second,
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
response, _ := client.QuickSell(ctx, 200.00)
|
||||
_ = response
|
||||
}
|
||||
|
||||
func ExampleFullWorkflow() {
|
||||
client := NewClient(Config{
|
||||
Token: "your-token",
|
||||
Cashier: "Петров",
|
||||
Defaults: &DefaultParams{
|
||||
ProductName: "Парковка",
|
||||
Taxgrp: "1",
|
||||
},
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
openResp, _ := client.OpenShift(ctx)
|
||||
_ = openResp
|
||||
|
||||
client.NewSellParams().
|
||||
Price(50.00).
|
||||
PayCash().
|
||||
ExecuteDefault()
|
||||
|
||||
client.NewSellParams().
|
||||
Price(100.00).
|
||||
Cnt(2).
|
||||
PayCard("411111****1111", "305299", "123456789012", "123456").
|
||||
ExecuteDefault()
|
||||
|
||||
zReport, _ := client.CloseShift(ctx)
|
||||
_ = zReport
|
||||
}
|
||||
|
||||
func ExampleMultipleSales() {
|
||||
client := NewClient(Config{
|
||||
Token: "your-token",
|
||||
Defaults: &DefaultParams{
|
||||
ProductName: "Парковка",
|
||||
Taxgrp: "1",
|
||||
},
|
||||
})
|
||||
|
||||
prices := []float64{50.00, 75.00, 100.00, 125.00}
|
||||
|
||||
for _, price := range prices {
|
||||
client.NewSellParams().
|
||||
Price(price).
|
||||
PayCash().
|
||||
ExecuteDefault()
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleWithDiscount() {
|
||||
client := NewClient(Config{
|
||||
Token: "your-token",
|
||||
})
|
||||
|
||||
response, _ := client.NewSellParams().
|
||||
Name("Парковка premium").
|
||||
Price(200.00).
|
||||
Disc(20.00).
|
||||
Comment("Скидка 10%").
|
||||
PayCash().
|
||||
ExecuteDefault()
|
||||
|
||||
_ = response
|
||||
}
|
||||
Reference in New Issue
Block a user