data

package
v1.99.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 36 Imported by: 0

README

Data

Documentation

Index

Constants

View Source
const (
	DefaultPageSize           int32 = 100
	BackgroundProcessPageSize int32 = 1000
)
View Source
const (
	TypeSubscribed             NotificationType = "SUBSCRIBED"
	TypeDidChangeRenewalPref   NotificationType = "DID_CHANGE_RENEWAL_PREF"
	TypeDidChangeRenewalStatus NotificationType = "DID_CHANGE_RENEWAL_STATUS"
	TypeOfferRedeemed          NotificationType = "OFFER_REDEEMED"
	TypeDidRenew               NotificationType = "DID_RENEW"
	TypeExpired                NotificationType = "EXPIRED"
	TypeDidFailToRenew         NotificationType = "DID_FAIL_TO_RENEW"
	TypeGracePeriodExpired     NotificationType = "GRACE_PERIOD_EXPIRED"
	TypePriceIncrease          NotificationType = "PRICE_INCREASE"
	TypeRefund                 NotificationType = "REFUND"
	TypeRefundDeclined         NotificationType = "REFUND_DECLINED"
	TypeConsumptionRequest     NotificationType = "CONSUMPTION_REQUEST"
	TypeRenewalExtended        NotificationType = "RENEWAL_EXTENDED"
	TypeRevoke                 NotificationType = "REVOKE"
	TypeTest                   NotificationType = "TEST"
	TypeRenewalExtension       NotificationType = "RENEWAL_EXTENSION"
	TypeRefundReversed         NotificationType = "REFUND_REVERSED"

	//nolint:gosec // external purchase token is notification type and not some credential
	TypeExternalPurchaseToken NotificationType = "EXTERNAL_PURCHASE_TOKEN"
	TypeOneTimeCharge         NotificationType = "ONE_TIME_CHARGE"

	SubtypeInitialBuy        NotificationSubtype = "INITIAL_BUY"
	SubtypeResubscribe       NotificationSubtype = "RESUBSCRIBE"
	SubtypeDowngrade         NotificationSubtype = "DOWNGRADE"
	SubtypeUpgrade           NotificationSubtype = "UPGRADE"
	SubtypeAutoRenewEnabled  NotificationSubtype = "AUTO_RENEW_ENABLED"
	SubtypeAutoRenewDisabled NotificationSubtype = "AUTO_RENEW_DISABLED"
	SubtypeVoluntary         NotificationSubtype = "VOLUNTARY"
	SubtypeBillingRetry      NotificationSubtype = "BILLING_RETRY"
	SubtypePriceIncrease     NotificationSubtype = "PRICE_INCREASE"
	SubtypeGracePeriod       NotificationSubtype = "GRACE_PERIOD"
	SubtypePending           NotificationSubtype = "PENDING"
	SubtypeAccepted          NotificationSubtype = "ACCEPTED"
	SubtypeBillingRecovery   NotificationSubtype = "BILLING_RECOVERY"
	SubtypeProductNotForSale NotificationSubtype = "PRODUCT_NOT_FOR_SALE"
	SubtypeSummary           NotificationSubtype = "SUMMARY"
	SubtypeFailure           NotificationSubtype = "FAILURE"
	SubtypeUnreported        NotificationSubtype = "UNREPORTED"

	UnintendedPurchase      ConsumptionRequestReason = "UNINTENDED_PURCHASE"
	FulfillmentIssue        ConsumptionRequestReason = "FULFILLMENT_ISSUE"
	UnsatisfiedWithPurchase ConsumptionRequestReason = "UNSATISFIED_WITH_PURCHASE"
	Legal                   ConsumptionRequestReason = "LEGAL"
	Other                   ConsumptionRequestReason = "OTHER"

	Sandbox    Environment = "Sandbox"
	Production Environment = "Production"

	OwnershipFamilyShared OwnershipType = "FAMILY_SHARED"
	OwnershipPurchased    OwnershipType = "PURCHASED"

	DiscountFreeTrial  OfferDiscountType = "FREE_TRIAL"
	DiscountPayAsYouGo OfferDiscountType = "PAY_AS_YOU_GO"
	DiscountPayUpFront OfferDiscountType = "PAY_UP_FRONT"

	ProductAutoRenewable ProductType = "Auto-Renewable Subscription"
	ProductNonRenewable  ProductType = "Non-Renewing Subscription"
	ProductNonConsumable ProductType = "Non-Consumable"
	ProductConsumable    ProductType = "Consumable"
)
View Source
const (
	TtpBaseURLProduction = "https://api.tiptoppay.kz"
	TtpDefaultTimeout    = 30 * time.Second
)

