2023-06-13 13:22:51 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"penahub.gitlab.yandexcloud.net/external/treasurer/internal/errors"
|
|
|
|
"penahub.gitlab.yandexcloud.net/external/treasurer/internal/models"
|
2024-04-17 22:35:13 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/external/treasurer/internal/utils"
|
|
|
|
"penahub.gitlab.yandexcloud.net/external/treasurer/internal/models/yandex"
|
2023-06-13 13:22:51 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/external/treasurer/internal/proto/treasurer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PaymentService interface {
|
2024-04-17 22:35:13 +00:00
|
|
|
CreatePaymentBankCard(context.Context, *models.CreatePayment[yandex.Receipt]) (string, errors.Error)
|
|
|
|
CreatePayment(context.Context, *models.CreatePayment[yandex.Receipt]) (string, errors.Error)
|
2023-06-13 13:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type PaymentControllerDeps struct {
|
|
|
|
Logger *zap.Logger
|
|
|
|
PaymentService PaymentService
|
|
|
|
}
|
|
|
|
|
|
|
|
type PaymentController struct {
|
|
|
|
logger *zap.Logger
|
|
|
|
paymentService PaymentService
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPaymentController(deps PaymentControllerDeps) (*PaymentController, errors.Error) {
|
|
|
|
if deps.Logger == nil {
|
|
|
|
return nil, errors.NewWithMessage("Logger in nil on <NewPaymentController>", errors.ErrInvalidArgs)
|
|
|
|
}
|
|
|
|
|
|
|
|
if deps.PaymentService == nil {
|
|
|
|
return nil, errors.NewWithMessage("PaymentService in nil on <NewPaymentController>", errors.ErrInvalidArgs)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &PaymentController{
|
|
|
|
logger: deps.Logger,
|
|
|
|
paymentService: deps.PaymentService,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-03-18 21:27:48 +00:00
|
|
|
func (receiver *PaymentController) GetPaymentLinkBankCard(ctx context.Context, in *treasurer.GetPaymentLinkRequest) (*treasurer.GetPaymentLinkResponse, error) {
|
2024-04-17 22:35:13 +00:00
|
|
|
link, err := receiver.paymentService.CreatePaymentBankCard(ctx, &models.CreatePayment[yandex.Receipt]{
|
2023-06-13 13:22:51 +00:00
|
|
|
Type: models.PaymentTypeBankCard,
|
|
|
|
Currency: in.MainSettings.Currency,
|
|
|
|
UserID: in.MainSettings.UserID,
|
|
|
|
ClientIP: in.MainSettings.ClientIP,
|
|
|
|
Amount: in.MainSettings.Amount,
|
|
|
|
CallbackHostGRPC: in.MainSettings.CallbackHostGRPC,
|
|
|
|
ReturnURL: in.MainSettings.ReturnURL,
|
2024-04-17 22:35:13 +00:00
|
|
|
Requisites: yandex.Receipt{
|
|
|
|
TaxSystemCode: 2,
|
|
|
|
Customer: yandex.Customer{
|
|
|
|
FullName: in.MainSettings.Customer.FullName,
|
|
|
|
INN: in.MainSettings.Customer.INN,
|
|
|
|
Email: in.MainSettings.Customer.Email,
|
|
|
|
Phone: in.MainSettings.Customer.Phone,
|
|
|
|
},
|
|
|
|
Items: utils.ProtoItems2ReceiptItems(in.MainSettings.Items),
|
|
|
|
|
|
|
|
},
|
2023-06-13 13:22:51 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
receiver.logger.Error("failed to get payment link on <GetPaymentLinkBankCard> of <PaymentController>", zap.Error(err))
|
|
|
|
return nil, errors.GRPC("failed to get payment link", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &treasurer.GetPaymentLinkResponse{RedirectURL: link}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver *PaymentController) GetPaymentLinkYooMoney(ctx context.Context, in *treasurer.GetPaymentLinkRequest) (*treasurer.GetPaymentLinkResponse, error) {
|
2024-04-17 22:35:13 +00:00
|
|
|
link, err := receiver.paymentService.CreatePayment(ctx, &models.CreatePayment[yandex.Receipt]{
|
2023-06-13 13:22:51 +00:00
|
|
|
Type: models.PaymentTypeYoomoney,
|
|
|
|
Currency: in.MainSettings.Currency,
|
|
|
|
UserID: in.MainSettings.UserID,
|
|
|
|
ClientIP: in.MainSettings.ClientIP,
|
|
|
|
Amount: in.MainSettings.Amount,
|
|
|
|
CallbackHostGRPC: in.MainSettings.CallbackHostGRPC,
|
|
|
|
ReturnURL: in.MainSettings.ReturnURL,
|
2024-04-17 22:35:13 +00:00
|
|
|
Requisites: yandex.Receipt{
|
|
|
|
TaxSystemCode: 2,
|
|
|
|
Customer: yandex.Customer{
|
|
|
|
FullName: in.MainSettings.Customer.FullName,
|
|
|
|
INN: in.MainSettings.Customer.INN,
|
|
|
|
Email: in.MainSettings.Customer.Email,
|
|
|
|
Phone: in.MainSettings.Customer.Phone,
|
|
|
|
},
|
|
|
|
Items: utils.ProtoItems2ReceiptItems(in.MainSettings.Items),
|
|
|
|
|
|
|
|
},
|
2023-06-13 13:22:51 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
receiver.logger.Error("failed to get payment link on <GetPaymentLinkYooMoney> of <PaymentController>", zap.Error(err))
|
|
|
|
return nil, errors.GRPC("failed to get payment link", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &treasurer.GetPaymentLinkResponse{RedirectURL: link}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver *PaymentController) GetPaymentLinkTinkoff(ctx context.Context, in *treasurer.GetPaymentLinkRequest) (*treasurer.GetPaymentLinkResponse, error) {
|
2024-04-17 22:35:13 +00:00
|
|
|
link, err := receiver.paymentService.CreatePayment(ctx, &models.CreatePayment[yandex.Receipt]{
|
2023-06-13 13:22:51 +00:00
|
|
|
Type: models.PaymentTypeTinkoff,
|
|
|
|
Currency: in.MainSettings.Currency,
|
|
|
|
UserID: in.MainSettings.UserID,
|
|
|
|
ClientIP: in.MainSettings.ClientIP,
|
|
|
|
Amount: in.MainSettings.Amount,
|
|
|
|
CallbackHostGRPC: in.MainSettings.CallbackHostGRPC,
|
|
|
|
ReturnURL: in.MainSettings.ReturnURL,
|
2024-04-17 22:35:13 +00:00
|
|
|
Requisites: yandex.Receipt{
|
|
|
|
TaxSystemCode: 2,
|
|
|
|
Customer: yandex.Customer{
|
|
|
|
FullName: in.MainSettings.Customer.FullName,
|
|
|
|
INN: in.MainSettings.Customer.INN,
|
|
|
|
Email: in.MainSettings.Customer.Email,
|
|
|
|
Phone: in.MainSettings.Customer.Phone,
|
|
|
|
},
|
|
|
|
Items: utils.ProtoItems2ReceiptItems(in.MainSettings.Items),
|
|
|
|
|
|
|
|
},
|
2023-06-13 13:22:51 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
receiver.logger.Error("failed to get payment link on <GetPaymentLinkTinkoff> of <PaymentController>", zap.Error(err))
|
|
|
|
return nil, errors.GRPC("failed to get payment link", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &treasurer.GetPaymentLinkResponse{RedirectURL: link}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver *PaymentController) GetPaymentLinkSBP(ctx context.Context, in *treasurer.GetPaymentLinkRequest) (*treasurer.GetPaymentLinkResponse, error) {
|
2024-04-17 22:35:13 +00:00
|
|
|
link, err := receiver.paymentService.CreatePayment(ctx, &models.CreatePayment[yandex.Receipt]{
|
2023-06-13 13:22:51 +00:00
|
|
|
Type: models.PaymentTypeSBP,
|
|
|
|
Currency: in.MainSettings.Currency,
|
|
|
|
UserID: in.MainSettings.UserID,
|
|
|
|
ClientIP: in.MainSettings.ClientIP,
|
|
|
|
Amount: in.MainSettings.Amount,
|
|
|
|
CallbackHostGRPC: in.MainSettings.CallbackHostGRPC,
|
|
|
|
ReturnURL: in.MainSettings.ReturnURL,
|
2024-04-17 22:35:13 +00:00
|
|
|
Requisites: yandex.Receipt{
|
|
|
|
TaxSystemCode: 2,
|
|
|
|
Customer: yandex.Customer{
|
|
|
|
FullName: in.MainSettings.Customer.FullName,
|
|
|
|
INN: in.MainSettings.Customer.INN,
|
|
|
|
Email: in.MainSettings.Customer.Email,
|
|
|
|
Phone: in.MainSettings.Customer.Phone,
|
|
|
|
},
|
|
|
|
Items: utils.ProtoItems2ReceiptItems(in.MainSettings.Items),
|
|
|
|
|
|
|
|
},
|
2023-06-13 13:22:51 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
receiver.logger.Error("failed to get payment link on <GetPaymentLinkSBP> of <PaymentController>", zap.Error(err))
|
|
|
|
return nil, errors.GRPC("failed to get payment link", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &treasurer.GetPaymentLinkResponse{RedirectURL: link}, nil
|
|
|
|
}
|
|
|
|
|
2024-03-18 21:27:48 +00:00
|
|
|
func (receiver *PaymentController) GetPaymentLinkSberPay(ctx context.Context, in *treasurer.GetPaymentLinkRequest) (*treasurer.GetPaymentLinkResponse, error) {
|
2024-04-17 22:35:13 +00:00
|
|
|
link, err := receiver.paymentService.CreatePayment(ctx, &models.CreatePayment[yandex.Receipt]{
|
2024-03-18 21:27:48 +00:00
|
|
|
Type: models.PaymentTypeSberPay,
|
|
|
|
Currency: in.MainSettings.Currency,
|
|
|
|
UserID: in.MainSettings.UserID,
|
|
|
|
ClientIP: in.MainSettings.ClientIP,
|
|
|
|
Amount: in.MainSettings.Amount,
|
|
|
|
CallbackHostGRPC: in.MainSettings.CallbackHostGRPC,
|
|
|
|
ReturnURL: in.MainSettings.ReturnURL,
|
2024-04-17 22:35:13 +00:00
|
|
|
Requisites: yandex.Receipt{
|
|
|
|
TaxSystemCode: 2,
|
|
|
|
Customer: yandex.Customer{
|
|
|
|
FullName: in.MainSettings.Customer.FullName,
|
|
|
|
INN: in.MainSettings.Customer.INN,
|
|
|
|
Email: in.MainSettings.Customer.Email,
|
|
|
|
Phone: in.MainSettings.Customer.Phone,
|
|
|
|
},
|
|
|
|
Items: utils.ProtoItems2ReceiptItems(in.MainSettings.Items),
|
|
|
|
|
|
|
|
},
|
2024-03-18 21:27:48 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
receiver.logger.Error("failed to get payment link on <GetPaymentLinkSberPay> of <PaymentController>", zap.Error(err))
|
|
|
|
return nil, errors.GRPC("failed to get payment link", err)
|
|
|
|
}
|
2023-06-13 13:22:51 +00:00
|
|
|
|
2024-03-18 21:27:48 +00:00
|
|
|
return &treasurer.GetPaymentLinkResponse{RedirectURL: link}, nil
|
2023-06-13 13:22:51 +00:00
|
|
|
}
|
2024-03-16 15:50:37 +00:00
|
|
|
|
2024-03-18 21:27:48 +00:00
|
|
|
func (receiver *PaymentController) GetPaymentLinkSberbankB2B(ctx context.Context, in *treasurer.GetPaymentLinkRequest) (*treasurer.GetPaymentLinkResponse, error) {
|
2024-04-17 22:35:13 +00:00
|
|
|
link, err := receiver.paymentService.CreatePayment(ctx, &models.CreatePayment[yandex.Receipt]{
|
2024-03-18 21:27:48 +00:00
|
|
|
Type: models.PaymentTypeSberB2B,
|
|
|
|
Currency: in.MainSettings.Currency,
|
|
|
|
UserID: in.MainSettings.UserID,
|
|
|
|
ClientIP: in.MainSettings.ClientIP,
|
|
|
|
Amount: in.MainSettings.Amount,
|
|
|
|
CallbackHostGRPC: in.MainSettings.CallbackHostGRPC,
|
|
|
|
ReturnURL: in.MainSettings.ReturnURL,
|
2024-04-17 22:35:13 +00:00
|
|
|
Requisites: yandex.Receipt{
|
|
|
|
TaxSystemCode: 2,
|
|
|
|
Customer: yandex.Customer{
|
|
|
|
FullName: in.MainSettings.Customer.FullName,
|
|
|
|
INN: in.MainSettings.Customer.INN,
|
|
|
|
Email: in.MainSettings.Customer.Email,
|
|
|
|
Phone: in.MainSettings.Customer.Phone,
|
|
|
|
},
|
|
|
|
Items: utils.ProtoItems2ReceiptItems(in.MainSettings.Items),
|
|
|
|
|
|
|
|
},
|
2024-03-18 21:27:48 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
receiver.logger.Error("failed to get payment link on <GetPaymentLinkB2B> of <PaymentController>", zap.Error(err))
|
|
|
|
return nil, errors.GRPC("failed to get payment link", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &treasurer.GetPaymentLinkResponse{RedirectURL: link}, nil
|
|
|
|
}
|