Skip to content

Commit

Permalink
v2.1.0 (#8)
Browse files Browse the repository at this point in the history
* Changes generated by 90afb7b0bfe8400aa172a0c41d12cc89cab3a0cb

* Changes generated by d03f550064463c26c11345d6f913b82145c463e0

* Changes generated by 761a5f396ff8e06739254ec3d5994647745a2fa5

* Changes generated by 3f7e469a9ed21afa7425ef1f6ce0682c66f9ee84

* Changes generated by 9673ff362be6a2c82b88a34e52b61b6d0603c461

* Changes generated by 89d28f103fc65da5c9f4677e2b85b06c9c07b799

* Changes generated by 73fa74b77ef5f5b5e400b81a3563af6e74c2ac85

* Changes generated by 61d47cd4272cbfc368540ec736da14486b76b71c

* Changes generated by 1ed5a6598f0c9a12807f982f379311f20ff11ef8

* Changes generated by 3331ffcbdfa84b6ac199045b0fb50f60c3641426

* Changes generated by d2ff61a58e5ba09526bcb19a0664e0d1442e91b3

* Changes generated by 976187b15a5e307bbe6d7c588f36530a45139186

* Changes generated by 79077ca0952a7a942c9316d617e923b73ddd1aa1

* Changes generated by 750627fba2f3ef092a26bd8227b6f4fa2f6bba96

* Changes generated by c59277736a2d0e40ac0f9d8a42e1b9463a39edef

* Changes generated by 6d1a66b2decd2844457e4f635aa396041d4415dd

* Changes generated by 96427efe0958d47a42deeed61d74dd839ff3b801

* Changes generated by 86653b3d64a2ebc708cad205f692c4ef4f6ff502

* Changes generated by 957c7b6a278d7bbc180d245e31cc075042869e54

* Changes generated by e5377575d33701f1530977ced9f07b992bece019

* Changes generated by b0985abebd47ede4bc75cec926b0c9cc5b5a7384

* Changes generated by 813e6acfab0094225dd4820af515683eed3bacb3

* Changes generated by 7f472b1ae11ec581267eca9b6564d29c2cd670fe

* Changes generated by e4a1f03495fe9b2018c66096ede365a866b439ff

* Changes generated by 5a05b83be196c2f03480373c45c6ec522bc55511

* Changes generated by 42926f644eb35ecfccc50067b295ee652e5eaf4d

* Changes generated by 5a05b83be196c2f03480373c45c6ec522bc55511

* Changes generated by 70cf5af9f9b2ded08ad3edc8e5341a887e06fd67

* Changes generated by b238b32e590ee8661f7d3460842e6c83b9e23474

* Changes generated by af16970bff9d006006e8cad69edd5e4402bdb70d

* Changes generated by 9e4cc2d3e9bc8d4b9d0f9183377407ac66630992

* Changes generated by 043027457162d8b0b8cde59791f627b7b2d01bdd

* Changes generated by 5dc56f9ceb3b969c993494e67c39f76dd3a53a39

* Changes generated by 8847570321f5bc9dd2797afef4bd6b770d784dd4

* Changes generated by db3102d5dfbb0d6581580a5e0926913900074f08

Co-authored-by: Robot <[email protected]>
  • Loading branch information
1 parent 1ef31e7 commit a163d97
Show file tree
Hide file tree
Showing 58 changed files with 334 additions and 202 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ toolchain will resolve and fetch the gocardless-pro-go module automatically.
Alternatively, you can also explicitly `go get` the package into a project:

```
go get -u github.com/gocardless/gocardless-pro-go@v2.0.0
go get -u github.com/gocardless/gocardless-pro-go@v2.1.0
```

## Initializing the client
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0
2.1.0
4 changes: 2 additions & 2 deletions bank_authorisation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *BankAuthorisationServiceImpl) Get(ctx context.Context, identity string,
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)

