Skip to content

Commit ca0d56b

Browse files
authored
read expiration and creation timestamp for payd response (#28)
1 parent 2250811 commit ca0d56b

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

data/payd/models/payd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package models
22

33
import (
4+
"time"
5+
46
"github.com/libsv/go-bc/spv"
57
"github.com/libsv/go-bt/v2"
68

@@ -25,4 +27,6 @@ type DestinationResponse struct {
2527
SPVRequired bool `json:"spvRequired"`
2628
Outputs []Destination `json:"outputs"`
2729
Fees *bt.FeeQuote `json:"fees"`
30+
CreatedAt time.Time `json:"createdAt"`
31+
ExpiresAt time.Time `json:"expiresAt"`
2832
}

data/payd/payd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ func (p *payd) Destinations(ctx context.Context, args p4.PaymentRequestArgs) (*p
6969
SPVRequired: resp.SPVRequired,
7070
Outputs: make([]p4.Output, 0),
7171
Fees: resp.Fees,
72+
CreatedAt: resp.CreatedAt,
73+
ExpiresAt: resp.ExpiresAt,
7274
}
7375
for _, o := range resp.Outputs {
7476
dests.Outputs = append(dests.Outputs, p4.Output{

destinations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package p4
22

33
import (
44
"context"
5+
"time"
56

67
"github.com/libsv/go-bt/v2"
78
)
@@ -28,6 +29,8 @@ type Destinations struct {
2829
SPVRequired bool
2930
Outputs []Output
3031
Fees *bt.FeeQuote
32+
CreatedAt time.Time
33+
ExpiresAt time.Time
3134
}
3235

3336
// DestinationReader interfaces retrieving payment destinations.

service/paymentrequest.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package service
33
import (
44
"context"
55
"fmt"
6-
"time"
76

87
"github.com/pkg/errors"
98
validator "github.com/theflyingcodr/govalidator"
@@ -37,7 +36,7 @@ func (p *paymentRequest) CreatePaymentRequest(ctx context.Context, args p4.Payme
3736

3837
dests, err := p.destRdr.Destinations(ctx, args)
3938
if err != nil {
40-
return nil, errors.Wrapf(err, "failed to geet destinations for paymentID %s", args.PaymentID)
39+
return nil, errors.Wrapf(err, "failed to get destinations for paymentID %s", args.PaymentID)
4140
}
4241

4342
// get merchant information
@@ -55,8 +54,8 @@ func (p *paymentRequest) CreatePaymentRequest(ctx context.Context, args p4.Payme
5554
SPVRequired: dests.SPVRequired,
5655
Destinations: p4.PaymentDestinations{Outputs: dests.Outputs},
5756
FeeRate: dests.Fees,
58-
CreationTimestamp: time.Now().UTC(),
59-
ExpirationTimestamp: time.Now().Add(24 * time.Hour).UTC(),
57+
CreationTimestamp: dests.CreatedAt,
58+
ExpirationTimestamp: dests.ExpiresAt,
6059
PaymentURL: fmt.Sprintf("http://%s/api/v1/payment/%s", p.walletCfg.FQDN, args.PaymentID),
6160
Memo: fmt.Sprintf("invoice %s", args.PaymentID),
6261
MerchantData: &p4.MerchantData{

0 commit comments

Comments
 (0)