-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/congiary/cdek-pay | ||
|
||
go 1.13 | ||
go 1.13 | ||
|
||
require github.com/google/go-querystring v1.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= | ||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= | ||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package cdek_pay | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
const ( | ||
PaymentColumnId = "id" | ||
PaymentColumnTime = "payment_time" | ||
) | ||
|
||
const ( | ||
PaymentDirectionASC = "ASC" | ||
PaymentDirectionDESC = "DESC" | ||
) | ||
|
||
const ( | ||
PaymentStatusSuccess = "success" // успешный платеж | ||
PaymentStatusCancelled = "cancelled" // возврат, данный платеж создается после успешного возврата | ||
PaymentStatusSuccessCancellation = "success_cancellation" // успешная отмена | ||
PaymentStatusCancellationRequested = "cancellation_requested" // запрошена отмена | ||
) | ||
|
||
type getPaymentsRequest struct { | ||
BaseRequest | ||
GetPaymentsRequest | ||
} | ||
|
||
// todo: сделать как-то более красиво структуры | ||
type GetPaymentsRequest struct { | ||
Page int `json:"p[page]" url:"p[page]"` | ||
PerPage int `json:"p[per_page]" url:"p[per_page]"` | ||
Column string `json:"o[column]" url:"o[column]"` | ||
Direction string `json:"o[direction]" url:"o[direction]"` | ||
|
||
OrderId *int `json:"q[order_id],omitempty" url:"q[order_id],omitempty"` | ||
AccessKey *int `json:"q[access_key],omitempty" url:"q[access_key],omitempty"` | ||
} | ||
|
||
func (i *getPaymentsRequest) GetValuesForSignature() map[string]interface{} { | ||
return FlattenStructToMap(GetPaymentsRequest{ | ||
Page: i.Page, | ||
PerPage: i.PerPage, | ||
Column: i.Column, | ||
Direction: i.Direction, | ||
OrderId: i.OrderId, | ||
AccessKey: i.AccessKey, | ||
}, "") | ||
} | ||
|
||
type GetPaymentsResponse struct { | ||
TotalPayments int `json:"total_payments"` // Общее количество платежей | ||
CurrentPage int `json:"current_page"` // Текущая страница списка платежей | ||
TotalPages int `json:"total_pages"` // Общее количество страниц списка платежей | ||
Payments []Payment `json:"payments"` // Массив объектов платежей | ||
} | ||
|
||
type Payment struct { | ||
ID int `json:"id"` // Идентификатор платежа | ||
OrderID int `json:"order_id"` // Сокращенный идентификатор заказа в системе CDEKFIN | ||
AccessKey string `json:"access_key"` // Уникальный идентификатор заказа в системе CDEKFIN | ||
Currency string `json:"currency"` // Валюта платежа | ||
PayAmount int `json:"pay_amount"` // Сумма платежа в копейках (отрицательная для возвратов) | ||
Status string `json:"status"` // Статус платежа | ||
PaymentTime int `json:"payment_time"` // Дата и время платежа в формате Timestamp | ||
} | ||
|
||
// GetPayments возвращает список платежей и возвратов | ||
func (c *Client) GetPayments(ctx context.Context, request *GetPaymentsRequest) (*GetPaymentsResponse, error) { | ||
req := getPaymentsRequest{ | ||
GetPaymentsRequest: *request, | ||
} | ||
response, err := c.GetRequestWithContext(ctx, "payments", &req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer response.Body.Close() | ||
|
||
var res GetPaymentsResponse | ||
err = c.decodeResponse(response, &res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters