Skip to content
Snippets Groups Projects
Commit efec4b26 authored by Роман Романов's avatar Роман Романов
Browse files

Merge branch 'revert-1922c59b' into 'release/v0.28'

Revert "Merge branch 'MRM-9007' into 'release/v0.28'"

See merge request mashroom/backend/expenses!68
parents 50ffbe55 18431840
Branches
Tags
No related merge requests found
......@@ -20,63 +20,39 @@ func (srv *serviceImpl) InvoiceChange(
) (resp *invoice.InvoiceChangeResponse, err error) {
switch req.GetInvoice().GetType() {
case invoice.InvoiceType_INVOICE_TYPE_PAYMENT:
err = srv.invoiceChangePayment(ctx, req.GetInvoice(), req.GetPayment())
case invoice.InvoiceType_INVOICE_TYPE_PAYOUT:
err = srv.invoiceChangePayout(ctx, req.GetInvoice(), req.GetPayment())
}
var rentpayment bool
if err != nil {
return nil, err
}
return &invoice.InvoiceChangeResponse{}, nil
}
func (srv *serviceImpl) invoiceChangePayment(
ctx context.Context,
inv *invoice.Invoice,
pmt *invoice.Payment,
) (err error) {
err = srv.Repo.RecordPaymentStateUpdateByCorrelationInvoice(
ctx,
expenses.CorrelationType_CORRELATION_TYPE_OFFER,
inv.GetCorrelationId(),
pmt.GetPaymentId(),
paymentStatus(pmt.GetStatus()),
pmt.GetUpdatedAt().AsTime(),
)
if err != nil {
log.WithError(err).Error("invoiceChangePayment: RecordPaymentStateUpdateByCorrelationInvoice")
return err
}
for _, s := range req.GetInvoice().GetServices() {
if s.GetService().GetType() == extras.ServiceType_RENT {
rentpayment = true
break
}
}
var rentpayment bool
if !rentpayment {
return &invoice.InvoiceChangeResponse{}, nil
}
for _, s := range inv.GetServices() {
if s.GetService().GetType() == extras.ServiceType_RENT {
rentpayment = true
break
err = srv.paymentTransactionMatches(ctx, req.GetInvoice(), req.GetPayment())
if err != nil {
return nil, err
}
}
if !rentpayment {
return
if req.GetPayment().GetStatus() == invoice.PaymentStatus_PAYMENT_SUCCESS {
err = srv.paymentSuccessPayment(ctx, req.GetInvoice(), req.GetPayment())
}
case invoice.InvoiceType_INVOICE_TYPE_PAYOUT:
err = srv.paymentPayout(ctx, req.GetInvoice(), req.GetPayment())
}
err = srv.invoiceChangeRentPaymentTransactionMatch(ctx, inv, pmt)
if err != nil {
return
}
if pmt.GetStatus() == invoice.PaymentStatus_PAYMENT_SUCCESS {
err = srv.invoiceChangeRentPaymentSuccess(ctx, inv, pmt)
return nil, err
}
return
return &invoice.InvoiceChangeResponse{}, nil
}
func (srv *serviceImpl) invoiceChangeRentPaymentTransactionMatch(
func (srv *serviceImpl) paymentTransactionMatches(
ctx context.Context,
inv *invoice.Invoice,
pmt *invoice.Payment,
......@@ -90,7 +66,7 @@ func (srv *serviceImpl) invoiceChangeRentPaymentTransactionMatch(
expenses.RecordType_RECORD_TYPE_INCOME,
)
if err != nil {
log.WithError(err).Error("invoiceChangeRentPaymentTransactionMatch: RecordGetByCorrelationOptions")
log.WithError(err).Error("paymentTransactionMatches: RecordGetByCorrelationOptions")
return err
}
......@@ -128,7 +104,7 @@ func (srv *serviceImpl) invoiceChangeRentPaymentTransactionMatch(
match,
)
if err != nil {
log.WithError(err).Error("invoiceChangeRentPaymentTransactionMatch: createPayout")
log.WithError(err).Error("paymentTransactionMatches: createPayout")
return err
}
......@@ -146,7 +122,7 @@ func (srv *serviceImpl) invoiceChangeRentPaymentTransactionMatch(
pmt.GetUpdatedAt().AsTime(),
)
if err != nil {
log.WithError(err).Error("invoiceChangeRentPaymentTransactionMatch: RecordPayoutInitByCorrelationInvoice")
log.WithError(err).Error("paymentTransactionMatches: RecordPayoutInitByCorrelationInvoice")
return err
}
......@@ -155,7 +131,7 @@ func (srv *serviceImpl) invoiceChangeRentPaymentTransactionMatch(
return nil
}
func (srv *serviceImpl) invoiceChangePayout(
func (srv *serviceImpl) paymentPayout(
ctx context.Context,
inv *invoice.Invoice,
pmt *invoice.Payment,
......@@ -268,11 +244,25 @@ func (srv *serviceImpl) createPayout(
return res.GetInvoice(), nil
}
func (srv *serviceImpl) invoiceChangeRentPaymentSuccess(
func (srv *serviceImpl) paymentSuccessPayment(
ctx context.Context,
inv *invoice.Invoice,
pmt *invoice.Payment,
) error {
err := srv.Repo.RecordPaymentStateUpdateByCorrelationInvoice(
ctx,
expenses.CorrelationType_CORRELATION_TYPE_OFFER,
inv.GetCorrelationId(),
pmt.GetPaymentId(),
paymentStatus(pmt.GetStatus()),
pmt.GetUpdatedAt().AsTime(),
)
if err != nil {
log.WithError(err).Error("paymentSuccessPayment: RecordPaymentStateUpdateByCorrelationInvoice")
return err
}
rec, err := srv.Repo.RecordGetByCorrelationOptions(
ctx,
expenses.CorrelationType_CORRELATION_TYPE_OFFER,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment