Skip to content

Commit

Permalink
Add transaction status methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AchoArnold committed Dec 1, 2024
1 parent c9aa158 commit d0fa02e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,24 @@ type RefundTransactionStatus struct {
CustomerSecret string `json:"customer_secret"`
FinalCustomerName string `json:"final_customer_name"`
FinalCustomerPhone string `json:"final_customer_phone"`
FinalCustomerNameAccuracy string `json:"final_customer_name_accuracy"`
FinalCustomerNameAccuracy any `json:"final_customer_name_accuracy"`
} `json:"parameters"`
CreatedAt string `json:"CreateAt"`
MessageID string `json:"MessageId"`
RefundStep string `json:"RefundStep"`
}

// IsPending checks if the refund transaction is pending
func (status *RefundTransactionStatus) IsPending() bool {
return status.Result.Data.Status == "" || status.Result.Data.Status == "PENDING" || status.Result.Data.Status == "INITIATED"
}

// IsSuccessful checks if the refund transaction is successful
func (status *RefundTransactionStatus) IsSuccessful() bool {
return status.Result.Data.Status == "SUCCESSFULL" || status.Result.Data.Status == "SUCCESSFUL"
}

// IsFailed checks if the refund transaction is failed
func (status *RefundTransactionStatus) IsFailed() bool {
return status.Result.Data.Status == "FAILED" || status.Result.Data.Status == "EXPIRED"
}
3 changes: 3 additions & 0 deletions refund_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func TestRefundService_Status(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode)
assert.Equal(t, "CI24120168FBF65A909F588B4480", transaction.Result.Data.PayToken)
assert.True(t, transaction.IsSuccessful())
assert.False(t, transaction.IsFailed())
assert.False(t, transaction.IsPending())

// Teardown
server.Close()
Expand Down

0 comments on commit d0fa02e

Please sign in to comment.