Variables

ProviderSet is data providers.

Functions

func NewNatsClient

func NewNatsClient(conf *conf.Bootstrap) (*nats.Conn, func(), error)

NewNatsClient .

func ParseAppleSignedBody

func ParseAppleSignedBody(signedBody string) (*jwt.Token, error)

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID adds idempotency key to context for TTP API calls.

Types

type BundleDto

type BundleDto struct {
	ItemID int64
	Amount float64
}

type ConsumptionRequestReason

type ConsumptionRequestReason string

type Data

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

Data .

func NewData

func NewData(bc *conf.Bootstrap, c *u_config.Config, logger log.Logger) (*Data, func(), error)

NewData .

type Environment

type Environment string

type InvoiceDto

type InvoiceDto struct {
	UserID         int64
	TenantID       int64
	AppID          string
	ProductID      int64
	Amount         int64
	Price          decimal.Decimal
	Status         enum.InvoiceStatus
	SubscriptionID int64

	IsRevoked           *bool
	RevokedAt           *time.Time
	PaidAt              *time.Time
	PaidTill            *time.Time
	IsRevokedProcessed  *bool
	IsPaidAtProcessed   *bool
	IsPaidTillProcessed *bool
	RecurrentProfileID  *int64

	AppleStoreTransactionID *string
	OneVisionTransactionID  *string
	TtpTransactionID        *string
	TtpSubscriptionID       *string
	IsTrial                 bool
}

type InvoiceFilter

type InvoiceFilter struct {
	TenantID       int64
	UserID         int64
	ProductID      int64
	Status         enum.InvoiceStatus
	Paid           bool
	PaidProcesses  *bool
	IsRevoked      *bool
	IsRevokedProc  *bool
	PaidTillProc   *bool
	SubscriptionID int64
	PaidTill       *time.Time
}

type InvoicesRepo

type InvoicesRepo interface {
	CreateInvoice(ctx context.Context, dto InvoiceDto) (*ent.Invoice, error)
	UpdateInvoice(ctx context.Context, invoiceData *ent.Invoice, dto InvoiceDto) (*ent.Invoice, error)
	DeleteInvoice(ctx context.Context, invoiceID int64) error
	GetInvoice(ctx context.Context, actorID, tenantID int64, appID string, invoiceID int64) (*ent.Invoice, error)
	CountInvoices(ctx context.Context, filter InvoiceFilter) (int32, error)
	ListInvoices(
		ctx context.Context, filter InvoiceFilter, paginate *utils_v1.PaginateRequest,
	) ([]*ent.Invoice, error)
	GetInvoicesToExpire(ctx context.Context, paidTill *time.Time) ([]*ent.Invoice, error)
	GetInvoicesToRevoke(ctx context.Context, paidTill *time.Time) ([]*ent.Invoice, error)
	GetInvoiceByID(ctx context.Context, id int64) (*ent.Invoice, error)
	FindByExternalTransactionID(ctx context.Context, txID string) (*ent.Invoice, error)
	FindByTtpSubscriptionID(ctx context.Context, subscriptionID string) (*ent.Invoice, error)
	GetLatestPaidInvoiceBySubscription(ctx context.Context, subscriptionID int64) (*ent.Invoice, error)
}

