Skip to content

Commit

Permalink
Исправлены случаи некорректного использования значения "0" при подпис…
Browse files Browse the repository at this point in the history
…и токена

#2
  • Loading branch information
nikita-vanyasin committed Apr 11, 2021
1 parent be7ff53 commit 163a249
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
11 changes: 4 additions & 7 deletions cancel.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package tinkoff

import (
"strconv"
)

type CancelRequest struct {
BaseRequest

Expand All @@ -14,11 +10,12 @@ type CancelRequest struct {
}

func (i *CancelRequest) GetValuesForToken() map[string]string {
return map[string]string{
"Amount": strconv.FormatUint(i.Amount, 10),
"IP": i.ClientIP,
v := map[string]string{
"PaymentId": i.PaymentID,
"IP": i.ClientIP,
}
serializeUintToMapIfNonEmpty(&v, "Amount", i.Amount)
return v
}

type CancelResponse struct {
Expand Down
9 changes: 4 additions & 5 deletions confirm.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package tinkoff

import "strconv"

type ConfirmRequest struct {
BaseRequest
PaymentID string `json:"PaymentId"` // Идентификатор платежа в системе банка
Expand All @@ -11,11 +9,12 @@ type ConfirmRequest struct {
}

func (i *ConfirmRequest) GetValuesForToken() map[string]string {
return map[string]string{
"Amount": strconv.FormatUint(i.Amount, 10),
"IP": i.ClientIP,
v := map[string]string{
"PaymentId": i.PaymentID,
"IP": i.ClientIP,
}
serializeUintToMapIfNonEmpty(&v, "Amount", i.Amount)
return v
}

type ConfirmResponse struct {
Expand Down
6 changes: 3 additions & 3 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tinkoff

import (
"fmt"
"strconv"
)

const (
Expand Down Expand Up @@ -38,8 +37,7 @@ func (i *InitRequest) SetIsRecurrent(r bool) {
}

func (i *InitRequest) GetValuesForToken() map[string]string {
return map[string]string{
"Amount": strconv.FormatUint(i.Amount, 10),
v := map[string]string{
"OrderId": i.OrderID,
"IP": i.ClientIP,
"Description": i.Description,
Expand All @@ -50,6 +48,8 @@ func (i *InitRequest) GetValuesForToken() map[string]string {
"SuccessURL": i.SuccessURL,
"FailURL": i.FailURL,
}
serializeUintToMapIfNonEmpty(&v, "Amount", i.Amount)
return v
}

type InitResponse struct {
Expand Down
7 changes: 7 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tinkoff

import (
"fmt"
"strconv"
"time"
)

Expand All @@ -19,6 +20,12 @@ func (t Time) String() string {
return original.Format(time.RFC3339)
}

func serializeUintToMapIfNonEmpty(m *map[string]string, key string, val uint64) {
if val != 0 {
(*m)[key] = strconv.FormatUint(val, 10)
}
}

func serializeBool(b bool) string {
if b {
return "true"
Expand Down

0 comments on commit 163a249

Please sign in to comment.