Skip to content

Commit

Permalink
Changes generated by 549624c0b07c73ac50b7117a9af1f2af70e6aa03
Browse files Browse the repository at this point in the history
  • Loading branch information
gocardless-robot committed May 30, 2024
1 parent f3b8118 commit f1c43ba
Show file tree
Hide file tree
Showing 38 changed files with 470 additions and 93 deletions.
17 changes: 12 additions & 5 deletions bank_details_lookup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,24 @@ type BankDetailsLookupService interface {

// BankDetailsLookupCreateParams parameters
type BankDetailsLookupCreateParams struct {
AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"`
BankCode string `url:"bank_code,omitempty" json:"bank_code,omitempty"`
BranchCode string `url:"branch_code,omitempty" json:"branch_code,omitempty"`
CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"`
Iban string `url:"iban,omitempty" json:"iban,omitempty"`
AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"`
AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"`
BankCode string `url:"bank_code,omitempty" json:"bank_code,omitempty"`
BranchCode string `url:"branch_code,omitempty" json:"branch_code,omitempty"`
CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"`
Iban string `url:"iban,omitempty" json:"iban,omitempty"`
}

// Create
// Performs a bank details lookup. As part of the lookup, a modulus check and
// reachability check are performed.
//
// For UK-based bank accounts, where an account holder name is provided (and an
// account number, a sort code or an iban
// are already present), we verify that the account holder name and bank account
// number match the details held by
// the relevant bank.
//
// If your request returns an [error](#api-usage-errors) or the
// `available_debit_schemes`
// attribute is an empty array, you will not be able to collect payments from
Expand Down
34 changes: 21 additions & 13 deletions billing_request_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ type BillingRequestPaymentRequestLinks struct {
}

type BillingRequestPaymentRequest struct {
Amount int `url:"amount,omitempty" json:"amount,omitempty"`
AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"`
Currency string `url:"currency,omitempty" json:"currency,omitempty"`
Description string `url:"description,omitempty" json:"description,omitempty"`
Links *BillingRequestPaymentRequestLinks `url:"links,omitempty" json:"links,omitempty"`
Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"`
Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"`
Amount int `url:"amount,omitempty" json:"amount,omitempty"`
AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"`
Currency string `url:"currency,omitempty" json:"currency,omitempty"`
Description string `url:"description,omitempty" json:"description,omitempty"`
FundsSettlement string `url:"funds_settlement,omitempty" json:"funds_settlement,omitempty"`
Links *BillingRequestPaymentRequestLinks `url:"links,omitempty" json:"links,omitempty"`
Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"`
Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"`
}

type BillingRequestResourcesCustomer struct {
Expand Down Expand Up @@ -227,12 +228,13 @@ type BillingRequestCreateParamsMandateRequest struct {
}

type BillingRequestCreateParamsPaymentRequest struct {
Amount int `url:"amount,omitempty" json:"amount,omitempty"`
AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"`
Currency string `url:"currency,omitempty" json:"currency,omitempty"`
Description string `url:"description,omitempty" json:"description,omitempty"`
Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"`
Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"`
Amount int `url:"amount,omitempty" json:"amount,omitempty"`
AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"`
Currency string `url:"currency,omitempty" json:"currency,omitempty"`
Description string `url:"description,omitempty" json:"description,omitempty"`
FundsSettlement string `url:"funds_settlement,omitempty" json:"funds_settlement,omitempty"`
Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"`
Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"`
}

// BillingRequestCreateParams parameters
Expand Down Expand Up @@ -502,6 +504,12 @@ type BillingRequestCollectBankAccountParams struct {
// Direct Debit. If a bank account is discovered to be closed or invalid, the
// customer is requested to adjust the account number/routing number and
// succeed in this check to continue with the flow.
//
// _BACS scheme_ [Payer Name
// Verification](https://hub.gocardless.com/s/article/Introduction-to-Payer-Name-Verification?language=en_GB)
// is enabled by default for UK based bank accounts, meaning we verify the
// account holder name and bank account
// number match the details held by the relevant bank.
func (s *BillingRequestServiceImpl) CollectBankAccount(ctx context.Context, identity string, p BillingRequestCollectBankAccountParams, opts ...RequestOption) (*BillingRequest, error) {
uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_requests/%v/actions/collect_bank_account",
identity))
Expand Down
6 changes: 6 additions & 0 deletions gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ type Service struct {
Events EventService
InstalmentSchedules InstalmentScheduleService
Institutions InstitutionService
Logos LogoService
Mandates MandateService
MandateImports MandateImportService
MandateImportEntries MandateImportEntryService
MandatePdfs MandatePdfService
NegativeBalanceLimits NegativeBalanceLimitService
PayerAuthorisations PayerAuthorisationService
PayerThemes PayerThemeService
Payments PaymentService
Payouts PayoutService
PayoutItems PayoutItemService
Expand Down Expand Up @@ -82,6 +84,8 @@ func New(config Config) (*Service, error) {
config: config,
}, Institutions: &InstitutionServiceImpl{
config: config,
}, Logos: &LogoServiceImpl{
config: config,
}, Mandates: &MandateServiceImpl{
config: config,
}, MandateImports: &MandateImportServiceImpl{
Expand All @@ -94,6 +98,8 @@ func New(config Config) (*Service, error) {
config: config,
}, PayerAuthorisations: &PayerAuthorisationServiceImpl{
config: config,
}, PayerThemes: &PayerThemeServiceImpl{
config: config,
}, Payments: &PaymentServiceImpl{
config: config,
}, Payouts: &PayoutServiceImpl{
Expand Down
137 changes: 137 additions & 0 deletions logo_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package gocardless

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"

"github.com/google/go-querystring/query"
)

var _ = query.Values
var _ = bytes.NewBuffer
var _ = json.NewDecoder
var _ = errors.New

// LogoService manages logos
type LogoServiceImpl struct {
config Config
}

// Logo model
type Logo struct {
Id string `url:"id,omitempty" json:"id,omitempty"`
}

type LogoService interface {
CreateForCreditor(ctx context.Context, p LogoCreateForCreditorParams, opts ...RequestOption) (*Logo, error)
}

type LogoCreateForCreditorParamsLinks struct {
Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"`
}

// LogoCreateForCreditorParams parameters
type LogoCreateForCreditorParams struct {
Image string `url:"image,omitempty" json:"image,omitempty"`
Links *LogoCreateForCreditorParamsLinks `url:"links,omitempty" json:"links,omitempty"`
}

// CreateForCreditor
// Creates a new logo associated with a creditor. If a creditor already has a
// logo, this will update the existing logo linked to the creditor.
func (s *LogoServiceImpl) CreateForCreditor(ctx context.Context, p LogoCreateForCreditorParams, opts ...RequestOption) (*Logo, error) {
uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/branding/logos"))
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 = 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", "3.9.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"`
Logo *Logo `json:"logos"`
}

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.Logo == nil {
return nil, errors.New("missing result")
}

return result.Logo, nil
}
34 changes: 34 additions & 0 deletions logo_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package gocardless

import (
"context"
"testing"
)

func TestLogoCreateForCreditor(t *testing.T) {
fixtureFile := "testdata/logos.json"
server := runServer(t, fixtureFile, "create_for_creditor")
defer server.Close()

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

p := LogoCreateForCreditorParams{}

o, err :=
client.Logos.CreateForCreditor(
ctx, p)

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

if o == nil {

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

}
}
Loading

0 comments on commit f1c43ba

Please sign in to comment.