func NewInvoicesRepo

func NewInvoicesRepo(d *Data) InvoicesRepo

type ItemDto

type ItemDto struct {
	Name        string
	Description string
	TopicName   *string
}

type ItemsRepo

type ItemsRepo interface {
	CreateItem(ctx context.Context, item ItemDto) (*ent.Item, error)
	UpdateItem(ctx context.Context, itemID int64, item ItemDto) (*ent.Item, error)
	DeleteItem(ctx context.Context, itemID int64) error
	GetItem(ctx context.Context, itemID int64) (*ent.Item, error)
	GetItems(ctx context.Context, itemIDs []int64) ([]*ent.Item, error)
	CountItems(ctx context.Context) (int32, error)
	ListItems(ctx context.Context, paginate *utils_v1.PaginateRequest) ([]*ent.Item, error)
}

func NewItemsRepo

func NewItemsRepo(d *Data) ItemsRepo

type JWSTransaction

type JWSTransaction struct {
	AppAccountToken             string            `json:"appAccountToken,omitempty"`
	BundleID                    string            `json:"bundleID,omitempty"`
	Currency                    string            `json:"currency,omitempty"`
	Environment                 Environment       `json:"environment,omitempty"`
	ExpiresDate                 int64             `json:"expiresDate,omitempty"`
	InAppOwnershipType          OwnershipType     `json:"inAppOwnershipType,omitempty"`
	OfferDiscountType           OfferDiscountType `json:"offerDiscountType,omitempty"`
	OfferIdentifier             string            `json:"offerIdentifier,omitempty"`
	OfferType                   int64             `json:"offerType,omitempty"`
	OriginalPurchaseDate        int64             `json:"originalPurchaseDate,omitempty"`
	OriginalTransactionID       string            `json:"originalTransactionID,omitempty"`
	Price                       int64             `json:"price,omitempty"` // holds price in milliunits
	ProductID                   string            `json:"productID,omitempty"`
	PurchaseDate                int64             `json:"purchaseDate,omitempty"`
	Quantity                    int64             `json:"quantity,omitempty"`
	RevocationDate              int64             `json:"revocationDate,omitempty"`
	RevocationReason            int64             `json:"revocationReason,omitempty"`
	SignedDate                  int64             `json:"signedDate,omitempty"`
	StoreFront                  string            `json:"storeFront,omitempty"`
	StoreFrontID                string            `json:"storeFrontID,omitempty"`
	SubscriptionGroupIdentifier string            `json:"subscriptionGroupIdentifier,omitempty"`
	TransactionID               string            `json:"transactionID,omitempty"`
	TransactionReason           string            `json:"transactionReason,omitempty"`
	Type                        ProductType       `json:"type,omitempty"`
	WebOrderLineItemID          string            `json:"webOrderLineItemID,omitempty"`
}

type NotificationSubtype

type NotificationSubtype string

type NotificationType

type NotificationType string

type OfferDiscountType

type OfferDiscountType string

type OwnershipType

type OwnershipType string

type Payload

