Skip to content

Commit

Permalink
Converts all time.Time fields to pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
martinseco committed Apr 26, 2023
1 parent 51ec9f0 commit aac895b
Show file tree
Hide file tree
Showing 31 changed files with 171 additions and 103 deletions.
4 changes: 2 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ type (

type (
DateRangeQuery struct {
From time.Time `url:"from,omitempty" layout:"2006-01-02T15:04:05Z"`
To time.Time `url:"to,omitempty" layout:"2006-01-02T15:04:05Z"`
From *time.Time `url:"from,omitempty" layout:"2006-01-02T15:04:05Z"`
To *time.Time `url:"to,omitempty" layout:"2006-01-02T15:04:05Z"`
}
)
2 changes: 1 addition & 1 deletion common/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type (
Filename string `json:"filename,omitempty"`
Purpose Purpose `json:"purpose,omitempty"`
Size uint64 `json:"size,omitempty"`
UploadedOn time.Time `json:"uploaded_on,omitempty"`
UploadedOn *time.Time `json:"uploaded_on,omitempty"`
Links map[string]Link `json:"_links"`
}
)
Expand Down
45 changes: 45 additions & 0 deletions common/serializer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package common

import (
"bytes"
"encoding/json"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestMarshal(t *testing.T) {
cases := []struct {
name string
request interface{}
checker func(*bytes.Buffer, error)
}{
{
name: "when serializing nil *time.Time field should not be included",
request: struct {
Time *time.Time `json:"time,omitempty"`
OtherField string `json:"other_field,omitempty"`
}{
OtherField: "value",
},
checker: func(serialized *bytes.Buffer, err error) {
assert.Nil(t, err)
assert.NotNil(t, serialized)

var deserialized map[string]interface{}
unmErr := json.Unmarshal(serialized.Bytes(), &deserialized)

assert.Nil(t, unmErr)
assert.Contains(t, deserialized, "other_field")
assert.NotContains(t, deserialized, "time")
},
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
tc.checker(Marshal(tc.request))
})
}
}
11 changes: 7 additions & 4 deletions disputes/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ func TestQuery(t *testing.T) {

disputesList = []DisputeSummary{dispute}

from = time.Now().Add(-5 * time.Hour)
to = time.Now()

queryResponse = QueryResponse{
HttpMetadata: mocks.HttpMetadataStatusOk,
Limit: 10,
Skip: 0,
From: time.Now().Add(-5 * time.Hour),
To: time.Now(),
From: &from,
To: &to,
TotalCount: 1,
Data: disputesList,
}
Expand All @@ -64,8 +67,8 @@ func TestQuery(t *testing.T) {
query: QueryFilter{
Limit: 10,
Skip: 0,
From: time.Now().Add(-5 * time.Hour),
To: time.Now(),
From: &from,
To: &to,
},
getAuthorization: func(m *mock.Mock) mock.Call {
return *m.On("GetAuthorization", mock.Anything).
Expand Down
30 changes: 15 additions & 15 deletions disputes/disputes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type (
ReasonCode string `json:"reason_code,omitempty"`
ResolvedReason DisputeResolvedReason `json:"resolved_reason,omitempty"`
RelevantEvidence []RelevantEvidence `json:"relevant_evidence,omitempty"`
EvidenceRequiredBy time.Time `json:"evidence_required_by,omitempty"`
ReceivedOn time.Time `json:"received_on,omitempty"`
LastUpdate time.Time `json:"last_update,omitempty"`
EvidenceRequiredBy *time.Time `json:"evidence_required_by,omitempty"`
ReceivedOn *time.Time `json:"received_on,omitempty"`
LastUpdate *time.Time `json:"last_update,omitempty"`
Payment *PaymentDispute `json:"payment,omitempty"`

// Not available on Previous
Expand All @@ -41,7 +41,7 @@ type (
Currency common.Currency `json:"currency,omitempty"`
Method string `json:"method,omitempty"`
Arn string `json:"arn,omitempty"`
ProcessedOn time.Time `json:"processed_on,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`

// Not available on Previous
ActionId string `json:"actionId,omitempty"`
Expand All @@ -68,10 +68,10 @@ type (
// Query
type (
QueryFilter struct {
Limit uint8 `url:"limit,omitempty"` //min=1 - max=250
Skip int `url:"skip,omitempty"`
From time.Time `url:"from,omitempty" layout:"2006-01-02T15:04:05Z"`
To time.Time `url:"to,omitempty" layout:"2006-01-02T15:04:05Z"`
Limit uint8 `url:"limit,omitempty"` //min=1 - max=250
Skip int `url:"skip,omitempty"`
From *time.Time `url:"from,omitempty" layout:"2006-01-02T15:04:05Z"`
To *time.Time `url:"to,omitempty" layout:"2006-01-02T15:04:05Z"`

Id string `url:"id,omitempty"`
Statuses string `url:"statuses,omitempty"` //One or more comma-separated statuses. This works like a logical OR operator
Expand All @@ -89,10 +89,10 @@ type (
QueryResponse struct {
HttpMetadata common.HttpMetadata

Limit uint8 `json:"limit,omitempty"` //min=1 - max=250
Skip int `json:"skip,omitempty"`
From time.Time `json:"from,omitempty" time_format:"2006-01-02T15:04:05Z"`
To time.Time `json:"to,omitempty" time_format:"2006-01-02T15:04:05Z"`
Limit uint8 `json:"limit,omitempty"` //min=1 - max=250
Skip int `json:"skip,omitempty"`
From *time.Time `json:"from,omitempty" time_format:"2006-01-02T15:04:05Z"`
To *time.Time `json:"to,omitempty" time_format:"2006-01-02T15:04:05Z"`

Id string `json:"id,omitempty"`
Statuses string `json:"statuses,omitempty"` //One or more comma-separated statuses. This works like a logical OR operator
Expand Down Expand Up @@ -122,9 +122,9 @@ type (
PaymentReference string `json:"payment_reference,omitempty"`
PaymentArn string `json:"payment_arn,omitempty"`
PaymentMethod string `json:"payment_method,omitempty"`
EvidenceRequiredBy time.Time `json:"evidence_required_by,omitempty"`
ReceivedOn time.Time `json:"received_on,omitempty"`
LastUpdate time.Time `json:"last_update,omitempty"`
EvidenceRequiredBy *time.Time `json:"evidence_required_by,omitempty"`
ReceivedOn *time.Time `json:"received_on,omitempty"`
LastUpdate *time.Time `json:"last_update,omitempty"`

// Not available on Previous
EntityId string `json:"entity_id,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion events/abc/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type (
ThreeDs *payments.ThreeDsEnrollment `json:"3ds,omitempty"`
Source *abc.ResponseCardSource `json:"source,omitempty"`
Customer *common.CustomerResponse `json:"customer,omitempty"`
ProcessedOn time.Time `json:"processed_on,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`
Reference string `json:"reference,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Expand Down
8 changes: 4 additions & 4 deletions financial/financial.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ type (
IssuerCountry common.Country `json:"issuer_country,omitempty"`
MerchantCategoryCode string `json:"merchant_category_code,omitempty"`
FxTradeId string `json:"fx_trade_id,omitempty"`
ProcessedOn time.Time `json:"processed_on,omitempty"`
RequestedOn time.Time `json:"requested_on,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`
RequestedOn *time.Time `json:"requested_on,omitempty"`
Breakdown []ActionBreakdown `json:"breakdown,omitempty"`
}

Expand All @@ -74,8 +74,8 @@ type (
TransactionToHoldingCurrencyFxRate float64 `json:"transaction_to_holding_currency_fx_rate,omitempty"`
FeeDetail string `json:"fee_detail,omitempty"`
ReserveRate string `json:"reserve_rate,omitempty"`
ReserveReleaseDate time.Time `json:"reserve_release_date,omitempty"`
ReserveDeductedDate time.Time `json:"reserve_deducted_date,omitempty"`
ReserveReleaseDate *time.Time `json:"reserve_release_date,omitempty"`
ReserveDeductedDate *time.Time `json:"reserve_deducted_date,omitempty"`
TaxFxRate float64 `json:"tax_fx_rate,omitempty"`
EntityCountryTaxCurrency common.Currency `json:"entity_country_tax_currency,omitempty"`
TaxCurrencyAmount float64 `json:"tax_currency_amount,omitempty"`
Expand Down
4 changes: 3 additions & 1 deletion forex/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

func TestRequestQuote(t *testing.T) {
var (
now = time.Now()

quote = QuoteResponse{
HttpMetadata: mocks.HttpMetadataStatusOk,
Id: "qte_id",
Expand All @@ -24,7 +26,7 @@ func TestRequestQuote(t *testing.T) {
DestinationCurrency: common.USD,
DestinationAmount: 35700,
Rate: 1.19,
ExpiresOn: time.Now(),
ExpiresOn: &now,
IsSingleUse: false,
}
)
Expand Down
2 changes: 1 addition & 1 deletion forex/forex.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type (
DestinationCurrency common.Currency `json:"destination_currency,omitempty"`
DestinationAmount int64 `json:"destination_amount,omitempty"`
Rate float64 `json:"rate,omitempty"`
ExpiresOn time.Time `json:"expires_on,omitempty"`
ExpiresOn *time.Time `json:"expires_on,omitempty"`
IsSingleUse bool `json:"is_single_use,omitempty"`
}
)
Expand Down
10 changes: 5 additions & 5 deletions payments/abc/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type (
Reference string `json:"reference,omitempty"`
Description string `json:"description,omitempty"`
Capture bool `json:"capture"`
CaptureOn time.Time `json:"capture_on,omitempty"`
CaptureOn *time.Time `json:"capture_on,omitempty"`
Customer *common.CustomerRequest `json:"customer,omitempty"`
BillingDescriptor *payments.BillingDescriptor `json:"billing_descriptor,omitempty"`
ShippingDetails *payments.ShippingDetails `json:"shipping,omitempty"`
Expand All @@ -43,7 +43,7 @@ type (
Reference string `json:"reference,omitempty"`
Description string `json:"description,omitempty"`
Capture bool `json:"capture"`
CaptureOn time.Time `json:"capture_on,omitempty"`
CaptureOn *time.Time `json:"capture_on,omitempty"`
Customer *common.CustomerRequest `json:"customer,omitempty"`
BillingDescriptor *payments.BillingDescriptor `json:"billing_descriptor,omitempty"`
ShippingDetails *payments.ShippingDetails `json:"shipping,omitempty"`
Expand Down Expand Up @@ -83,7 +83,7 @@ type (
ResponseCode string `json:"response_code,omitempty"`
ResponseSummary string `json:"response_summary,omitempty"`
Risk *payments.RiskAssessment `json:"risk,omitempty"`
ProcessedOn time.Time `json:"processed_on,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`
Processing *payments.PaymentProcessing `json:"processing,omitempty"`
Eci string `json:"eci,omitempty"`
SchemeId string `json:"scheme_id,omitempty"`
Expand All @@ -93,7 +93,7 @@ type (
GetPaymentResponse struct {
HttpMetadata common.HttpMetadata
Id string `json:"id,omitempty"`
RequestedOn time.Time `json:"requested_on,omitempty"`
RequestedOn *time.Time `json:"requested_on,omitempty"`
Source interface{} `json:"source,omitempty"`
Destination interface{} `json:"destination,omitempty"`
Amount int64 `json:"amount,omitempty"`
Expand Down Expand Up @@ -125,7 +125,7 @@ type (
PaymentAction struct {
Id string `json:"id,omitempty"`
Type payments.ActionType `json:"type,omitempty"`
ProcessedOn time.Time `json:"processed_on,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`
Amount int64 `json:"amount,omitempty"`
Approved bool `json:"approved,omitempty"`
AuthCode string `json:"auth_code,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion payments/abc/sources/apm/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type (
CustomerProfileId string `json:"customer_profile_id,omitempty"`
CustomerEmail string `json:"customer_email,omitempty"`
CustomerMobile string `json:"customer_mobile,omitempty"`
ExpiresOn time.Time `json:"expires_on,omitempty"`
ExpiresOn *time.Time `json:"expires_on,omitempty"`
Products []FawryProduct `json:"products,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion payments/hosted/hosted.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type (
Locale string `json:"locale,omitempty"`
ThreeDs *payments.ThreeDsRequest `json:"3ds,omitempty"`
Capture bool `json:"capture,omitempty"`
CaptureOn time.Time `json:"capture_on,omitempty"`
CaptureOn *time.Time `json:"capture_on,omitempty"`
//Not available on previous
ProcessingChannelId string `json:"processing_channel_id,omitempty"`
AmountAllocations []common.AmountAllocations `json:"amount_allocations,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion payments/links/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type (
ReturnUrl string `json:"return_url,omitempty"`
Locale string `json:"locale,omitempty"`
Capture bool `json:"capture,omitempty"`
CaptureOn time.Time `json:"capture_on,omitempty"`
CaptureOn *time.Time `json:"capture_on,omitempty"`
//Not available on previous
ProcessingChannelId string `json:"processing_channel_id,omitempty"`
AmountAllocations []common.AmountAllocations `json:"amount_allocations,omitempty"`
Expand Down
18 changes: 9 additions & 9 deletions payments/nas/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type (
}
)

//Request
// Request
type (
PaymentRequest struct {
Source payments.PaymentSource `json:"source,omitempty"`
Expand All @@ -91,7 +91,7 @@ type (
Description string `json:"description,omitempty"`
AuthorizationType AuthorizationType `json:"authorization_type,omitempty"`
Capture bool `json:"capture"`
CaptureOn time.Time `json:"capture_on,omitempty"`
CaptureOn *time.Time `json:"capture_on,omitempty"`
Customer *common.CustomerRequest `json:"customer,omitempty"`
BillingDescriptor *payments.BillingDescriptor `json:"billing_descriptor,omitempty"`
ShippingDetails *payments.ShippingDetails `json:"shipping,omitempty"`
Expand Down Expand Up @@ -140,7 +140,7 @@ type (
}
)

//Response
// Response
type (
PaymentResponse struct {
HttpMetadata common.HttpMetadata
Expand All @@ -158,8 +158,8 @@ type (
ResponseCode string `json:"response_code,omitempty"`
ResponseSummary string `json:"response_summary,omitempty"`
Risk *payments.RiskAssessment `json:"risk,omitempty"`
ProcessedOn time.Time `json:"processed_on,omitempty"`
ExpiresOn time.Time `json:"expires_on,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`
ExpiresOn *time.Time `json:"expires_on,omitempty"`
Balances *PaymentResponseBalances `json:"balances,omitempty"`
Processing *payments.PaymentProcessing `json:"processing,omitempty"`
Eci string `json:"eci,omitempty"`
Expand All @@ -178,7 +178,7 @@ type (
GetPaymentResponse struct {
HttpMetadata common.HttpMetadata
Id string `json:"id,omitempty"`
RequestedOn time.Time `json:"requested_on,omitempty"`
RequestedOn *time.Time `json:"requested_on,omitempty"`
Source *SourceResponse `json:"source,omitempty"`
Destination *DestinationResponse `json:"destination,omitempty"`
Sender *SenderResponse `json:"sender,omitempty"`
Expand All @@ -188,7 +188,7 @@ type (
Reference string `json:"reference,omitempty"`
Description string `json:"description,omitempty"`
Approved bool `json:"approved,omitempty"`
ExpiresOn time.Time `json:"expires_on,omitempty"`
ExpiresOn *time.Time `json:"expires_on,omitempty"`
Status payments.PaymentStatus `json:"status,omitempty"`
Balances *PaymentResponseBalances `json:"balances,omitempty"`
ThreeDs *payments.ThreeDsData `json:"3ds,omitempty"`
Expand All @@ -206,7 +206,7 @@ type (
Eci string `json:"eci,omitempty"`
SchemeId string `json:"scheme_id,omitempty"`
Actions []payments.PaymentActionSummary `json:"actions,omitempty"`
ProcessedOn time.Time `json:"processed_on,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`
Links map[string]common.Link `json:"_links"`
}

Expand All @@ -218,7 +218,7 @@ type (
PaymentAction struct {
Id string `json:"id,omitempty"`
Type payments.ActionType `json:"type,omitempty"`
ProcessedOn time.Time `json:"processed_on,omitempty"`
ProcessedOn *time.Time `json:"processed_on,omitempty"`
Amount int64 `json:"amount,omitempty"`
Approved bool `json:"approved,omitempty"`
AuthCode string `json:"auth_code,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion payments/nas/sources/apm/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type (
CustomerProfileId string `json:"customer_profile_id,omitempty"`
CustomerEmail string `json:"customer_email,omitempty"`
CustomerMobile string `json:"customer_mobile,omitempty"`
ExpiresOn time.Time `json:"expires_on,omitempty"`
ExpiresOn *time.Time `json:"expires_on,omitempty"`
Products []FawryProduct `json:"Products,omitempty"`
}

Expand Down
6 changes: 3 additions & 3 deletions payments/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ type (
AllowUpgrade bool `json:"allow_upgrade,omitempty"`
// Not available on Previous
Status string `json:"status,omitempty"`
AuthenticationDate time.Time `json:"authentication_date,omitempty"`
AuthenticationDate *time.Time `json:"authentication_date,omitempty"`
AuthenticationAmount float64 `json:"authentication_amount,omitempty"`
FlowType common.ThreeDsFlowType `json:"flow_type,omitempty"`
StatusReasonCode string `json:"status_reason_code,omitempty"`
Expand Down Expand Up @@ -391,7 +391,7 @@ type (
}
)

//Request
// Request
type (
RefundRequest struct {
Amount int64 `json:"amount,omitempty"`
Expand All @@ -413,7 +413,7 @@ type (
}
)

//Response
// Response
type (
CaptureResponse struct {
HttpMetadata common.HttpMetadata
Expand Down
Loading

0 comments on commit aac895b

Please sign in to comment.