Skip to content

Commit

Permalink
fix in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
cksidharthan committed Sep 21, 2024
1 parent c3d6dbd commit a516fff
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 64 deletions.
44 changes: 21 additions & 23 deletions accounts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package gocardless

import "time"

type Account struct {
ID string `json:"id"`
Created string `json:"created"`
Expand All @@ -13,12 +11,12 @@ type Account struct {
}

type Balance struct {
BalanceAmount Amount `json:"balanceAmount"`
BalanceType string `json:"balanceType"`
ReferenceDate string `json:"referenceDate"`
CreditLimitIncluded bool `json:"creditLimitIncluded"`
LastChangeDateTime time.Time `json:"lastChangeDateTime"`
LastCommittedTransaction string `json:"lastCommittedTransaction"`
BalanceAmount Amount `json:"balanceAmount"`
BalanceType string `json:"balanceType"`
ReferenceDate string `json:"referenceDate"`
CreditLimitIncluded bool `json:"creditLimitIncluded"`
LastChangeDateTime TimeWithTimeZoneInfo `json:"lastChangeDateTime"`
LastCommittedTransaction string `json:"lastCommittedTransaction"`
}

type Amount struct {
Expand Down Expand Up @@ -61,21 +59,21 @@ type TransactionParams struct {
}

type Transaction struct {
TransactionID string `json:"transactionId"`
BookingDate string `json:"bookingDate"`
ValueDate string `json:"valueDate"`
BookingDateTime time.Time `json:"bookingDateTime"`
ValueDateTime time.Time `json:"valueDateTime"`
TransactionAmount Amount `json:"transactionAmount"`
CreditorName string `json:"creditorName"`
CreditorAccount Account `json:"creditorAccount"`
DebtorName string `json:"debtorName"`
DebtorAccount Account `json:"debtorAccount"`
BankTransactionCode string `json:"bankTransactionCode"`
RemittanceInformationUnstructured string `json:"remittanceInformationUnstructured"`
RemittanceInformationUnstructuredArray []string `json:"remittanceInformationUnstructuredArray"`
ProprietaryBankTransactionCode string `json:"proprietaryBankTransactionCode"`
InternalTransactionID string `json:"internalTransactionId"`
TransactionID string `json:"transactionId"`
BookingDate string `json:"bookingDate"`
ValueDate string `json:"valueDate"`
BookingDateTime TimeWithTimeZoneInfo `json:"bookingDateTime"`
ValueDateTime TimeWithTimeZoneInfo `json:"valueDateTime"`
TransactionAmount Amount `json:"transactionAmount"`
CreditorName string `json:"creditorName"`
CreditorAccount Account `json:"creditorAccount"`
DebtorName string `json:"debtorName"`
DebtorAccount Account `json:"debtorAccount"`
BankTransactionCode string `json:"bankTransactionCode"`
RemittanceInformationUnstructured string `json:"remittanceInformationUnstructured"`
RemittanceInformationUnstructuredArray []string `json:"remittanceInformationUnstructuredArray"`
ProprietaryBankTransactionCode string `json:"proprietaryBankTransactionCode"`
InternalTransactionID string `json:"internalTransactionId"`

AdditionalInformation string `json:"additionalInformation"`
AdditionalInformationStructured string `json:"additionalInformationStructured"`
Expand Down
16 changes: 7 additions & 9 deletions agreements.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package gocardless

import "time"

type AgreementRequestBody struct {
InstitutionID string `json:"institution_id"`
MaxHistoricalDays string `json:"max_historical_days"`
Expand All @@ -10,13 +8,13 @@ type AgreementRequestBody struct {
}

type Agreement struct {
ID string `json:"id"`
Created time.Time `json:"created"`
InstitutionID string `json:"institution_id"`
MaxHistoricalDays int `json:"max_historical_days"`
AccessValidForDays int `json:"access_valid_for_days"`
AccessScope []string `json:"access_scope"`
Accepted time.Time `json:"accepted"`
ID string `json:"id"`
Created TimeWithTimeZoneInfoZ `json:"created"`
InstitutionID string `json:"institution_id"`
MaxHistoricalDays int `json:"max_historical_days"`
AccessValidForDays int `json:"access_valid_for_days"`
AccessScope []string `json:"access_scope"`
Accepted TimeWithTimeZoneInfoZ `json:"accepted"`
}

type ListAgreementsParams struct {
Expand Down
34 changes: 34 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gocardless

import (
"fmt"
"strings"
"time"
)

func RequestHeadersWithAuth(token string) map[string]string {
Expand Down Expand Up @@ -34,3 +36,35 @@ func BuildQueryURL(path string, queryParams map[string]string) string {

return queryURL
}

type TimeWithTimeZoneInfo struct {
time.Time
}

const timeWithTimeZoneInfo = "2006-01-02T15:04:05.999999"

func (ct *TimeWithTimeZoneInfo) UnmarshalJSON(b []byte) error {
str := strings.Trim(string(b), `"`)
t, err := time.Parse(timeWithTimeZoneInfo, str)
if err != nil {
return fmt.Errorf("failed to parse time: %w", err)
}
ct.Time = t
return nil
}

type TimeWithTimeZoneInfoZ struct {
time.Time
}

const timeWithTimeZoneInfoZ = "2006-01-02T15:04:05.999999Z"

func (ct *TimeWithTimeZoneInfoZ) UnmarshalJSON(b []byte) error {
str := strings.Trim(string(b), `"`)
t, err := time.Parse(timeWithTimeZoneInfoZ, str)
if err != nil {
return fmt.Errorf("failed to parse time: %w", err)
}
ct.Time = t
return nil
}
32 changes: 15 additions & 17 deletions premium.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package gocardless

import "time"

type PremiumTransactions struct {
Transactions PremiumTransactionList `json:"transactions"`
}
Expand All @@ -12,21 +10,21 @@ type PremiumTransactionList struct {
}

type PremiumTransaction struct {
TransactionID string `json:"transactionId"`
BookingDate string `json:"bookingDate"`
ValueDate string `json:"valueDate"`
BookingDateTime time.Time `json:"bookingDateTime"`
ValueDateTime time.Time `json:"valueDateTime"`
TransactionAmount Amount `json:"transactionAmount"`
CreditorName string `json:"creditorName"`
CreditorAccount Account `json:"creditorAccount"`
DebtorName string `json:"debtorName"`
DebtorAccount Account `json:"debtorAccount"`
BankTransactionCode string `json:"bankTransactionCode"`
RemittanceInformationUnstructured string `json:"remittanceInformationUnstructured"`
RemittanceInformationUnstructuredArray []string `json:"remittanceInformationUnstructuredArray"`
ProprietaryBankTransactionCode string `json:"proprietaryBankTransactionCode"`
InternalTransactionID string `json:"internalTransactionId"`
TransactionID string `json:"transactionId"`
BookingDate string `json:"bookingDate"`
ValueDate string `json:"valueDate"`
BookingDateTime TimeWithTimeZoneInfo `json:"bookingDateTime"`
ValueDateTime TimeWithTimeZoneInfo `json:"valueDateTime"`
TransactionAmount Amount `json:"transactionAmount"`
CreditorName string `json:"creditorName"`
CreditorAccount Account `json:"creditorAccount"`
DebtorName string `json:"debtorName"`
DebtorAccount Account `json:"debtorAccount"`
BankTransactionCode string `json:"bankTransactionCode"`
RemittanceInformationUnstructured string `json:"remittanceInformationUnstructured"`
RemittanceInformationUnstructuredArray []string `json:"remittanceInformationUnstructuredArray"`
ProprietaryBankTransactionCode string `json:"proprietaryBankTransactionCode"`
InternalTransactionID string `json:"internalTransactionId"`

AdditionalInformation string `json:"additionalInformation"`
AdditionalInformationStructured string `json:"additionalInformationStructured"`
Expand Down
28 changes: 13 additions & 15 deletions requisitions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package gocardless

import "time"

type ListRequisitionsParams struct {
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
Offset int `url:"offset,omitempty" json:"offset,omitempty"`
Expand All @@ -19,19 +17,19 @@ type RequisitionRequestBody struct {
}

type Requisition struct {
ID string `json:"id"`
Created time.Time `json:"created"`
Redirect string `json:"redirect"`
Status string `json:"status"`
InstitutionID string `json:"institution_id"`
Agreement string `json:"agreement"`
Reference string `json:"reference"`
Accounts []string `json:"accounts"`
UserLanguage string `json:"user_language"`
Link string `json:"link"`
SSN string `json:"ssn"`
AccountSelection bool `json:"account_selection"`
RedirectImmediate bool `json:"redirect_immediate"`
ID string `json:"id"`
Created TimeWithTimeZoneInfo `json:"created"`
Redirect string `json:"redirect"`
Status string `json:"status"`
InstitutionID string `json:"institution_id"`
Agreement string `json:"agreement"`
Reference string `json:"reference"`
Accounts []string `json:"accounts"`
UserLanguage string `json:"user_language"`
Link string `json:"link"`
SSN string `json:"ssn"`
AccountSelection bool `json:"account_selection"`
RedirectImmediate bool `json:"redirect_immediate"`
}

type Requisitions struct {
Expand Down

0 comments on commit a516fff

Please sign in to comment.