Skip to content

Commit 8dcacea

Browse files
ipinakipinak
ipinak
authored andcommitted
fix issues with create transaction
1 parent 0387b0d commit 8dcacea

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

basicauth.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,12 @@ func (c BasicAuthClient) performReq(req *http.Request) ([]byte, error) {
6969
return nil, fmt.Errorf("failed to perform request %s", httpErr)
7070
}
7171

72+
defer resp.Body.Close()
7273
body, bodyErr := io.ReadAll(resp.Body)
73-
if bodyErr == nil {
74-
resp.Body.Close()
75-
}
7674

7775
if resp.StatusCode != 200 {
7876
return nil, fmt.Errorf("failed to perform request with status %d", resp.StatusCode)
7977
}
8078

81-
return body, nil
79+
return body, bodyErr
8280
}

example/main.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func main() {
4545
}
4646

4747
fmt.Printf("\nGet transaction\n")
48-
trx, err4 := oauthClient.GetTransaction("a9531058-f0f7-44ff-a718-98920804ceab")
48+
trxID := "a9531058-f0f7-44ff-a718-98920804ceab"
49+
trx, err4 := oauthClient.GetTransaction(trxID)
4950
if err4 != nil {
5051
fmt.Printf("\nerr: %s\n", err4.Error())
5152
} else {
@@ -80,4 +81,18 @@ func main() {
8081
fmt.Printf("%v", opCancel)
8182
fmt.Println("\nsuccess")
8283
}
84+
85+
trx2, err9 := basicAuthClient.CancelTransaction("aacf07cf-9102-4b02-8172-72b7e1efd5d9", 100, "Default")
86+
if err9 != nil {
87+
fmt.Printf("\nerr: %s\n", err9.Error())
88+
} else {
89+
fmt.Printf("%v", trx2)
90+
fmt.Println("\nsuccess")
91+
}
92+
93+
payload := vivawallet.CreateTransaction{
94+
Amount: 100,
95+
}
96+
trx3, err2 := basicAuthClient.CreateTransaction("cdc8e764-daf3-49de-9f44-c7f3b563c2d6", payload)
97+
fmt.Printf("%v\nERR: %v\n", trx3, err2)
8398
}

transactions.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@ type CreateTransaction struct {
6363
}
6464

6565
type TransactionResponse struct {
66-
Emv *string `json:"Emv"`
67-
Amount int `json:"Amount"`
68-
StatusID string `json:"StatusId"`
69-
CurrencyCode int `json:"CurrencyCode"`
70-
TransactionID string `json:"TransactionId"`
71-
ReferenceNumber int `json:"ReferenceNumber"`
72-
AuthorizationID int `json:"AuthorizationId"`
73-
RetrievalReferenceNumber int `json:"RetrievalReferenceNumber"`
74-
ThreeDSecureStatusID int `json:"ThreeDSecureStatusId"`
75-
ErrorCode int `json:"ErrorCode"`
76-
ErrorText string `json:"ErrorText"`
77-
Timestamp time.Time `json:"TimeStamp"`
78-
CorrelationID *string `json:"CorrelationId"`
79-
EventID int `json:"EventId"`
80-
Success bool `json:"Success"`
66+
Emv string `json:"Emv,omitempty"`
67+
Amount float64 `json:"Amount"`
68+
StatusID string `json:"StatusId,omitempty"`
69+
CurrencyCode string `json:"CurrencyCode,omitempty"`
70+
TransactionID string `json:"TransactionId,omitempty"`
71+
ReferenceNumber int `json:"ReferenceNumber,omitempty"`
72+
AuthorizationID string `json:"AuthorizationId,omitempty"`
73+
RetrievalReferenceNumber string `json:"RetrievalReferenceNumber,omitempty"`
74+
ThreeDSecureStatusID int `json:"ThreeDSecureStatusId,omitempty"`
75+
ErrorCode int `json:"ErrorCode,omitempty"`
76+
ErrorText string `json:"ErrorText,omitempty"`
77+
Timestamp time.Time `json:"TimeStamp,omitempty"`
78+
CorrelationID string `json:"CorrelationId,omitempty"`
79+
EventID int `json:"EventId,omitempty"`
80+
Success bool `json:"Success,omitempty"`
8181
}
8282

8383
// CreateTransaction creates a new transaction for a recurring payment or a pre-auth

0 commit comments

Comments
 (0)