payment recipient data

This commit is contained in:
Stephan D
2025-12-26 15:14:31 +01:00
parent 3836ff5ef3
commit 8adfab94b5
20 changed files with 442 additions and 68 deletions

View File

@@ -0,0 +1,15 @@
package srequest
// Customer captures payer/recipient identity details for downstream processing.
type Customer struct {
ID string `json:"id,omitempty"`
FirstName string `json:"first_name,omitempty"`
MiddleName string `json:"middle_name,omitempty"`
LastName string `json:"last_name,omitempty"`
IP string `json:"ip,omitempty"`
Zip string `json:"zip,omitempty"`
Country string `json:"country,omitempty"`
State string `json:"state,omitempty"`
City string `json:"city,omitempty"`
Address string `json:"address,omitempty"`
}

View File

@@ -13,6 +13,7 @@ type PaymentIntent struct {
FX *FXIntent `json:"fx,omitempty"`
SettlementMode SettlementMode `json:"settlement_mode,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
Customer *Customer `json:"customer,omitempty"`
}
type AssetResolverStub struct{}

View File

@@ -0,0 +1,25 @@
package paymentapiimp
import (
"net"
"strings"
"github.com/tech/sendico/server/interface/api/srequest"
)
func applyCustomerIP(intent *srequest.PaymentIntent, remoteAddr string) {
if intent == nil {
return
}
ip := strings.TrimSpace(remoteAddr)
if ip == "" {
return
}
if host, _, err := net.SplitHostPort(ip); err == nil && host != "" {
ip = host
}
if intent.Customer == nil {
intent.Customer = &srequest.Customer{}
}
intent.Customer.IP = strings.TrimSpace(ip)
}

View File

@@ -50,6 +50,7 @@ func mapPaymentIntent(intent *srequest.PaymentIntent) (*orchestratorv1.PaymentIn
Fx: fx,
SettlementMode: settlementMode,
Attributes: copyStringMap(intent.Attributes),
Customer: mapCustomer(intent.Customer),
}, nil
}
@@ -200,6 +201,24 @@ func mapFXIntent(fx *srequest.FXIntent) (*orchestratorv1.FXIntent, error) {
}, nil
}
func mapCustomer(customer *srequest.Customer) *orchestratorv1.Customer {
if customer == nil {
return nil
}
return &orchestratorv1.Customer{
Id: strings.TrimSpace(customer.ID),
FirstName: strings.TrimSpace(customer.FirstName),
MiddleName: strings.TrimSpace(customer.MiddleName),
LastName: strings.TrimSpace(customer.LastName),
Ip: strings.TrimSpace(customer.IP),
Zip: strings.TrimSpace(customer.Zip),
Country: strings.TrimSpace(customer.Country),
State: strings.TrimSpace(customer.State),
City: strings.TrimSpace(customer.City),
Address: strings.TrimSpace(customer.Address),
}
}
func mapCurrencyPair(pair *srequest.CurrencyPair) *fxv1.CurrencyPair {
if pair == nil {
return nil

View File

@@ -59,6 +59,7 @@ func (a *PaymentAPI) initiatePayment(r *http.Request, account *model.Account, to
var intent *orchestratorv1.PaymentIntent
if payload.Intent != nil {
applyCustomerIP(payload.Intent, r.RemoteAddr)
intent, err = mapPaymentIntent(payload.Intent)
if err != nil {
return response.BadPayload(a.logger, a.Name(), err)

View File

@@ -44,6 +44,7 @@ func (a *PaymentAPI) quotePayment(r *http.Request, account *model.Account, token
return response.Auto(a.logger, a.Name(), err)
}
applyCustomerIP(&payload.Intent, r.RemoteAddr)
intent, err := mapPaymentIntent(&payload.Intent)
if err != nil {
a.logger.Debug("Failed to map payment intent", zap.Error(err), mutil.PLog(a.oph, r))
@@ -97,6 +98,7 @@ func (a *PaymentAPI) quotePayments(r *http.Request, account *model.Account, toke
intents := make([]*orchestratorv1.PaymentIntent, 0, len(payload.Intents))
for i := range payload.Intents {
applyCustomerIP(&payload.Intents[i], r.RemoteAddr)
intent, err := mapPaymentIntent(&payload.Intents[i])
if err != nil {
a.logger.Debug("Failed to map payment intent", zap.Error(err), mutil.PLog(a.oph, r))