for key, value := range o.headers {
Expand Down Expand Up @@ -178,7 +178,7 @@ func (s *BankAuthorisationServiceImpl) Create(ctx context.Context, p BankAuthori
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down
2 changes: 1 addition & 1 deletion bank_details_lookup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *BankDetailsLookupServiceImpl) Create(ctx context.Context, p BankDetails
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down
4 changes: 2 additions & 2 deletions billing_request_flow_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *BillingRequestFlowServiceImpl) Create(ctx context.Context, p BillingReq
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down Expand Up @@ -203,7 +203,7 @@ func (s *BillingRequestFlowServiceImpl) Initialise(ctx context.Context, identity
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down
148 changes: 125 additions & 23 deletions billing_request_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ type BillingRequestResources struct {

// BillingRequest model
type BillingRequest struct {
Actions []BillingRequestActions `url:"actions,omitempty" json:"actions,omitempty"`
CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"`
Id string `url:"id,omitempty" json:"id,omitempty"`
Links *BillingRequestLinks `url:"links,omitempty" json:"links,omitempty"`
MandateRequest *BillingRequestMandateRequest `url:"mandate_request,omitempty" json:"mandate_request,omitempty"`
Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"`
PaymentRequest *BillingRequestPaymentRequest `url:"payment_request,omitempty" json:"payment_request,omitempty"`
Resources *BillingRequestResources `url:"resources,omitempty" json:"resources,omitempty"`
Status string `url:"status,omitempty" json:"status,omitempty"`
Actions []BillingRequestActions `url:"actions,omitempty" json:"actions,omitempty"`
CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"`
FallbackEnabled bool `url:"fallback_enabled,omitempty" json:"fallback_enabled,omitempty"`
Id string `url:"id,omitempty" json:"id,omitempty"`
Links *BillingRequestLinks `url:"links,omitempty" json:"links,omitempty"`
MandateRequest *BillingRequestMandateRequest `url:"mandate_request,omitempty" json:"mandate_request,omitempty"`
Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"`
PaymentRequest *BillingRequestPaymentRequest `url:"payment_request,omitempty" json:"payment_request,omitempty"`
Resources *BillingRequestResources `url:"resources,omitempty" json:"resources,omitempty"`
Status string `url:"status,omitempty" json:"status,omitempty"`
}

type BillingRequestService interface {
Expand All @@ -157,6 +158,7 @@ type BillingRequestService interface {
ConfirmPayerDetails(ctx context.Context, identity string, p BillingRequestConfirmPayerDetailsParams, opts ...RequestOption) (*BillingRequest, error)
Cancel(ctx context.Context, identity string, p BillingRequestCancelParams, opts ...RequestOption) (*BillingRequest, error)
Notify(ctx context.Context, identity string, p BillingRequestNotifyParams, opts ...RequestOption) (*BillingRequest, error)
Fallback(ctx context.Context, identity string, p BillingRequestFallbackParams, opts ...RequestOption) (*BillingRequest, error)
}

// BillingRequestListParams parameters
Expand Down Expand Up @@ -219,7 +221,7 @@ func (s *BillingRequestServiceImpl) List(ctx context.Context, p BillingRequestLi
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)

for key, value := range o.headers {
Expand Down Expand Up @@ -328,7 +330,7 @@ func (c *BillingRequestListPagingIterator) Value(ctx context.Context) (*BillingR
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)

for key, value := range o.headers {
Expand Down Expand Up @@ -415,10 +417,11 @@ type BillingRequestCreateParamsPaymentRequest struct {

// BillingRequestCreateParams parameters
type BillingRequestCreateParams struct {
Links *BillingRequestCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"`
MandateRequest *BillingRequestCreateParamsMandateRequest `url:"mandate_request,omitempty" json:"mandate_request,omitempty"`
Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"`
PaymentRequest *BillingRequestCreateParamsPaymentRequest `url:"payment_request,omitempty" json:"payment_request,omitempty"`
FallbackEnabled bool `url:"fallback_enabled,omitempty" json:"fallback_enabled,omitempty"`
Links *BillingRequestCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"`
MandateRequest *BillingRequestCreateParamsMandateRequest `url:"mandate_request,omitempty" json:"mandate_request,omitempty"`
Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"`
PaymentRequest *BillingRequestCreateParamsPaymentRequest `url:"payment_request,omitempty" json:"payment_request,omitempty"`
}

// Create
Expand Down Expand Up @@ -461,7 +464,7 @@ func (s *BillingRequestServiceImpl) Create(ctx context.Context, p BillingRequest
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down Expand Up @@ -543,7 +546,7 @@ func (s *BillingRequestServiceImpl) Get(ctx context.Context, identity string, op
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)

for key, value := range o.headers {
Expand Down Expand Up @@ -672,7 +675,7 @@ func (s *BillingRequestServiceImpl) CollectCustomerDetails(ctx context.Context,
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down Expand Up @@ -786,7 +789,7 @@ func (s *BillingRequestServiceImpl) CollectBankAccount(ctx context.Context, iden
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down Expand Up @@ -886,7 +889,7 @@ func (s *BillingRequestServiceImpl) Fulfil(ctx context.Context, identity string,
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down Expand Up @@ -987,7 +990,7 @@ func (s *BillingRequestServiceImpl) ConfirmPayerDetails(ctx context.Context, ide
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down Expand Up @@ -1087,7 +1090,7 @@ func (s *BillingRequestServiceImpl) Cancel(ctx context.Context, identity string,
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down Expand Up @@ -1189,7 +1192,106 @@ func (s *BillingRequestServiceImpl) Notify(ctx context.Context, identity string,
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)

for key, value := range o.headers {
req.Header.Set(key, value)
}

client := s.config.Client()
if client == nil {
client = http.DefaultClient
}

var result struct {
Err *APIError `json:"error"`
BillingRequest *BillingRequest `json:"billing_requests"`
}

err = try(o.retries, func() error {
res, err := client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()

err = responseErr(res)
if err != nil {
return err
}

err = json.NewDecoder(res.Body).Decode(&result)
if err != nil {
return err
}

if result.Err != nil {
return result.Err
}

return nil
})
if err != nil {
return nil, err
}

if result.BillingRequest == nil {
return nil, errors.New("missing result")
}

return result.BillingRequest, nil
}

// BillingRequestFallbackParams parameters
type BillingRequestFallbackParams struct {
}

// Fallback
// Triggers a fallback from the open-banking flow to direct debit. Note, the
// billing request must have fallback enabled.
func (s *BillingRequestServiceImpl) Fallback(ctx context.Context, identity string, p BillingRequestFallbackParams, opts ...RequestOption) (*BillingRequest, error) {
uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_requests/%v/actions/fallback",
identity))
if err != nil {
return nil, err
}

o := &requestOptions{
retries: 3,
}
for _, opt := range opts {
err := opt(o)
if err != nil {
return nil, err
}
}
if o.idempotencyKey == "" {
o.idempotencyKey = NewIdempotencyKey()
}

var body io.Reader

var buf bytes.Buffer
err = json.NewEncoder(&buf).Encode(map[string]interface{}{
"data": p,
})
if err != nil {
return nil, err
}
body = &buf

req, err := http.NewRequest("POST", uri.String(), body)
if err != nil {
return nil, err
}
req.WithContext(ctx)
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down
28 changes: 28 additions & 0 deletions billing_request_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,31 @@ func TestBillingRequestNotify(t *testing.T) {

}
}

func TestBillingRequestFallback(t *testing.T) {
fixtureFile := "testdata/billing_requests.json"
server := runServer(t, fixtureFile, "fallback")
defer server.Close()

ctx := context.TODO()
client, err := getClient(t, server.URL)
if err != nil {
t.Fatal(err)
}

p := BillingRequestFallbackParams{}

o, err :=
client.BillingRequests.Fallback(
ctx, "ID123", p)

if err != nil {
t.Fatal(err)
}

if o == nil {

t.Fatalf("Expected BillingRequest, got nil")

}
}
10 changes: 5 additions & 5 deletions billing_request_template_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *BillingRequestTemplateServiceImpl) List(ctx context.Context, p BillingR
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)

for key, value := range o.headers {
Expand Down Expand Up @@ -217,7 +217,7 @@ func (c *BillingRequestTemplateListPagingIterator) Value(ctx context.Context) (*
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)

for key, value := range o.headers {
Expand Down Expand Up @@ -309,7 +309,7 @@ func (s *BillingRequestTemplateServiceImpl) Get(ctx context.Context, identity st
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)

for key, value := range o.headers {
Expand Down Expand Up @@ -421,7 +421,7 @@ func (s *BillingRequestTemplateServiceImpl) Create(ctx context.Context, p Billin
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down Expand Up @@ -532,7 +532,7 @@ func (s *BillingRequestTemplateServiceImpl) Update(ctx context.Context, identity
req.Header.Set("Authorization", "Bearer "+s.config.Token())
req.Header.Set("GoCardless-Version", "2015-07-06")
req.Header.Set("GoCardless-Client-Library", "gocardless-pro-go")
req.Header.Set("GoCardless-Client-Version", "2.0.0")
req.Header.Set("GoCardless-Client-Version", "2.1.0")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", o.idempotencyKey)
Expand Down
Loading

0 comments on commit a163d97

Please sign in to comment.