config

package
v0.2.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: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	PaymentType  payment.PaymentType `yaml:"payment_type" json:"payment_type"`
	IconURLs     []string            `yaml:"icon_urls" json:"icon_urls"`
	Installments []Installment       `yaml:"installments" json:"installments"`
}

Card represent the credit card payment config retrieved from the yaml config file

func (Card) GetInstallment

func (cfg Card) GetInstallment(bank payment.Bank, aType payment.InstallmentType) (*Installment, error)

GetInstallment returns an installment information for a given bank and its type

type CardPayment

type CardPayment struct {
	Card
	// contains filtered or unexported fields
}

CardPayment represent credit card based payment method. This struct might have information about the value of a product will be paid by using cards.

func NewCardPayment

func NewCardPayment(cfg Card, value *payment.Money) *CardPayment

NewCardPayment creates a new CardPayment. if value is provided, each installment within this payment can calculate its own admin/installment fee in money notation. Otherwise, it just returns the percentage and/or the value of the fee.

type Fee

type Fee struct {
	PercentageVal float64 `yaml:"val_percentage"`
	CurrencyVal   float64 `yaml:"val_currency"`
	Currency      string  `yaml:"currency" json:"currency"`
}

Fee stores fee information in percentage / in currenc value

func (Fee) Estimate

func (f Fee) Estimate(val float64) float64

Estimate estimates the fee for a given value. It adds up the percentage against the val and the static currency val.

type FeeConfigReader

type FeeConfigReader interface {
	GetGateway() payment.Gateway
	GetPaymentWaitingTime() *time.Duration
	GetAdminFeeConfig(currency string) *Fee
	GetInstallmentFeeConfig(currency string) *Fee
}

FeeConfigReader holds function used for retrieving payment method's information (gateway and fee)

type Installment

type Installment struct {
	Gateway     payment.Gateway         `yaml:"gateway" json:"-"`
	DisplayName string                  `yaml:"display_name" json:"display_name"`
	Type        payment.InstallmentType `yaml:"type" json:"type"`
	Bank        payment.Bank            `yaml:"bank" json:"bank"`
	Channel     string                  `yaml:"channel" json:"-"`
	IsActive    bool                    `yaml:"active" json:"-"`
	IsDefault   bool                    `yaml:"default" json:"-"`
	Terms       []InstallmentTerm       `yaml:"terms" json:"terms"`
}

Installment contains information about the package of the installment, issuer bank, its type, and installment terms along with its fee information

func (Installment) GetTerm

func (i Installment) GetTerm(term int) (*InstallmentTerm, error)

GetTerm finds an installment given its term. If it doesn't exist, it returns ErrNotFound error

func (*Installment) SetValue

func (i *Installment) SetValue(val *payment.Money) error

SetValue sets the value of money which will be used for admin/installment fee

func (*Installment) UnmarshalYAML

func (i *Installment) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML custom unmarshall for installment. This will add payment gateway info to each terms in an installment

type InstallmentTerm

type InstallmentTerm struct {
	Gateway       payment.Gateway `yaml:"-" json:"-"`
	Term          int             `yaml:"term" json:"term"`
	AdminFee      map[string]Fee  `yaml:"admin_fee,omitempty" json:"-"`
	InstalmentFee map[string]Fee  `yaml:"installment_fee,omitempty" json:"-"`
	// contains filtered or unexported fields
}

InstallmentTerm stores information about the admin/installment fee applicable for a particular term

func (*InstallmentTerm) GetAdminFee

func (p *InstallmentTerm) GetAdminFee() *payment.Money

GetAdminFee returns the admin fee of an installment term in money notation

func (*InstallmentTerm) GetAdminFeeConfig

func (p *InstallmentTerm) GetAdminFeeConfig(currency string) *Fee

GetAdminFeeConfig returns admin fee rules of an installment term

func (*InstallmentTerm) GetGateway

func (p *InstallmentTerm) GetGateway() payment.Gateway

GetGateway returns payment gateway for current installment term

func (*InstallmentTerm) GetInstallmentFee

