nomod

package
v1.0.49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NomodBaseURL is the base URL for Nomod API
	NomodBaseURL = "https://api.nomod.com"

	// DefaultItemName is the default name for line items when no display name is available
	DefaultItemName = "Subscription"

	// DefaultInvoiceLabel is the default label for invoice reference
	DefaultInvoiceLabel = "Invoice"
)

Constants for Nomod integration

Variables

This section is empty.

Functions

This section is empty.

Types

type ChargeCustomer

type ChargeCustomer struct {
	ID           string `json:"id"`
	FirstName    string `json:"first_name"`
	LastName     string `json:"last_name"`
	BusinessName string `json:"business_name"`
	Email        string `json:"email"`
}

ChargeCustomer represents the customer in Nomod

type ChargeCustomerInfo

type ChargeCustomerInfo struct {
	FirstName   string `json:"first_name"`
	LastName    string `json:"last_name"`
	Email       string `json:"email"`
	PhoneNumber string `json:"phone_number"`
}

ChargeCustomerInfo represents customer information from the charge

type ChargeEvent

type ChargeEvent struct {
	Created string      `json:"created"`
	Type    string      `json:"type"`
	Message string      `json:"message"`
	User    *ChargeUser `json:"user"`
}

ChargeEvent represents an event in the charge history

type ChargeFeeBreakdown

type ChargeFeeBreakdown struct {
	Currency string          `json:"currency"`
	Amount   string          `json:"amount"`
	Fees     []ChargeFeeItem `json:"fees"`
}

ChargeFeeBreakdown represents fee breakdown

type ChargeFeeItem

type ChargeFeeItem struct {
	Currency    string   `json:"currency"`
	Amount      string   `json:"amount"`
	Description string   `json:"description"`
	Details     []string `json:"details"`
}

ChargeFeeItem represents individual fee item

type ChargeItem

type ChargeItem struct {
	Amount      string      `json:"amount"`
	Name        string      `json:"name"`
	TotalAmount string      `json:"total_amount"`
	Quantity    int         `json:"quantity"`
	Product     interface{} `json:"product"`
	SKU         interface{} `json:"sku"`
}

ChargeItem represents an item in the charge

type ChargeLink struct {
	ID          string `json:"id"`
	ReferenceID string `json:"reference_id"`
	Status      string `json:"status"`
}

ChargeLink represents payment link details (if payment was made via link)

type ChargeNetworkCost

type ChargeNetworkCost struct {
	Currency string `json:"currency"`
	Amount   string `json:"amount"`
}

ChargeNetworkCost represents network cost details

type ChargeResponse

type ChargeResponse struct {
	ID                   string                 `json:"id"`
	ReferenceID          int                    `json:"reference_id"`
	Created              string                 `json:"created"`
	Items                []ChargeItem           `json:"items"`
	Currency             string                 `json:"currency"`
	Discount             string                 `json:"discount"`
	ServiceFee           string                 `json:"service_fee"`
	Status               string                 `json:"status"` // paid, pending, failed, etc.
	Tip                  string                 `json:"tip"`
	Tax                  string                 `json:"tax"`
	Total                string                 `json:"total"`
	RefundTotal          string                 `json:"refund_total"`
	Note                 string                 `json:"note"`
	PaymentMethod        string                 `json:"payment_method"`
	DiscountPercentage   *int                   `json:"discount_percentage"`
	ServiceFeePercentage *string                `json:"service_fee_percentage"`
	TipPercentage        string                 `json:"tip_percentage"`
	User                 ChargeUser             `json:"user"`
	CustomFields         interface{}            `json:"custom_fields"`
	Refunds              []interface{}          `json:"refunds"`
	Events               []ChargeEvent          `json:"events"`
	SettlementCurrency   string                 `json:"settlement_currency"`
	Fee                  string                 `json:"fee"`
	FxFee                string                 `json:"fx_fee"`
	FeeTax               string                 `json:"fee_tax"`
	Net                  string                 `json:"net"`
	NetworkCost          ChargeNetworkCost      `json:"network_cost"`
	SuccessURL           string                 `json:"success_url"`
	FailureURL           *string                `json:"failure_url"`
	ShippingAddress      *ChargeShippingAddress `json:"shipping_address"`
	CustomerInfo         ChargeCustomerInfo     `json:"customer_info"`
	Link                 *ChargeLink            `json:"link,omitempty"`
	Source               string                 `json:"source"`
	IconURL              string                 `json:"icon_url"`
	FeeBreakdown         ChargeFeeBreakdown     `json:"fee_breakdown"`
	Customer             ChargeCustomer         `json:"customer"`
}

