Skip to content

Commit cb7cba7

Browse files
committed
feat(transaction): add productDetails and customerDetail to MintRequest
Add support for new optional API fields: - productDetails: override default payment page note (max 255 chars) - customerDetail: override customer info with firstName, lastName, email (max 50 chars each) Includes validation and test coverage.
1 parent c1e6770 commit cb7cba7

4 files changed

Lines changed: 90 additions & 5 deletions

File tree

examples/mint-redemption/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ func main() {
5353
DestinationWalletAddress: "0x61Ba72c10983Def54AA7F93a334837BAA5d93396", // change this to your destination wallet address
5454
NetworkChainID: string(models.ChainPolygon), // Polygon
5555
ExpiryPeriod: 3600, // 1 hour
56+
// Optional fields for customizing payment page
57+
ProductDetails: "Custom IDRX Purchase", // Override default "Minting IDRX" note
58+
CustomerDetail: &models.CustomerDetail{
59+
FirstName: "John",
60+
LastName: "Doe",
61+
Email: "john.doe@example.com",
62+
},
5663
}
5764

5865
mintResp, err := client.Transaction.MintRequest(ctx, mintReq)

models/transaction.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ import (
44
"time"
55
)
66

7+
// CustomerDetail represents optional customer information for mint requests.
8+
type CustomerDetail struct {
9+
FirstName string `json:"firstName,omitempty"`
10+
LastName string `json:"lastName,omitempty"`
11+
Email string `json:"email,omitempty"`
12+
}
13+
714
// MintRequest represents the request to mint IDRX or other stablecoins.
815
type MintRequest struct {
9-
ToBeMinted string `json:"toBeMinted" validate:"required"`
10-
DestinationWalletAddress string `json:"destinationWalletAddress" validate:"required"`
11-
NetworkChainID string `json:"networkChainId" validate:"required"`
12-
ExpiryPeriod int `json:"expiryPeriod" validate:"required"`
13-
RequestType RequestType `json:"requestType,omitempty"`
16+
ToBeMinted string `json:"toBeMinted" validate:"required"`
17+
DestinationWalletAddress string `json:"destinationWalletAddress" validate:"required"`
18+
NetworkChainID string `json:"networkChainId" validate:"required"`
19+
ExpiryPeriod int `json:"expiryPeriod" validate:"required"`
20+
RequestType RequestType `json:"requestType,omitempty"`
21+
ProductDetails string `json:"productDetails,omitempty"`
22+
CustomerDetail *CustomerDetail `json:"customerDetail,omitempty"`
1423
}
1524

1625
// MintResponse represents the response from a mint request.

transaction_service.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,25 @@ func (s *TransactionService) validateMintRequest(req *models.MintRequest) error
198198
if req.ExpiryPeriod <= 0 {
199199
return fmt.Errorf("expiryPeriod must be greater than 0")
200200
}
201+
202+
// Validate optional productDetails length
203+
if len(req.ProductDetails) > 255 {
204+
return fmt.Errorf("productDetails must not exceed 255 characters")
205+
}
206+
207+
// Validate optional customerDetail fields
208+
if req.CustomerDetail != nil {
209+
if len(req.CustomerDetail.FirstName) > 50 {
210+
return fmt.Errorf("customerDetail.firstName must not exceed 50 characters")
211+
}
212+
if len(req.CustomerDetail.LastName) > 50 {
213+
return fmt.Errorf("customerDetail.lastName must not exceed 50 characters")
214+
}
215+
if len(req.CustomerDetail.Email) > 50 {
216+
return fmt.Errorf("customerDetail.email must not exceed 50 characters")
217+
}
218+
}
219+
201220
return nil
202221
}
203222

transaction_service_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,56 @@ func TestTransactionService_MintRequestValidation(t *testing.T) {
359359
},
360360
wantErr: "expiryPeriod must be greater than 0",
361361
},
362+
{
363+
name: "productDetails exceeds 255 characters",
364+
request: &models.MintRequest{
365+
ToBeMinted: "1000",
366+
DestinationWalletAddress: "0x123",
367+
NetworkChainID: "137",
368+
ExpiryPeriod: 3600,
369+
ProductDetails: strings.Repeat("a", 256),
370+
},
371+
wantErr: "productDetails must not exceed 255 characters",
372+
},
373+
{
374+
name: "customerDetail firstName exceeds 50 characters",
375+
request: &models.MintRequest{
376+
ToBeMinted: "1000",
377+
DestinationWalletAddress: "0x123",
378+
NetworkChainID: "137",
379+
ExpiryPeriod: 3600,
380+
CustomerDetail: &models.CustomerDetail{
381+
FirstName: strings.Repeat("a", 51),
382+
},
383+
},
384+
wantErr: "customerDetail.firstName must not exceed 50 characters",
385+
},
386+
{
387+
name: "customerDetail lastName exceeds 50 characters",
388+
request: &models.MintRequest{
389+
ToBeMinted: "1000",
390+
DestinationWalletAddress: "0x123",
391+
NetworkChainID: "137",
392+
ExpiryPeriod: 3600,
393+
CustomerDetail: &models.CustomerDetail{
394+
LastName: strings.Repeat("b", 51),
395+
},
396+
},
397+
wantErr: "customerDetail.lastName must not exceed 50 characters",
398+
},
399+
{
400+
name: "customerDetail email exceeds 50 characters",
401+
request: &models.MintRequest{
402+
ToBeMinted: "1000",
403+
DestinationWalletAddress: "0x123",
404+
NetworkChainID: "137",
405+
ExpiryPeriod: 3600,
406+
CustomerDetail: &models.CustomerDetail{
407+
Email: strings.Repeat("c", 51) + "@example.com",
408+
},
409+
},
410+
wantErr: "customerDetail.email must not exceed 50 characters",
411+
},
362412
}
363413

364414
for _, tt := range tests {

0 commit comments

Comments
 (0)