payment recipient data
This commit is contained in:
15
api/server/interface/api/srequest/customer.go
Normal file
15
api/server/interface/api/srequest/customer.go
Normal 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"`
|
||||
}
|
||||
@@ -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{}
|
||||
|
||||
25
api/server/internal/server/paymentapiimp/customer.go
Normal file
25
api/server/internal/server/paymentapiimp/customer.go
Normal 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)
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user