-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from rjjatson/feature/disbursement-callback-s…
…truct disbursement-callback-struct
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |