Compare commits
No commits in common. "e3d77d55b980eb01f6c49bf22ea94bab5ac25ff7" and "744ac00d4dafd14de88993d39ba2ef0b5849d9a2" have entirely different histories.
e3d77d55b9
...
744ac00d4d
15
main.go
15
main.go
|
@ -371,6 +371,21 @@ func stripeHandlers(g *gin.RouterGroup, provider *database.PaymentEntryProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
func wsPayHandlers(g *gin.RouterGroup, provider *database.PaymentEntryProvider, wspayService *wspay2.Service) {
|
func wsPayHandlers(g *gin.RouterGroup, provider *database.PaymentEntryProvider, wspayService *wspay2.Service) {
|
||||||
|
g.GET("/initialize/:id", func(c *gin.Context) {
|
||||||
|
entry, err := provider.FetchById(uuid.MustParse(c.Param("id")))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusNotFound, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if entry.State != state.StatePreinitialized {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
form := wspayService.InitializePayment(entry)
|
||||||
|
|
||||||
|
c.HTML(200, "wspay.gohtml", gin.H{"Action": wspay2.AuthorisationForm, "Form": form})
|
||||||
|
})
|
||||||
|
|
||||||
g.GET("success", func(c *gin.Context) {
|
g.GET("success", func(c *gin.Context) {
|
||||||
url, err := wspayService.HandleSuccessResponse(c, provider)
|
url, err := wspayService.HandleSuccessResponse(c, provider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
8
makefile
8
makefile
|
@ -10,10 +10,10 @@ setup:
|
||||||
go get
|
go get
|
||||||
|
|
||||||
docker-dev:
|
docker-dev:
|
||||||
docker image build -t registry.s2internal.com/opgdirekt/payment-poc/backend:$(VERSION)-dev .
|
docker image build -t registry.bbr-dev.info/payment-poc/backend:$(VERSION)-dev .
|
||||||
docker tag registry.s2internal.com/opgdirekt/payment-poc/backend:$(VERSION)-dev registry.s2internal.com/opgdirekt/payment-poc/backend:latest-dev
|
docker tag registry.bbr-dev.info/payment-poc/backend:$(VERSION)-dev registry.bbr-dev.info/payment-poc/backend:latest-dev
|
||||||
docker image push registry.s2internal.com/opgdirekt/payment-poc/backend:$(VERSION)-dev
|
docker image push registry.bbr-dev.info/payment-poc/backend:$(VERSION)-dev
|
||||||
docker image push registry.s2internal.com/opgdirekt/payment-poc/backend:latest-dev
|
docker image push registry.bbr-dev.info/payment-poc/backend:latest-dev
|
||||||
|
|
||||||
|
|
||||||
docker-prod:
|
docker-prod:
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"io"
|
"io"
|
||||||
|
@ -78,11 +77,7 @@ func determineState(response StatusCheckResponse) state.PaymentState {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) CreatePaymentUrl(entry database.PaymentEntry) (database.PaymentEntry, string, error) {
|
func (s *Service) CreatePaymentUrl(entry database.PaymentEntry) (database.PaymentEntry, string, error) {
|
||||||
entry, url, err := s.InitializePayment(entry)
|
return entry, "/wspay/initialize/" + entry.Id.String(), nil
|
||||||
if err != nil {
|
|
||||||
return entry, "", err
|
|
||||||
}
|
|
||||||
return entry, url, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) CompleteTransaction(entry database.PaymentEntry, amount int64) (database.PaymentEntry, error) {
|
func (s *Service) CompleteTransaction(entry database.PaymentEntry, amount int64) (database.PaymentEntry, error) {
|
||||||
|
@ -164,42 +159,18 @@ func (s *Service) CancelTransaction(entry database.PaymentEntry) (database.Payme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) InitializePayment(entry database.PaymentEntry) (database.PaymentEntry, string, error) {
|
func (s *Service) InitializePayment(entry database.PaymentEntry) Form {
|
||||||
formattedAmount := fmt.Sprintf("%d,%02d", entry.TotalAmount/100, entry.TotalAmount%100)
|
form := Form{
|
||||||
|
|
||||||
var request = CreateTransaction{
|
|
||||||
ShopID: s.ShopId,
|
ShopID: s.ShopId,
|
||||||
ShoppingCardID: entry.Id.String(),
|
ShoppingCartID: entry.Id.String(),
|
||||||
Version: "2.0",
|
Version: "2.0",
|
||||||
TotalAmount: formattedAmount,
|
TotalAmount: entry.TotalAmount,
|
||||||
ReturnUrl: s.BackendUrl + "/wspay/success",
|
ReturnURL: s.BackendUrl + "/wspay/success",
|
||||||
ReturnErrorUrl: s.BackendUrl + "/wspay/error",
|
ReturnErrorURL: s.BackendUrl + "/wspay/error",
|
||||||
CancelUrl: s.BackendUrl + "/wspay/cancel",
|
CancelURL: s.BackendUrl + "/wspay/cancel",
|
||||||
Signature: CalculateFormSignature(s.ShopId, s.ShopSecret, entry.Id.String(), entry.TotalAmount),
|
Signature: CalculateFormSignature(s.ShopId, s.ShopSecret, entry.Id.String(), entry.TotalAmount),
|
||||||
}
|
}
|
||||||
|
return form
|
||||||
httpResponse, err := createRequest(
|
|
||||||
"POST",
|
|
||||||
"https://formtest.wspay.biz/api/create-transaction",
|
|
||||||
map[string]string{"content-type": "application/json"},
|
|
||||||
toJson(request),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return database.PaymentEntry{}, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
var response TransactionResponse
|
|
||||||
err = readResponse(httpResponse, &response)
|
|
||||||
if err != nil {
|
|
||||||
return database.PaymentEntry{}, "", err
|
|
||||||
}
|
|
||||||
if response.TransactionId == nil {
|
|
||||||
return database.PaymentEntry{}, "", errors.New("received bad response")
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.State = state.StateInitialized
|
|
||||||
|
|
||||||
return entry, *response.PaymentFormUrl, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) HandleSuccessResponse(c *gin.Context, provider *database.PaymentEntryProvider) (string, error) {
|
func (s *Service) HandleSuccessResponse(c *gin.Context, provider *database.PaymentEntryProvider) (string, error) {
|
||||||
|
|
|
@ -1,19 +1,34 @@
|
||||||
package wspay
|
package wspay
|
||||||
|
|
||||||
type CreateTransaction struct {
|
const AuthorisationForm = "https://formtest.wspay.biz/authorization.aspx"
|
||||||
ShopID string `json:"ShopID"`
|
|
||||||
ShoppingCardID string `json:"ShoppingCartID"`
|
|
||||||
Version string `json:"Version"`
|
|
||||||
TotalAmount string `json:"TotalAmount"`
|
|
||||||
ReturnUrl string `json:"ReturnURL"`
|
|
||||||
ReturnErrorUrl string `json:"ReturnErrorURL"`
|
|
||||||
CancelUrl string `json:"CancelURL"`
|
|
||||||
Signature string `json:"Signature"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TransactionResponse struct {
|
type Form struct {
|
||||||
TransactionId *string `json:"TransactionId"`
|
// required args
|
||||||
PaymentFormUrl *string `json:"PaymentFormUrl"`
|
ShopID string
|
||||||
|
ShoppingCartID string
|
||||||
|
Version string
|
||||||
|
TotalAmount int64
|
||||||
|
ReturnURL string
|
||||||
|
ReturnErrorURL string
|
||||||
|
CancelURL string
|
||||||
|
Signature string
|
||||||
|
|
||||||
|
// optional args
|
||||||
|
Lang string
|
||||||
|
CustomerFirstName string
|
||||||
|
CustomerLastName string
|
||||||
|
CustomerAddress string
|
||||||
|
CustomerCity string
|
||||||
|
CustomerZIP string
|
||||||
|
CustomerCountry string
|
||||||
|
CustomerPhone string
|
||||||
|
PaymentPlan string
|
||||||
|
CreditCardName string
|
||||||
|
PaymentMethod string
|
||||||
|
IntAmount int64
|
||||||
|
IntCurrency string
|
||||||
|
ReturnMethod string
|
||||||
|
CurrencyCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
type FormReturn struct {
|
type FormReturn struct {
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>Izradi planćanje</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
|
||||||
|
<style>
|
||||||
|
h2 {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body class="container" style="margin-top: 32px">
|
||||||
|
<h2>Započni proces plaćanja</h2>
|
||||||
|
|
||||||
|
<form id="wspay-form" action="{{.Action}}" method="POST">
|
||||||
|
<input type="hidden" name="ShopID" value="{{.Form.ShopID}}">
|
||||||
|
<input type="hidden" name="ShoppingCartID" value="{{.Form.ShoppingCartID}}">
|
||||||
|
<input type="hidden" name="Version" value="{{.Form.Version}}">
|
||||||
|
<input type="hidden" name="TotalAmount" value="{{formatCurrency .Form.TotalAmount}}">
|
||||||
|
<input type="hidden" name="Signature" value="{{.Form.Signature}}">
|
||||||
|
<input type="hidden" name="ReturnURL" value="{{.Form.ReturnURL}}">
|
||||||
|
<input type="hidden" name="CancelURL" value="{{.Form.CancelURL}}">
|
||||||
|
<input type="hidden" name="ReturnErrorURL" value="{{.Form.ReturnErrorURL}}">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.querySelector("#wspay-form").submit();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue