51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package paymentgateway
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"online-back/pkg/logging"
|
|
)
|
|
|
|
// ChargeRequest describes a single debit to submit to the external payment
|
|
// gateway ("GBÜS") for a loan payment.
|
|
type ChargeRequest struct {
|
|
Reference string
|
|
AccountNumber string
|
|
AmountTmt string
|
|
}
|
|
|
|
// ChargeResult is the outcome of a Charge call.
|
|
type ChargeResult struct {
|
|
Status string // "success" or "failed"
|
|
ProviderReference string
|
|
RawResponse []byte
|
|
}
|
|
|
|
// Client charges a customer's account through the external gateway. Plug
|
|
// your real provider in by implementing this interface once GBÜS's API
|
|
// contract (base URL, auth, request/response shape) is available.
|
|
type Client interface {
|
|
Charge(ctx context.Context, req ChargeRequest) (ChargeResult, error)
|
|
}
|
|
|
|
// LogClient is a stand-in used until a real GBÜS client is wired in. It
|
|
// logs the charge and reports success so the loan payment flow is usable
|
|
// end-to-end in the meantime.
|
|
type LogClient struct {
|
|
logger *logging.Logger
|
|
}
|
|
|
|
func NewLogClient(logger *logging.Logger) *LogClient {
|
|
return &LogClient{logger: logger}
|
|
}
|
|
|
|
func (c *LogClient) Charge(_ context.Context, req ChargeRequest) (ChargeResult, error) {
|
|
reference := fmt.Sprintf("LOG-%s-%d", req.Reference, time.Now().UnixNano())
|
|
if c.logger != nil {
|
|
c.logger.Infof("payment gateway charge (stub): account=%s amount=%s reference=%s", req.AccountNumber, req.AmountTmt, reference)
|
|
}
|
|
return ChargeResult{Status: "success", ProviderReference: reference}, nil
|
|
}
|