From 64ac63f1420931c318f8ab8ac289d1dcdb5646b2 Mon Sep 17 00:00:00 2001 From: ricky-julianjatsono Date: Mon, 10 Jul 2023 14:13:01 +0900 Subject: [PATCH] disbursement-callback-struct --- disbursement/event.go | 16 ++++++++ disbursement/event_test.go | 83 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 disbursement/event.go create mode 100644 disbursement/event_test.go diff --git a/disbursement/event.go b/disbursement/event.go new file mode 100644 index 00000000..08a33123 --- /dev/null +++ b/disbursement/event.go @@ -0,0 +1,16 @@ +package disbursement + +type DisbursementCallback struct { + ID string `json:"id"` + Created string `json:"created"` + Updated string `json:"updated"` + ExternalID string `json:"external_id"` + UserID string `json:"user_id"` + Amount float64 `json:"amount"` + BankCode string `json:"bank_code"` + AccountHolderName string `json:"account_holder_name"` + DisbursementDescription string `json:"disbursement_description"` + Status string `json:"status"` + FailureCode string `json:"failure_code,omitempty"` + IsInstant bool `json:"is_instant,omitempty"` +} diff --git a/disbursement/event_test.go b/disbursement/event_test.go new file mode 100644 index 00000000..e9d5969f --- /dev/null +++ b/disbursement/event_test.go @@ -0,0 +1,83 @@ +package disbursement_test + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/xendit/xendit-go/disbursement" +) + +func TestPayload_Completed(t *testing.T) { + payload := `{ + "id": "57e214ba82b034c325e84d6e", + "created": "2021-07-10T08:15:03.404Z", + "updated": "2021-07-10T08:15:03.404Z", + "external_id": "disbursement_123124123", + "user_id": "57c5aa7a36e3b6a709b6e148", + "amount": 150000, + "bank_code": "BCA", + "account_holder_name": "MICHAEL CHEN", + "disbursement_description": "Refund for shoes", + "status": "COMPLETED", + "is_instant": true + }` + + expectedPayload := disbursement.DisbursementCallback{ + ID: "57e214ba82b034c325e84d6e", + Created: "2021-07-10T08:15:03.404Z", + Updated: "2021-07-10T08:15:03.404Z", + ExternalID: "disbursement_123124123", + UserID: "57c5aa7a36e3b6a709b6e148", + Amount: 150000, + BankCode: "BCA", + AccountHolderName: "MICHAEL CHEN", + DisbursementDescription: "Refund for shoes", + Status: "COMPLETED", + IsInstant: true, + } + + var actualPayload disbursement.DisbursementCallback + err := json.Unmarshal([]byte(payload), &actualPayload) + assert.NoError(t, err) + + assert.Equal(t, expectedPayload, actualPayload) +} + +func TestPayload_Failed(t *testing.T) { + payload := `{ + "id": "57e214ba82b034c325e84d6e", + "created": "2021-07-10T08:15:03.404Z", + "updated": "2021-07-10T08:15:03.404Z", + "external_id": "disbursement_123124123", + "user_id": "57c5aa7a36e3b6a709b6e148", + "amount": 150000, + "bank_code": "BCA", + "account_holder_name": "MICHAEL CHEN", + "disbursement_description": "Refund for shoes", + "status": "FAILED", + "failure_code": "INVALID_DESTINATION", + "is_instant": true + }` + + expectedPayload := disbursement.DisbursementCallback{ + ID: "57e214ba82b034c325e84d6e", + Created: "2021-07-10T08:15:03.404Z", + Updated: "2021-07-10T08:15:03.404Z", + ExternalID: "disbursement_123124123", + UserID: "57c5aa7a36e3b6a709b6e148", + Amount: 150000, + BankCode: "BCA", + AccountHolderName: "MICHAEL CHEN", + DisbursementDescription: "Refund for shoes", + Status: "FAILED", + FailureCode: "INVALID_DESTINATION", + IsInstant: true, + } + + var actualPayload disbursement.DisbursementCallback + err := json.Unmarshal([]byte(payload), &actualPayload) + assert.NoError(t, err) + + assert.Equal(t, expectedPayload, actualPayload) +}