Skip to content

Commit

Permalink
fix issues with create transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ipinak authored and ipinak committed Feb 18, 2023
1 parent 0387b0d commit 8dcacea
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
6 changes: 2 additions & 4 deletions basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 16 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
30 changes: 15 additions & 15 deletions transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8dcacea

Please sign in to comment.