Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add invoice paid event callback struct #124

Merged
merged 3 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package xendit

type EventInvoicePaid struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be renamed to InvoiceCallback to reflect what we define on the API Reference here? Thanks!

Could we also move this to the invoice folder over here since this logic is specific to Invoices?

Copy link
Author

@rjjatson rjjatson May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good !
i renamed it to InvoiceCallback and moved it to invoice package.

ID string `json:"id"`
Fees []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 InvoicePaymentDetail `json:"payment_details"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you declare this as a pointer since this field is optional? *InvoicePaymentDetail

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!
i also fixed it here 930783e

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"`
}
67 changes: 67 additions & 0 deletions event_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package xendit_test

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/xendit/xendit-go"
)

func TestEventInvoicePaid_EWallet(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help to rename this test to reflect the new callback struct, thank you!

Copy link
Author

@rjjatson rjjatson May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks ! i renamed it to match the InvoiceCallback
i also add test for bank, retail outlet, and expired cases.
copy and pasted the test payload from the docs

testPayload := `{
"id": "12345",
"fees": [
{
"type": "example fee",
"value": 100
}
],
"amount": 1000,
"status": "PAID",
"created": "2023-05-14T07:32:42.646Z",
"is_high": false,
"paid_at": "2023-05-14T07:35:14.000Z",
"updated": "2023-05-14T07:35:15.810Z",
"user_id": "example",
"currency": "IDR",
"payment_id": "qrpy_example",
"external_id": "example",
"paid_amount": 1000,
"merchant_name": "Example Merchant",
"payment_method": "QR_CODE",
"payment_channel": "QRIS",
"payment_details": {
"source": "Ovo",
"receipt_id": "example"
},
"payment_method_id": "pm-example-123"
}`
expectedPayload := xendit.EventInvoicePaid{
ID: "12345",
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",
Updated: "2023-05-14T07:35:15.810Z",
UserID: "example",
Currency: "IDR",
PaymentID: "qrpy_example",
ExternalID: "example",
PaidAmount: 1000,
MerchantName: "Example Merchant",
PaymentMethod: "QR_CODE",
PaymentChannel: "QRIS",
PaymentDetails: xendit.InvoicePaymentDetail{
Source: "Ovo",
ReceiptID: "example",
},
PaymentMethodID: "pm-example-123",
}
var actualPayload xendit.EventInvoicePaid
err := json.Unmarshal([]byte(testPayload), &actualPayload)
assert.NoError(t, err)
assert.Equal(t, expectedPayload, actualPayload)
}