Skip to content

faridyusof727/e-invoice-go-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

E-Invoice Go SDK

A Go SDK for interacting with the E-Invoice system. This SDK provides a simple and efficient way to authenticate and interact with the E-Invoice API.

Requirements

  • Go 1.22.5 or higher

Installation

go get github.com/faridyusof727/e-invoice-go-sdk

Features

  • Authentication client for E-Invoice system
  • Support for both sandbox and production environments
  • Easy configuration management
  • Intermediary login support
  • Document type client for retrieving available document types

Usage

Basic Setup

import (
    "github.com/faridyusof727/e-invoice-go-sdk/auth"
    "github.com/faridyusof727/e-invoice-go-sdk/config"
)

// Create client configuration
clientConfig := &config.Client{
    ID:     "your-client-id",
    Secret: "your-client-secret",
}

// Create service configuration
serviceConfig := &config.Service{
    Environment: config.EnvironmentSandbox, // or config.EnvironmentProduction for production
}

// Initialize auth client
authClient := auth.New(
    auth.WithClientConfig(clientConfig),
    auth.WithServiceConfig(serviceConfig),
)

Login as Intermediary

auth, err := authClient.LoginAsIntermediary(context.Background(), "your-tax-id")
if err != nil {
    // Handle error
}

// Use the access token
token := auth.AccessToken

Login as Tax Payer

auth, err := authClient.LoginAsTaxPayer(context.Background())
if err != nil {
    // Handle error
}

// Use the access token
token := auth.AccessToken

Retrieve All Document Types

import (
    "context"
    "github.com/faridyusof727/e-invoice-go-sdk/platform"
    "github.com/faridyusof727/e-invoice-go-sdk/auth"
    "github.com/faridyusof727/e-invoice-go-sdk/config"
)

// Assume you have already initialized serviceConfig and authClient as shown above

// Perform login to get an auth token
auth, err := authClient.LoginAsTaxPayer(context.Background())
if err != nil {
    // Handle error
}

// Create a DocumentType client
docTypeClient, err := platform.NewDocumentType(serviceConfig, auth)
if err != nil {
    // Handle error
}

// Retrieve all document types
docTypes, err := docTypeClient.AllDocumentTypes(context.Background())
if err != nil {
    // Handle error
}

// Use the list of document types
for _, docType := range docTypes {
    // Process each docType
}

Configuration

The SDK supports two environments:

  • Sandbox (for testing)
  • Production (for live usage)

Configure the environment using the config.Service struct:

serviceConfig := &config.Service{
    Environment: config.EnvironmentSandbox, // or config.EnvironmentProduction
}

Development

Running Tests

go test ./...

License

[License information to be added]

Contributing

[Contributing guidelines to be added]

About

LHDN's E-Invoice Unofficial SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages