payment-poc/providers/mock/service.go

45 lines
1.3 KiB
Go
Raw Normal View History

2023-07-31 07:21:37 +00:00
package mock
import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
2023-07-31 08:01:37 +00:00
"log"
2023-07-31 07:21:37 +00:00
"payment-poc/database"
"payment-poc/state"
)
type Service struct {
BackendUrl string
}
func (s Service) UpdatePayment(entry database.PaymentEntry) (updatedEntry database.PaymentEntry, err error) {
return entry, nil
}
func (s Service) CreatePaymentUrl(entry database.PaymentEntry) (updateEntry database.PaymentEntry, url string, err error) {
return entry, "/mock/gateway/" + entry.Id.String(), nil
}
func (s Service) CompleteTransaction(entry database.PaymentEntry, amount int64) (database.PaymentEntry, error) {
entry.Amount = &amount
entry.State = state.StateCompleted
return entry, nil
}
func (s Service) CancelTransaction(entry database.PaymentEntry) (database.PaymentEntry, error) {
entry.State = state.StateVoided
return entry, nil
}
func (s Service) HandleResponse(c *gin.Context, provider *database.PaymentEntryProvider, paymentState state.PaymentState) (string, error) {
id := uuid.MustParse(c.Query("id"))
entry, err := provider.FetchById(id)
if err != nil {
return "", err
}
entry.State = paymentState
_, err = provider.UpdateEntry(entry)
2023-07-31 08:01:37 +00:00
log.Printf("[%s:%s] received authorization response", entry.Id.String(), entry.State)
2023-07-31 07:21:37 +00:00
return "/entries/" + id.String(), err
}