type Payload struct {
	NotificationType NotificationType    `json:"notificationType,omitempty"`
	Subtype          NotificationSubtype `json:"subtype,omitempty"`
	Data             struct {
		AppAppleID               int64       `json:"appAppleID,omitempty"`
		BundleID                 string      `json:"bundleID,omitempty"`
		BundleVersion            string      `json:"bundleVersion,omitempty"`
		ConsumptionRequestReason string      `json:"consumptionRequestReason,omitempty"`
		Environment              Environment `json:"environment,omitempty"`
		SignedRenewalInfo        string      `json:"signedRenewalInfo,omitempty"`
		SignedTransactionInfo    string      `json:"signedTransactionInfo,omitempty"`
		Status                   int64       `json:"status,omitempty"`
	} `json:"data"`
	Summary struct {
		RequestIdentifier      string      `json:"requestIdentifier,omitempty"`
		Environment            Environment `json:"environment,omitempty"`
		AppAppleID             int64       `json:"appAppleID,omitempty"`
		BundleID               string      `json:"bundleID,omitempty"`
		ProductID              string      `json:"productID,omitempty"`
		StoreFrontCountryCodes []string    `json:"storeFrontCountryCodes,omitempty"`
		FailedCount            int64       `json:"failedCount,omitempty"`
		SucceededCount         int64       `json:"succeededCount,omitempty"`
	} `json:"summary"`
	ExternalPurchaseToken struct {
		ExternalPurchaseID string `json:"externalPurchaseID,omitempty"`
		TokenCreationDate  int64  `json:"tokenCreationDate,omitempty"`
		AppAppleID         int64  `json:"appAppleID,omitempty"`
		BundleID           string `json:"bundleID,omitempty"`
	} `json:"externalPurchaseToken"`
	Version          string `json:"version,omitempty"`
	SignedDate       int64  `json:"signedDate,omitempty"`
	NotificationUUID string `json:"notificationUUID,omitempty"`
}

type PaymentClient

type PaymentClient interface {
	Charge(ctx context.Context, req TtpChargeRequest) (*TtpResponse, error)
	Post3ds(ctx context.Context, req TtpPost3dsRequest) (*TtpResponse, error)
	TokenCharge(ctx context.Context, req TtpTokenChargeRequest) (*TtpResponse, error)
	CreateSubscription(ctx context.Context, req TtpRecurrentCreateRequest) (*TtpSubscriptionResponse, error)
	CancelSubscription(ctx context.Context, subscriptionId string) (*TtpSubscriptionResponse, error)
	Refund(ctx context.Context, req TtpRefundRequest) (*TtpResponse, error)
	GetTransaction(ctx context.Context, transactionId int64) (*TtpResponse, error)
}

type PaymentProfileDto

type PaymentProfileDto struct {
	UserID         int64
	PanMasked      string
	Holder         string
	Email          *string
	Phone          *string
	UserToken      string
	RecurrentToken *string
}

type PaymentProfileRepo

type PaymentProfileRepo interface {
	CreateProfile(ctx context.Context, dto PaymentProfileDto) (*ent.PaymentProfile, error)
	GetProfileByUserID(ctx context.Context, userID int64) (*ent.PaymentProfile, error)
	UpdateProfile(ctx context.Context, profileID int64, dto PaymentProfileDto) error
}

func NewPaymentProfileRepo

func NewPaymentProfileRepo(d *Data) PaymentProfileRepo

type ProductDto

type ProductDto struct {
	AppID         string
	Name          string
	Description   string
	Price         decimal.Decimal
	Currency      string
	IsActive      bool
	IsLimited     bool
	LimitedTill   *time.Time
	Left          int64
	IsUnique      bool
	UniqueLimit   int64
	IsExpiring    bool
	ExpiringTime  *time.Time
	Bundles       []BundleDto
	PaymentModel  *enum.PaymentModel
	ProductPeriod *enum.ProductPeriod
}

type ProductRepo

type ProductRepo interface {
	CreateProduct(ctx context.Context, product ProductDto) (*ent.Product, error)
	UpdateProduct(ctx context.Context, productEnt *ent.Product, product ProductDto) (*ent.Product, error)
	DeleteProduct(ctx context.Context, productID int64) error
	GetProduct(ctx context.Context, productID int64) (*ent.Product, error)
	ListProducts(ctx context.Context, appID string, paginate *utils_v1.PaginateRequest) ([]*ent.Product, error)
	CountProducts(ctx context.Context, appID string) (int32, error)
}

func NewProductsRepo

func NewProductsRepo(d *Data) ProductRepo

type ProductReservationDto

type ProductReservationDto struct {
	UserID              int64
	InvoiceID           int64
	ProductID           int64
	ReservationQuantity int64
	Status              enum.ReservationStatus

	ExpirationTime *time.Time
}

type ProductReservationRepo

