Skip to content

Commit

Permalink
Merge pull request #82 from xendit/fix/issue-1
Browse files Browse the repository at this point in the history
  • Loading branch information
hecharles authored Dec 2, 2021
2 parents 0776657 + 2f047f7 commit 980c9f0
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ bin/

*.coverprofile
*.cov
*.vscode
122 changes: 80 additions & 42 deletions invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,47 @@ import "time"
// For more API details see https://xendit.github.io/apireference/?bash#invoices.
// For documentation of subpackage invoice, checkout https://pkg.go.dev/github.com/xendit/xendit-go/invoice
type Invoice struct {
ID string `json:"id"`
Status string `json:"status"`
ExternalID string `json:"external_id"`
UserID string `json:"user_id"`
PayerEmail string `json:"payer_email"`
Description string `json:"description"`
Amount float64 `json:"amount"`
MerchantName string `json:"merchant_name"`
MerchantProfilePictureURL string `json:"merchant_profile_picture_url"`
InvoiceURL string `json:"invoice_url"`
ExpiryDate *time.Time `json:"expiry_date"`
AvailableBanks []InvoiceBank `json:"available_banks,omitempty"`
AvailableEWallets []InvoiceEWallet `json:"available_ewallets,omitempty"`
AvailableRetailOutlets []InvoiceRetailOutlet `json:"available_retail_outlets,omitempty"`
ShouldExcludeCreditCard bool `json:"should_exclude_credit_card"`
ShouldSendEmail bool `json:"should_send_email"`
Created *time.Time `json:"created"`
Updated *time.Time `json:"updated"`
BankCode string `json:"bank_code,omitempty"`
PaidAmount float64 `json:"paid_amount,omitempty"`
AdjustedReceivedAmount float64 `json:"adjusted_received_amount,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 string `json:"initial_amount,omitempty"`
PaidAt *time.Time `json:"paid_at,omitempty"`
MidLabel string `json:"mid_label,omitempty"`
PaymentChannel string `json:"payment_channel,omitempty"`
PaymentMethod string `json:"payment_method,omitempty"`
PaymentDestination string `json:"payment_destination,omitempty"`
SuccessRedirectURL string `json:"success_redirect_url,omitempty"`
FailureRedirectURL string `json:"failure_redirect_url,omitempty"`
Items []InvoiceItem `json:"items,omitempty"`
FixedVA bool `json:"fixed_va,omitempty"`
ID string `json:"id"`
InvoiceURL string `json:"invoice_url"`
UserID string `json:"user_id,omitempty"`
ExternalID string `json:"external_id"`
Status string `json:"status"`
MerchantName string `json:"merchant_name"`
MerchantProfilePictureURL string `json:"merchant_profile_picture_url,omitempty"`
Amount float64 `json:"amount"`
Locale string `json:"locale,omitempty"`
Items []InvoiceItem `json:"items,omitempty"`
Fees []InvoiceFee `json:"fees,omitempty"`
PayerEmail string `json:"payer_email,omitempty"`
Description string `json:"description,omitempty"`
ExpiryDate *time.Time `json:"expiry_date"`
Customer InvoiceCustomer `json:"customer,omitempty"`
CustomerNotificationPreference InvoiceCustomerNotificationPreference `json:"customer_notification_preference,omitempty"`
AvailableBanks []InvoiceBank `json:"available_banks,omitempty"`
AvailableEWallets []InvoiceEWallet `json:"available_ewallets,omitempty"`
AvailableRetailOutlets []InvoiceRetailOutlet `json:"available_retail_outlets,omitempty"`
ReminderDate *time.Time `json:"reminder_date,omitempty"`
FixedVA bool `json:"fixed_va,omitempty"`
MidLabel string `json:"mid_label,omitempty"`
ShouldExcludeCreditCard bool `json:"should_exclude_credit_card,omitempty"`
ShouldAuthenticateCreditCard bool `json:"should_authenticate_credit_card,omitempty"`
ShouldSendEmail bool `json:"should_send_email"`
Created *time.Time `json:"created"`
Updated *time.Time `json:"updated"`
Currency string `json:"currency,omitempty"`
PaidAt *time.Time `json:"paid_at,omitempty"`
PaymentMethod string `json:"payment_method,omitempty"`
PaymentChannel string `json:"payment_channel,omitempty"`
PaymentDestination string `json:"payment_destination,omitempty"`
PaymentDetail InvoicePaymentDetail `json:"payment_details,omitempty"`
SuccessRedirectURL string `json:"success_redirect_url,omitempty"`
FailureRedirectURL string `json:"failure_redirect_url,omitempty"`
RecurringPaymentID string `json:"recurring_payment_id,omitempty"`
CreditCardChargeID string `json:"credit_card_charge_id,omitempty"`
AdjustedReceivedAmount float64 `json:"adjusted_received_amount,omitempty"`
//deprecated
BankCode string `json:"bank_code,omitempty"`
PaidAmount float64 `json:"paid_amount,omitempty"`
}

// InvoiceBank is data that contained in `Invoice` at AvailableBanks
Expand All @@ -61,15 +67,47 @@ type InvoiceEWallet struct {

// InvoiceRetailOutlet is data that contained in `Invoice` at AvailableRetailOutlets
type InvoiceRetailOutlet struct {
RetailOutletName string `json:"retail_outlet_name"`
PaymentCode string `json:"payment_code"`
TransferAmount float64 `json:"transfer_amount"`
MerchantName string `json:"merchant_name,omitempty"`
RetailOutletName string `json:"retail_outlet_name"`
//WILL BE DEPRECATED SOON
PaymentCode string `json:"payment_code,omitempty"`
//WILL BE DEPRECATED SOON
TransferAmount float64 `json:"transfer_amount,omitempty"`
MerchantName string `json:"merchant_name,omitempty"`
}

// InvoiceItem is data that contained in `Invoice` at Items
type InvoiceItem struct {
Name string `json:"name"`
Price float64 `json:"price"`
Quantity int `json:"quantity"`
Name string `json:"name" validate:"required"`
Price float64 `json:"price" validate:"required"`
Quantity int `json:"quantity" validate:"required"`
Category string `json:"category,omitempty"`
Url string `json:"url,omitempty"`
}

// InvoiceCustomer is data that contained in `Invoice` at Customer
type InvoiceCustomer struct {
GivenNames string `json:"given_names,omitempty"`
Email string `json:"email,omitempty"`
MobileNumber string `json:"mobile_number,omitempty"`
Address string `json:"address,omitempty"`
}

// InvoiceCustomerNotificationPreference is data that contained in `Invoice` at CustomerNotificationPreference
type InvoiceCustomerNotificationPreference struct {
InvoiceCreated []string `json:"invoice_created,omitempty"`
InvoiceReminder []string `json:"invoice_reminder,omitempty"`
InvoicePaid []string `json:"invoice_paid,omitempty"`
InvoiceExpired []string `json:"invoice_expired,omitempty"`
}

// InvoiceFee is data that contained in `Invoice` at Fees
type InvoiceFee struct {
Type string `json:"type" validate:"required"`
Value string `value:"value" validate:"required"`
}

// InvoiceFInvoicePaymentDetaile is data that contained in `Invoice` at PaymentDetail
type InvoicePaymentDetail struct {
Type string `json:"receipt_id,omitempty"`
Value string `value:"source,omitempty"`
}
6 changes: 3 additions & 3 deletions invoice/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ func TestCreate(t *testing.T) {
{
desc: "should report missing required fields",
data: &invoice.CreateParams{
ExternalID: "invoice-external-id",
Amount: 200000,
// ExternalID: "invoice-external-id",
Amount: 200000,
},
expectedRes: nil,
expectedErr: validator.APIValidatorErr(errors.New("Missing required fields: 'PayerEmail', 'Description'")),
expectedErr: validator.APIValidatorErr(errors.New("Missing required fields: 'ExternalID'")),
},
}

Expand Down
37 changes: 23 additions & 14 deletions invoice/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@ import (
"strconv"
"time"

"github.com/xendit/xendit-go"
"github.com/xendit/xendit-go/utils/urlvalues"
)

// CreateParams contains parameters for Create
type CreateParams struct {
ForUserID string `json:"-"`
ExternalID string `json:"external_id" validate:"required"`
PayerEmail string `json:"payer_email" validate:"required"`
Description string `json:"description" validate:"required"`
Amount float64 `json:"amount" validate:"required"`
ShouldSendEmail *bool `json:"should_send_email,omitempty"`
CallbackVirtualAccountID string `json:"callback_virtual_account_id,omitempty"`
InvoiceDuration int `json:"invoice_duration,omitempty"`
SuccessRedirectURL string `json:"success_redirect_url,omitempty"`
FailureRedirectURL string `json:"failure_redirect_url,omitempty"`
PaymentMethods []string `json:"payment_methods,omitempty"`
MidLabel string `json:"mid_label,omitempty"`
Currency string `json:"currency,omitempty"`
FixedVA *bool `json:"fixed_va,omitempty"`
ForUserID string `json:"-"`
ExternalID string `json:"external_id" validate:"required"`
Amount float64 `json:"amount" validate:"required"`
Description string `json:"description,omitempty"`
PayerEmail string `json:"payer_email,omitempty"`
ShouldSendEmail *bool `json:"should_send_email,omitempty"`
Customer xendit.InvoiceCustomer `json:"customer,omitempty"`
CustomerNotificationPreference xendit.InvoiceCustomerNotificationPreference `json:"customer_notification_preference,omitempty"`
InvoiceDuration int `json:"invoice_duration,omitempty"`
SuccessRedirectURL string `json:"success_redirect_url,omitempty"`
FailureRedirectURL string `json:"failure_redirect_url,omitempty"`
PaymentMethods []string `json:"payment_methods,omitempty"`
Currency string `json:"currency,omitempty"`
FixedVA *bool `json:"fixed_va,omitempty"`
CallbackVirtualAccountID string `json:"callback_virtual_account_id,omitempty"`
MidLabel string `json:"mid_label,omitempty"`
ReminderTimeUnit string `json:"reminder_time_unit,omitempty"`
ReminderTime int `json:"reminder_time,omitempty"`
Locale string `json:"locale,omitempty"`
Items []xendit.InvoiceItem `json:"items,omitempty"`
Fees []xendit.InvoiceFee `json:"fees,omitempty"`
ShouldAuthenticateCreditCard bool `json:"should_authenticate_credit_card,omitempty"`
}

// GetParams contains parameters for Get
Expand Down

0 comments on commit 980c9f0

Please sign in to comment.