45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package mock
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
"log"
|
|
"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)
|
|
log.Printf("[%s:%s] received authorization response", entry.Id.String(), entry.State)
|
|
return "/entries/" + id.String(), err
|
|
}
|