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

add check order method #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
48 changes: 48 additions & 0 deletions checkorder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tinkoff

import (
"context"
)

type CheckOrderRequest struct {
BaseRequest
OrderID string `json:"OrderId"` // Номер заказа в системе Продавца
}

type CheckOrderResponse struct {
BaseResponse
OrderID string `json:"OrderId"` // Номер заказа в системе Продавца
Payments []Payment
}

type Payment struct {
AlexTransit marked this conversation as resolved.
Show resolved Hide resolved
PaymentID string `json:"PaymentId"`
Amount uint64 `json:"Amount"` // Стоимость товара в копейках
AlexTransit marked this conversation as resolved.
Show resolved Hide resolved
Status string `json:"Status"` // Статус платежа
RRN string `json:"RRN"` // Внутренний номер операции в платежной системе — кроме операций по СБП.
AlexTransit marked this conversation as resolved.
Show resolved Hide resolved
Success bool `json:"Success"` // Успешность операции
ErrorCode string `json:"ErrorCode"` // Код ошибки, «0» - если успешно
AlexTransit marked this conversation as resolved.
Show resolved Hide resolved
ErrorMessage string `json:"Message,omitempty"` // Краткое описание ошибки
}

func (i *CheckOrderRequest) GetValuesForToken() map[string]string {
return map[string]string{
"OrderID": i.OrderID,
}
}

func (c *Client) CheckOrderWithContext(ctx context.Context, request *CheckOrderRequest) (*CheckOrderResponse, error) {
response, err := c.PostRequestWithContext(ctx, "/CheckOrder", request)
if err != nil {
return nil, err
}
defer response.Body.Close()

var res CheckOrderResponse
err = c.decodeResponse(response, &res)
if err != nil {
return nil, err
}

return &res, res.Error()
}