Removed unnecessary redirect on WsPay initialization
This commit is contained in:
1 parent
5623e01f7f
commit
e3d77d55b9
4 files changed
+51
-87
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"io"
|
||||
@@ -77,7 +78,11 @@ func determineState(response StatusCheckResponse) state.PaymentState {
|
||||
}
|
||||
|
||||
func (s *Service) CreatePaymentUrl(entry database.PaymentEntry) (database.PaymentEntry, string, error) {
|
||||
return entry, "/wspay/initialize/" + entry.Id.String(), nil
|
||||
entry, url, err := s.InitializePayment(entry)
|
||||
if err != nil {
|
||||
return entry, "", err
|
||||
}
|
||||
return entry, url, nil
|
||||
}
|
||||
|
||||
func (s *Service) CompleteTransaction(entry database.PaymentEntry, amount int64) (database.PaymentEntry, error) {
|
||||
@@ -159,18 +164,42 @@ func (s *Service) CancelTransaction(entry database.PaymentEntry) (database.Payme
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) InitializePayment(entry database.PaymentEntry) Form {
|
||||
form := Form{
|
||||
func (s *Service) InitializePayment(entry database.PaymentEntry) (database.PaymentEntry, string, error) {
|
||||
formattedAmount := fmt.Sprintf("%d,%02d", entry.TotalAmount/100, entry.TotalAmount%100)
|
||||
|
||||
var request = CreateTransaction{
|
||||
ShopID: s.ShopId,
|
||||
ShoppingCartID: entry.Id.String(),
|
||||
ShoppingCardID: entry.Id.String(),
|
||||
Version: "2.0",
|
||||
TotalAmount: entry.TotalAmount,
|
||||
ReturnURL: s.BackendUrl + "/wspay/success",
|
||||
ReturnErrorURL: s.BackendUrl + "/wspay/error",
|
||||
CancelURL: s.BackendUrl + "/wspay/cancel",
|
||||
TotalAmount: formattedAmount,
|
||||
ReturnUrl: s.BackendUrl + "/wspay/success",
|
||||
ReturnErrorUrl: s.BackendUrl + "/wspay/error",
|
||||
CancelUrl: s.BackendUrl + "/wspay/cancel",
|
||||
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) {
|
||||
|
||||
+13
-28
@@ -1,34 +1,19 @@
|
||||
package wspay
|
||||
|
||||
const AuthorisationForm = "https://formtest.wspay.biz/authorization.aspx"
|
||||
type CreateTransaction struct {
|
||||
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 Form struct {
|
||||
// required args
|
||||
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 TransactionResponse struct {
|
||||
TransactionId *string `json:"TransactionId"`
|
||||
PaymentFormUrl *string `json:"PaymentFormUrl"`
|
||||
}
|
||||
|
||||
type FormReturn struct {
|
||||
|
||||
Reference in new issue
Block a user