manage

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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"`
	Item 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:"item"`
}

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)

	// return invoice given its invoice number
	GetInvoice(ctx context.Context, number string) (*invoice.Invoice, error)

	// generate new invoice
	GenerateInvoice(ctx context.Context, gir *GenerateInvoiceRequest) (*invoice.Invoice, error)

	// PayInvoice pays an invoice
	PayInvoice(ctx context.Context, pir *PayInvoiceRequest) (*invoice.Invoice, error)

	// ProcessInvoice ...
	ProcessInvoice(ctx context.Context, invoiceNumber string) (*invoice.Invoice, error)

	// FailInvoice make the invoice failed
	FailInvoice(ctx context.Context, fir *FailInvoiceRequest) (*invoice.Invoice, error)
}

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) 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) 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

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