Skip to content

Commit

Permalink
Fix GetQR method to use DataType for signature (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-vanyasin authored Jun 18, 2024
1 parent dbae444 commit ce535cd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ req := &tinkoff.InitRequest{
res, err := client.Init(req)
// ...
gqr := &tinkoff.GetQrRequest{
PaymentID: res.PayID,
PaymentID: res.PaymentID,
}
resQR, errQ := client.GetQRWithContext(ctx, gqr)
resQR, err := client.GetQRWithContext(ctx, gqr)
```
#### Cancel or refund payment
Expand Down
18 changes: 18 additions & 0 deletions compound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ func TestCallsChain(t *testing.T) {
assertNotEmptyString(t, initRes.OrderID)
assertNotEmptyString(t, initRes.PaymentURL)

// get QR for payment (payload)
gqr := &tinkoff.GetQRRequest{
PaymentID: initRes.PaymentID,
DataType: tinkoff.QRTypePayload,
}
resQR, err := c.GetQR(gqr)
assertNotError(t, err)
assertNotEmptyString(t, resQR.Data)

// get QR for payment (SVG)
gqr = &tinkoff.GetQRRequest{
PaymentID: initRes.PaymentID,
DataType: tinkoff.QRTypeImage,
}
resQR, err = c.GetQR(gqr)
assertNotError(t, err)
assertNotEmptyString(t, resQR.Data)

// cancel it
req := &tinkoff.CancelRequest{
PaymentID: initRes.PaymentID,
Expand Down
9 changes: 8 additions & 1 deletion qr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ package tinkoff

import "context"

const (
QRTypePayload = "PAYLOAD"
QRTypeImage = "IMAGE"
)

type GetQRRequest struct {
BaseRequest

PaymentID string `json:"PaymentId"` // Идентификатор платежа в системе банка. По офф. документации это number(20), но фактически значение передается в виде строки
DataType string `json:"DataType"` //Тип возвращаемых данных. PAYLOAD – В ответе возвращается только Payload (по-умолчанию). IMAGE – В ответе возвращается SVG изображение QR
DataType string `json:"DataType"` // Тип возвращаемых данных. PAYLOAD (QRTypePayload) – В ответе возвращается только Payload (по-умолчанию). IMAGE (QRTypeImage) – В ответе возвращается SVG изображение QR
}

func (i *GetQRRequest) GetValuesForToken() map[string]string {
return map[string]string{
"PaymentId": i.PaymentID,
"TerminalKey": i.TerminalKey,
"DataType": i.DataType,
}
}

Expand All @@ -38,6 +44,7 @@ func (i *GetQRTestRequest) GetValuesForToken() map[string]string {
}
}

// Deprecated: use GetQRWithContext instead
func (c *Client) GetQR(request *GetQRRequest) (*GetQRResponse, error) {
return c.GetQRWithContext(context.Background(), request)
}
Expand Down

0 comments on commit ce535cd

Please sign in to comment.