type ProductReservationRepo interface {
	CreateReservation(ctx context.Context, reservationDto ProductReservationDto) (*ent.ProductReservation, error)
	GetReservation(ctx context.Context, id int64) (*ent.ProductReservation, error)
	UpdateReservationStatusByInvoiceID(ctx context.Context, invoiceID int64, status enum.ReservationStatus) error
	CancelReservationByInvoiceID(ctx context.Context, invoiceID int64) error
	ProcessExpiredReservations(ctx context.Context) error
}

func NewProductReservationRepo

func NewProductReservationRepo(d *Data) ProductReservationRepo

NewProductReservationRepo creates a new repository instance.

type ProductType

type ProductType string

type RenewalInfo

type RenewalInfo struct {
	AutoRenewProductID          string
	AutoRenewStatus             int64
	Currency                    string
	EligibleWinBackOfferIDs     []string
	Environment                 Environment
	ExpirationIntent            int64
	GracePeriodExpiresDate      int64
	IsInBillingRetryPeriod      bool
	OfferDiscountType           OfferDiscountType
	OfferIdentifier             string
	OfferType                   int64
	OriginalTransactionID       string
	PriceIncreaseStatus         int64
	ProductID                   string
	RecentSubscriptionStartDate int64
	RenewalDate                 int64
	RenewalPrice                int64 // holds price in milliunits
	SignedDate                  int64
}

type SubscriptionDto

type SubscriptionDto struct {
	UserID    int64
	TenantID  int64
	AppID     string
	ProductID int64
}

type SubscriptionsRepo

type SubscriptionsRepo interface {
	CreateSubscription(
		ctx context.Context, actorID, tenantID int64, appID string, dto SubscriptionDto,
	) (*ent.Subscriptions, error)
	GetSubscription(
		ctx context.Context, actorID, tenantID int64, appID string, subscriptionID int64, withInvoices bool,
	) (*ent.Subscriptions, error)
	GetSubscriptionByOriginalAppleTransactionID(
		ctx context.Context, originalTransactionID string, withInvoices bool,
	) (*ent.Subscriptions, error)
	RevokeActiveSubscription(
		ctx context.Context, subscriptionID int64, revokedAt time.Time,
	) error
	DeleteSubscription(ctx context.Context, actorID, subscriptionID int64) error
	CountSubscriptions(ctx context.Context, actorID int64) (int32, error)
	ListSubscriptions(
		ctx context.Context, actorID int64, withInvoices bool, paginate *utils_v1.PaginateRequest,
	) ([]*ent.Subscriptions, error)
	GetSubscriptionsByUser(
		ctx context.Context, userID, tenantID int64, appID string,
	) ([]*ent.Subscriptions, error)
}

func NewSubscriptionsRepo

func NewSubscriptionsRepo(d *Data) SubscriptionsRepo

type TtpChargeRequest

type TtpChargeRequest struct {
	Amount               float64 `json:"Amount"`
	Currency             string  `json:"Currency"`
	CardCryptogramPacket string  `json:"CardCryptogramPacket"`
	IpAddress            string  `json:"IpAddress"`
	Name                 string  `json:"Name,omitempty"`
	InvoiceId            string  `json:"InvoiceId,omitempty"`
	Description          string  `json:"Description,omitempty"`
	AccountId            string  `json:"AccountId,omitempty"`
	Email                string  `json:"Email,omitempty"`
	JsonData             any     `json:"JsonData,omitempty"`
}

type TtpClient

type TtpClient struct {
	SuccessURL string
	FailureURL string
	// contains filtered or unexported fields
}

func NewTtpClient

func NewTtpClient(cfg *config.Config, logger log.Logger) (*TtpClient, error)

func (*TtpClient) CancelSubscription

func (c *TtpClient) CancelSubscription(ctx context.Context, subscriptionId string) (*TtpSubscriptionResponse, error)

func (*TtpClient) Charge

func (c *TtpClient) Charge(ctx context.Context, req TtpChargeRequest) (*TtpResponse, error)

