Skip to content

Commit

Permalink
matching the structs with the one provided by invoice team
Browse files Browse the repository at this point in the history
  • Loading branch information
ricky-julianjatsono authored and ricky-julianjatsono committed May 18, 2023
1 parent 930783e commit 3024ee5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
62 changes: 38 additions & 24 deletions invoice/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,42 @@ package invoice
import "github.com/xendit/xendit-go"

type InvoiceCallback struct {
ID string `json:"id"`
Fees []xendit.InvoiceFee `json:"fees"`
Amount int `json:"amount"`
Status string `json:"status"`
Created string `json:"created"`
IsHigh bool `json:"is_high"`
PaidAt string `json:"paid_at"`
Updated string `json:"updated"`
UserID string `json:"user_id"`
Currency string `json:"currency"`
PaymentID string `json:"payment_id"`
ExternalID string `json:"external_id"`
PaidAmount int `json:"paid_amount"`
MerchantName string `json:"merchant_name"`
PaymentMethod string `json:"payment_method"`
PaymentChannel string `json:"payment_channel"`
PaymentDetails *xendit.InvoicePaymentDetail `json:"payment_details"`
PaymentMethodID string `json:"payment_method_id"`
BankCode string `json:"bank_code,omitempty"`
PayerEmail string `json:"payer_email,omitempty"`
Description string `json:"description,omitempty"`
PaymentDestination string `json:"payment_destination,omitempty"`
SuccessRedirectURL string `json:"success_redirect_url,omitempty"`
FailureRedirectURL string `json:"failure_redirect_url,omitempty"`
ID string `json:"id"`
UserID string `json:"user_id"`
ExternalID string `json:"external_id"`
IsHigh bool `json:"is_high"`
Status string `json:"status"`
MerchantName string `json:"merchant_name"`
Amount float64 `json:"amount"`
Created string `json:"created"`
Updated string `json:"updated"`
PayerEmail string `json:"payer_email,omitempty"`
Description string `json:"description,omitempty"`
PaymentID string `json:"payment_id,omitempty"`
PaidAmount float64 `json:"paid_amount,omitempty"`
PaymentMethod string `json:"payment_method,omitempty"`
BankCode string `json:"bank_code,omitempty"`
EwalletType string `json:"ewallet_type,omitempty"`
CallbackAuthenticationToken string `json:"callback_authentication_token,omitempty"`
CallbackURL string `json:"callback_url,omitempty"`
BusinessID string `json:"business_id,omitempty"`
BusinessName string `json:"business_name,omitempty"`
OnDemandLink string `json:"on_demand_link,omitempty"`
RecurringPaymentID string `json:"recurring_payment_id,omitempty"`
CreditCardChargeID string `json:"credit_card_charge_id,omitempty"`
Currency string `json:"currency,omitempty"`
InitialCurrency string `json:"initial_currency,omitempty"`
InitialAmount float64 `json:"initial_amount,omitempty"`
PaidAt *string `json:"paid_at,omitempty"`
MidLabel string `json:"mid_label,omitempty"`
PaymentChannel string `json:"payment_channel,omitempty"`
PaymentDestination string `json:"payment_destination,omitempty"`
SuccessRedirectURL string `json:"success_redirect_url,omitempty"`
FailureRedirectURL string `json:"failure_redirect_url,omitempty"`
CreditCardToken string `json:"credit_card_token,omitempty"`
PaymentMethodID string `json:"payment_method_id,omitempty"`
ShouldAuthenticateCreditCard bool `json:"should_authenticate_credit_card,omitempty"`
PaymentDetails *xendit.InvoicePaymentDetail `json:"payment_details,omitempty"`
Fees *[]xendit.InvoiceFee `json:"fees,omitempty"`
Items *[]xendit.InvoiceItem `json:"items,omitempty"`
}
12 changes: 8 additions & 4 deletions invoice/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"github.com/xendit/xendit-go/invoice"
)

func toPointerString(v string) *string {
return &v
}

func TestInvoiceCallback_EWallet(t *testing.T) {
testPayload := `{
"id": "12345",
Expand Down Expand Up @@ -40,12 +44,12 @@ func TestInvoiceCallback_EWallet(t *testing.T) {
}`
expectedPayload := invoice.InvoiceCallback{
ID: "12345",
Fees: []xendit.InvoiceFee{{Type: "example fee", Value: 100}},
Fees: &[]xendit.InvoiceFee{{Type: "example fee", Value: 100}},
Amount: 1000,
Status: "PAID",
Created: "2023-05-14T07:32:42.646Z",
IsHigh: false,
PaidAt: "2023-05-14T07:35:14.000Z",
PaidAt: toPointerString("2023-05-14T07:35:14.000Z"),
Updated: "2023-05-14T07:35:15.810Z",
UserID: "example",
Currency: "IDR",
Expand Down Expand Up @@ -99,7 +103,7 @@ func TestInvoiceCallback_Bank(t *testing.T) {
Amount: 2000000,
PaidAmount: 2000000,
BankCode: "TESTBANK",
PaidAt: "2020-01-14T02:32:50.912Z",
PaidAt: toPointerString("2020-01-14T02:32:50.912Z"),
PayerEmail: "[email protected]",
Description: "Invoice callback test",
Created: "2020-01-13T02:32:49.827Z",
Expand Down Expand Up @@ -144,7 +148,7 @@ func TestInvoiceCallback_RetailOutlet(t *testing.T) {
MerchantName: "Xendit",
Amount: 2000000,
PaidAmount: 2000000,
PaidAt: "2020-01-14T02:32:50.912Z",
PaidAt: toPointerString("2020-01-14T02:32:50.912Z"),
PayerEmail: "[email protected]",
Description: "Invoice callback test",
Created: "2020-01-13T02:32:49.827Z",
Expand Down

0 comments on commit 3024ee5

Please sign in to comment.