forked from kevholditch/go-form3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builders.go
101 lines (87 loc) · 2.6 KB
/
builders.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package form3
import (
"fmt"
"github.com/ewilde/go-form3/models"
"github.com/go-openapi/strfmt"
"github.com/nu7hatch/gouuid"
"math"
"math/rand"
"time"
)
type PaymentBuilder struct {
payment models.Payment
}
func (b *PaymentBuilder) WithDefaults() *PaymentBuilder {
id, _ := uuid.NewV4()
organisationId, _ := uuid.NewV4()
b.payment = models.Payment{
ID: ConvertUUIDtoStrFmtUUID(id),
OrganisationID: ConvertUUIDtoStrFmtUUID(organisationId),
Attributes: &models.PaymentAttributes{
Amount: "60.00",
BeneficiaryParty: &models.PaymentAttributesBeneficiaryParty{
AccountNumber: "12345678",
AccountNumberCode: "BBAN",
AccountWith: &models.AccountHoldingEntity{
BankID: "888888",
BankIDCode: "GBDSC",
},
},
Currency: "GBP",
DebtorParty: &models.PaymentAttributesDebtorParty{
AccountNumber: "87654321",
AccountNumberCode: "BBAN",
AccountWith: &models.AccountHoldingEntity{
BankID: "333333",
BankIDCode: "GBDSC",
},
},
EndToEndReference: "00151519632ZCBBBJQ",
SchemeTransactionID: b.NewSchemeTransactionID(),
ProcessingDate: strfmt.Date(time.Now()),
PaymentScheme: "Bacs",
SchemePaymentType: "TelephoneBanking",
PaymentType: "Dividend",
},
}
return b
}
func (b *PaymentBuilder) WithAmount(amount string) *PaymentBuilder {
b.payment.Attributes.Amount = amount
return b
}
func (b *PaymentBuilder) WithOrganisationID(id strfmt.UUID) *PaymentBuilder {
b.payment.OrganisationID = ConvertUUIDtoPointer(id)
return b
}
func (b *PaymentBuilder) WithPaymentScheme(scheme string) *PaymentBuilder {
b.payment.Attributes.PaymentScheme = scheme
return b
}
func (b *PaymentBuilder) WithSchemePaymentType(schemePaymentType string) *PaymentBuilder {
b.payment.Attributes.SchemePaymentType = schemePaymentType
return b
}
func (b *PaymentBuilder) WithDebtorPartyAccountWithBankID(bankID string) *PaymentBuilder {
b.payment.Attributes.DebtorParty.AccountWith.BankID = bankID
return b
}
func (b *PaymentBuilder) WithSchemeTransactionID(schemeTransactionID string) *PaymentBuilder {
b.payment.Attributes.SchemeTransactionID = schemeTransactionID
return b
}
func (b *PaymentBuilder) NewSchemeTransactionID() string {
uniqueId := float64(rand.Int63n(math.MaxInt64 / 100))
return fmt.Sprintf("%17.0f", uniqueId)
}
func init() {
rand.Seed(time.Now().UnixNano())
}
func (b *PaymentBuilder) NewMessageID() string {
timestamp := time.Now().UTC().Format("20060102150405")
uniqueId := b.NewSchemeTransactionID()
return timestamp + uniqueId
}
func (b *PaymentBuilder) Build() *models.Payment {
return &b.payment
}