func (*TtpClient) CreateSubscription

func (*TtpClient) GetTransaction

func (c *TtpClient) GetTransaction(ctx context.Context, transactionId int64) (*TtpResponse, error)

func (*TtpClient) Post3ds

func (c *TtpClient) Post3ds(ctx context.Context, req TtpPost3dsRequest) (*TtpResponse, error)

func (*TtpClient) Refund

func (c *TtpClient) Refund(ctx context.Context, req TtpRefundRequest) (*TtpResponse, error)

func (*TtpClient) TokenCharge

func (c *TtpClient) TokenCharge(ctx context.Context, req TtpTokenChargeRequest) (*TtpResponse, error)

type TtpPost3dsRequest

type TtpPost3dsRequest struct {
	TransactionId int64  `json:"TransactionId"`
	PaRes         string `json:"PaRes"`
}

type TtpRecurrentCreateRequest

type TtpRecurrentCreateRequest struct {
	AccountId   string  `json:"AccountId"`
	Amount      float64 `json:"Amount"`
	Currency    string  `json:"Currency"`
	Token       string  `json:"Token"`
	Period      int     `json:"Period"`
	Interval    string  `json:"Interval"`
	StartDate   string  `json:"StartDate"`
	Description string  `json:"Description,omitempty"`
	MaxPeriods  int     `json:"MaxPeriods,omitempty"`
}

type TtpRefundRequest

type TtpRefundRequest struct {
	TransactionId int64   `json:"TransactionId"`
	Amount        float64 `json:"Amount"`
}

type TtpResponse

type TtpResponse struct {
	Success bool                `json:"Success"`
	Message string              `json:"Message"`
	Model   TtpTransactionModel `json:"Model"`
}

type TtpSubscriptionModel

type TtpSubscriptionModel struct {
	SubscriptionId  string  `json:"SubscriptionId"`
	AccountId       string  `json:"AccountId"`
	Status          string  `json:"Status"`
	Amount          float64 `json:"Amount"`
	Currency        string  `json:"Currency"`
	Period          int     `json:"Period"`
	Interval        string  `json:"Interval"`
	NextPaymentDate string  `json:"NextPaymentDate"`
}

type TtpSubscriptionResponse

type TtpSubscriptionResponse struct {
	Success bool                 `json:"Success"`
	Message string               `json:"Message"`
	Model   TtpSubscriptionModel `json:"Model"`
}

type TtpTokenChargeRequest

type TtpTokenChargeRequest struct {
	Amount      float64 `json:"Amount"`
	Currency    string  `json:"Currency"`
	Token       string  `json:"Token"`
	AccountId   string  `json:"AccountId"`
	InvoiceId   string  `json:"InvoiceId,omitempty"`
	Description string  `json:"Description,omitempty"`
	IpAddress   string  `json:"IpAddress,omitempty"`
}

type TtpTransactionModel

type TtpTransactionModel struct {
	TransactionId int64   `json:"TransactionId"`
	Amount        float64 `json:"Amount"`
	Currency      string  `json:"Currency"`
	Status        string  `json:"Status"`
	StatusCode    int     `json:"StatusCode"`
	ReasonCode    int     `json:"ReasonCode"`
	Token         string  `json:"Token"`
	AccountId     string  `json:"AccountId"`
	InvoiceId     string  `json:"InvoiceId"`
	CardFirstSix  string  `json:"CardFirstSix"`
	CardLastFour  string  `json:"CardLastFour"`
	CardExpDate   string  `json:"CardExpDate"`
	CardType      string  `json:"CardType"`
	AuthCode      string  `json:"AuthCode"`
	Rrn           string  `json:"Rrn"`
	TestMode      bool    `json:"TestMode"`
	// 3DS fields
	PaReq  string `json:"PaReq,omitempty"`
	AcsUrl string `json:"AcsUrl,omitempty"`
}

Jump to

Keyboard shortcuts

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