ChargeResponse represents Nomod charge details from GET /v1/charges/{id}

type ChargeShippingAddress

type ChargeShippingAddress struct {
}

ChargeShippingAddress represents shipping address (if any)

type ChargeUser

type ChargeUser struct {
	ID        string `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
}

ChargeUser represents the user who made the payment

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles Nomod API client setup and configuration

func (*Client) CreateCustomer

func (c *Client) CreateCustomer(ctx context.Context, req CreateCustomerRequest) (*CustomerResponse, error)

CreateCustomer creates a customer in Nomod

func (*Client) CreateInvoice

func (c *Client) CreateInvoice(ctx context.Context, req CreateInvoiceRequest) (*InvoiceResponse, error)

CreateInvoice creates an invoice in Nomod

func (c *Client) CreatePaymentLink(ctx context.Context, req CreatePaymentLinkRequest) (*PaymentLinkResponse, error)

CreatePaymentLink creates a payment link in Nomod

func (*Client) GetCharge

func (c *Client) GetCharge(ctx context.Context, chargeID string) (*ChargeResponse, error)

GetCharge retrieves charge details from Nomod API

func (*Client) GetConnection

func (c *Client) GetConnection(ctx context.Context) (*connection.Connection, error)

GetConnection retrieves the Nomod connection for the current context

func (*Client) GetDecryptedNomodConfig

func (c *Client) GetDecryptedNomodConfig(conn *connection.Connection) (*NomodConfig, error)

GetDecryptedNomodConfig decrypts and returns Nomod configuration

func (*Client) GetNomodConfig

func (c *Client) GetNomodConfig(ctx context.Context) (*NomodConfig, error)

GetNomodConfig retrieves and decrypts Nomod configuration for the current environment

func (*Client) HasNomodConnection

func (c *Client) HasNomodConnection(ctx context.Context) bool

HasNomodConnection checks if the tenant has a Nomod connection available

func (*Client) VerifyWebhookAuth

func (c *Client) VerifyWebhookAuth(ctx context.Context, providedAPIKey string) error

VerifyWebhookAuth verifies X-API-KEY header for webhooks

type CreateCustomerRequest

type CreateCustomerRequest struct {
	FirstName    string  `json:"first_name"`              // Required, non-empty, <= 150 chars
	LastName     *string `json:"last_name,omitempty"`     // Optional, <= 150 chars
	Email        string  `json:"email"`                   // Email format
	PhoneNumber  *string `json:"phone_number,omitempty"`  // Optional, <= 15 chars
	BusinessName *string `json:"business_name,omitempty"` // Optional, <= 50 chars
	JobTitle     *string `json:"job_title,omitempty"`     // Optional, <= 50 chars
	Country      *string `json:"country,omitempty"`       // Optional, country code, <= 2 chars
	Province     *string `json:"province,omitempty"`      // Optional, province UUID
	Street       *string `json:"street,omitempty"`        // Optional, <= 100 chars
	City         *string `json:"city,omitempty"`          // Optional, <= 100 chars
	ZipCode      *string `json:"zip_code,omitempty"`      // Optional, <= 16 chars
}

CreateCustomerRequest represents a request to create a Nomod customer

type CreateInvoiceRequest

type CreateInvoiceRequest struct {
	Currency                string        `json:"currency"`                            // Required, ISO 4217, <= 3 chars
	Items                   []LineItem    `json:"items"`                               // Required
	DiscountPercentage      *int          `json:"discount_percentage,omitempty"`       // Optional, 0-100, default 0
	Customer                string        `json:"customer"`                            // Required, customer UUID
	InvoiceNumber           *string       `json:"invoice_number,omitempty"`            // Optional, <= 30 chars
	Title                   *string       `json:"title,omitempty"`                     // Optional, <= 50 chars
	Note                    *string       `json:"note,omitempty"`                      // Optional, <= 280 chars
	ShippingAddressRequired *bool         `json:"shipping_address_required,omitempty"` // Optional, default false
	DueDate                 string        `json:"due_date"`                            // Required, date format
	StartsAt                *string       `json:"starts_at,omitempty"`                 // Optional, date format
	CustomFields            []CustomField `json:"custom_fields,omitempty"`             // Optional
	AllowTabby              *bool         `json:"allow_tabby,omitempty"`               // Optional, default true
	AllowTamara             *bool         `json:"allow_tamara,omitempty"`              // Optional, default true
	AllowServiceFee         *bool         `json:"allow_service_fee,omitempty"`         // Optional, default true
	SuccessURL              *string       `json:"success_url,omitempty"`               // Optional URI
	FailureURL              *string       `json:"failure_url,omitempty"`               // Optional URI
}

CreateInvoiceRequest represents a request to create a Nomod invoice

type CreatePaymentLinkReq

type CreatePaymentLinkReq struct {
	InvoiceID     string
	CustomerID    string
	Amount        decimal.Decimal
	Currency      string
	SuccessURL    string
	FailureURL    string
	Metadata      map[string]string
	PaymentID     string
	EnvironmentID string
}

CreatePaymentLinkRequest represents a FlexPrice request to create a Nomod payment link

type CreatePaymentLinkRequest

type CreatePaymentLinkRequest struct {
	Currency                string        `json:"currency"`                            // Required, ISO 4217, <= 3 chars
	Items                   []LineItem    `json:"items"`                               // Required
	Title                   *string       `json:"title,omitempty"`                     // Optional, <= 50 chars
	Note                    *string       `json:"note,omitempty"`                      // Optional, <= 280 chars
	DiscountPercentage      *int          `json:"discount_percentage,omitempty"`       // Optional, 0-100, default 0
	ShippingAddressRequired *bool         `json:"shipping_address_required,omitempty"` // Optional, default false
	AllowTip                *bool         `json:"allow_tip,omitempty"`                 // Optional, default false
	CustomFields            []CustomField `json:"custom_fields,omitempty"`             // Optional
	SuccessURL              *string       `json:"success_url,omitempty"`               // Optional URI
	FailureURL              *string       `json:"failure_url,omitempty"`               // Optional URI
	AllowTabby              *bool         `json:"allow_tabby,omitempty"`               // Optional, default true
	AllowTamara             *bool         `json:"allow_tamara,omitempty"`              // Optional, default true
	AllowServiceFee         *bool         `json:"allow_service_fee,omitempty"`         // Optional, default true
	PaymentExpiryLimit      *int          `json:"payment_expiry_limit,omitempty"`      // Optional, >= 1
	ExpiryDate              *string       `json:"expiry_date,omitempty"`               // Optional, date format
}

CreatePaymentLinkRequest represents a request to create a Nomod payment link

type CreatePaymentLinkResp

type CreatePaymentLinkResp struct {
	ID                 string          // Nomod payment link ID
	PaymentURL         string          // URL for the payment link
	Amount             decimal.Decimal // Amount in original currency
	Currency           string          // Currency code
	Status             string          // Payment link status
	ReferenceID        string          // Nomod reference ID
	IsNomodInvoiceLink bool            // Whether the payment link is a Nomod invoice link
}

CreatePaymentLinkResponse represents the response after creating a payment link

type CustomField

type CustomField struct {
	Name string `json:"name"`
}

CustomField represents a custom field

type CustomerResponse

type CustomerResponse struct {
	ID           string `json:"id"`
	Created      string `json:"created"`
	FirstName    string `json:"first_name"`
	LastName     string `json:"last_name"`
	BusinessName string `json:"business_name"`
	JobTitle     string `json:"job_title"`
	Province     int    `json:"province"`
	City         string `json:"city"`
	Street       string `json:"street"`
	ZipCode      string `json:"zip_code"`
	Country      string `json:"country"`
	Email        string `json:"email"`
	PhoneNumber  string `json:"phone_number"`
}

CustomerResponse represents a Nomod customer response

type CustomerService

type CustomerService struct {
	// contains filtered or unexported fields
}

CustomerService handles Nomod customer operations

func (*CustomerService) CreateCustomerInNomod

func (s *CustomerService) CreateCustomerInNomod(ctx context.Context, customerID string, customerService interfaces.CustomerService) error

CreateCustomerInNomod creates a customer in Nomod and updates our customer with Nomod ID

func (*CustomerService) EnsureCustomerSyncedToNomod

func (s *CustomerService) EnsureCustomerSyncedToNomod(ctx context.Context, customerID string, customerService interfaces.CustomerService) (*customer.Customer, error)

EnsureCustomerSyncedToNomod ensures a customer is synced to Nomod

func (*CustomerService) GetNomodCustomerID

func (s *CustomerService) GetNomodCustomerID(ctx context.Context, customerID string) (string, error)

GetNomodCustomerID retrieves the Nomod customer ID for a FlexPrice customer

func (*CustomerService) SyncCustomerToNomod

func (s *CustomerService) SyncCustomerToNomod(ctx context.Context, flexpriceCustomer *customer.Customer) (string, error)

SyncCustomerToNomod creates a customer in Nomod and stores the mapping

type InvoiceResponse

type InvoiceResponse struct {
	ID                   string        `json:"id"`
	ReferenceID          string        `json:"reference_id"`
	Created              string        `json:"created"`
	Title                string        `json:"title"`
	Code                 string        `json:"code"`
	URL                  string        `json:"url"`
	Amount               string        `json:"amount"`
	Currency             string        `json:"currency"`
	Status               string        `json:"status"` // paid, unpaid, overdue, cancelled, scheduled
	Discount             string        `json:"discount"`
	ServiceFee           *string       `json:"service_fee,omitempty"`
	Tax                  string        `json:"tax"`
	ShippingAddressReq   bool          `json:"shipping_address_required"`
	Items                []interface{} `json:"items"`
	Note                 string        `json:"note"`
	Expiry               string        `json:"expiry"`
	DiscountPercentage   *string       `json:"discount_percentage,omitempty"`
	ServiceFeePercentage *string       `json:"service_fee_percentage,omitempty"`
	TipPercentage        *string       `json:"tip_percentage,omitempty"`
	User                 interface{}   `json:"user"`
	Tip                  string        `json:"tip"`
	InvoiceNumber        string        `json:"invoice_number"`
	ServiceDate          string        `json:"service_date"`
	DueDate              string        `json:"due_date"`
	IntervalCount        int           `json:"interval_count"`
	StartsAt             string        `json:"starts_at"`
	EndsAt               string        `json:"ends_at"`
	DueDays              int           `json:"due_days"`
	CustomFields         []interface{} `json:"custom_fields"`
	Source               string        `json:"source"`
	SuccessURL           *string       `json:"success_url,omitempty"`
	FailureURL           *string       `json:"failure_url,omitempty"`
	PaymentCaptureSource *string       `json:"payment_capture_source,omitempty"`
	Files                []interface{} `json:"files"`
	Reminders            []interface{} `json:"reminders"`
	Events               []interface{} `json:"events"`
	Customer             interface{}   `json:"customer"`
}

InvoiceResponse represents a Nomod invoice response

type InvoiceSyncService

type InvoiceSyncService struct {
	// contains filtered or unexported fields
}

InvoiceSyncService handles synchronization of FlexPrice invoices with Nomod

func NewInvoiceSyncService

func NewInvoiceSyncService(
	client NomodClient,
	customerSvc *CustomerService,
	invoiceRepo invoice.Repository,
	entityIntegrationMappingRepo entityintegrationmapping.Repository,
	logger *logger.Logger,
) *InvoiceSyncService

NewInvoiceSyncService creates a new Nomod invoice sync service

func (*InvoiceSyncService) GetExistingNomodMapping

func (s *InvoiceSyncService) GetExistingNomodMapping(
	ctx context.Context,
	flexInvoiceID string,
) (*entityintegrationmapping.EntityIntegrationMapping, error)

GetExistingNomodMapping checks if invoice is already synced to Nomod

func (*InvoiceSyncService) GetFlexPriceInvoiceID

func (s *InvoiceSyncService) GetFlexPriceInvoiceID(ctx context.Context, nomodInvoiceID string) (string, error)

GetFlexPriceInvoiceID retrieves the FlexPrice invoice ID from a Nomod invoice ID (reverse lookup) This is used when processing external Nomod payments to find the corresponding FlexPrice invoice

func (*InvoiceSyncService) GetNomodInvoiceID

func (s *InvoiceSyncService) GetNomodInvoiceID(ctx context.Context, flexInvoiceID string) (string, error)

GetNomodInvoiceID retrieves the Nomod invoice ID from a FlexPrice invoice ID

func (*InvoiceSyncService) SyncInvoiceToNomod

SyncInvoiceToNomod syncs a FlexPrice invoice to Nomod This creates an invoice in Nomod with all line items in a single API call

type LineItem

type LineItem struct {
	Name     string `json:"name"`     // Item name
	Amount   string `json:"amount"`   // Decimal string
	Quantity int    `json:"quantity"` // Quantity
}

LineItem represents a line item in a payment link or invoice

type NomodClient

type NomodClient interface {
	GetNomodConfig(ctx context.Context) (*NomodConfig, error)
	GetDecryptedNomodConfig(conn *connection.Connection) (*NomodConfig, error)
	HasNomodConnection(ctx context.Context) bool
	GetConnection(ctx context.Context) (*connection.Connection, error)
	CreateCustomer(ctx context.Context, req CreateCustomerRequest) (*CustomerResponse, error)
	CreatePaymentLink(ctx context.Context, req CreatePaymentLinkRequest) (*PaymentLinkResponse, error)
	CreateInvoice(ctx context.Context, req CreateInvoiceRequest) (*InvoiceResponse, error)
	GetCharge(ctx context.Context, chargeID string) (*ChargeResponse, error)
	VerifyWebhookAuth(ctx context.Context, providedSecret string) error
}

NomodClient defines the interface for Nomod API operations

func NewClient

func NewClient(
	connectionRepo connection.Repository,
	encryptionService security.EncryptionService,
	logger *logger.Logger,
) NomodClient

NewClient creates a new Nomod client

type NomodConfig

type NomodConfig struct {
	APIKey        string // API Key for authentication
	WebhookSecret string // Webhook secret for basic auth (optional)
}

NomodConfig holds decrypted Nomod configuration

type NomodCustomerService

type NomodCustomerService interface {
	EnsureCustomerSyncedToNomod(ctx context.Context, customerID string, customerService interfaces.CustomerService) (*customer.Customer, error)
	SyncCustomerToNomod(ctx context.Context, flexpriceCustomer *customer.Customer) (string, error)
	GetNomodCustomerID(ctx context.Context, customerID string) (string, error)
}

NomodCustomerService defines the interface for Nomod customer operations

func NewCustomerService

func NewCustomerService(
	client NomodClient,
	customerRepo customer.Repository,
	entityIntegrationMappingRepo entityintegrationmapping.Repository,
	logger *logger.Logger,
) NomodCustomerService

NewCustomerService creates a new Nomod customer service

type NomodInvoiceStatus

type NomodInvoiceStatus string

NomodInvoiceStatus represents Nomod invoice status values

const (
	NomodInvoiceStatusPaid      NomodInvoiceStatus = "paid"
	NomodInvoiceStatusUnpaid    NomodInvoiceStatus = "unpaid"
	NomodInvoiceStatusOverdue   NomodInvoiceStatus = "overdue"
	NomodInvoiceStatusCancelled NomodInvoiceStatus = "cancelled"
	NomodInvoiceStatusScheduled NomodInvoiceStatus = "scheduled"
)

type NomodInvoiceSyncRequest

type NomodInvoiceSyncRequest struct {
	InvoiceID string // FlexPrice invoice ID to sync
}

NomodInvoiceSyncRequest represents a request to sync FlexPrice invoice to Nomod

type NomodInvoiceSyncResponse

type NomodInvoiceSyncResponse struct {
	NomodInvoiceID string          // Nomod invoice ID
	ReferenceID    string          // Nomod reference ID
	InvoiceNumber  string          // Invoice number in Nomod
	Code           string          // Nomod invoice code
	URL            string          // Payment URL for the invoice
	Status         string          // Invoice status (paid, unpaid, overdue, cancelled, scheduled)
	Amount         decimal.Decimal // Invoice total amount
	Currency       string          // Currency code
	CreatedAt      string          // Created timestamp
}

NomodInvoiceSyncResponse represents the response after syncing invoice to Nomod

type PaymentLinkResponse

type PaymentLinkResponse struct {
	ID                   string        `json:"id"`
	ReferenceID          string        `json:"reference_id"`
	Title                string        `json:"title"`
	URL                  string        `json:"url"`
	Amount               string        `json:"amount"`
	Currency             string        `json:"currency"`
	Status               string        `json:"status"`
	Discount             string        `json:"discount"`
	ServiceFee           string        `json:"service_fee"`
	AllowTip             bool          `json:"allow_tip"`
	ShippingAddressReq   bool          `json:"shipping_address_required"`
	Items                []interface{} `json:"items"`
	Tax                  string        `json:"tax"`
	Note                 string        `json:"note"`
	Taxes                []interface{} `json:"taxes"`
	DiscountPercentage   int           `json:"discount_percentage"`
	ServiceFeePercentage string        `json:"service_fee_percentage"`
	Tip                  string        `json:"tip"`
	TipPercentage        int           `json:"tip_percentage"`
	DueDate              *string       `json:"due_date,omitempty"`
	CustomFields         []interface{} `json:"custom_fields"`
	Source               string        `json:"source"`
	AllowTabby           bool          `json:"allow_tabby"`
	AllowTamara          bool          `json:"allow_tamara"`
	AllowServiceFee      bool          `json:"allow_service_fee"`
	PaymentExpiryLimit   *int          `json:"payment_expiry_limit,omitempty"`
	ExpiryDate           *string       `json:"expiry_date,omitempty"`
}

PaymentLinkResponse represents a Nomod payment link response

type PaymentService

type PaymentService struct {
	// contains filtered or unexported fields
}

PaymentService handles Nomod payment operations

func NewPaymentService

func NewPaymentService(
	client NomodClient,
	customerSvc NomodCustomerService,
	invoiceSyncSvc *InvoiceSyncService,
	logger *logger.Logger,
) *PaymentService

NewPaymentService creates a new Nomod payment service

func (s *PaymentService) CreatePaymentLink(ctx context.Context, req CreatePaymentLinkReq, customerService interfaces.CustomerService, invoiceService interfaces.InvoiceService) (*CreatePaymentLinkResp, error)

CreatePaymentLink creates a payment link in Nomod This creates a standalone payment link without requiring invoice sync

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL