diff --git a/basicauth.go b/basicauth.go index 360615e..6ccd793 100644 --- a/basicauth.go +++ b/basicauth.go @@ -69,14 +69,12 @@ func (c BasicAuthClient) performReq(req *http.Request) ([]byte, error) { return nil, fmt.Errorf("failed to perform request %s", httpErr) } + defer resp.Body.Close() body, bodyErr := io.ReadAll(resp.Body) - if bodyErr == nil { - resp.Body.Close() - } if resp.StatusCode != 200 { return nil, fmt.Errorf("failed to perform request with status %d", resp.StatusCode) } - return body, nil + return body, bodyErr } diff --git a/example/main.go b/example/main.go index 36b935d..cade17f 100644 --- a/example/main.go +++ b/example/main.go @@ -45,7 +45,8 @@ func main() { } fmt.Printf("\nGet transaction\n") - trx, err4 := oauthClient.GetTransaction("a9531058-f0f7-44ff-a718-98920804ceab") + trxID := "a9531058-f0f7-44ff-a718-98920804ceab" + trx, err4 := oauthClient.GetTransaction(trxID) if err4 != nil { fmt.Printf("\nerr: %s\n", err4.Error()) } else { @@ -80,4 +81,18 @@ func main() { fmt.Printf("%v", opCancel) fmt.Println("\nsuccess") } + + trx2, err9 := basicAuthClient.CancelTransaction("aacf07cf-9102-4b02-8172-72b7e1efd5d9", 100, "Default") + if err9 != nil { + fmt.Printf("\nerr: %s\n", err9.Error()) + } else { + fmt.Printf("%v", trx2) + fmt.Println("\nsuccess") + } + + payload := vivawallet.CreateTransaction{ + Amount: 100, + } + trx3, err2 := basicAuthClient.CreateTransaction("cdc8e764-daf3-49de-9f44-c7f3b563c2d6", payload) + fmt.Printf("%v\nERR: %v\n", trx3, err2) } diff --git a/transactions.go b/transactions.go index 1f9028b..e98d3cb 100644 --- a/transactions.go +++ b/transactions.go @@ -63,21 +63,21 @@ type CreateTransaction struct { } type TransactionResponse struct { - Emv *string `json:"Emv"` - Amount int `json:"Amount"` - StatusID string `json:"StatusId"` - CurrencyCode int `json:"CurrencyCode"` - TransactionID string `json:"TransactionId"` - ReferenceNumber int `json:"ReferenceNumber"` - AuthorizationID int `json:"AuthorizationId"` - RetrievalReferenceNumber int `json:"RetrievalReferenceNumber"` - ThreeDSecureStatusID int `json:"ThreeDSecureStatusId"` - ErrorCode int `json:"ErrorCode"` - ErrorText string `json:"ErrorText"` - Timestamp time.Time `json:"TimeStamp"` - CorrelationID *string `json:"CorrelationId"` - EventID int `json:"EventId"` - Success bool `json:"Success"` + Emv string `json:"Emv,omitempty"` + Amount float64 `json:"Amount"` + StatusID string `json:"StatusId,omitempty"` + CurrencyCode string `json:"CurrencyCode,omitempty"` + TransactionID string `json:"TransactionId,omitempty"` + ReferenceNumber int `json:"ReferenceNumber,omitempty"` + AuthorizationID string `json:"AuthorizationId,omitempty"` + RetrievalReferenceNumber string `json:"RetrievalReferenceNumber,omitempty"` + ThreeDSecureStatusID int `json:"ThreeDSecureStatusId,omitempty"` + ErrorCode int `json:"ErrorCode,omitempty"` + ErrorText string `json:"ErrorText,omitempty"` + Timestamp time.Time `json:"TimeStamp,omitempty"` + CorrelationID string `json:"CorrelationId,omitempty"` + EventID int `json:"EventId,omitempty"` + Success bool `json:"Success,omitempty"` } // CreateTransaction creates a new transaction for a recurring payment or a pre-auth