Added mock provider

This commit is contained in:
Borna Rajković 2023-07-31 09:21:37 +02:00
parent 1307c7bc6e
commit b6203d8a03
1 changed files with 42 additions and 0 deletions

42
mock/service.go Normal file
View File

@ -0,0 +1,42 @@
package mock
import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"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)
return "/entries/" + id.String(), err
}