Files
online-backend/pkg/paymentgateway/client.go
GuwandykA b8455625b5
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled
add payment settting
2026-09-19 02:12:59 +05:00

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
}