generated from PenaSide/GolangTemplate
205 lines
7.3 KiB
Go
205 lines
7.3 KiB
Go
![]() |
package swagger
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"go.uber.org/zap"
|
||
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/treasurer"
|
||
|
)
|
||
|
|
||
|
func (api *API2) GetPaymentLink(ctx context.Context, request *models.GetPaymentLinkRequest) (string, errors.Error) {
|
||
|
if _, userErr := api.clients.auth.GetUser(ctx, request.UserID); userErr != nil {
|
||
|
api.logger.Error("failed to get user on <GetPaymentLink> on <PaymentService>",
|
||
|
zap.Error(userErr),
|
||
|
zap.String("userID", request.UserID),
|
||
|
)
|
||
|
|
||
|
return "", userErr
|
||
|
}
|
||
|
|
||
|
switch request.Body.Type {
|
||
|
case models.PaymentTypeBankCard:
|
||
|
return api.GetPaymentLinkBankCard(ctx, request)
|
||
|
case models.PaymentTypeYoomoney:
|
||
|
return api.GetPaymentLinkYooMoney(ctx, request)
|
||
|
case models.PaymentTypeQiwi:
|
||
|
return api.GetPaymentLinkQIWI(ctx, request)
|
||
|
case models.PaymentTypeSberPay:
|
||
|
return api.GetPaymentLinkSberPay(ctx, request)
|
||
|
case models.PaymentTypeAlfabank:
|
||
|
return api.GetPaymentLinkAlfaClick(ctx, request)
|
||
|
case models.PaymentTypeTinkoff:
|
||
|
return api.GetPaymentLinkTinkoff(ctx, request)
|
||
|
case models.PaymentTypeMobile:
|
||
|
return api.GetPaymentLinkMobile(ctx, request)
|
||
|
case models.PaymentTypeCash:
|
||
|
return api.GetPaymentLinkCash(ctx, request)
|
||
|
}
|
||
|
|
||
|
return "", errors.NewWithMessage("invalid payment method type", errors.ErrInvalidArgs)
|
||
|
}
|
||
|
|
||
|
func (api *API2) GetPaymentLinkBankCard(ctx context.Context, request *models.GetPaymentLinkRequest) (string, errors.Error) {
|
||
|
link, err := api.clients.payment.GetPaymentLinkBankCard(ctx, &treasurer.GetBankCardPaymentLinkRequest{
|
||
|
MainSettings: &treasurer.MainPaymentSettings{
|
||
|
Currency: request.Body.Currency,
|
||
|
Amount: request.Body.Amount,
|
||
|
UserID: request.UserID,
|
||
|
ClientIP: request.ClientIP,
|
||
|
CallbackHostGRPC: []string{api.grpc.Domen},
|
||
|
ReturnURL: request.Body.ReturnURL,
|
||
|
},
|
||
|
BankCard: &treasurer.BankCardInformation{
|
||
|
Number: request.Body.BankCard.Number,
|
||
|
ExpiryYear: request.Body.BankCard.ExpiryYear,
|
||
|
ExpiryMonth: request.Body.BankCard.ExpiryMonth,
|
||
|
},
|
||
|
})
|
||
|
if err != nil {
|
||
|
api.logger.Error("failed to get bankcard payment link on <GetPaymentLinkBankCard> of <PaymentService>", zap.Error(err))
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return link, nil
|
||
|
}
|
||
|
|
||
|
func (api *API2) GetPaymentLinkYooMoney(ctx context.Context, request *models.GetPaymentLinkRequest) (string, errors.Error) {
|
||
|
link, err := api.clients.payment.GetPaymentLinkYooMoney(ctx, &treasurer.GetPaymentLinkBody{
|
||
|
MainSettings: &treasurer.MainPaymentSettings{
|
||
|
Currency: request.Body.Currency,
|
||
|
Amount: request.Body.Amount,
|
||
|
UserID: request.UserID,
|
||
|
ClientIP: request.ClientIP,
|
||
|
CallbackHostGRPC: []string{api.grpc.Domen},
|
||
|
ReturnURL: request.Body.ReturnURL,
|
||
|
},
|
||
|
})
|
||
|
if err != nil {
|
||
|
api.logger.Error("failed to get yoomoney payment link on <GetPaymentLinkYooMoney> of <PaymentService>", zap.Error(err))
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return link, nil
|
||
|
}
|
||
|
|
||
|
func (api *API2) GetPaymentLinkQIWI(ctx context.Context, request *models.GetPaymentLinkRequest) (string, errors.Error) {
|
||
|
link, err := api.clients.payment.GetPaymentLinkQIWI(ctx, &treasurer.GetPhonePaymentLinkRequest{
|
||
|
MainSettings: &treasurer.MainPaymentSettings{
|
||
|
Currency: request.Body.Currency,
|
||
|
Amount: request.Body.Amount,
|
||
|
UserID: request.UserID,
|
||
|
ClientIP: request.ClientIP,
|
||
|
CallbackHostGRPC: []string{api.grpc.Domen},
|
||
|
ReturnURL: request.Body.ReturnURL,
|
||
|
},
|
||
|
Phone: request.Body.PhoneNumber,
|
||
|
})
|
||
|
if err != nil {
|
||
|
api.logger.Error("failed to get qiwi payment link on <GetPaymentLinkQIWI> of <PaymentService>", zap.Error(err))
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return link, nil
|
||
|
}
|
||
|
|
||
|
func (api *API2) GetPaymentLinkSberPay(ctx context.Context, request *models.GetPaymentLinkRequest) (string, errors.Error) {
|
||
|
link, err := api.clients.payment.GetPaymentLinkSberPay(ctx, &treasurer.GetPhonePaymentLinkRequest{
|
||
|
MainSettings: &treasurer.MainPaymentSettings{
|
||
|
Currency: request.Body.Currency,
|
||
|
Amount: request.Body.Amount,
|
||
|
UserID: request.UserID,
|
||
|
ClientIP: request.ClientIP,
|
||
|
CallbackHostGRPC: []string{api.grpc.Domen},
|
||
|
ReturnURL: request.Body.ReturnURL,
|
||
|
},
|
||
|
Phone: request.Body.PhoneNumber,
|
||
|
})
|
||
|
if err != nil {
|
||
|
api.logger.Error("failed to get sberpay payment link on <GetPaymentLinkSberPay> of <PaymentService>", zap.Error(err))
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return link, nil
|
||
|
}
|
||
|
|
||
|
func (api *API2) GetPaymentLinkAlfaClick(ctx context.Context, request *models.GetPaymentLinkRequest) (string, errors.Error) {
|
||
|
link, err := api.clients.payment.GetPaymentLinkAlfaClick(ctx, &treasurer.GetLoginPaymentLinkRequest{
|
||
|
MainSettings: &treasurer.MainPaymentSettings{
|
||
|
Currency: request.Body.Currency,
|
||
|
Amount: request.Body.Amount,
|
||
|
UserID: request.UserID,
|
||
|
ClientIP: request.ClientIP,
|
||
|
CallbackHostGRPC: []string{api.grpc.Domen},
|
||
|
ReturnURL: request.Body.ReturnURL,
|
||
|
},
|
||
|
Login: request.Body.Login,
|
||
|
})
|
||
|
if err != nil {
|
||
|
api.logger.Error("failed to get alfaclick payment link on <GetPaymentLinkAlfaClick> of <PaymentService>", zap.Error(err))
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return link, nil
|
||
|
}
|
||
|
|
||
|
func (api *API2) GetPaymentLinkTinkoff(ctx context.Context, request *models.GetPaymentLinkRequest) (string, errors.Error) {
|
||
|
link, err := api.clients.payment.GetPaymentLinkTinkoff(ctx, &treasurer.GetPaymentLinkBody{
|
||
|
MainSettings: &treasurer.MainPaymentSettings{
|
||
|
Currency: request.Body.Currency,
|
||
|
Amount: request.Body.Amount,
|
||
|
UserID: request.UserID,
|
||
|
ClientIP: request.ClientIP,
|
||
|
CallbackHostGRPC: []string{api.grpc.Domen},
|
||
|
ReturnURL: request.Body.ReturnURL,
|
||
|
},
|
||
|
})
|
||
|
if err != nil {
|
||
|
api.logger.Error("failed to get tinkoff payment link on <GetPaymentLinkTinkoff> of <PaymentService>", zap.Error(err))
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return link, nil
|
||
|
}
|
||
|
|
||
|
func (api *API2) GetPaymentLinkMobile(ctx context.Context, request *models.GetPaymentLinkRequest) (string, errors.Error) {
|
||
|
link, err := api.clients.payment.GetPaymentLinkMobile(ctx, &treasurer.GetPhonePaymentLinkRequest{
|
||
|
MainSettings: &treasurer.MainPaymentSettings{
|
||
|
Currency: request.Body.Currency,
|
||
|
Amount: request.Body.Amount,
|
||
|
UserID: request.UserID,
|
||
|
ClientIP: request.ClientIP,
|
||
|
CallbackHostGRPC: []string{api.grpc.Domen},
|
||
|
ReturnURL: request.Body.ReturnURL,
|
||
|
},
|
||
|
Phone: request.Body.PhoneNumber,
|
||
|
})
|
||
|
if err != nil {
|
||
|
api.logger.Error("failed to get mobile payment link on <GetPaymentLinkMobile> of <PaymentService>", zap.Error(err))
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return link, nil
|
||
|
}
|
||
|
|
||
|
func (api *API2) GetPaymentLinkCash(ctx context.Context, request *models.GetPaymentLinkRequest) (string, errors.Error) {
|
||
|
link, err := api.clients.payment.GetPaymentLinkCash(ctx, &treasurer.GetPhonePaymentLinkRequest{
|
||
|
MainSettings: &treasurer.MainPaymentSettings{
|
||
|
Currency: request.Body.Currency,
|
||
|
Amount: request.Body.Amount,
|
||
|
UserID: request.UserID,
|
||
|
ClientIP: request.ClientIP,
|
||
|
CallbackHostGRPC: []string{api.grpc.Domen},
|
||
|
ReturnURL: request.Body.ReturnURL,
|
||
|
},
|
||
|
Phone: request.Body.PhoneNumber,
|
||
|
})
|
||
|
if err != nil {
|
||
|
api.logger.Error("failed to get cash payment link on <GetPaymentLinkCash> of <PaymentService>", zap.Error(err))
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return link, nil
|
||
|
}
|