Documentation
¶
Index ¶
- type Controller
- type CreateResponse
- type IntervalUnit
- type MissedPaymentAction
- type Schedule
- type Status
- type Subscription
- func (s *Subscription) MarshalJSON() ([]byte, error)
- func (s *Subscription) Pause(ctx context.Context, p pauser) error
- func (s *Subscription) Resume(ctx context.Context, r resumer) error
- func (s *Subscription) Save(inv *invoice.Invoice) error
- func (s *Subscription) Start(ctx context.Context, c creator) error
- func (s *Subscription) Stop(ctx context.Context, st stopper) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller interface {
// contains filtered or unexported methods
}
Controller is payment gateway interface for subscription handling
type CreateResponse ¶
CreateResponse is a wrapper for create subscription response
type IntervalUnit ¶
type IntervalUnit string
IntervalUnit defines the unit of recurrence period
const ( // IntervalUnitDay recurrence happend every day IntervalUnitDay IntervalUnit = "day" // IntervalUnitWeek ... IntervalUnitWeek IntervalUnit = "week" // IntervalUnitMonth ... IntervalUnitMonth IntervalUnit = "month" )
func NewIntervalUnit ¶
func NewIntervalUnit(s string) IntervalUnit
NewIntervalUnit return an IntervalUnit based on the string given
func (IntervalUnit) Duration ¶
func (iu IntervalUnit) Duration() time.Duration
type MissedPaymentAction ¶
type MissedPaymentAction string
MissedPaymentAction defines action should be taken if user miss the payment
const ( // MissedPaymentActionIgnore subscription will be continue on the // next term MissedPaymentActionIgnore MissedPaymentAction = "ignore" // MissedPaymentActionStop subscription will be stopped immediately MissedPaymentActionStop MissedPaymentAction = "stop" )
type Schedule ¶
type Schedule struct {
payment.Model
SubscriptionID uint64 `json:"-" gorm:"index:schedule_subs_id"`
Interval int `json:"interval"`
IntervalUnit IntervalUnit `json:"interval_unit"`
StartAt *time.Time `json:"start_at"`
PreviousExecutionAt *time.Time `json:"previous_execution_at"`
NextExecutionAt *time.Time `json:"next_execution_at"`
}
Schedule tells when subscription starts and charges
func NewSchedule ¶
func NewSchedule(interval int, unit IntervalUnit, start *time.Time) *Schedule
NewSchedule create new payment schedule
func (*Schedule) NextAfterPause ¶
NextAfterPause calculate when the next payment should be executed after it is paused
type Subscription ¶
type Subscription struct {
payment.Model
Number string `json:"number" gorm:"unique_index:subs_number_k"`
Name string `json:"name"`
Description string `json:"description" gorm:"type:text"`
Amount float64 `json:"amount"`
UserID string `json:"user_id"`
Currency string `json:"currency"`
Schedule Schedule `json:"schedule" gorm:"ForeignKey:SubscriptionID"`
TotalReccurence int `json:"total_recurrence"`
InvoiceDuration time.Duration `json:"invoice_duration"`
ShouldSendEmail bool `json:"should_send_email"`
MissedPaymentAction MissedPaymentAction `json:"missed_payment_action"`
Recharge bool `json:"recharge"`
CardToken string `json:"card_token"`
GatewayRecurringID string `json:"gateway_recurring_id"`
Gateway string `json:"gateway"`
Invoices []invoice.Invoice `json:"invoices"`
// ChargeImmediately will create first invoice no matter
// what the startat value is
ChargeImmediately bool `json:"charge_immediately"`
LastCreatedInvoice string `json:"last_created_invoice"`
Status Status `json:"-"`
}
Subscription is object recording the recurring payment
func (*Subscription) MarshalJSON ¶
func (s *Subscription) MarshalJSON() ([]byte, error)
MarshalJSON ...
func (*Subscription) Pause ¶
func (s *Subscription) Pause(ctx context.Context, p pauser) error
Pause change the subscription status to paused and stop the schedule
func (*Subscription) Resume ¶
func (s *Subscription) Resume(ctx context.Context, r resumer) error
Resume ...
func (*Subscription) Save ¶
func (s *Subscription) Save(inv *invoice.Invoice) error
Save stores invoice created for subscription and renew subscription schedule