-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
534 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package appsandbox | ||
|
||
import "github.com/openmeterio/openmeter/openmeter/billing" | ||
|
||
var ErrSimulatedPaymentFailure = billing.NewValidationError("simulated_payment_failure", "simulated payment failure") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package billing | ||
|
||
import ( | ||
"fmt" | ||
"slices" | ||
|
||
"github.com/qmuntal/stateless" | ||
) | ||
|
||
type InvoiceTrigger = stateless.Trigger | ||
|
||
var ( | ||
// TriggerRetry is used to retry a state transition that failed, used by the end user to invoke it manually | ||
TriggerRetry InvoiceTrigger = "trigger_retry" | ||
// TriggerApprove is used to approve a state manually | ||
TriggerApprove InvoiceTrigger = "trigger_approve" | ||
// TriggerNext is used to advance the invoice to the next state if automatically possible | ||
TriggerNext InvoiceTrigger = "trigger_next" | ||
// TriggerFailed is used to trigger the failure state transition associated with the current state | ||
TriggerFailed InvoiceTrigger = "trigger_failed" | ||
// TriggerUpdated is used to trigger a change in the invoice (we are using this to calculate the immutable states | ||
// and trigger re-validation) | ||
TriggerUpdated InvoiceTrigger = "trigger_updated" | ||
// triggerDelete is used to delete the invoice | ||
TriggerDelete InvoiceTrigger = "trigger_delete" | ||
|
||
// TODO[OM-989]: we should have a triggerAsyncNext to signify that a transition should be done asynchronously ( | ||
// e.g. the invoice needs to be synced to an external system such as stripe) | ||
|
||
// TriggerPaid is used to signify that the invoice has been paid | ||
TriggerPaid InvoiceTrigger = "trigger_paid" | ||
// TriggerActionRequired is used to signify that the invoice requires action | ||
TriggerActionRequired InvoiceTrigger = "trigger_action_required" | ||
|
||
// TriggerPaymentUncollectible is used to signify that the invoice is uncollectible | ||
TriggerPaymentUncollectible InvoiceTrigger = "trigger_payment_uncollectible" | ||
// TriggerPaymentOverdue is used to signify that the invoice is overdue | ||
TriggerPaymentOverdue InvoiceTrigger = "trigger_payment_overdue" | ||
) | ||
|
||
type InvoiceOperation string | ||
|
||
const ( | ||
InvoiceOpValidate InvoiceOperation = "validate" | ||
InvoiceOpSync InvoiceOperation = "sync" | ||
InvoiceOpDelete InvoiceOperation = "delete" | ||
InvoiceOpFinalize InvoiceOperation = "finalize" | ||
InvoiceOpInitiatePayment InvoiceOperation = "initiate_payment" | ||
|
||
InvoiceOpPostAdvanceHook InvoiceOperation = "post_advance_hook" | ||
) | ||
|
||
var InvoiceOperations = []InvoiceOperation{ | ||
InvoiceOpValidate, | ||
InvoiceOpSync, | ||
InvoiceOpDelete, | ||
InvoiceOpFinalize, | ||
InvoiceOpInitiatePayment, | ||
|
||
InvoiceOpPostAdvanceHook, | ||
} | ||
|
||
func (o InvoiceOperation) Validate() error { | ||
if !slices.Contains(InvoiceOperations, o) { | ||
return fmt.Errorf("invalid invoice operation: %s", o) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.