update orderflow
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// PassthroughProvider records an already-settled authorization and capture without
|
||||
// calling an external provider. It is the bridge between the checkout grain's
|
||||
// externally-processed payments (Klarna, Adyen) and the order grain's event log:
|
||||
// the payment was already settled by the provider, so the order grain just needs
|
||||
// to record the facts.
|
||||
//
|
||||
// Create one per order with the exact provider name, reference and amount the
|
||||
// external processor returned. Refund returns an error — use the external
|
||||
// processor's own refund API for that. Void is a no-op.
|
||||
type PassthroughProvider struct {
|
||||
name string
|
||||
reference string
|
||||
amount int64
|
||||
}
|
||||
|
||||
// NewPassthroughProvider returns a provider that records provider/ref/amount
|
||||
// for both authorize and capture. amount is in minor currency units (öre).
|
||||
func NewPassthroughProvider(providerName, reference string, amount int64) *PassthroughProvider {
|
||||
return &PassthroughProvider{
|
||||
name: providerName,
|
||||
reference: reference,
|
||||
amount: amount,
|
||||
}
|
||||
}
|
||||
|
||||
var _ PaymentProvider = (*PassthroughProvider)(nil)
|
||||
|
||||
func (p *PassthroughProvider) Name() string { return p.name }
|
||||
|
||||
func (p *PassthroughProvider) Authorize(_ context.Context, _ string, _ int64, _ string) (Authorization, error) {
|
||||
return Authorization{
|
||||
Provider: p.name,
|
||||
Reference: p.reference,
|
||||
Amount: p.amount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *PassthroughProvider) Capture(_ context.Context, _ string, _ int64) (Capture, error) {
|
||||
if p.reference == "" {
|
||||
return Capture{}, fmt.Errorf("passthrough: capture requires a processor reference")
|
||||
}
|
||||
return Capture{
|
||||
Provider: p.name,
|
||||
Reference: p.reference,
|
||||
Amount: p.amount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *PassthroughProvider) Refund(_ context.Context, _ string, _ int64) (RefundResult, error) {
|
||||
return RefundResult{}, fmt.Errorf("passthrough: refund not implemented — use the external provider directly")
|
||||
}
|
||||
|
||||
func (p *PassthroughProvider) Void(_ context.Context, _ string) error { return nil }
|
||||
Reference in New Issue
Block a user