feat: Added AuthCode and RRN support to card payment system

This commit is contained in:
2025-10-03 16:27:49 +03:00
parent 5c8540d3d0
commit 0d800e014e
2 changed files with 25 additions and 16 deletions

View File

@@ -40,7 +40,7 @@ func createReceiptPayCash(PayType int, sum float64, comment string) ReceiptPay {
} }
} }
func createReceiptPayCard(PayType int, sum float64, comment string, cardmask string, bankID string) ReceiptPay { func createReceiptPayCard(PayType int, sum float64, comment string, cardmask string, bankID string, rrnCode string, authCode string) ReceiptPay {
return ReceiptPay{ return ReceiptPay{
Type: PayType, Type: PayType,
Sum: sum, Sum: sum,
@@ -48,6 +48,8 @@ func createReceiptPayCard(PayType int, sum float64, comment string, cardmask str
Paysys: "parking_pos", Paysys: "parking_pos",
Cardmask: cardmask, Cardmask: cardmask,
BankID: bankID, BankID: bankID,
Rrn: rrnCode,
AuthCode: authCode,
} }
} }
@@ -59,7 +61,7 @@ func getReceiptSum(rows []ReceiptRow, taxgrp string) float64 {
return sum return sum
} }
func createReceipt(PayType int, sum float64, comment string, cardmask string, bankID string, name string, cnt int, price float64, disc float64, taxgrp string) Receipt { func createReceipt(PayType int, sum float64, comment string, cardmask string, bankID string, name string, cnt int, price float64, disc float64, taxgrp string, rrnCode string, authCode string) Receipt {
rows := []ReceiptRow{createReceiptRow(name, cnt, price, comment, disc, taxgrp)} rows := []ReceiptRow{createReceiptRow(name, cnt, price, comment, disc, taxgrp)}
sum = getReceiptSum(rows, taxgrp) sum = getReceiptSum(rows, taxgrp)
@@ -69,7 +71,7 @@ func createReceipt(PayType int, sum float64, comment string, cardmask string, ba
Disc: 0, Disc: 0,
DiscType: 0, DiscType: 0,
Rows: rows, Rows: rows,
Pays: []ReceiptPay{createReceiptPayCard(PayType, sum, comment, cardmask, bankID)}, Pays: []ReceiptPay{createReceiptPayCard(PayType, sum, comment, cardmask, bankID, rrnCode, authCode)},
} }
fmt.Println("Receipt sum:", r.Sum) fmt.Println("Receipt sum:", r.Sum)
@@ -109,19 +111,19 @@ func createReceipt(PayType int, sum float64, comment string, cardmask string, ba
// } // }
// } // }
func createFiscal(source string, cashier string, PayType int, sum float64, comment string, cardmask string, bankID string, name string, cnt int, price float64, disc float64, taxgrp string) FiskalCheck { func createFiscal(source string, cashier string, PayType int, sum float64, comment string, cardmask string, bankID string, name string, cnt int, price float64, disc float64, taxgrp string, rrnCode string, authCode string) FiskalCheck {
return FiskalCheck{ return FiskalCheck{
Source: source, Source: source,
Fiscal: Fiscal{ Fiscal: Fiscal{
Task: 1, Task: 1,
Cashier: cashier, Cashier: cashier,
Receipt: createReceipt(PayType, sum, comment, cardmask, bankID, name, cnt, price, disc, taxgrp), Receipt: createReceipt(PayType, sum, comment, cardmask, bankID, name, cnt, price, disc, taxgrp, rrnCode, authCode),
}, },
} }
} }
func (k *Kasa) NewSell(ctx context.Context, PayType int, sum float64, comment string, cardmask string, bankID string, name string, cnt int, price float64, disc float64, taxgrp string) (*KasaResponse, error) { func (k *Kasa) NewSell(ctx context.Context, PayType int, sum float64, comment string, cardmask string, bankID string, name string, cnt int, price float64, disc float64, taxgrp string, rrnCode string, authCode string) (*KasaResponse, error) {
fiscal := createFiscal("kasa", "test", PayType, sum, comment, cardmask, bankID, name, cnt, price, disc, taxgrp) fiscal := createFiscal("kasa", "test", PayType, sum, comment, cardmask, bankID, name, cnt, price, disc, taxgrp, rrnCode, authCode)
// create a POST request to the kasa api https://kasa.vchasno.ua/api/v3/fiscal/execute with resty // create a POST request to the kasa api https://kasa.vchasno.ua/api/v3/fiscal/execute with resty
request, err := k.resty.R().SetBody(fiscal).SetHeader("Authorization", k.token).Post("https://kasa.vchasno.ua/api/v3/fiscal/execute") request, err := k.resty.R().SetBody(fiscal).SetHeader("Authorization", k.token).Post("https://kasa.vchasno.ua/api/v3/fiscal/execute")

View File

@@ -20,13 +20,20 @@ type SellParams struct {
PayType int PayType int
Sum float64 Sum float64
Comment string Comment string
Cardmask string
BankID string
Name string Name string
Cnt int Cnt int
Price float64 Price float64
Disc float64 Disc float64
Taxgrp string Taxgrp string
CardParams CardParams
}
type CardParams struct {
Cardmask string
BankID string
RrnCode string
AuthCode string
} }
func NewVchasno(token string) *Vchasno { func NewVchasno(token string) *Vchasno {
@@ -38,7 +45,7 @@ func NewVchasno(token string) *Vchasno {
func (v *Vchasno) NewSell(params SellParams) (*api.KasaResponse, error) { func (v *Vchasno) NewSell(params SellParams) (*api.KasaResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()
return v.api.NewSell(ctx, params.PayType, params.Sum, params.Comment, params.Cardmask, params.BankID, params.Name, params.Cnt, params.Price, params.Disc, params.Taxgrp) return v.api.NewSell(ctx, params.PayType, params.Sum, params.Comment, params.CardParams.Cardmask, params.CardParams.BankID, params.Name, params.Cnt, params.Price, params.Disc, params.Taxgrp, params.CardParams.RrnCode, params.CardParams.AuthCode)
} }
func SetDefaultParams() SellParams { func SetDefaultParams() SellParams {