From d0fa02e29d2df893c172387881cc2a1d6dadd4ad Mon Sep 17 00:00:00 2001 From: Acho Arnold Date: Sun, 1 Dec 2024 17:43:36 +0200 Subject: [PATCH] Add transaction status methods --- refund.go | 17 ++++++++++++++++- refund_service_test.go | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/refund.go b/refund.go index 709e5d3..2cbecde 100644 --- a/refund.go +++ b/refund.go @@ -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" +} diff --git a/refund_service_test.go b/refund_service_test.go index d1bc012..f7b02a8 100644 --- a/refund_service_test.go +++ b/refund_service_test.go @@ -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()