func (p *InstallmentTerm) GetInstallmentFee() *payment.Money

GetInstallmentFee returns the installment fee of an installment term in money notation

func (*InstallmentTerm) GetInstallmentFeeConfig

func (p *InstallmentTerm) GetInstallmentFeeConfig(currency string) *Fee

GetInstallmentFeeConfig returns installment fee rules of an installment term

func (*InstallmentTerm) GetPaymentWaitingTime

func (p *InstallmentTerm) GetPaymentWaitingTime() *time.Duration

GetPaymentWaitingTime is the max waiting time for payment completion after customer initiate the payment

func (*InstallmentTerm) MarshalJSON

func (p *InstallmentTerm) MarshalJSON() ([]byte, error)

MarshalJSON augments admin and installment fee in money notation to installment term struct

type NonCard

type NonCard struct {
	PaymentType payment.PaymentType `yaml:"payment_type" json:"payment_type"`
	IconURLs    []string            `yaml:"icon_urls" json:"icon_urls"`
	Gateway     payment.Gateway     `yaml:"gateway" json:"-"`
	DisplayName string              `yaml:"display_name" json:"display_name"`
	AdminFee    map[string]Fee      `yaml:"admin_fee,omitempty" json:"-"`
	WaitingTime *waitingTime        `yaml:"waiting_time" json:"-"`
}

NonCard represent the configuration for non cards payment (ewallet, retail outlet, cardless credit, virtual account).

func (*NonCard) GetAdminFeeConfig

func (p *NonCard) GetAdminFeeConfig(currency string) *Fee

GetAdminFeeConfig returns the fee configuration for a given currency.

func (*NonCard) GetGateway

func (p *NonCard) GetGateway() payment.Gateway

GetGateway returns the payment gateway used for this payment methods

func (*NonCard) GetInstallmentFeeConfig

func (p *NonCard) GetInstallmentFeeConfig(currency string) *Fee

GetInstallmentFeeConfig returns nil since the non card payment method doesn't has installment feature

func (*NonCard) GetPaymentWaitingTime

func (p *NonCard) GetPaymentWaitingTime() *time.Duration

GetPaymentWaitingTime is the max waiting time for payment completion after customer initiate the payment

type NonCardPayment

type NonCardPayment struct {
	NonCard
	// contains filtered or unexported fields
}

NonCardPayment represent all payment method other than cards. This includes ewallet, virtual account, retail outlet, and cardless credit. This struct might have information about the value of a product will be paid by using cards.

func NewNonCardPayment

func NewNonCardPayment(cfg NonCard, value *payment.Money) *NonCardPayment

NewNonCardPayment returns new NonCardPayment. if value is not nil, the admin fee of this payment method can be calculated.

func (*NonCardPayment) GetAdminFee

func (p *NonCardPayment) GetAdminFee() *payment.Money

GetAdminFee returns the admin fee in money notation

func (*NonCardPayment) GetInstallmentFee

func (p *NonCardPayment) GetInstallmentFee() *payment.Money

GetInstallmentFee returns nil since non card payment has no installment

func (*NonCardPayment) MarshalJSON

func (p *NonCardPayment) MarshalJSON() ([]byte, error)

type PaymentConfig

type PaymentConfig struct {
	CardPayment     Card      `yaml:"card_payment" json:"card_payment"`
	BankTransfers   []NonCard `yaml:"bank_transfers" json:"bank_transfers"`
	EWallets        []NonCard `yaml:"ewallets" json:"ewallets"`
	CStores         []NonCard `yaml:"cstores" json:"cstores"`
	CardlessCredits []NonCard `yaml:"cardless_credits" json:"cardless_credits"`
}

PaymentConfig stores all configuration for payment methods. This struct represent the yaml config file used for storing information about payment method fee (admin and installment fee), its max waiting time, also payment gateway information

func LoadPaymentConfigs

func LoadPaymentConfigs(data []byte) (*PaymentConfig, error)

LoadPaymentConfigs reads payment yaml config file

Jump to

Keyboard shortcuts

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