manage

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateSubscriptionRequest added in v0.5.0

type CreateSubscriptionRequest struct {
	Name              string  `json:"name"`
	Description       string  `json:"description"`
	Amount            float64 `json:"amount"`
	UserID            string  `json:"user_id"`
	Currency          string  `json:"currency"`
	TotalReccurence   int     `json:"total_recurrence"`
	CardToken         string  `json:"card_token"`
	ChargeImmediately bool    `json:"charge_immediately"`
	Schedule          struct {
		Interval     int        `json:"interval"`
		IntervalUnit string     `json:"interval_unit"`
		StartAt      *time.Time `json:"start_at"`
	} `json:"schedule"`
}

CreateSubscriptionRequest contains data for creating subscription

func (CreateSubscriptionRequest) StartAt added in v0.5.0

func (csr CreateSubscriptionRequest) StartAt() *time.Time

StartAt return the first time for generating the invoice. If it is charged immediately, start at will be now, otherwise it will be the start at send by user

func (CreateSubscriptionRequest) ToSubscription added in v0.5.0

func (csr CreateSubscriptionRequest) ToSubscription() *subscription.Subscription

ToSubscription creates new subscription instance

func (*CreateSubscriptionRequest) UnmarshalJSON added in v0.5.0

func (csr *CreateSubscriptionRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON validates some data

type FailInvoiceRequest

type FailInvoiceRequest struct {
	InvoiceNumber string `json:"invoice_number"`
	TransactionID string `json:"transaction_id"`
	Reason        string `json:"reason"`
}

FailInvoiceRequest provide which invoice that is failed and its reason

type GenerateInvoiceRequest

type GenerateInvoiceRequest struct {
	Payment struct {
		PaymentType      payment.PaymentType       `json:"payment_type"`
		CreditCardDetail *invoice.CreditCardDetail `json:"credit_card,omitempty"`
	} `json:"payment"`
	Customer struct {
		Name        string `json:"name"`
		Email       string `json:"email"`
		PhoneNumber string `json:"phone_number"`
	} `json:"customer"`
	Items []struct {
		Name         string  `json:"name"`
		Category     string  `json:"category"`
		MerchantName string  `json:"merchant"`
		Description  string  `json:"description"`
		Qty          int     `json:"qty"`
		Price        float64 `json:"price"`
		Currency     string  `json:"currency"`
	} `json:"items"`
}

GenerateInvoiceRequest provide to generate new invoice

type Interface

type Interface interface {

	// return the payment methods available in payment service
	GetPaymentMethods(ctx context.Context, opts ...payment.Option) (*PaymentMethodList, error)
	// contains filtered or unexported methods
}

Interface payment management interface

type Manager

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

Manager handle business logic related to payment gateway

func NewManager

func NewManager(
	secret localconfig.PaymentSecret,
) *Manager

NewManager creates a new payment manager

func (*Manager) CreateSubscription added in v0.5.0

func (m *Manager) CreateSubscription(ctx context.Context, csr *CreateSubscriptionRequest) (*subscription.Subscription, error)

CreateSubscription creates new subscription

func (*Manager) FailInvoice

func (m *Manager) FailInvoice(ctx context.Context, fir *FailInvoiceRequest) (*invoice.Invoice, error)

FailInvoice fails an invoice if the payment is either failed or expired

func (*Manager) GenerateInvoice

func (m *Manager) GenerateInvoice(ctx context.Context, gir *GenerateInvoiceRequest) (*invoice.Invoice, error)

GenerateInvoice generates new invoice

func (*Manager) GetInvoice

func (m *Manager) GetInvoice(ctx context.Context, number string) (*invoice.Invoice, error)

GetInvoice return invoice given its invoice number

func (*Manager) GetPaymentMethods

func (m *Manager) GetPaymentMethods(ctx context.Context, opts ...payment.Option) (*PaymentMethodList, error)

GetPaymentMethods return the payment methods available in payment service

func (*Manager) MapMidtransTransactionStatusRepository

func (m *Manager) MapMidtransTransactionStatusRepository(repo datastore.MidtransTransactionStatusRepository) error

MapMidtransTransactionStatusRepository mapping the midtrans transaction status repository

func (*Manager) MustInvoiceRepository

func (m *Manager) MustInvoiceRepository(repo datastore.InvoiceRepository)

MustInvoiceRepository mandatory mapping the invoice repository

func (*Manager) MustMidtransTransactionStatusRepository

func (m *Manager) MustMidtransTransactionStatusRepository(repo datastore.MidtransTransactionStatusRepository)

MustMidtransTransactionStatusRepository mandatory mapping the midtrans transaction status repo interface

func (*Manager) MustPaymentConfigReader

func (m *Manager) MustPaymentConfigReader(repo datastore.PaymentConfigReader)

MustPaymentConfigReader mandatory mapping for payment config repository

func (*Manager) MustSubscriptionRepository added in v0.5.0

func (m *Manager) MustSubscriptionRepository(repo datastore.SubscriptionRepository)

MustSubscriptionRepository mandatory mapping the subscription repository

func (*Manager) PauseSubscription added in v0.5.0

func (m *Manager) PauseSubscription(ctx context.Context, subsNumber string) (*subscription.Subscription, error)

PauseSubscription pause active subscription

func (*Manager) PayInvoice

func (m *Manager) PayInvoice(ctx context.Context, pir *PayInvoiceRequest) (*invoice.Invoice, error)

PayInvoice pays an invoice. Invoice can only be paid if it is in right state

func (*Manager) ProcessDANACallback

func (m *Manager) ProcessDANACallback(ctx context.Context, dps *xendit.DANAPaymentStatus) error

ProcessDANACallback process dana payment notification from xendit

func (*Manager) ProcessInvoice

func (m *Manager) ProcessInvoice(ctx context.Context, invoiceNumber string) (*invoice.Invoice, error)

ProcessInvoice used if payment is initiated from user's end. It's either because they are using VA or any payment methods that requires payment action from the user after they choose a payment method/see payment instruction

func (*Manager) ProcessLinkAjaCallback

func (m *Manager) ProcessLinkAjaCallback(ctx context.Context, lps *xendit.LinkAjaPaymentStatus) error

ProcessLinkAjaCallback process linkaja payment notification from xendit

func (*Manager) ProcessMidtransCallback

func (m *Manager) ProcessMidtransCallback(ctx context.Context, mr midgo.Response) error

ProcessMidtransCallback takes care of notification sent by midtrans. This checks the validity of the sign key and the similarity between the notification and transaction satus.

func (*Manager) ProcessOVOCallback

func (m *Manager) ProcessOVOCallback(ctx context.Context, ops *xendit.OVOPaymentStatus) error

ProcessOVOCallback process ovo payment notification from xendit

func (*Manager) ProcessXenditInvoicesCallback

func (m *Manager) ProcessXenditInvoicesCallback(ctx context.Context, ips *xendit.InvoicePaymentStatus) error

ProcessXenditInvoicesCallback process xendit invoice payment notification from xendit

func (*Manager) ResumeSubscription added in v0.5.0

func (m *Manager) ResumeSubscription(ctx context.Context, subsNumber string) (*subscription.Subscription, error)

ResumeSubscription resume paused subscription

func (*Manager) StopSubscription added in v0.5.0

func (m *Manager) StopSubscription(ctx context.Context, subsNumber string) (*subscription.Subscription, error)

StopSubscription stop subscription

type MidtransProcessor

type MidtransProcessor interface {
	ProcessMidtransCallback(ctx context.Context, mr mgo.Response) error
}

MidtransProcessor callback handler for midtrans

type PayInvoiceRequest

type PayInvoiceRequest struct {
	InvoiceNumber string `json:"invoice_number"`
	TransactionID string `json:"transaction_id"`
}

PayInvoiceRequest provide information which invoice to pay and by using what transactionID

type Payment

type Payment interface {
	Interface
	XenditProcessor
	MidtransProcessor
}

Payment combines all interface used for payment manager

type PaymentMethodList

type PaymentMethodList struct {
	CardPayment     *config.CardPayment     `json:"card_payment"`
	BankTransfers   []config.NonCardPayment `json:"bank_transfers"`
	EWallets        []config.NonCardPayment `json:"ewallets"`
	CStores         []config.NonCardPayment `json:"cstores"`
	CardlessCredits []config.NonCardPayment `json:"cardless_credits"`
}

PaymentMethodList is the payment method list showed to the user

type XenditProcessor

type XenditProcessor interface {
	ProcessDANACallback(ctx context.Context, dps *xendit.DANAPaymentStatus) error
	ProcessLinkAjaCallback(ctx context.Context, lps *xendit.LinkAjaPaymentStatus) error
	ProcessOVOCallback(ctx context.Context, ops *xendit.OVOPaymentStatus) error
	ProcessXenditInvoicesCallback(ctx context.Context, ips *xendit.InvoicePaymentStatus) error
}

XenditProcessor callback handler for xendit

Jump to

Keyboard shortcuts

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