Added mock provider
This commit is contained in:
parent
1307c7bc6e
commit
b6203d8a03
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue