diff --git a/README.md b/README.md index f2a11d1..e57d478 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Go Client Library for GoCardless Pro Api +# Go Client Library for GoCardless Pro API [![CircleCI](https://circleci.com/gh/gocardless/gocardless-pro-go-template/tree/master.svg?style=svg&circle-token=68c31e704d9b0020a5f42b4b89b0a77a17bdac6c)](https://circleci.com/gh/gocardless/gocardless-pro-go-template/tree/master) This library provides a simple wrapper around the [GoCardless API](http://developer.gocardless.com/api-reference). @@ -18,7 +18,7 @@ go mod tidy Then, reference gocardless-pro-go in a Go program with `import`: ``` go import ( - gocardless "github.com/gocardless/gocardless-pro-go" + gocardless "github.com/gocardless/gocardless-pro-go/v2" ) ``` @@ -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/v1.0.0 +go get -u github.com/gocardless/gocardless-pro-go@v2.0.0 ``` ## Initializing the client @@ -38,14 +38,31 @@ The client is initialised with an access token, and is configured to use GoCardl ```go token := "your_access_token" - client, err := gocardless.New(token) + config, err := gocardless.NewConfig(token) + if err != nil { + fmt.Printf("got err in initialising config: %s", err.Error()) + return + } + client, err := gocardless.New(config) + if err != nil { + fmt.Printf("error in initialisating client: %s", err.Error()) + return + } ``` Optionally, the client can be customised with endpoint, for ex: sandbox environment ```go - opts := gocardless.WithEndpoint(gocardless.SandboxEndpoint) - client, err := gocardless.New(token, opts) + config, err := gocardless.NewConfig(token, gocardless.WithEndpoint(gocardless.SandboxEndpoint)) + if err != nil { + fmt.Printf("got err in initialising config: %s", err.Error()) + return + } + client, err := gocardless.New(config) + if err != nil { + fmt.Printf("error in initialisating client: %s", err.Error()) + return + } ``` the client can also be initialised with a customised http client, for ex; @@ -53,8 +70,16 @@ the client can also be initialised with a customised http client, for ex; customHttpClient := &http.Client{ Timeout: time.Second * 10, } - opts := gocardless.WithClient(customHttpClient) - client, err := gocardless.New(token, opts) + config, err := gocardless.NewConfig(token, gocardless.WithClient(customHttpClient)) + if err != nil { + fmt.Printf("got err in initialising config: %s", err.Error()) + return + } + client, err := gocardless.New(config) + if err != nil { + fmt.Printf("error in initialisating client: %s", err.Error()) + return + } ``` ## Examples @@ -92,7 +117,7 @@ To fetch items in a collection, there are two options: ```go ctx := context.TODO() customerListParams := gocardless.CustomerListParams{} - customerListIterator := service.Customers.All(ctx, customerListParams) + customerListIterator := client.Customers.All(ctx, customerListParams) for customerListIterator.Next() { customerListResult, err := customerListIterator.Value(ctx) if err != nil { @@ -109,14 +134,15 @@ Resources can be created with the `Create` method: ```go ctx := context.TODO() - customerCreateParams := CustomerCreateParams{} - customerCreateParams.AddressLine1 = "9 Acer Gardens" - customerCreateParams.City = "Birmingham" - customerCreateParams.CountryCode = "GB" - customerCreateParams.Email = "bbr@example.xom" - customerCreateParams.FamilyName = "Rodgriguez" - customerCreateParams.GivenName = "Bender Bending" - customerCreateParams.PostalCode = "B4 7NJ" + customerCreateParams := gocardless.CustomerCreateParams{ + AddressLine1: "9 Acer Gardens" + City: "Birmingham", + PostalCode: "B4 7NJ", + CountryCode: "GB", + Email: "bbr@example.com", + GivenName: "Bender Bending", + FamilyName: "Rodgriguez", + } customer, err := client.Customers.Create(ctx, customerCreateParams) ``` @@ -127,8 +153,9 @@ Resources can be updates with the `Update` method: ```go ctx := context.TODO() - customerUpdateParams := CustomerUpdateParams{} - customerUpdateParams.GivenName = "New name" + customerUpdateParams := CustomerUpdateParams{ + GivenName: "New Name", + } customer, err := client.Customers.Update(ctx, "CU123", customerUpdateParams) ``` @@ -152,7 +179,7 @@ The library will attempt to retry most failing requests automatically (with the ```go requestOption := gocardless.WithoutRetries() - customersCreateResult, err := service.Customers.Create(ctx, customerCreateParams, requestOption) + customersCreateResult, err := client.Customers.Create(ctx, customerCreateParams, requestOption) ``` ### Setting custom headers @@ -163,7 +190,7 @@ in some cases (for example if you want to send an `Accept-Language` header when headers := make(map[string]string) headers["Accept-Language"] = "fr" requestOption := gocardless.WithHeaders(headers) - customersCreateResult, err := service.Customers.Create(ctx, customerCreateParams, requestOption) + customersCreateResult, err := client.Customers.Create(ctx, customerCreateParams, requestOption) ``` Custom headers you specify will override any headers generated by the library itself (for @@ -171,7 +198,7 @@ example, an `Idempotency-Key` header with a randomly-generated value or one you' manually). Custom headers always take precedence. ```go requestOption := gocardless.WithIdempotencyKey("test-idemptency-key-123") - customersCreateResult, err := service.Customers.Create(ctx, customerCreateParams, requestOption) + customersCreateResult, err := client.Customers.Create(ctx, customerCreateParams, requestOption) ``` ### Handling webhooks @@ -197,6 +224,21 @@ The client allows you to validate that a webhook you receive is genuinely from G } ``` +### Error Handling + +When the library returns an `error` defined by us rather than the stdlib, it can be converted into a `gocardless.APIError` using `errors.As`: + +```go + billingRequest, err := client.BillingRequests.Create(ctx, billingRequestCreateParams) + if err != nil { + var apiErr *gocardless.APIError + if errors.As(err, &apiErr) { + fmt.Printf("got err: %v", apiErr.Message) + } + return nil, err + } +``` + ## Compatibility This library requires go 1.16 and above. diff --git a/VERSION b/VERSION index afaf360..359a5b9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 \ No newline at end of file +2.0.0 \ No newline at end of file diff --git a/bank_authorisation_service.go b/bank_authorisation_service.go index 1bb9992..8ee936e 100644 --- a/bank_authorisation_service.go +++ b/bank_authorisation_service.go @@ -19,32 +19,37 @@ var _ = json.NewDecoder var _ = errors.New // BankAuthorisationService manages bank_authorisations -type BankAuthorisationService struct { - endpoint string - token string - client *http.Client +type BankAuthorisationServiceImpl struct { + config Config +} + +type BankAuthorisationLinks struct { + BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` + Institution string `url:"institution,omitempty" json:"institution,omitempty"` } // BankAuthorisation model type BankAuthorisation struct { - AuthorisationType string `url:"authorisation_type,omitempty" json:"authorisation_type,omitempty"` - AuthorisedAt string `url:"authorised_at,omitempty" json:"authorised_at,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - ExpiresAt string `url:"expires_at,omitempty" json:"expires_at,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - LastVisitedAt string `url:"last_visited_at,omitempty" json:"last_visited_at,omitempty"` - Links struct { - BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` - Institution string `url:"institution,omitempty" json:"institution,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` - Url string `url:"url,omitempty" json:"url,omitempty"` + AuthorisationType string `url:"authorisation_type,omitempty" json:"authorisation_type,omitempty"` + AuthorisedAt string `url:"authorised_at,omitempty" json:"authorised_at,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + ExpiresAt string `url:"expires_at,omitempty" json:"expires_at,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + LastVisitedAt string `url:"last_visited_at,omitempty" json:"last_visited_at,omitempty"` + Links *BankAuthorisationLinks `url:"links,omitempty" json:"links,omitempty"` + RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` + Url string `url:"url,omitempty" json:"url,omitempty"` +} + +type BankAuthorisationService interface { + Get(ctx context.Context, identity string, opts ...RequestOption) (*BankAuthorisation, error) + Create(ctx context.Context, p BankAuthorisationCreateParams, opts ...RequestOption) (*BankAuthorisation, error) } // Get // Fetches a bank authorisation -func (s *BankAuthorisationService) Get(ctx context.Context, identity string, opts ...RequestOption) (*BankAuthorisation, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/bank_authorisations/%v", +func (s *BankAuthorisationServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*BankAuthorisation, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/bank_authorisations/%v", identity)) if err != nil { return nil, err @@ -67,17 +72,17 @@ func (s *BankAuthorisationService) Get(ctx context.Context, identity string, opt return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -121,20 +126,22 @@ func (s *BankAuthorisationService) Get(ctx context.Context, identity string, opt return result.BankAuthorisation, nil } +type BankAuthorisationCreateParamsLinks struct { + BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` + Institution string `url:"institution,omitempty" json:"institution,omitempty"` +} + // BankAuthorisationCreateParams parameters type BankAuthorisationCreateParams struct { - AuthorisationType string `url:"authorisation_type,omitempty" json:"authorisation_type,omitempty"` - Links struct { - BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` - Institution string `url:"institution,omitempty" json:"institution,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` + AuthorisationType string `url:"authorisation_type,omitempty" json:"authorisation_type,omitempty"` + Links BankAuthorisationCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` } // Create // Create a Bank Authorisation. -func (s *BankAuthorisationService) Create(ctx context.Context, p BankAuthorisationCreateParams, opts ...RequestOption) (*BankAuthorisation, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/bank_authorisations")) +func (s *BankAuthorisationServiceImpl) Create(ctx context.Context, p BankAuthorisationCreateParams, opts ...RequestOption) (*BankAuthorisation, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/bank_authorisations")) if err != nil { return nil, err } @@ -168,10 +175,10 @@ func (s *BankAuthorisationService) Create(ctx context.Context, p BankAuthorisati return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -180,7 +187,7 @@ func (s *BankAuthorisationService) Create(ctx context.Context, p BankAuthorisati req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/bank_details_lookup_service.go b/bank_details_lookup_service.go index b4770fd..cd9c547 100644 --- a/bank_details_lookup_service.go +++ b/bank_details_lookup_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // BankDetailsLookupService manages bank_details_lookups -type BankDetailsLookupService struct { - endpoint string - token string - client *http.Client +type BankDetailsLookupServiceImpl struct { + config Config } // BankDetailsLookup model @@ -32,6 +30,10 @@ type BankDetailsLookup struct { Bic string `url:"bic,omitempty" json:"bic,omitempty"` } +type BankDetailsLookupService interface { + Create(ctx context.Context, p BankDetailsLookupCreateParams, opts ...RequestOption) (*BankDetailsLookup, error) +} + // BankDetailsLookupCreateParams parameters type BankDetailsLookupCreateParams struct { AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` @@ -60,8 +62,8 @@ type BankDetailsLookupCreateParams struct { // GoCardless for // modulus or reachability checking but not for payment collection, please get // in touch. -func (s *BankDetailsLookupService) Create(ctx context.Context, p BankDetailsLookupCreateParams, opts ...RequestOption) (*BankDetailsLookup, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/bank_details_lookups")) +func (s *BankDetailsLookupServiceImpl) Create(ctx context.Context, p BankDetailsLookupCreateParams, opts ...RequestOption) (*BankDetailsLookup, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/bank_details_lookups")) if err != nil { return nil, err } @@ -95,10 +97,10 @@ func (s *BankDetailsLookupService) Create(ctx context.Context, p BankDetailsLook return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -107,7 +109,7 @@ func (s *BankDetailsLookupService) Create(ctx context.Context, p BankDetailsLook req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/billing_request_flow_service.go b/billing_request_flow_service.go index 5267293..8cdafe4 100644 --- a/billing_request_flow_service.go +++ b/billing_request_flow_service.go @@ -19,45 +19,54 @@ var _ = json.NewDecoder var _ = errors.New // BillingRequestFlowService manages billing_request_flows -type BillingRequestFlowService struct { - endpoint string - token string - client *http.Client +type BillingRequestFlowServiceImpl struct { + config Config +} + +type BillingRequestFlowLinks struct { + BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` } // BillingRequestFlow model type BillingRequestFlow struct { - AuthorisationUrl string `url:"authorisation_url,omitempty" json:"authorisation_url,omitempty"` - AutoFulfil bool `url:"auto_fulfil,omitempty" json:"auto_fulfil,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - ExitUri string `url:"exit_uri,omitempty" json:"exit_uri,omitempty"` - ExpiresAt string `url:"expires_at,omitempty" json:"expires_at,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - LockBankAccount bool `url:"lock_bank_account,omitempty" json:"lock_bank_account,omitempty"` - LockCustomerDetails bool `url:"lock_customer_details,omitempty" json:"lock_customer_details,omitempty"` - RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` - SessionToken string `url:"session_token,omitempty" json:"session_token,omitempty"` + AuthorisationUrl string `url:"authorisation_url,omitempty" json:"authorisation_url,omitempty"` + AutoFulfil bool `url:"auto_fulfil,omitempty" json:"auto_fulfil,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + ExitUri string `url:"exit_uri,omitempty" json:"exit_uri,omitempty"` + ExpiresAt string `url:"expires_at,omitempty" json:"expires_at,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *BillingRequestFlowLinks `url:"links,omitempty" json:"links,omitempty"` + LockBankAccount bool `url:"lock_bank_account,omitempty" json:"lock_bank_account,omitempty"` + LockCustomerDetails bool `url:"lock_customer_details,omitempty" json:"lock_customer_details,omitempty"` + RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` + SessionToken string `url:"session_token,omitempty" json:"session_token,omitempty"` + ShowRedirectButtons bool `url:"show_redirect_buttons,omitempty" json:"show_redirect_buttons,omitempty"` +} + +type BillingRequestFlowService interface { + Create(ctx context.Context, p BillingRequestFlowCreateParams, opts ...RequestOption) (*BillingRequestFlow, error) + Initialise(ctx context.Context, identity string, p BillingRequestFlowInitialiseParams, opts ...RequestOption) (*BillingRequestFlow, error) +} + +type BillingRequestFlowCreateParamsLinks struct { + BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` } // BillingRequestFlowCreateParams parameters type BillingRequestFlowCreateParams struct { - AutoFulfil bool `url:"auto_fulfil,omitempty" json:"auto_fulfil,omitempty"` - ExitUri string `url:"exit_uri,omitempty" json:"exit_uri,omitempty"` - Links struct { - BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - LockBankAccount bool `url:"lock_bank_account,omitempty" json:"lock_bank_account,omitempty"` - LockCustomerDetails bool `url:"lock_customer_details,omitempty" json:"lock_customer_details,omitempty"` - RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` + AutoFulfil bool `url:"auto_fulfil,omitempty" json:"auto_fulfil,omitempty"` + ExitUri string `url:"exit_uri,omitempty" json:"exit_uri,omitempty"` + Links BillingRequestFlowCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + LockBankAccount bool `url:"lock_bank_account,omitempty" json:"lock_bank_account,omitempty"` + LockCustomerDetails bool `url:"lock_customer_details,omitempty" json:"lock_customer_details,omitempty"` + RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` + ShowRedirectButtons bool `url:"show_redirect_buttons,omitempty" json:"show_redirect_buttons,omitempty"` } // Create // Creates a new billing request flow. -func (s *BillingRequestFlowService) Create(ctx context.Context, p BillingRequestFlowCreateParams, opts ...RequestOption) (*BillingRequestFlow, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/billing_request_flows")) +func (s *BillingRequestFlowServiceImpl) Create(ctx context.Context, p BillingRequestFlowCreateParams, opts ...RequestOption) (*BillingRequestFlow, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/billing_request_flows")) if err != nil { return nil, err } @@ -91,10 +100,10 @@ func (s *BillingRequestFlowService) Create(ctx context.Context, p BillingRequest return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -103,7 +112,7 @@ func (s *BillingRequestFlowService) Create(ctx context.Context, p BillingRequest req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -148,14 +157,15 @@ func (s *BillingRequestFlowService) Create(ctx context.Context, p BillingRequest } // BillingRequestFlowInitialiseParams parameters -type BillingRequestFlowInitialiseParams struct{} +type BillingRequestFlowInitialiseParams struct { +} // Initialise // Returns the flow having generated a fresh session token which can be used to // power // integrations that manipulate the flow. -func (s *BillingRequestFlowService) Initialise(ctx context.Context, identity string, p BillingRequestFlowInitialiseParams, opts ...RequestOption) (*BillingRequestFlow, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_request_flows/%v/actions/initialise", +func (s *BillingRequestFlowServiceImpl) Initialise(ctx context.Context, identity string, p BillingRequestFlowInitialiseParams, opts ...RequestOption) (*BillingRequestFlow, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_request_flows/%v/actions/initialise", identity)) if err != nil { return nil, err @@ -190,10 +200,10 @@ func (s *BillingRequestFlowService) Initialise(ctx context.Context, identity str return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -202,7 +212,7 @@ func (s *BillingRequestFlowService) Initialise(ctx context.Context, identity str req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/billing_request_service.go b/billing_request_service.go index d6c0ab3..5574e56 100644 --- a/billing_request_service.go +++ b/billing_request_service.go @@ -19,105 +19,144 @@ var _ = json.NewDecoder var _ = errors.New // BillingRequestService manages billing_requests -type BillingRequestService struct { - endpoint string - token string - client *http.Client +type BillingRequestServiceImpl struct { + config Config +} + +type BillingRequestActionsBankAuthorisation struct { + Adapter string `url:"adapter,omitempty" json:"adapter,omitempty"` + AuthorisationType string `url:"authorisation_type,omitempty" json:"authorisation_type,omitempty"` + RequiresInstitution bool `url:"requires_institution,omitempty" json:"requires_institution,omitempty"` +} + +type BillingRequestActionsCollectCustomerDetails struct { + DefaultCountryCode string `url:"default_country_code,omitempty" json:"default_country_code,omitempty"` +} + +type BillingRequestActions struct { + BankAuthorisation *BillingRequestActionsBankAuthorisation `url:"bank_authorisation,omitempty" json:"bank_authorisation,omitempty"` + CollectCustomerDetails *BillingRequestActionsCollectCustomerDetails `url:"collect_customer_details,omitempty" json:"collect_customer_details,omitempty"` + CompletesActions []string `url:"completes_actions,omitempty" json:"completes_actions,omitempty"` + Required bool `url:"required,omitempty" json:"required,omitempty"` + RequiresActions []string `url:"requires_actions,omitempty" json:"requires_actions,omitempty"` + Status string `url:"status,omitempty" json:"status,omitempty"` + Type string `url:"type,omitempty" json:"type,omitempty"` +} + +type BillingRequestLinks struct { + BankAuthorisation string `url:"bank_authorisation,omitempty" json:"bank_authorisation,omitempty"` + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` + CustomerBillingDetail string `url:"customer_billing_detail,omitempty" json:"customer_billing_detail,omitempty"` + MandateRequest string `url:"mandate_request,omitempty" json:"mandate_request,omitempty"` + MandateRequestMandate string `url:"mandate_request_mandate,omitempty" json:"mandate_request_mandate,omitempty"` + PaymentRequest string `url:"payment_request,omitempty" json:"payment_request,omitempty"` + PaymentRequestPayment string `url:"payment_request_payment,omitempty" json:"payment_request_payment,omitempty"` +} + +type BillingRequestMandateRequestLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` +} + +type BillingRequestMandateRequest struct { + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Links *BillingRequestMandateRequestLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` + Verify string `url:"verify,omitempty" json:"verify,omitempty"` +} + +type BillingRequestPaymentRequestLinks struct { + Payment string `url:"payment,omitempty" json:"payment,omitempty"` +} + +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"` +} + +type BillingRequestResourcesCustomer struct { + CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Email string `url:"email,omitempty" json:"email,omitempty"` + FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` + GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Language string `url:"language,omitempty" json:"language,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` +} + +type BillingRequestResourcesCustomerBankAccountLinks struct { + Customer string `url:"customer,omitempty" json:"customer,omitempty"` +} + +type BillingRequestResourcesCustomerBankAccount struct { + AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` + AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` + AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` + BankName string `url:"bank_name,omitempty" json:"bank_name,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *BillingRequestResourcesCustomerBankAccountLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` +} + +type BillingRequestResourcesCustomerBillingDetail struct { + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + IpAddress string `url:"ip_address,omitempty" json:"ip_address,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + Schemes []string `url:"schemes,omitempty" json:"schemes,omitempty"` + SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` +} + +type BillingRequestResources struct { + Customer *BillingRequestResourcesCustomer `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBankAccount *BillingRequestResourcesCustomerBankAccount `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` + CustomerBillingDetail *BillingRequestResourcesCustomerBillingDetail `url:"customer_billing_detail,omitempty" json:"customer_billing_detail,omitempty"` } // BillingRequest model type BillingRequest struct { - Actions []struct { - BankAuthorisation struct { - Adapter string `url:"adapter,omitempty" json:"adapter,omitempty"` - AuthorisationType string `url:"authorisation_type,omitempty" json:"authorisation_type,omitempty"` - RequiresInstitution bool `url:"requires_institution,omitempty" json:"requires_institution,omitempty"` - } `url:"bank_authorisation,omitempty" json:"bank_authorisation,omitempty"` - CollectCustomerDetails struct { - DefaultCountryCode string `url:"default_country_code,omitempty" json:"default_country_code,omitempty"` - } `url:"collect_customer_details,omitempty" json:"collect_customer_details,omitempty"` - CompletesActions []string `url:"completes_actions,omitempty" json:"completes_actions,omitempty"` - Required bool `url:"required,omitempty" json:"required,omitempty"` - RequiresActions []string `url:"requires_actions,omitempty" json:"requires_actions,omitempty"` - Status string `url:"status,omitempty" json:"status,omitempty"` - Type string `url:"type,omitempty" json:"type,omitempty"` - } `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 struct { - BankAuthorisation string `url:"bank_authorisation,omitempty" json:"bank_authorisation,omitempty"` - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` - CustomerBillingDetail string `url:"customer_billing_detail,omitempty" json:"customer_billing_detail,omitempty"` - MandateRequest string `url:"mandate_request,omitempty" json:"mandate_request,omitempty"` - MandateRequestMandate string `url:"mandate_request_mandate,omitempty" json:"mandate_request_mandate,omitempty"` - PaymentRequest string `url:"payment_request,omitempty" json:"payment_request,omitempty"` - PaymentRequestPayment string `url:"payment_request_payment,omitempty" json:"payment_request_payment,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - MandateRequest struct { - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - Verify string `url:"verify,omitempty" json:"verify,omitempty"` - } `url:"mandate_request,omitempty" json:"mandate_request,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PaymentRequest 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 struct { - Payment string `url:"payment,omitempty" json:"payment,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - } `url:"payment_request,omitempty" json:"payment_request,omitempty"` - Resources struct { - Customer struct { - CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Email string `url:"email,omitempty" json:"email,omitempty"` - FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` - GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Language string `url:"language,omitempty" json:"language,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` - } `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBankAccount struct { - AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` - AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` - AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` - BankName string `url:"bank_name,omitempty" json:"bank_name,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - } `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` - CustomerBillingDetail struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - IpAddress string `url:"ip_address,omitempty" json:"ip_address,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - Schemes []string `url:"schemes,omitempty" json:"schemes,omitempty"` - SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` - } `url:"customer_billing_detail,omitempty" json:"customer_billing_detail,omitempty"` - } `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"` + 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 { + List(ctx context.Context, p BillingRequestListParams, opts ...RequestOption) (*BillingRequestListResult, error) + All(ctx context.Context, p BillingRequestListParams, opts ...RequestOption) *BillingRequestListPagingIterator + Create(ctx context.Context, p BillingRequestCreateParams, opts ...RequestOption) (*BillingRequest, error) + Get(ctx context.Context, identity string, opts ...RequestOption) (*BillingRequest, error) + CollectCustomerDetails(ctx context.Context, identity string, p BillingRequestCollectCustomerDetailsParams, opts ...RequestOption) (*BillingRequest, error) + CollectBankAccount(ctx context.Context, identity string, p BillingRequestCollectBankAccountParams, opts ...RequestOption) (*BillingRequest, error) + Fulfil(ctx context.Context, identity string, p BillingRequestFulfilParams, opts ...RequestOption) (*BillingRequest, error) + 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) } // BillingRequestListParams parameters @@ -130,23 +169,26 @@ type BillingRequestListParams struct { Status string `url:"status,omitempty" json:"status,omitempty"` } -// BillingRequestListResult response including pagination metadata +type BillingRequestListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type BillingRequestListResultMeta struct { + Cursors *BillingRequestListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + type BillingRequestListResult struct { - BillingRequests []BillingRequest `json:"billing_requests"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + BillingRequests []BillingRequest `json:"billing_requests"` + Meta BillingRequestListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your -// billing_requests. -func (s *BillingRequestService) List(ctx context.Context, p BillingRequestListParams, opts ...RequestOption) (*BillingRequestListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/billing_requests")) +// billing requests. +func (s *BillingRequestServiceImpl) List(ctx context.Context, p BillingRequestListParams, opts ...RequestOption) (*BillingRequestListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/billing_requests")) if err != nil { return nil, err } @@ -174,17 +216,17 @@ func (s *BillingRequestService) List(ctx context.Context, p BillingRequestListPa return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -232,7 +274,7 @@ type BillingRequestListPagingIterator struct { cursor string response *BillingRequestListResult params BillingRequestListParams - service *BillingRequestService + service *BillingRequestServiceImpl requestOptions []RequestOption } @@ -253,7 +295,7 @@ func (c *BillingRequestListPagingIterator) Value(ctx context.Context) (*BillingR p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/billing_requests")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/billing_requests")) if err != nil { return nil, err @@ -283,16 +325,16 @@ func (c *BillingRequestListPagingIterator) Value(ctx context.Context) (*BillingR } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -339,7 +381,7 @@ func (c *BillingRequestListPagingIterator) Value(ctx context.Context) (*BillingR return c.response, nil } -func (s *BillingRequestService) All(ctx context.Context, +func (s *BillingRequestServiceImpl) All(ctx context.Context, p BillingRequestListParams, opts ...RequestOption) *BillingRequestListPagingIterator { return &BillingRequestListPagingIterator{ @@ -349,31 +391,40 @@ func (s *BillingRequestService) All(ctx context.Context, } } +type BillingRequestCreateParamsLinks struct { + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` +} + +type BillingRequestCreateParamsMandateRequest struct { + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` + Verify string `url:"verify,omitempty" json:"verify,omitempty"` +} + +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"` +} + // BillingRequestCreateParams parameters type BillingRequestCreateParams struct { - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - MandateRequest struct { - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - } `url:"mandate_request,omitempty" json:"mandate_request,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PaymentRequest 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"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - } `url:"payment_request,omitempty" json:"payment_request,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 // -func (s *BillingRequestService) Create(ctx context.Context, p BillingRequestCreateParams, opts ...RequestOption) (*BillingRequest, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/billing_requests")) +func (s *BillingRequestServiceImpl) Create(ctx context.Context, p BillingRequestCreateParams, opts ...RequestOption) (*BillingRequest, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/billing_requests")) if err != nil { return nil, err } @@ -407,10 +458,10 @@ func (s *BillingRequestService) Create(ctx context.Context, p BillingRequestCrea return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -419,7 +470,7 @@ func (s *BillingRequestService) Create(ctx context.Context, p BillingRequestCrea req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -465,8 +516,8 @@ func (s *BillingRequestService) Create(ctx context.Context, p BillingRequestCrea // Get // Fetches a billing request -func (s *BillingRequestService) Get(ctx context.Context, identity string, opts ...RequestOption) (*BillingRequest, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_requests/%v", +func (s *BillingRequestServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*BillingRequest, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_requests/%v", identity)) if err != nil { return nil, err @@ -489,17 +540,17 @@ func (s *BillingRequestService) Get(ctx context.Context, identity string, opts . return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -543,28 +594,32 @@ func (s *BillingRequestService) Get(ctx context.Context, identity string, opts . return result.BillingRequest, nil } +type BillingRequestCollectCustomerDetailsParamsCustomer struct { + CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` + Email string `url:"email,omitempty" json:"email,omitempty"` + FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` + GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` + Language string `url:"language,omitempty" json:"language,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` +} + +type BillingRequestCollectCustomerDetailsParamsCustomerBillingDetail struct { + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` +} + // BillingRequestCollectCustomerDetailsParams parameters type BillingRequestCollectCustomerDetailsParams struct { - Customer struct { - CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` - Email string `url:"email,omitempty" json:"email,omitempty"` - FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` - GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` - Language string `url:"language,omitempty" json:"language,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` - } `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBillingDetail struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` - } `url:"customer_billing_detail,omitempty" json:"customer_billing_detail,omitempty"` + Customer *BillingRequestCollectCustomerDetailsParamsCustomer `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBillingDetail *BillingRequestCollectCustomerDetailsParamsCustomerBillingDetail `url:"customer_billing_detail,omitempty" json:"customer_billing_detail,omitempty"` } // CollectCustomerDetails @@ -578,8 +633,8 @@ type BillingRequestCollectCustomerDetailsParams struct { // Whatever is provided to this endpoint is used to update the referenced // customer, and will take effect immediately after the request is // successful. -func (s *BillingRequestService) CollectCustomerDetails(ctx context.Context, identity string, p BillingRequestCollectCustomerDetailsParams, opts ...RequestOption) (*BillingRequest, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_requests/%v/actions/collect_customer_details", +func (s *BillingRequestServiceImpl) CollectCustomerDetails(ctx context.Context, identity string, p BillingRequestCollectCustomerDetailsParams, opts ...RequestOption) (*BillingRequest, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_requests/%v/actions/collect_customer_details", identity)) if err != nil { return nil, err @@ -614,10 +669,10 @@ func (s *BillingRequestService) CollectCustomerDetails(ctx context.Context, iden return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -626,7 +681,7 @@ func (s *BillingRequestService) CollectCustomerDetails(ctx context.Context, iden req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -692,8 +747,8 @@ type BillingRequestCollectBankAccountParams struct { // The endpoint takes the same payload as Customer Bank Accounts, but check // the bank account is valid for the billing request scheme before creating // and attaching it. -func (s *BillingRequestService) CollectBankAccount(ctx context.Context, identity string, p BillingRequestCollectBankAccountParams, opts ...RequestOption) (*BillingRequest, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_requests/%v/actions/collect_bank_account", +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)) if err != nil { return nil, err @@ -728,10 +783,10 @@ func (s *BillingRequestService) CollectBankAccount(ctx context.Context, identity return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -740,7 +795,7 @@ func (s *BillingRequestService) CollectBankAccount(ctx context.Context, identity req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -792,8 +847,8 @@ type BillingRequestFulfilParams struct { // Fulfil // If a billing request is ready to be fulfilled, call this endpoint to cause // it to fulfil, executing the payment. -func (s *BillingRequestService) Fulfil(ctx context.Context, identity string, p BillingRequestFulfilParams, opts ...RequestOption) (*BillingRequest, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_requests/%v/actions/fulfil", +func (s *BillingRequestServiceImpl) Fulfil(ctx context.Context, identity string, p BillingRequestFulfilParams, opts ...RequestOption) (*BillingRequest, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_requests/%v/actions/fulfil", identity)) if err != nil { return nil, err @@ -828,10 +883,10 @@ func (s *BillingRequestService) Fulfil(ctx context.Context, identity string, p B return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -840,7 +895,7 @@ func (s *BillingRequestService) Fulfil(ctx context.Context, identity string, p B req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -890,11 +945,11 @@ type BillingRequestConfirmPayerDetailsParams struct { } // ConfirmPayerDetails -// This is needed when you have mandate_request. As a scheme compliance rule we -// are required to +// This is needed when you have a mandate request. As a scheme compliance rule +// we are required to // allow the payer to crosscheck the details entered by them and confirm it. -func (s *BillingRequestService) ConfirmPayerDetails(ctx context.Context, identity string, p BillingRequestConfirmPayerDetailsParams, opts ...RequestOption) (*BillingRequest, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_requests/%v/actions/confirm_payer_details", +func (s *BillingRequestServiceImpl) ConfirmPayerDetails(ctx context.Context, identity string, p BillingRequestConfirmPayerDetailsParams, opts ...RequestOption) (*BillingRequest, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_requests/%v/actions/confirm_payer_details", identity)) if err != nil { return nil, err @@ -929,10 +984,10 @@ func (s *BillingRequestService) ConfirmPayerDetails(ctx context.Context, identit return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -941,7 +996,7 @@ func (s *BillingRequestService) ConfirmPayerDetails(ctx context.Context, identit req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -993,8 +1048,8 @@ type BillingRequestCancelParams struct { // Cancel // Immediately cancels a billing request, causing all billing request flows // to expire. -func (s *BillingRequestService) Cancel(ctx context.Context, identity string, p BillingRequestCancelParams, opts ...RequestOption) (*BillingRequest, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_requests/%v/actions/cancel", +func (s *BillingRequestServiceImpl) Cancel(ctx context.Context, identity string, p BillingRequestCancelParams, opts ...RequestOption) (*BillingRequest, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_requests/%v/actions/cancel", identity)) if err != nil { return nil, err @@ -1029,10 +1084,10 @@ func (s *BillingRequestService) Cancel(ctx context.Context, identity string, p B return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -1041,7 +1096,7 @@ func (s *BillingRequestService) Cancel(ctx context.Context, identity string, p B req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -1095,8 +1150,8 @@ type BillingRequestNotifyParams struct { // Notifies the customer linked to the billing request, asking them to authorise // it. // Currently, the customer can only be notified by email. -func (s *BillingRequestService) Notify(ctx context.Context, identity string, p BillingRequestNotifyParams, opts ...RequestOption) (*BillingRequest, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_requests/%v/actions/notify", +func (s *BillingRequestServiceImpl) Notify(ctx context.Context, identity string, p BillingRequestNotifyParams, opts ...RequestOption) (*BillingRequest, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_requests/%v/actions/notify", identity)) if err != nil { return nil, err @@ -1131,10 +1186,10 @@ func (s *BillingRequestService) Notify(ctx context.Context, identity string, p B return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -1143,7 +1198,7 @@ func (s *BillingRequestService) Notify(ctx context.Context, identity string, p B req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/billing_request_template_service.go b/billing_request_template_service.go index 9886384..9f503e6 100644 --- a/billing_request_template_service.go +++ b/billing_request_template_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // BillingRequestTemplateService manages billing_request_templates -type BillingRequestTemplateService struct { - endpoint string - token string - client *http.Client +type BillingRequestTemplateServiceImpl struct { + config Config } // BillingRequestTemplate model @@ -45,6 +43,14 @@ type BillingRequestTemplate struct { UpdatedAt string `url:"updated_at,omitempty" json:"updated_at,omitempty"` } +type BillingRequestTemplateService interface { + List(ctx context.Context, p BillingRequestTemplateListParams, opts ...RequestOption) (*BillingRequestTemplateListResult, error) + All(ctx context.Context, p BillingRequestTemplateListParams, opts ...RequestOption) *BillingRequestTemplateListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*BillingRequestTemplate, error) + Create(ctx context.Context, p BillingRequestTemplateCreateParams, opts ...RequestOption) (*BillingRequestTemplate, error) + Update(ctx context.Context, identity string, p BillingRequestTemplateUpdateParams, opts ...RequestOption) (*BillingRequestTemplate, error) +} + // BillingRequestTemplateListParams parameters type BillingRequestTemplateListParams struct { After string `url:"after,omitempty" json:"after,omitempty"` @@ -52,23 +58,26 @@ type BillingRequestTemplateListParams struct { Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// BillingRequestTemplateListResult response including pagination metadata +type BillingRequestTemplateListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type BillingRequestTemplateListResultMeta struct { + Cursors *BillingRequestTemplateListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + type BillingRequestTemplateListResult struct { - BillingRequestTemplates []BillingRequestTemplate `json:"billing_request_templates"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + BillingRequestTemplates []BillingRequestTemplate `json:"billing_request_templates"` + Meta BillingRequestTemplateListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // Billing Request Templates. -func (s *BillingRequestTemplateService) List(ctx context.Context, p BillingRequestTemplateListParams, opts ...RequestOption) (*BillingRequestTemplateListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/billing_request_templates")) +func (s *BillingRequestTemplateServiceImpl) List(ctx context.Context, p BillingRequestTemplateListParams, opts ...RequestOption) (*BillingRequestTemplateListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/billing_request_templates")) if err != nil { return nil, err } @@ -96,17 +105,17 @@ func (s *BillingRequestTemplateService) List(ctx context.Context, p BillingReque return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -154,7 +163,7 @@ type BillingRequestTemplateListPagingIterator struct { cursor string response *BillingRequestTemplateListResult params BillingRequestTemplateListParams - service *BillingRequestTemplateService + service *BillingRequestTemplateServiceImpl requestOptions []RequestOption } @@ -175,7 +184,7 @@ func (c *BillingRequestTemplateListPagingIterator) Value(ctx context.Context) (* p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/billing_request_templates")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/billing_request_templates")) if err != nil { return nil, err @@ -205,16 +214,16 @@ func (c *BillingRequestTemplateListPagingIterator) Value(ctx context.Context) (* } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -261,7 +270,7 @@ func (c *BillingRequestTemplateListPagingIterator) Value(ctx context.Context) (* return c.response, nil } -func (s *BillingRequestTemplateService) All(ctx context.Context, +func (s *BillingRequestTemplateServiceImpl) All(ctx context.Context, p BillingRequestTemplateListParams, opts ...RequestOption) *BillingRequestTemplateListPagingIterator { return &BillingRequestTemplateListPagingIterator{ @@ -273,8 +282,8 @@ func (s *BillingRequestTemplateService) All(ctx context.Context, // Get // Fetches a Billing Request Template -func (s *BillingRequestTemplateService) Get(ctx context.Context, identity string, opts ...RequestOption) (*BillingRequestTemplate, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_request_templates/%v", +func (s *BillingRequestTemplateServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*BillingRequestTemplate, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_request_templates/%v", identity)) if err != nil { return nil, err @@ -297,17 +306,17 @@ func (s *BillingRequestTemplateService) Get(ctx context.Context, identity string return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -351,29 +360,31 @@ func (s *BillingRequestTemplateService) Get(ctx context.Context, identity string return result.BillingRequestTemplate, nil } +type BillingRequestTemplateCreateParamsLinks struct { + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` +} + // BillingRequestTemplateCreateParams parameters type BillingRequestTemplateCreateParams struct { - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - MandateRequestCurrency string `url:"mandate_request_currency,omitempty" json:"mandate_request_currency,omitempty"` - MandateRequestMetadata map[string]interface{} `url:"mandate_request_metadata,omitempty" json:"mandate_request_metadata,omitempty"` - MandateRequestScheme string `url:"mandate_request_scheme,omitempty" json:"mandate_request_scheme,omitempty"` - MandateRequestVerify string `url:"mandate_request_verify,omitempty" json:"mandate_request_verify,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` - PaymentRequestAmount int `url:"payment_request_amount,omitempty" json:"payment_request_amount,omitempty"` - PaymentRequestCurrency string `url:"payment_request_currency,omitempty" json:"payment_request_currency,omitempty"` - PaymentRequestDescription string `url:"payment_request_description,omitempty" json:"payment_request_description,omitempty"` - PaymentRequestMetadata map[string]interface{} `url:"payment_request_metadata,omitempty" json:"payment_request_metadata,omitempty"` - PaymentRequestScheme string `url:"payment_request_scheme,omitempty" json:"payment_request_scheme,omitempty"` - RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` + Links *BillingRequestTemplateCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + MandateRequestCurrency string `url:"mandate_request_currency,omitempty" json:"mandate_request_currency,omitempty"` + MandateRequestMetadata map[string]interface{} `url:"mandate_request_metadata,omitempty" json:"mandate_request_metadata,omitempty"` + MandateRequestScheme string `url:"mandate_request_scheme,omitempty" json:"mandate_request_scheme,omitempty"` + MandateRequestVerify string `url:"mandate_request_verify,omitempty" json:"mandate_request_verify,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + PaymentRequestAmount int `url:"payment_request_amount,omitempty" json:"payment_request_amount,omitempty"` + PaymentRequestCurrency string `url:"payment_request_currency,omitempty" json:"payment_request_currency,omitempty"` + PaymentRequestDescription string `url:"payment_request_description,omitempty" json:"payment_request_description,omitempty"` + PaymentRequestMetadata map[string]interface{} `url:"payment_request_metadata,omitempty" json:"payment_request_metadata,omitempty"` + PaymentRequestScheme string `url:"payment_request_scheme,omitempty" json:"payment_request_scheme,omitempty"` + RedirectUri string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"` } // Create // -func (s *BillingRequestTemplateService) Create(ctx context.Context, p BillingRequestTemplateCreateParams, opts ...RequestOption) (*BillingRequestTemplate, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/billing_request_templates")) +func (s *BillingRequestTemplateServiceImpl) Create(ctx context.Context, p BillingRequestTemplateCreateParams, opts ...RequestOption) (*BillingRequestTemplate, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/billing_request_templates")) if err != nil { return nil, err } @@ -407,10 +418,10 @@ func (s *BillingRequestTemplateService) Create(ctx context.Context, p BillingReq return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -419,7 +430,7 @@ func (s *BillingRequestTemplateService) Create(ctx context.Context, p BillingReq req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -482,8 +493,8 @@ type BillingRequestTemplateUpdateParams struct { // Update // Updates a Billing Request Template, which will affect all future Billing // Requests created by this template. -func (s *BillingRequestTemplateService) Update(ctx context.Context, identity string, p BillingRequestTemplateUpdateParams, opts ...RequestOption) (*BillingRequestTemplate, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/billing_request_templates/%v", +func (s *BillingRequestTemplateServiceImpl) Update(ctx context.Context, identity string, p BillingRequestTemplateUpdateParams, opts ...RequestOption) (*BillingRequestTemplate, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/billing_request_templates/%v", identity)) if err != nil { return nil, err @@ -518,10 +529,10 @@ func (s *BillingRequestTemplateService) Update(ctx context.Context, identity str return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -530,7 +541,7 @@ func (s *BillingRequestTemplateService) Update(ctx context.Context, identity str req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/block_service.go b/block_service.go index 2a6f684..1ff49dd 100644 --- a/block_service.go +++ b/block_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // BlockService manages blocks -type BlockService struct { - endpoint string - token string - client *http.Client +type BlockServiceImpl struct { + config Config } // Block model @@ -37,6 +35,17 @@ type Block struct { UpdatedAt string `url:"updated_at,omitempty" json:"updated_at,omitempty"` } +type BlockService interface { + Create(ctx context.Context, p BlockCreateParams, opts ...RequestOption) (*Block, error) + Get(ctx context.Context, identity string, opts ...RequestOption) (*Block, error) + List(ctx context.Context, p BlockListParams, opts ...RequestOption) (*BlockListResult, error) + All(ctx context.Context, p BlockListParams, opts ...RequestOption) *BlockListPagingIterator + Disable(ctx context.Context, identity string, opts ...RequestOption) (*Block, error) + Enable(ctx context.Context, identity string, opts ...RequestOption) (*Block, error) + BlockByRef(ctx context.Context, p BlockBlockByRefParams, opts ...RequestOption) ( + *BlockBlockByRefResult, error) +} + // BlockCreateParams parameters type BlockCreateParams struct { Active bool `url:"active,omitempty" json:"active,omitempty"` @@ -48,8 +57,8 @@ type BlockCreateParams struct { // Create // Creates a new Block of a given type. By default it will be active. -func (s *BlockService) Create(ctx context.Context, p BlockCreateParams, opts ...RequestOption) (*Block, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/blocks")) +func (s *BlockServiceImpl) Create(ctx context.Context, p BlockCreateParams, opts ...RequestOption) (*Block, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/blocks")) if err != nil { return nil, err } @@ -83,10 +92,10 @@ func (s *BlockService) Create(ctx context.Context, p BlockCreateParams, opts ... return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -95,7 +104,7 @@ func (s *BlockService) Create(ctx context.Context, p BlockCreateParams, opts ... req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -141,8 +150,8 @@ func (s *BlockService) Create(ctx context.Context, p BlockCreateParams, opts ... // Get // Retrieves the details of an existing block. -func (s *BlockService) Get(ctx context.Context, identity string, opts ...RequestOption) (*Block, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/blocks/%v", +func (s *BlockServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*Block, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/blocks/%v", identity)) if err != nil { return nil, err @@ -165,17 +174,17 @@ func (s *BlockService) Get(ctx context.Context, identity string, opts ...Request return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -231,23 +240,26 @@ type BlockListParams struct { UpdatedAt string `url:"updated_at,omitempty" json:"updated_at,omitempty"` } -// BlockListResult response including pagination metadata +type BlockListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type BlockListResultMeta struct { + Cursors *BlockListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + type BlockListResult struct { - Blocks []Block `json:"blocks"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Blocks []Block `json:"blocks"` + Meta BlockListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // blocks. -func (s *BlockService) List(ctx context.Context, p BlockListParams, opts ...RequestOption) (*BlockListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/blocks")) +func (s *BlockServiceImpl) List(ctx context.Context, p BlockListParams, opts ...RequestOption) (*BlockListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/blocks")) if err != nil { return nil, err } @@ -275,17 +287,17 @@ func (s *BlockService) List(ctx context.Context, p BlockListParams, opts ...Requ return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -333,7 +345,7 @@ type BlockListPagingIterator struct { cursor string response *BlockListResult params BlockListParams - service *BlockService + service *BlockServiceImpl requestOptions []RequestOption } @@ -354,7 +366,7 @@ func (c *BlockListPagingIterator) Value(ctx context.Context) (*BlockListResult, p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/blocks")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/blocks")) if err != nil { return nil, err @@ -384,16 +396,16 @@ func (c *BlockListPagingIterator) Value(ctx context.Context) (*BlockListResult, } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -440,7 +452,7 @@ func (c *BlockListPagingIterator) Value(ctx context.Context) (*BlockListResult, return c.response, nil } -func (s *BlockService) All(ctx context.Context, +func (s *BlockServiceImpl) All(ctx context.Context, p BlockListParams, opts ...RequestOption) *BlockListPagingIterator { return &BlockListPagingIterator{ @@ -452,8 +464,8 @@ func (s *BlockService) All(ctx context.Context, // Disable // Disables a block so that it no longer will prevent mandate creation. -func (s *BlockService) Disable(ctx context.Context, identity string, opts ...RequestOption) (*Block, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/blocks/%v/actions/disable", +func (s *BlockServiceImpl) Disable(ctx context.Context, identity string, opts ...RequestOption) (*Block, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/blocks/%v/actions/disable", identity)) if err != nil { return nil, err @@ -479,10 +491,10 @@ func (s *BlockService) Disable(ctx context.Context, identity string, opts ...Req return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -491,7 +503,7 @@ func (s *BlockService) Disable(ctx context.Context, identity string, opts ...Req req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -537,8 +549,8 @@ func (s *BlockService) Disable(ctx context.Context, identity string, opts ...Req // Enable // Enables a previously disabled block so that it will prevent mandate creation -func (s *BlockService) Enable(ctx context.Context, identity string, opts ...RequestOption) (*Block, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/blocks/%v/actions/enable", +func (s *BlockServiceImpl) Enable(ctx context.Context, identity string, opts ...RequestOption) (*Block, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/blocks/%v/actions/enable", identity)) if err != nil { return nil, err @@ -564,10 +576,10 @@ func (s *BlockService) Enable(ctx context.Context, identity string, opts ...Requ return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -576,7 +588,7 @@ func (s *BlockService) Enable(ctx context.Context, identity string, opts ...Requ req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -628,24 +640,20 @@ type BlockBlockByRefParams struct { ReferenceType string `url:"reference_type,omitempty" json:"reference_type,omitempty"` ReferenceValue string `url:"reference_value,omitempty" json:"reference_value,omitempty"` } + +type BlockBlockByRefResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type BlockBlockByRefResultMeta struct { + Cursors *BlockBlockByRefResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + type BlockBlockByRefResult struct { - Blocks []struct { - Active bool `url:"active,omitempty" json:"active,omitempty"` - BlockType string `url:"block_type,omitempty" json:"block_type,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - ReasonDescription string `url:"reason_description,omitempty" json:"reason_description,omitempty"` - ReasonType string `url:"reason_type,omitempty" json:"reason_type,omitempty"` - ResourceReference string `url:"resource_reference,omitempty" json:"resource_reference,omitempty"` - UpdatedAt string `url:"updated_at,omitempty" json:"updated_at,omitempty"` - } `url:"blocks,omitempty" json:"blocks,omitempty"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `url:"meta,omitempty" json:"meta,omitempty"` + Blocks []Block `json:"blocks"` + Meta BlockBlockByRefResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // BlockByRef @@ -653,9 +661,9 @@ type BlockBlockByRefResult struct { // Returns 201 if at least one block was created. Returns 200 if there were no // new // blocks created. -func (s *BlockService) BlockByRef(ctx context.Context, p BlockBlockByRefParams, opts ...RequestOption) ( +func (s *BlockServiceImpl) BlockByRef(ctx context.Context, p BlockBlockByRefParams, opts ...RequestOption) ( *BlockBlockByRefResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/block_by_ref")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/block_by_ref")) if err != nil { return nil, err } @@ -689,10 +697,10 @@ func (s *BlockService) BlockByRef(ctx context.Context, p BlockBlockByRefParams, return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -701,7 +709,7 @@ func (s *BlockService) BlockByRef(ctx context.Context, p BlockBlockByRefParams, req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/creditor_bank_account_service.go b/creditor_bank_account_service.go index 74254ab..b5226a5 100644 --- a/creditor_bank_account_service.go +++ b/creditor_bank_account_service.go @@ -19,50 +19,60 @@ var _ = json.NewDecoder var _ = errors.New // CreditorBankAccountService manages creditor_bank_accounts -type CreditorBankAccountService struct { - endpoint string - token string - client *http.Client +type CreditorBankAccountServiceImpl struct { + config Config +} + +type CreditorBankAccountLinks struct { + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` } // CreditorBankAccount model type CreditorBankAccount struct { - AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` - AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` - AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` - BankName string `url:"bank_name,omitempty" json:"bank_name,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` + AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` + AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` + BankName string `url:"bank_name,omitempty" json:"bank_name,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *CreditorBankAccountLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` +} + +type CreditorBankAccountService interface { + Create(ctx context.Context, p CreditorBankAccountCreateParams, opts ...RequestOption) (*CreditorBankAccount, error) + List(ctx context.Context, p CreditorBankAccountListParams, opts ...RequestOption) (*CreditorBankAccountListResult, error) + All(ctx context.Context, p CreditorBankAccountListParams, opts ...RequestOption) *CreditorBankAccountListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*CreditorBankAccount, error) + Disable(ctx context.Context, identity string, opts ...RequestOption) (*CreditorBankAccount, error) +} + +type CreditorBankAccountCreateParamsLinks struct { + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` } // CreditorBankAccountCreateParams parameters type CreditorBankAccountCreateParams struct { - AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` - AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` - AccountType string `url:"account_type,omitempty" json:"account_type,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"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Iban string `url:"iban,omitempty" json:"iban,omitempty"` - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - SetAsDefaultPayoutAccount bool `url:"set_as_default_payout_account,omitempty" json:"set_as_default_payout_account,omitempty"` + AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` + AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` + AccountType string `url:"account_type,omitempty" json:"account_type,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"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Iban string `url:"iban,omitempty" json:"iban,omitempty"` + Links CreditorBankAccountCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + SetAsDefaultPayoutAccount bool `url:"set_as_default_payout_account,omitempty" json:"set_as_default_payout_account,omitempty"` } // Create // Creates a new creditor bank account object. -func (s *CreditorBankAccountService) Create(ctx context.Context, p CreditorBankAccountCreateParams, opts ...RequestOption) (*CreditorBankAccount, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/creditor_bank_accounts")) +func (s *CreditorBankAccountServiceImpl) Create(ctx context.Context, p CreditorBankAccountCreateParams, opts ...RequestOption) (*CreditorBankAccount, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/creditor_bank_accounts")) if err != nil { return nil, err } @@ -96,10 +106,10 @@ func (s *CreditorBankAccountService) Create(ctx context.Context, p CreditorBankA return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -108,7 +118,7 @@ func (s *CreditorBankAccountService) Create(ctx context.Context, p CreditorBankA req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -152,38 +162,43 @@ func (s *CreditorBankAccountService) Create(ctx context.Context, p CreditorBankA return result.CreditorBankAccount, nil } +type CreditorBankAccountListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // CreditorBankAccountListParams parameters type CreditorBankAccountListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *CreditorBankAccountListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + +type CreditorBankAccountListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type CreditorBankAccountListResultMeta struct { + Cursors *CreditorBankAccountListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// CreditorBankAccountListResult response including pagination metadata type CreditorBankAccountListResult struct { - CreditorBankAccounts []CreditorBankAccount `json:"creditor_bank_accounts"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + CreditorBankAccounts []CreditorBankAccount `json:"creditor_bank_accounts"` + Meta CreditorBankAccountListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // creditor bank accounts. -func (s *CreditorBankAccountService) List(ctx context.Context, p CreditorBankAccountListParams, opts ...RequestOption) (*CreditorBankAccountListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/creditor_bank_accounts")) +func (s *CreditorBankAccountServiceImpl) List(ctx context.Context, p CreditorBankAccountListParams, opts ...RequestOption) (*CreditorBankAccountListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/creditor_bank_accounts")) if err != nil { return nil, err } @@ -211,17 +226,17 @@ func (s *CreditorBankAccountService) List(ctx context.Context, p CreditorBankAcc return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -269,7 +284,7 @@ type CreditorBankAccountListPagingIterator struct { cursor string response *CreditorBankAccountListResult params CreditorBankAccountListParams - service *CreditorBankAccountService + service *CreditorBankAccountServiceImpl requestOptions []RequestOption } @@ -290,7 +305,7 @@ func (c *CreditorBankAccountListPagingIterator) Value(ctx context.Context) (*Cre p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/creditor_bank_accounts")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/creditor_bank_accounts")) if err != nil { return nil, err @@ -320,16 +335,16 @@ func (c *CreditorBankAccountListPagingIterator) Value(ctx context.Context) (*Cre } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -376,7 +391,7 @@ func (c *CreditorBankAccountListPagingIterator) Value(ctx context.Context) (*Cre return c.response, nil } -func (s *CreditorBankAccountService) All(ctx context.Context, +func (s *CreditorBankAccountServiceImpl) All(ctx context.Context, p CreditorBankAccountListParams, opts ...RequestOption) *CreditorBankAccountListPagingIterator { return &CreditorBankAccountListPagingIterator{ @@ -388,8 +403,8 @@ func (s *CreditorBankAccountService) All(ctx context.Context, // Get // Retrieves the details of an existing creditor bank account. -func (s *CreditorBankAccountService) Get(ctx context.Context, identity string, opts ...RequestOption) (*CreditorBankAccount, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/creditor_bank_accounts/%v", +func (s *CreditorBankAccountServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*CreditorBankAccount, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/creditor_bank_accounts/%v", identity)) if err != nil { return nil, err @@ -412,17 +427,17 @@ func (s *CreditorBankAccountService) Get(ctx context.Context, identity string, o return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -475,8 +490,8 @@ func (s *CreditorBankAccountService) Get(ctx context.Context, identity string, o // // A disabled bank account can be re-enabled by creating a new bank account // resource with the same details. -func (s *CreditorBankAccountService) Disable(ctx context.Context, identity string, opts ...RequestOption) (*CreditorBankAccount, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/creditor_bank_accounts/%v/actions/disable", +func (s *CreditorBankAccountServiceImpl) Disable(ctx context.Context, identity string, opts ...RequestOption) (*CreditorBankAccount, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/creditor_bank_accounts/%v/actions/disable", identity)) if err != nil { return nil, err @@ -502,10 +517,10 @@ func (s *CreditorBankAccountService) Disable(ctx context.Context, identity strin return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -514,7 +529,7 @@ func (s *CreditorBankAccountService) Disable(ctx context.Context, identity strin req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/creditor_service.go b/creditor_service.go index 14df70d..a267420 100644 --- a/creditor_service.go +++ b/creditor_service.go @@ -19,58 +19,68 @@ var _ = json.NewDecoder var _ = errors.New // CreditorService manages creditors -type CreditorService struct { - endpoint string - token string - client *http.Client +type CreditorServiceImpl struct { + config Config +} + +type CreditorLinks struct { + DefaultAudPayoutAccount string `url:"default_aud_payout_account,omitempty" json:"default_aud_payout_account,omitempty"` + DefaultCadPayoutAccount string `url:"default_cad_payout_account,omitempty" json:"default_cad_payout_account,omitempty"` + DefaultDkkPayoutAccount string `url:"default_dkk_payout_account,omitempty" json:"default_dkk_payout_account,omitempty"` + DefaultEurPayoutAccount string `url:"default_eur_payout_account,omitempty" json:"default_eur_payout_account,omitempty"` + DefaultGbpPayoutAccount string `url:"default_gbp_payout_account,omitempty" json:"default_gbp_payout_account,omitempty"` + DefaultNzdPayoutAccount string `url:"default_nzd_payout_account,omitempty" json:"default_nzd_payout_account,omitempty"` + DefaultSekPayoutAccount string `url:"default_sek_payout_account,omitempty" json:"default_sek_payout_account,omitempty"` + DefaultUsdPayoutAccount string `url:"default_usd_payout_account,omitempty" json:"default_usd_payout_account,omitempty"` +} + +type CreditorSchemeIdentifiers struct { + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + CanSpecifyMandateReference bool `url:"can_specify_mandate_reference,omitempty" json:"can_specify_mandate_reference,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Email string `url:"email,omitempty" json:"email,omitempty"` + MinimumAdvanceNotice int `url:"minimum_advance_notice,omitempty" json:"minimum_advance_notice,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` } // Creditor model type Creditor struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - CanCreateRefunds bool `url:"can_create_refunds,omitempty" json:"can_create_refunds,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - CustomPaymentPagesEnabled bool `url:"custom_payment_pages_enabled,omitempty" json:"custom_payment_pages_enabled,omitempty"` - FxPayoutCurrency string `url:"fx_payout_currency,omitempty" json:"fx_payout_currency,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - DefaultAudPayoutAccount string `url:"default_aud_payout_account,omitempty" json:"default_aud_payout_account,omitempty"` - DefaultCadPayoutAccount string `url:"default_cad_payout_account,omitempty" json:"default_cad_payout_account,omitempty"` - DefaultDkkPayoutAccount string `url:"default_dkk_payout_account,omitempty" json:"default_dkk_payout_account,omitempty"` - DefaultEurPayoutAccount string `url:"default_eur_payout_account,omitempty" json:"default_eur_payout_account,omitempty"` - DefaultGbpPayoutAccount string `url:"default_gbp_payout_account,omitempty" json:"default_gbp_payout_account,omitempty"` - DefaultNzdPayoutAccount string `url:"default_nzd_payout_account,omitempty" json:"default_nzd_payout_account,omitempty"` - DefaultSekPayoutAccount string `url:"default_sek_payout_account,omitempty" json:"default_sek_payout_account,omitempty"` - DefaultUsdPayoutAccount string `url:"default_usd_payout_account,omitempty" json:"default_usd_payout_account,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - LogoUrl string `url:"logo_url,omitempty" json:"logo_url,omitempty"` - MandateImportsEnabled bool `url:"mandate_imports_enabled,omitempty" json:"mandate_imports_enabled,omitempty"` - MerchantResponsibleForNotifications bool `url:"merchant_responsible_for_notifications,omitempty" json:"merchant_responsible_for_notifications,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - SchemeIdentifiers []struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - CanSpecifyMandateReference bool `url:"can_specify_mandate_reference,omitempty" json:"can_specify_mandate_reference,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Email string `url:"email,omitempty" json:"email,omitempty"` - MinimumAdvanceNotice int `url:"minimum_advance_notice,omitempty" json:"minimum_advance_notice,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` - PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - } `url:"scheme_identifiers,omitempty" json:"scheme_identifiers,omitempty"` - VerificationStatus string `url:"verification_status,omitempty" json:"verification_status,omitempty"` + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + CanCreateRefunds bool `url:"can_create_refunds,omitempty" json:"can_create_refunds,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + CustomPaymentPagesEnabled bool `url:"custom_payment_pages_enabled,omitempty" json:"custom_payment_pages_enabled,omitempty"` + FxPayoutCurrency string `url:"fx_payout_currency,omitempty" json:"fx_payout_currency,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *CreditorLinks `url:"links,omitempty" json:"links,omitempty"` + LogoUrl string `url:"logo_url,omitempty" json:"logo_url,omitempty"` + MandateImportsEnabled bool `url:"mandate_imports_enabled,omitempty" json:"mandate_imports_enabled,omitempty"` + MerchantResponsibleForNotifications bool `url:"merchant_responsible_for_notifications,omitempty" json:"merchant_responsible_for_notifications,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + SchemeIdentifiers []CreditorSchemeIdentifiers `url:"scheme_identifiers,omitempty" json:"scheme_identifiers,omitempty"` + VerificationStatus string `url:"verification_status,omitempty" json:"verification_status,omitempty"` +} + +type CreditorService interface { + Create(ctx context.Context, p CreditorCreateParams, opts ...RequestOption) (*Creditor, error) + List(ctx context.Context, p CreditorListParams, opts ...RequestOption) (*CreditorListResult, error) + All(ctx context.Context, p CreditorListParams, opts ...RequestOption) *CreditorListPagingIterator + Get(ctx context.Context, identity string, p CreditorGetParams, opts ...RequestOption) (*Creditor, error) + Update(ctx context.Context, identity string, p CreditorUpdateParams, opts ...RequestOption) (*Creditor, error) } // CreditorCreateParams parameters @@ -88,8 +98,8 @@ type CreditorCreateParams struct { // Create // Creates a new creditor. -func (s *CreditorService) Create(ctx context.Context, p CreditorCreateParams, opts ...RequestOption) (*Creditor, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/creditors")) +func (s *CreditorServiceImpl) Create(ctx context.Context, p CreditorCreateParams, opts ...RequestOption) (*Creditor, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/creditors")) if err != nil { return nil, err } @@ -123,10 +133,10 @@ func (s *CreditorService) Create(ctx context.Context, p CreditorCreateParams, op return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -135,7 +145,7 @@ func (s *CreditorService) Create(ctx context.Context, p CreditorCreateParams, op req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -179,36 +189,41 @@ func (s *CreditorService) Create(ctx context.Context, p CreditorCreateParams, op return result.Creditor, nil } +type CreditorListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // CreditorListParams parameters type CreditorListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *CreditorListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + +type CreditorListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type CreditorListResultMeta struct { + Cursors *CreditorListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// CreditorListResult response including pagination metadata type CreditorListResult struct { - Creditors []Creditor `json:"creditors"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Creditors []Creditor `json:"creditors"` + Meta CreditorListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // creditors. -func (s *CreditorService) List(ctx context.Context, p CreditorListParams, opts ...RequestOption) (*CreditorListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/creditors")) +func (s *CreditorServiceImpl) List(ctx context.Context, p CreditorListParams, opts ...RequestOption) (*CreditorListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/creditors")) if err != nil { return nil, err } @@ -236,17 +251,17 @@ func (s *CreditorService) List(ctx context.Context, p CreditorListParams, opts . return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -294,7 +309,7 @@ type CreditorListPagingIterator struct { cursor string response *CreditorListResult params CreditorListParams - service *CreditorService + service *CreditorServiceImpl requestOptions []RequestOption } @@ -315,7 +330,7 @@ func (c *CreditorListPagingIterator) Value(ctx context.Context) (*CreditorListRe p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/creditors")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/creditors")) if err != nil { return nil, err @@ -345,16 +360,16 @@ func (c *CreditorListPagingIterator) Value(ctx context.Context) (*CreditorListRe } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -401,7 +416,7 @@ func (c *CreditorListPagingIterator) Value(ctx context.Context) (*CreditorListRe return c.response, nil } -func (s *CreditorService) All(ctx context.Context, +func (s *CreditorServiceImpl) All(ctx context.Context, p CreditorListParams, opts ...RequestOption) *CreditorListPagingIterator { return &CreditorListPagingIterator{ @@ -412,12 +427,13 @@ func (s *CreditorService) All(ctx context.Context, } // CreditorGetParams parameters -type CreditorGetParams map[string]interface{} +type CreditorGetParams struct { +} // Get // Retrieves the details of an existing creditor. -func (s *CreditorService) Get(ctx context.Context, identity string, p CreditorGetParams, opts ...RequestOption) (*Creditor, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/creditors/%v", +func (s *CreditorServiceImpl) Get(ctx context.Context, identity string, p CreditorGetParams, opts ...RequestOption) (*Creditor, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/creditors/%v", identity)) if err != nil { return nil, err @@ -440,17 +456,17 @@ func (s *CreditorService) Get(ctx context.Context, identity string, p CreditorGe return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -494,33 +510,35 @@ func (s *CreditorService) Get(ctx context.Context, identity string, p CreditorGe return result.Creditor, nil } +type CreditorUpdateParamsLinks struct { + DefaultAudPayoutAccount string `url:"default_aud_payout_account,omitempty" json:"default_aud_payout_account,omitempty"` + DefaultCadPayoutAccount string `url:"default_cad_payout_account,omitempty" json:"default_cad_payout_account,omitempty"` + DefaultDkkPayoutAccount string `url:"default_dkk_payout_account,omitempty" json:"default_dkk_payout_account,omitempty"` + DefaultEurPayoutAccount string `url:"default_eur_payout_account,omitempty" json:"default_eur_payout_account,omitempty"` + DefaultGbpPayoutAccount string `url:"default_gbp_payout_account,omitempty" json:"default_gbp_payout_account,omitempty"` + DefaultNzdPayoutAccount string `url:"default_nzd_payout_account,omitempty" json:"default_nzd_payout_account,omitempty"` + DefaultSekPayoutAccount string `url:"default_sek_payout_account,omitempty" json:"default_sek_payout_account,omitempty"` + DefaultUsdPayoutAccount string `url:"default_usd_payout_account,omitempty" json:"default_usd_payout_account,omitempty"` +} + // CreditorUpdateParams parameters type CreditorUpdateParams struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - Links struct { - DefaultAudPayoutAccount string `url:"default_aud_payout_account,omitempty" json:"default_aud_payout_account,omitempty"` - DefaultCadPayoutAccount string `url:"default_cad_payout_account,omitempty" json:"default_cad_payout_account,omitempty"` - DefaultDkkPayoutAccount string `url:"default_dkk_payout_account,omitempty" json:"default_dkk_payout_account,omitempty"` - DefaultEurPayoutAccount string `url:"default_eur_payout_account,omitempty" json:"default_eur_payout_account,omitempty"` - DefaultGbpPayoutAccount string `url:"default_gbp_payout_account,omitempty" json:"default_gbp_payout_account,omitempty"` - DefaultNzdPayoutAccount string `url:"default_nzd_payout_account,omitempty" json:"default_nzd_payout_account,omitempty"` - DefaultSekPayoutAccount string `url:"default_sek_payout_account,omitempty" json:"default_sek_payout_account,omitempty"` - DefaultUsdPayoutAccount string `url:"default_usd_payout_account,omitempty" json:"default_usd_payout_account,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + Links *CreditorUpdateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` } // Update // Updates a creditor object. Supports all of the fields supported when creating // a creditor. -func (s *CreditorService) Update(ctx context.Context, identity string, p CreditorUpdateParams, opts ...RequestOption) (*Creditor, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/creditors/%v", +func (s *CreditorServiceImpl) Update(ctx context.Context, identity string, p CreditorUpdateParams, opts ...RequestOption) (*Creditor, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/creditors/%v", identity)) if err != nil { return nil, err @@ -555,10 +573,10 @@ func (s *CreditorService) Update(ctx context.Context, identity string, p Credito return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -567,7 +585,7 @@ func (s *CreditorService) Update(ctx context.Context, identity string, p Credito req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/currency_exchange_rate_service.go b/currency_exchange_rate_service.go index 419cf20..cab537c 100644 --- a/currency_exchange_rate_service.go +++ b/currency_exchange_rate_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // CurrencyExchangeRateService manages currency_exchange_rates -type CurrencyExchangeRateService struct { - endpoint string - token string - client *http.Client +type CurrencyExchangeRateServiceImpl struct { + config Config } // CurrencyExchangeRate model @@ -33,38 +31,48 @@ type CurrencyExchangeRate struct { Time string `url:"time,omitempty" json:"time,omitempty"` } +type CurrencyExchangeRateService interface { + List(ctx context.Context, p CurrencyExchangeRateListParams, opts ...RequestOption) (*CurrencyExchangeRateListResult, error) + All(ctx context.Context, p CurrencyExchangeRateListParams, opts ...RequestOption) *CurrencyExchangeRateListPagingIterator +} + +type CurrencyExchangeRateListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // CurrencyExchangeRateListParams parameters type CurrencyExchangeRateListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - Source string `url:"source,omitempty" json:"source,omitempty"` - Target string `url:"target,omitempty" json:"target,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *CurrencyExchangeRateListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + Source string `url:"source,omitempty" json:"source,omitempty"` + Target string `url:"target,omitempty" json:"target,omitempty"` +} + +type CurrencyExchangeRateListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type CurrencyExchangeRateListResultMeta struct { + Cursors *CurrencyExchangeRateListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// CurrencyExchangeRateListResult response including pagination metadata type CurrencyExchangeRateListResult struct { - CurrencyExchangeRates []CurrencyExchangeRate `json:"currency_exchange_rates"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + CurrencyExchangeRates []CurrencyExchangeRate `json:"currency_exchange_rates"` + Meta CurrencyExchangeRateListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of all // exchange rates. -func (s *CurrencyExchangeRateService) List(ctx context.Context, p CurrencyExchangeRateListParams, opts ...RequestOption) (*CurrencyExchangeRateListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/currency_exchange_rates")) +func (s *CurrencyExchangeRateServiceImpl) List(ctx context.Context, p CurrencyExchangeRateListParams, opts ...RequestOption) (*CurrencyExchangeRateListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/currency_exchange_rates")) if err != nil { return nil, err } @@ -92,17 +100,17 @@ func (s *CurrencyExchangeRateService) List(ctx context.Context, p CurrencyExchan return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -150,7 +158,7 @@ type CurrencyExchangeRateListPagingIterator struct { cursor string response *CurrencyExchangeRateListResult params CurrencyExchangeRateListParams - service *CurrencyExchangeRateService + service *CurrencyExchangeRateServiceImpl requestOptions []RequestOption } @@ -171,7 +179,7 @@ func (c *CurrencyExchangeRateListPagingIterator) Value(ctx context.Context) (*Cu p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/currency_exchange_rates")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/currency_exchange_rates")) if err != nil { return nil, err @@ -201,16 +209,16 @@ func (c *CurrencyExchangeRateListPagingIterator) Value(ctx context.Context) (*Cu } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -257,7 +265,7 @@ func (c *CurrencyExchangeRateListPagingIterator) Value(ctx context.Context) (*Cu return c.response, nil } -func (s *CurrencyExchangeRateService) All(ctx context.Context, +func (s *CurrencyExchangeRateServiceImpl) All(ctx context.Context, p CurrencyExchangeRateListParams, opts ...RequestOption) *CurrencyExchangeRateListPagingIterator { return &CurrencyExchangeRateListPagingIterator{ diff --git a/customer_bank_account_service.go b/customer_bank_account_service.go index 7e7fb76..6d5ae3a 100644 --- a/customer_bank_account_service.go +++ b/customer_bank_account_service.go @@ -19,44 +19,55 @@ var _ = json.NewDecoder var _ = errors.New // CustomerBankAccountService manages customer_bank_accounts -type CustomerBankAccountService struct { - endpoint string - token string - client *http.Client +type CustomerBankAccountServiceImpl struct { + config Config +} + +type CustomerBankAccountLinks struct { + Customer string `url:"customer,omitempty" json:"customer,omitempty"` } // CustomerBankAccount model type CustomerBankAccount struct { - AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` - AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` - AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` - BankName string `url:"bank_name,omitempty" json:"bank_name,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` + AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` + AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` + BankName string `url:"bank_name,omitempty" json:"bank_name,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *CustomerBankAccountLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` +} + +type CustomerBankAccountService interface { + Create(ctx context.Context, p CustomerBankAccountCreateParams, opts ...RequestOption) (*CustomerBankAccount, error) + List(ctx context.Context, p CustomerBankAccountListParams, opts ...RequestOption) (*CustomerBankAccountListResult, error) + All(ctx context.Context, p CustomerBankAccountListParams, opts ...RequestOption) *CustomerBankAccountListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*CustomerBankAccount, error) + Update(ctx context.Context, identity string, p CustomerBankAccountUpdateParams, opts ...RequestOption) (*CustomerBankAccount, error) + Disable(ctx context.Context, identity string, opts ...RequestOption) (*CustomerBankAccount, error) +} + +type CustomerBankAccountCreateParamsLinks struct { + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBankAccountToken string `url:"customer_bank_account_token,omitempty" json:"customer_bank_account_token,omitempty"` } // CustomerBankAccountCreateParams parameters type CustomerBankAccountCreateParams struct { - AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` - AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` - AccountType string `url:"account_type,omitempty" json:"account_type,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"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Iban string `url:"iban,omitempty" json:"iban,omitempty"` - Links struct { - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBankAccountToken string `url:"customer_bank_account_token,omitempty" json:"customer_bank_account_token,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` + AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` + AccountType string `url:"account_type,omitempty" json:"account_type,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"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Iban string `url:"iban,omitempty" json:"iban,omitempty"` + Links CustomerBankAccountCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` } // Create @@ -73,8 +84,8 @@ type CustomerBankAccountCreateParams struct { // // For more information on the different fields required in each country, see // [local bank details](#appendix-local-bank-details). -func (s *CustomerBankAccountService) Create(ctx context.Context, p CustomerBankAccountCreateParams, opts ...RequestOption) (*CustomerBankAccount, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/customer_bank_accounts")) +func (s *CustomerBankAccountServiceImpl) Create(ctx context.Context, p CustomerBankAccountCreateParams, opts ...RequestOption) (*CustomerBankAccount, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/customer_bank_accounts")) if err != nil { return nil, err } @@ -108,10 +119,10 @@ func (s *CustomerBankAccountService) Create(ctx context.Context, p CustomerBankA return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -120,7 +131,7 @@ func (s *CustomerBankAccountService) Create(ctx context.Context, p CustomerBankA req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -164,38 +175,43 @@ func (s *CustomerBankAccountService) Create(ctx context.Context, p CustomerBankA return result.CustomerBankAccount, nil } +type CustomerBankAccountListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // CustomerBankAccountListParams parameters type CustomerBankAccountListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *CustomerBankAccountListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + Enabled bool `url:"enabled,omitempty" json:"enabled,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + +type CustomerBankAccountListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type CustomerBankAccountListResultMeta struct { + Cursors *CustomerBankAccountListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// CustomerBankAccountListResult response including pagination metadata type CustomerBankAccountListResult struct { - CustomerBankAccounts []CustomerBankAccount `json:"customer_bank_accounts"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + CustomerBankAccounts []CustomerBankAccount `json:"customer_bank_accounts"` + Meta CustomerBankAccountListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your bank // accounts. -func (s *CustomerBankAccountService) List(ctx context.Context, p CustomerBankAccountListParams, opts ...RequestOption) (*CustomerBankAccountListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/customer_bank_accounts")) +func (s *CustomerBankAccountServiceImpl) List(ctx context.Context, p CustomerBankAccountListParams, opts ...RequestOption) (*CustomerBankAccountListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/customer_bank_accounts")) if err != nil { return nil, err } @@ -223,17 +239,17 @@ func (s *CustomerBankAccountService) List(ctx context.Context, p CustomerBankAcc return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -281,7 +297,7 @@ type CustomerBankAccountListPagingIterator struct { cursor string response *CustomerBankAccountListResult params CustomerBankAccountListParams - service *CustomerBankAccountService + service *CustomerBankAccountServiceImpl requestOptions []RequestOption } @@ -302,7 +318,7 @@ func (c *CustomerBankAccountListPagingIterator) Value(ctx context.Context) (*Cus p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/customer_bank_accounts")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/customer_bank_accounts")) if err != nil { return nil, err @@ -332,16 +348,16 @@ func (c *CustomerBankAccountListPagingIterator) Value(ctx context.Context) (*Cus } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -388,7 +404,7 @@ func (c *CustomerBankAccountListPagingIterator) Value(ctx context.Context) (*Cus return c.response, nil } -func (s *CustomerBankAccountService) All(ctx context.Context, +func (s *CustomerBankAccountServiceImpl) All(ctx context.Context, p CustomerBankAccountListParams, opts ...RequestOption) *CustomerBankAccountListPagingIterator { return &CustomerBankAccountListPagingIterator{ @@ -400,8 +416,8 @@ func (s *CustomerBankAccountService) All(ctx context.Context, // Get // Retrieves the details of an existing bank account. -func (s *CustomerBankAccountService) Get(ctx context.Context, identity string, opts ...RequestOption) (*CustomerBankAccount, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/customer_bank_accounts/%v", +func (s *CustomerBankAccountServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*CustomerBankAccount, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/customer_bank_accounts/%v", identity)) if err != nil { return nil, err @@ -424,17 +440,17 @@ func (s *CustomerBankAccountService) Get(ctx context.Context, identity string, o return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -486,8 +502,8 @@ type CustomerBankAccountUpdateParams struct { // Update // Updates a customer bank account object. Only the metadata parameter is // allowed. -func (s *CustomerBankAccountService) Update(ctx context.Context, identity string, p CustomerBankAccountUpdateParams, opts ...RequestOption) (*CustomerBankAccount, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/customer_bank_accounts/%v", +func (s *CustomerBankAccountServiceImpl) Update(ctx context.Context, identity string, p CustomerBankAccountUpdateParams, opts ...RequestOption) (*CustomerBankAccount, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/customer_bank_accounts/%v", identity)) if err != nil { return nil, err @@ -522,10 +538,10 @@ func (s *CustomerBankAccountService) Update(ctx context.Context, identity string return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -534,7 +550,7 @@ func (s *CustomerBankAccountService) Update(ctx context.Context, identity string req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -586,8 +602,8 @@ func (s *CustomerBankAccountService) Update(ctx context.Context, identity string // // A disabled bank account can be re-enabled by creating a new bank account // resource with the same details. -func (s *CustomerBankAccountService) Disable(ctx context.Context, identity string, opts ...RequestOption) (*CustomerBankAccount, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/customer_bank_accounts/%v/actions/disable", +func (s *CustomerBankAccountServiceImpl) Disable(ctx context.Context, identity string, opts ...RequestOption) (*CustomerBankAccount, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/customer_bank_accounts/%v/actions/disable", identity)) if err != nil { return nil, err @@ -613,10 +629,10 @@ func (s *CustomerBankAccountService) Disable(ctx context.Context, identity strin return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -625,7 +641,7 @@ func (s *CustomerBankAccountService) Disable(ctx context.Context, identity strin req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/customer_notification_service.go b/customer_notification_service.go index 1b55506..7c74018 100644 --- a/customer_notification_service.go +++ b/customer_notification_service.go @@ -19,31 +19,36 @@ var _ = json.NewDecoder var _ = errors.New // CustomerNotificationService manages customer_notifications -type CustomerNotificationService struct { - endpoint string - token string - client *http.Client +type CustomerNotificationServiceImpl struct { + config Config +} + +type CustomerNotificationLinks struct { + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + Event string `url:"event,omitempty" json:"event,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + Payment string `url:"payment,omitempty" json:"payment,omitempty"` + Refund string `url:"refund,omitempty" json:"refund,omitempty"` + Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` } // CustomerNotification model type CustomerNotification struct { - ActionTaken string `url:"action_taken,omitempty" json:"action_taken,omitempty"` - ActionTakenAt string `url:"action_taken_at,omitempty" json:"action_taken_at,omitempty"` - ActionTakenBy string `url:"action_taken_by,omitempty" json:"action_taken_by,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - Event string `url:"event,omitempty" json:"event,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - Payment string `url:"payment,omitempty" json:"payment,omitempty"` - Refund string `url:"refund,omitempty" json:"refund,omitempty"` - Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Type string `url:"type,omitempty" json:"type,omitempty"` + ActionTaken string `url:"action_taken,omitempty" json:"action_taken,omitempty"` + ActionTakenAt string `url:"action_taken_at,omitempty" json:"action_taken_at,omitempty"` + ActionTakenBy string `url:"action_taken_by,omitempty" json:"action_taken_by,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *CustomerNotificationLinks `url:"links,omitempty" json:"links,omitempty"` + Type string `url:"type,omitempty" json:"type,omitempty"` +} + +type CustomerNotificationService interface { + Handle(ctx context.Context, identity string, p CustomerNotificationHandleParams, opts ...RequestOption) (*CustomerNotification, error) } // CustomerNotificationHandleParams parameters -type CustomerNotificationHandleParams map[string]interface{} +type CustomerNotificationHandleParams struct { +} // Handle // "Handling" a notification means that you have sent the notification yourself @@ -54,8 +59,8 @@ type CustomerNotificationHandleParams map[string]interface{} // this endpoint will return an `already_actioned` error and you should not take // further action. This endpoint takes no additional parameters. // -func (s *CustomerNotificationService) Handle(ctx context.Context, identity string, p CustomerNotificationHandleParams, opts ...RequestOption) (*CustomerNotification, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/customer_notifications/%v/actions/handle", +func (s *CustomerNotificationServiceImpl) Handle(ctx context.Context, identity string, p CustomerNotificationHandleParams, opts ...RequestOption) (*CustomerNotification, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/customer_notifications/%v/actions/handle", identity)) if err != nil { return nil, err @@ -90,10 +95,10 @@ func (s *CustomerNotificationService) Handle(ctx context.Context, identity strin return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -102,7 +107,7 @@ func (s *CustomerNotificationService) Handle(ctx context.Context, identity strin req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/customer_service.go b/customer_service.go index 8c1aff8..59fabfc 100644 --- a/customer_service.go +++ b/customer_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // CustomerService manages customers -type CustomerService struct { - endpoint string - token string - client *http.Client +type CustomerServiceImpl struct { + config Config } // Customer model @@ -47,6 +45,15 @@ type Customer struct { SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` } +type CustomerService interface { + Create(ctx context.Context, p CustomerCreateParams, opts ...RequestOption) (*Customer, error) + List(ctx context.Context, p CustomerListParams, opts ...RequestOption) (*CustomerListResult, error) + All(ctx context.Context, p CustomerListParams, opts ...RequestOption) *CustomerListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*Customer, error) + Update(ctx context.Context, identity string, p CustomerUpdateParams, opts ...RequestOption) (*Customer, error) + Remove(ctx context.Context, identity string, p CustomerRemoveParams, opts ...RequestOption) (*Customer, error) +} + // CustomerCreateParams parameters type CustomerCreateParams struct { AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` @@ -69,8 +76,8 @@ type CustomerCreateParams struct { // Create // Creates a new customer object. -func (s *CustomerService) Create(ctx context.Context, p CustomerCreateParams, opts ...RequestOption) (*Customer, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/customers")) +func (s *CustomerServiceImpl) Create(ctx context.Context, p CustomerCreateParams, opts ...RequestOption) (*Customer, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/customers")) if err != nil { return nil, err } @@ -104,10 +111,10 @@ func (s *CustomerService) Create(ctx context.Context, p CustomerCreateParams, op return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -116,7 +123,7 @@ func (s *CustomerService) Create(ctx context.Context, p CustomerCreateParams, op req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -160,39 +167,44 @@ func (s *CustomerService) Create(ctx context.Context, p CustomerCreateParams, op return result.Customer, nil } +type CustomerListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // CustomerListParams parameters type CustomerListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - SortDirection string `url:"sort_direction,omitempty" json:"sort_direction,omitempty"` - SortField string `url:"sort_field,omitempty" json:"sort_field,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *CustomerListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + SortDirection string `url:"sort_direction,omitempty" json:"sort_direction,omitempty"` + SortField string `url:"sort_field,omitempty" json:"sort_field,omitempty"` +} + +type CustomerListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type CustomerListResultMeta struct { + Cursors *CustomerListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// CustomerListResult response including pagination metadata type CustomerListResult struct { - Customers []Customer `json:"customers"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Customers []Customer `json:"customers"` + Meta CustomerListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // customers. -func (s *CustomerService) List(ctx context.Context, p CustomerListParams, opts ...RequestOption) (*CustomerListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/customers")) +func (s *CustomerServiceImpl) List(ctx context.Context, p CustomerListParams, opts ...RequestOption) (*CustomerListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/customers")) if err != nil { return nil, err } @@ -220,17 +232,17 @@ func (s *CustomerService) List(ctx context.Context, p CustomerListParams, opts . return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -278,7 +290,7 @@ type CustomerListPagingIterator struct { cursor string response *CustomerListResult params CustomerListParams - service *CustomerService + service *CustomerServiceImpl requestOptions []RequestOption } @@ -299,7 +311,7 @@ func (c *CustomerListPagingIterator) Value(ctx context.Context) (*CustomerListRe p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/customers")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/customers")) if err != nil { return nil, err @@ -329,16 +341,16 @@ func (c *CustomerListPagingIterator) Value(ctx context.Context) (*CustomerListRe } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -385,7 +397,7 @@ func (c *CustomerListPagingIterator) Value(ctx context.Context) (*CustomerListRe return c.response, nil } -func (s *CustomerService) All(ctx context.Context, +func (s *CustomerServiceImpl) All(ctx context.Context, p CustomerListParams, opts ...RequestOption) *CustomerListPagingIterator { return &CustomerListPagingIterator{ @@ -397,8 +409,8 @@ func (s *CustomerService) All(ctx context.Context, // Get // Retrieves the details of an existing customer. -func (s *CustomerService) Get(ctx context.Context, identity string, opts ...RequestOption) (*Customer, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/customers/%v", +func (s *CustomerServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*Customer, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/customers/%v", identity)) if err != nil { return nil, err @@ -421,17 +433,17 @@ func (s *CustomerService) Get(ctx context.Context, identity string, opts ...Requ return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -498,8 +510,8 @@ type CustomerUpdateParams struct { // Update // Updates a customer object. Supports all of the fields supported when creating // a customer. -func (s *CustomerService) Update(ctx context.Context, identity string, p CustomerUpdateParams, opts ...RequestOption) (*Customer, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/customers/%v", +func (s *CustomerServiceImpl) Update(ctx context.Context, identity string, p CustomerUpdateParams, opts ...RequestOption) (*Customer, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/customers/%v", identity)) if err != nil { return nil, err @@ -534,10 +546,10 @@ func (s *CustomerService) Update(ctx context.Context, identity string, p Custome return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -546,7 +558,7 @@ func (s *CustomerService) Update(ctx context.Context, identity string, p Custome req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -591,7 +603,8 @@ func (s *CustomerService) Update(ctx context.Context, identity string, p Custome } // CustomerRemoveParams parameters -type CustomerRemoveParams map[string]interface{} +type CustomerRemoveParams struct { +} // Remove // Removed customers will not appear in search results or lists of customers (in @@ -602,8 +615,8 @@ type CustomerRemoveParams map[string]interface{} // //

The action of removing a customer cannot // be reversed, so please use with care.

-func (s *CustomerService) Remove(ctx context.Context, identity string, p CustomerRemoveParams, opts ...RequestOption) (*Customer, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/customers/%v", +func (s *CustomerServiceImpl) Remove(ctx context.Context, identity string, p CustomerRemoveParams, opts ...RequestOption) (*Customer, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/customers/%v", identity)) if err != nil { return nil, err @@ -638,10 +651,10 @@ func (s *CustomerService) Remove(ctx context.Context, identity string, p Custome return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -650,7 +663,7 @@ func (s *CustomerService) Remove(ctx context.Context, identity string, p Custome req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/event_service.go b/event_service.go index ae58523..9546ec4 100644 --- a/event_service.go +++ b/event_service.go @@ -19,102 +19,118 @@ var _ = json.NewDecoder var _ = errors.New // EventService manages events -type EventService struct { - endpoint string - token string - client *http.Client +type EventServiceImpl struct { + config Config +} + +type EventCustomerNotifications struct { + Deadline string `url:"deadline,omitempty" json:"deadline,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Mandatory bool `url:"mandatory,omitempty" json:"mandatory,omitempty"` + Type string `url:"type,omitempty" json:"type,omitempty"` +} + +type EventDetails struct { + BankAccountId string `url:"bank_account_id,omitempty" json:"bank_account_id,omitempty"` + Cause string `url:"cause,omitempty" json:"cause,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Description string `url:"description,omitempty" json:"description,omitempty"` + NotRetriedReason string `url:"not_retried_reason,omitempty" json:"not_retried_reason,omitempty"` + Origin string `url:"origin,omitempty" json:"origin,omitempty"` + Property string `url:"property,omitempty" json:"property,omitempty"` + ReasonCode string `url:"reason_code,omitempty" json:"reason_code,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` + WillAttemptRetry bool `url:"will_attempt_retry,omitempty" json:"will_attempt_retry,omitempty"` +} + +type EventLinks struct { + BankAuthorisation string `url:"bank_authorisation,omitempty" json:"bank_authorisation,omitempty"` + BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` + BillingRequestFlow string `url:"billing_request_flow,omitempty" json:"billing_request_flow,omitempty"` + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` + InstalmentSchedule string `url:"instalment_schedule,omitempty" json:"instalment_schedule,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + MandateRequestMandate string `url:"mandate_request_mandate,omitempty" json:"mandate_request_mandate,omitempty"` + NewCustomerBankAccount string `url:"new_customer_bank_account,omitempty" json:"new_customer_bank_account,omitempty"` + NewMandate string `url:"new_mandate,omitempty" json:"new_mandate,omitempty"` + Organisation string `url:"organisation,omitempty" json:"organisation,omitempty"` + ParentEvent string `url:"parent_event,omitempty" json:"parent_event,omitempty"` + PayerAuthorisation string `url:"payer_authorisation,omitempty" json:"payer_authorisation,omitempty"` + Payment string `url:"payment,omitempty" json:"payment,omitempty"` + PaymentRequestPayment string `url:"payment_request_payment,omitempty" json:"payment_request_payment,omitempty"` + Payout string `url:"payout,omitempty" json:"payout,omitempty"` + PreviousCustomerBankAccount string `url:"previous_customer_bank_account,omitempty" json:"previous_customer_bank_account,omitempty"` + Refund string `url:"refund,omitempty" json:"refund,omitempty"` + Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` } // Event model type Event struct { - Action string `url:"action,omitempty" json:"action,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - CustomerNotifications []struct { - Deadline string `url:"deadline,omitempty" json:"deadline,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Mandatory bool `url:"mandatory,omitempty" json:"mandatory,omitempty"` - Type string `url:"type,omitempty" json:"type,omitempty"` - } `url:"customer_notifications,omitempty" json:"customer_notifications,omitempty"` - Details struct { - BankAccountId string `url:"bank_account_id,omitempty" json:"bank_account_id,omitempty"` - Cause string `url:"cause,omitempty" json:"cause,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Description string `url:"description,omitempty" json:"description,omitempty"` - NotRetriedReason string `url:"not_retried_reason,omitempty" json:"not_retried_reason,omitempty"` - Origin string `url:"origin,omitempty" json:"origin,omitempty"` - Property string `url:"property,omitempty" json:"property,omitempty"` - ReasonCode string `url:"reason_code,omitempty" json:"reason_code,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - WillAttemptRetry bool `url:"will_attempt_retry,omitempty" json:"will_attempt_retry,omitempty"` - } `url:"details,omitempty" json:"details,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - BankAuthorisation string `url:"bank_authorisation,omitempty" json:"bank_authorisation,omitempty"` - BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` - BillingRequestFlow string `url:"billing_request_flow,omitempty" json:"billing_request_flow,omitempty"` - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` - InstalmentSchedule string `url:"instalment_schedule,omitempty" json:"instalment_schedule,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - MandateRequestMandate string `url:"mandate_request_mandate,omitempty" json:"mandate_request_mandate,omitempty"` - NewCustomerBankAccount string `url:"new_customer_bank_account,omitempty" json:"new_customer_bank_account,omitempty"` - NewMandate string `url:"new_mandate,omitempty" json:"new_mandate,omitempty"` - Organisation string `url:"organisation,omitempty" json:"organisation,omitempty"` - ParentEvent string `url:"parent_event,omitempty" json:"parent_event,omitempty"` - PayerAuthorisation string `url:"payer_authorisation,omitempty" json:"payer_authorisation,omitempty"` - Payment string `url:"payment,omitempty" json:"payment,omitempty"` - PaymentRequestPayment string `url:"payment_request_payment,omitempty" json:"payment_request_payment,omitempty"` - Payout string `url:"payout,omitempty" json:"payout,omitempty"` - PreviousCustomerBankAccount string `url:"previous_customer_bank_account,omitempty" json:"previous_customer_bank_account,omitempty"` - Refund string `url:"refund,omitempty" json:"refund,omitempty"` - Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - ResourceType string `url:"resource_type,omitempty" json:"resource_type,omitempty"` + Action string `url:"action,omitempty" json:"action,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + CustomerNotifications []EventCustomerNotifications `url:"customer_notifications,omitempty" json:"customer_notifications,omitempty"` + Details *EventDetails `url:"details,omitempty" json:"details,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *EventLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + ResourceType string `url:"resource_type,omitempty" json:"resource_type,omitempty"` +} + +type EventService interface { + List(ctx context.Context, p EventListParams, opts ...RequestOption) (*EventListResult, error) + All(ctx context.Context, p EventListParams, opts ...RequestOption) *EventListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*Event, error) +} + +type EventListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` } // EventListParams parameters type EventListParams struct { - Action string `url:"action,omitempty" json:"action,omitempty"` - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Include string `url:"include,omitempty" json:"include,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - ParentEvent string `url:"parent_event,omitempty" json:"parent_event,omitempty"` - PayerAuthorisation string `url:"payer_authorisation,omitempty" json:"payer_authorisation,omitempty"` - Payment string `url:"payment,omitempty" json:"payment,omitempty"` - Payout string `url:"payout,omitempty" json:"payout,omitempty"` - Refund string `url:"refund,omitempty" json:"refund,omitempty"` - ResourceType string `url:"resource_type,omitempty" json:"resource_type,omitempty"` - Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` + Action string `url:"action,omitempty" json:"action,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` + CreatedAt *EventListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Include string `url:"include,omitempty" json:"include,omitempty"` + InstalmentSchedule string `url:"instalment_schedule,omitempty" json:"instalment_schedule,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + ParentEvent string `url:"parent_event,omitempty" json:"parent_event,omitempty"` + PayerAuthorisation string `url:"payer_authorisation,omitempty" json:"payer_authorisation,omitempty"` + Payment string `url:"payment,omitempty" json:"payment,omitempty"` + Payout string `url:"payout,omitempty" json:"payout,omitempty"` + Refund string `url:"refund,omitempty" json:"refund,omitempty"` + ResourceType string `url:"resource_type,omitempty" json:"resource_type,omitempty"` + Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` +} + +type EventListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type EventListResultMeta struct { + Cursors *EventListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// EventListResult response including pagination metadata type EventListResult struct { - Events []Event `json:"events"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Events []Event `json:"events"` + Meta EventListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // events. -func (s *EventService) List(ctx context.Context, p EventListParams, opts ...RequestOption) (*EventListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/events")) +func (s *EventServiceImpl) List(ctx context.Context, p EventListParams, opts ...RequestOption) (*EventListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/events")) if err != nil { return nil, err } @@ -142,17 +158,17 @@ func (s *EventService) List(ctx context.Context, p EventListParams, opts ...Requ return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -200,7 +216,7 @@ type EventListPagingIterator struct { cursor string response *EventListResult params EventListParams - service *EventService + service *EventServiceImpl requestOptions []RequestOption } @@ -221,7 +237,7 @@ func (c *EventListPagingIterator) Value(ctx context.Context) (*EventListResult, p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/events")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/events")) if err != nil { return nil, err @@ -251,16 +267,16 @@ func (c *EventListPagingIterator) Value(ctx context.Context) (*EventListResult, } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -307,7 +323,7 @@ func (c *EventListPagingIterator) Value(ctx context.Context) (*EventListResult, return c.response, nil } -func (s *EventService) All(ctx context.Context, +func (s *EventServiceImpl) All(ctx context.Context, p EventListParams, opts ...RequestOption) *EventListPagingIterator { return &EventListPagingIterator{ @@ -319,8 +335,8 @@ func (s *EventService) All(ctx context.Context, // Get // Retrieves the details of a single event. -func (s *EventService) Get(ctx context.Context, identity string, opts ...RequestOption) (*Event, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/events/%v", +func (s *EventServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*Event, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/events/%v", identity)) if err != nil { return nil, err @@ -343,17 +359,17 @@ func (s *EventService) Get(ctx context.Context, identity string, opts ...Request return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/gc.go b/gc.go index f9f6d25..79794e5 100644 --- a/gc.go +++ b/gc.go @@ -6,212 +6,109 @@ import ( "fmt" ) -const ( - - // Live environment - LiveEndpoint = "https://api.gocardless.com" - - // Sandbox environment - SandboxEndpoint = "https://api-sandbox.gocardless.com" -) - type Service struct { - BankAuthorisations *BankAuthorisationService - BankDetailsLookups *BankDetailsLookupService - BillingRequests *BillingRequestService - BillingRequestFlows *BillingRequestFlowService - BillingRequestTemplates *BillingRequestTemplateService - Blocks *BlockService - Creditors *CreditorService - CreditorBankAccounts *CreditorBankAccountService - CurrencyExchangeRates *CurrencyExchangeRateService - Customers *CustomerService - CustomerBankAccounts *CustomerBankAccountService - CustomerNotifications *CustomerNotificationService - Events *EventService - InstalmentSchedules *InstalmentScheduleService - Institutions *InstitutionService - Mandates *MandateService - MandateImports *MandateImportService - MandateImportEntries *MandateImportEntryService - MandatePdfs *MandatePdfService - PayerAuthorisations *PayerAuthorisationService - Payments *PaymentService - Payouts *PayoutService - PayoutItems *PayoutItemService - RedirectFlows *RedirectFlowService - Refunds *RefundService - ScenarioSimulators *ScenarioSimulatorService - Subscriptions *SubscriptionService - TaxRates *TaxRateService - Webhooks *WebhookService + BankAuthorisations BankAuthorisationService + BankDetailsLookups BankDetailsLookupService + BillingRequests BillingRequestService + BillingRequestFlows BillingRequestFlowService + BillingRequestTemplates BillingRequestTemplateService + Blocks BlockService + Creditors CreditorService + CreditorBankAccounts CreditorBankAccountService + CurrencyExchangeRates CurrencyExchangeRateService + Customers CustomerService + CustomerBankAccounts CustomerBankAccountService + CustomerNotifications CustomerNotificationService + Events EventService + InstalmentSchedules InstalmentScheduleService + Institutions InstitutionService + Mandates MandateService + MandateImports MandateImportService + MandateImportEntries MandateImportEntryService + MandatePdfs MandatePdfService + PayerAuthorisations PayerAuthorisationService + Payments PaymentService + Payouts PayoutService + PayoutItems PayoutItemService + RedirectFlows RedirectFlowService + Refunds RefundService + ScenarioSimulators ScenarioSimulatorService + Subscriptions SubscriptionService + TaxRates TaxRateService + Webhooks WebhookService } func init() { initUserAgent() } -func New(token string, opts ...Option) (*Service, error) { - if token == "" { - return nil, errors.New("token required") +func New(config Config) (*Service, error) { + if config == nil { + return nil, errors.New("invalid configuration") } - o := &options{ - endpoint: LiveEndpoint, - } - for _, opt := range opts { - if err := opt(o); err != nil { - return nil, err - } + s := &Service{ + BankAuthorisations: &BankAuthorisationServiceImpl{ + config: config, + }, BankDetailsLookups: &BankDetailsLookupServiceImpl{ + config: config, + }, BillingRequests: &BillingRequestServiceImpl{ + config: config, + }, BillingRequestFlows: &BillingRequestFlowServiceImpl{ + config: config, + }, BillingRequestTemplates: &BillingRequestTemplateServiceImpl{ + config: config, + }, Blocks: &BlockServiceImpl{ + config: config, + }, Creditors: &CreditorServiceImpl{ + config: config, + }, CreditorBankAccounts: &CreditorBankAccountServiceImpl{ + config: config, + }, CurrencyExchangeRates: &CurrencyExchangeRateServiceImpl{ + config: config, + }, Customers: &CustomerServiceImpl{ + config: config, + }, CustomerBankAccounts: &CustomerBankAccountServiceImpl{ + config: config, + }, CustomerNotifications: &CustomerNotificationServiceImpl{ + config: config, + }, Events: &EventServiceImpl{ + config: config, + }, InstalmentSchedules: &InstalmentScheduleServiceImpl{ + config: config, + }, Institutions: &InstitutionServiceImpl{ + config: config, + }, Mandates: &MandateServiceImpl{ + config: config, + }, MandateImports: &MandateImportServiceImpl{ + config: config, + }, MandateImportEntries: &MandateImportEntryServiceImpl{ + config: config, + }, MandatePdfs: &MandatePdfServiceImpl{ + config: config, + }, PayerAuthorisations: &PayerAuthorisationServiceImpl{ + config: config, + }, Payments: &PaymentServiceImpl{ + config: config, + }, Payouts: &PayoutServiceImpl{ + config: config, + }, PayoutItems: &PayoutItemServiceImpl{ + config: config, + }, RedirectFlows: &RedirectFlowServiceImpl{ + config: config, + }, Refunds: &RefundServiceImpl{ + config: config, + }, ScenarioSimulators: &ScenarioSimulatorServiceImpl{ + config: config, + }, Subscriptions: &SubscriptionServiceImpl{ + config: config, + }, TaxRates: &TaxRateServiceImpl{ + config: config, + }, Webhooks: &WebhookServiceImpl{ + config: config, + }, } - s := &Service{} - - s.BankAuthorisations = &BankAuthorisationService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.BankDetailsLookups = &BankDetailsLookupService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.BillingRequests = &BillingRequestService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.BillingRequestFlows = &BillingRequestFlowService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.BillingRequestTemplates = &BillingRequestTemplateService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Blocks = &BlockService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Creditors = &CreditorService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.CreditorBankAccounts = &CreditorBankAccountService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.CurrencyExchangeRates = &CurrencyExchangeRateService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Customers = &CustomerService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.CustomerBankAccounts = &CustomerBankAccountService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.CustomerNotifications = &CustomerNotificationService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Events = &EventService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.InstalmentSchedules = &InstalmentScheduleService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Institutions = &InstitutionService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Mandates = &MandateService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.MandateImports = &MandateImportService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.MandateImportEntries = &MandateImportEntryService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.MandatePdfs = &MandatePdfService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.PayerAuthorisations = &PayerAuthorisationService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Payments = &PaymentService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Payouts = &PayoutService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.PayoutItems = &PayoutItemService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.RedirectFlows = &RedirectFlowService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Refunds = &RefundService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.ScenarioSimulators = &ScenarioSimulatorService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Subscriptions = &SubscriptionService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.TaxRates = &TaxRateService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } - s.Webhooks = &WebhookService{ - token: token, - endpoint: o.endpoint, - client: o.client, - } return s, nil } diff --git a/go.mod b/go.mod index 722d500..564ee29 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/gocardless/gocardless-pro-go +module github.com/gocardless/gocardless-pro-go/v2 go 1.16 diff --git a/instalment_schedule_service.go b/instalment_schedule_service.go index b56fd5d..5aad4a3 100644 --- a/instalment_schedule_service.go +++ b/instalment_schedule_service.go @@ -19,46 +19,60 @@ var _ = json.NewDecoder var _ = errors.New // InstalmentScheduleService manages instalment_schedules -type InstalmentScheduleService struct { - endpoint string - token string - client *http.Client +type InstalmentScheduleServiceImpl struct { + config Config +} + +type InstalmentScheduleLinks struct { + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + Payments []string `url:"payments,omitempty" json:"payments,omitempty"` } // InstalmentSchedule model type InstalmentSchedule struct { - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - Payments []string `url:"payments,omitempty" json:"payments,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` - PaymentErrors map[string]interface{} `url:"payment_errors,omitempty" json:"payment_errors,omitempty"` - Status string `url:"status,omitempty" json:"status,omitempty"` - TotalAmount int `url:"total_amount,omitempty" json:"total_amount,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *InstalmentScheduleLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + PaymentErrors map[string]interface{} `url:"payment_errors,omitempty" json:"payment_errors,omitempty"` + Status string `url:"status,omitempty" json:"status,omitempty"` + TotalAmount int `url:"total_amount,omitempty" json:"total_amount,omitempty"` +} + +type InstalmentScheduleService interface { + CreateWithDates(ctx context.Context, p InstalmentScheduleCreateWithDatesParams, opts ...RequestOption) (*InstalmentSchedule, error) + CreateWithSchedule(ctx context.Context, p InstalmentScheduleCreateWithScheduleParams, opts ...RequestOption) (*InstalmentSchedule, error) + List(ctx context.Context, p InstalmentScheduleListParams, opts ...RequestOption) (*InstalmentScheduleListResult, error) + All(ctx context.Context, p InstalmentScheduleListParams, opts ...RequestOption) *InstalmentScheduleListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*InstalmentSchedule, error) + Update(ctx context.Context, identity string, p InstalmentScheduleUpdateParams, opts ...RequestOption) (*InstalmentSchedule, error) + Cancel(ctx context.Context, identity string, p InstalmentScheduleCancelParams, opts ...RequestOption) (*InstalmentSchedule, error) +} + +type InstalmentScheduleCreateWithDatesParamsInstalments struct { + Amount int `url:"amount,omitempty" json:"amount,omitempty"` + ChargeDate string `url:"charge_date,omitempty" json:"charge_date,omitempty"` + Description string `url:"description,omitempty" json:"description,omitempty"` +} + +type InstalmentScheduleCreateWithDatesParamsLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` } // InstalmentScheduleCreateWithDatesParams parameters type InstalmentScheduleCreateWithDatesParams struct { - AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Instalments []struct { - Amount int `url:"amount,omitempty" json:"amount,omitempty"` - ChargeDate string `url:"charge_date,omitempty" json:"charge_date,omitempty"` - Description string `url:"description,omitempty" json:"description,omitempty"` - } `url:"instalments,omitempty" json:"instalments,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` - PaymentReference string `url:"payment_reference,omitempty" json:"payment_reference,omitempty"` - RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` - TotalAmount int `url:"total_amount,omitempty" json:"total_amount,omitempty"` + AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Instalments []InstalmentScheduleCreateWithDatesParamsInstalments `url:"instalments,omitempty" json:"instalments,omitempty"` + Links InstalmentScheduleCreateWithDatesParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + PaymentReference string `url:"payment_reference,omitempty" json:"payment_reference,omitempty"` + RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` + TotalAmount int `url:"total_amount,omitempty" json:"total_amount,omitempty"` } // CreateWithDates @@ -81,8 +95,8 @@ type InstalmentScheduleCreateWithDatesParams struct { // to the created payments, or the status `error` and detailed information about // the // failures. -func (s *InstalmentScheduleService) CreateWithDates(ctx context.Context, p InstalmentScheduleCreateWithDatesParams, opts ...RequestOption) (*InstalmentSchedule, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/instalment_schedules")) +func (s *InstalmentScheduleServiceImpl) CreateWithDates(ctx context.Context, p InstalmentScheduleCreateWithDatesParams, opts ...RequestOption) (*InstalmentSchedule, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/instalment_schedules")) if err != nil { return nil, err } @@ -116,10 +130,10 @@ func (s *InstalmentScheduleService) CreateWithDates(ctx context.Context, p Insta return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -128,7 +142,7 @@ func (s *InstalmentScheduleService) CreateWithDates(ctx context.Context, p Insta req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -172,24 +186,28 @@ func (s *InstalmentScheduleService) CreateWithDates(ctx context.Context, p Insta return result.InstalmentSchedule, nil } +type InstalmentScheduleCreateWithScheduleParamsInstalments struct { + Amounts []int `url:"amounts,omitempty" json:"amounts,omitempty"` + Interval int `url:"interval,omitempty" json:"interval,omitempty"` + IntervalUnit string `url:"interval_unit,omitempty" json:"interval_unit,omitempty"` + StartDate string `url:"start_date,omitempty" json:"start_date,omitempty"` +} + +type InstalmentScheduleCreateWithScheduleParamsLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` +} + // InstalmentScheduleCreateWithScheduleParams parameters type InstalmentScheduleCreateWithScheduleParams struct { - AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Instalments struct { - Amounts []int `url:"amounts,omitempty" json:"amounts,omitempty"` - Interval int `url:"interval,omitempty" json:"interval,omitempty"` - IntervalUnit string `url:"interval_unit,omitempty" json:"interval_unit,omitempty"` - StartDate string `url:"start_date,omitempty" json:"start_date,omitempty"` - } `url:"instalments,omitempty" json:"instalments,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` - PaymentReference string `url:"payment_reference,omitempty" json:"payment_reference,omitempty"` - RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` - TotalAmount int `url:"total_amount,omitempty" json:"total_amount,omitempty"` + AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Instalments InstalmentScheduleCreateWithScheduleParamsInstalments `url:"instalments,omitempty" json:"instalments,omitempty"` + Links InstalmentScheduleCreateWithScheduleParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + PaymentReference string `url:"payment_reference,omitempty" json:"payment_reference,omitempty"` + RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` + TotalAmount int `url:"total_amount,omitempty" json:"total_amount,omitempty"` } // CreateWithSchedule @@ -209,8 +227,8 @@ type InstalmentScheduleCreateWithScheduleParams struct { // the created payments, or the status `error` and detailed information about // the // failures. -func (s *InstalmentScheduleService) CreateWithSchedule(ctx context.Context, p InstalmentScheduleCreateWithScheduleParams, opts ...RequestOption) (*InstalmentSchedule, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/instalment_schedules")) +func (s *InstalmentScheduleServiceImpl) CreateWithSchedule(ctx context.Context, p InstalmentScheduleCreateWithScheduleParams, opts ...RequestOption) (*InstalmentSchedule, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/instalment_schedules")) if err != nil { return nil, err } @@ -244,10 +262,10 @@ func (s *InstalmentScheduleService) CreateWithSchedule(ctx context.Context, p In return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -256,7 +274,7 @@ func (s *InstalmentScheduleService) CreateWithSchedule(ctx context.Context, p In req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -300,39 +318,44 @@ func (s *InstalmentScheduleService) CreateWithSchedule(ctx context.Context, p In return result.InstalmentSchedule, nil } +type InstalmentScheduleListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // InstalmentScheduleListParams parameters type InstalmentScheduleListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - Status []string `url:"status,omitempty" json:"status,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *InstalmentScheduleListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + Status []string `url:"status,omitempty" json:"status,omitempty"` +} + +type InstalmentScheduleListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type InstalmentScheduleListResultMeta struct { + Cursors *InstalmentScheduleListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// InstalmentScheduleListResult response including pagination metadata type InstalmentScheduleListResult struct { - InstalmentSchedules []InstalmentSchedule `json:"instalment_schedules"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + InstalmentSchedules []InstalmentSchedule `json:"instalment_schedules"` + Meta InstalmentScheduleListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // instalment schedules. -func (s *InstalmentScheduleService) List(ctx context.Context, p InstalmentScheduleListParams, opts ...RequestOption) (*InstalmentScheduleListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/instalment_schedules")) +func (s *InstalmentScheduleServiceImpl) List(ctx context.Context, p InstalmentScheduleListParams, opts ...RequestOption) (*InstalmentScheduleListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/instalment_schedules")) if err != nil { return nil, err } @@ -360,17 +383,17 @@ func (s *InstalmentScheduleService) List(ctx context.Context, p InstalmentSchedu return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -418,7 +441,7 @@ type InstalmentScheduleListPagingIterator struct { cursor string response *InstalmentScheduleListResult params InstalmentScheduleListParams - service *InstalmentScheduleService + service *InstalmentScheduleServiceImpl requestOptions []RequestOption } @@ -439,7 +462,7 @@ func (c *InstalmentScheduleListPagingIterator) Value(ctx context.Context) (*Inst p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/instalment_schedules")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/instalment_schedules")) if err != nil { return nil, err @@ -469,16 +492,16 @@ func (c *InstalmentScheduleListPagingIterator) Value(ctx context.Context) (*Inst } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -525,7 +548,7 @@ func (c *InstalmentScheduleListPagingIterator) Value(ctx context.Context) (*Inst return c.response, nil } -func (s *InstalmentScheduleService) All(ctx context.Context, +func (s *InstalmentScheduleServiceImpl) All(ctx context.Context, p InstalmentScheduleListParams, opts ...RequestOption) *InstalmentScheduleListPagingIterator { return &InstalmentScheduleListPagingIterator{ @@ -537,8 +560,8 @@ func (s *InstalmentScheduleService) All(ctx context.Context, // Get // Retrieves the details of an existing instalment schedule. -func (s *InstalmentScheduleService) Get(ctx context.Context, identity string, opts ...RequestOption) (*InstalmentSchedule, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/instalment_schedules/%v", +func (s *InstalmentScheduleServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*InstalmentSchedule, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/instalment_schedules/%v", identity)) if err != nil { return nil, err @@ -561,17 +584,17 @@ func (s *InstalmentScheduleService) Get(ctx context.Context, identity string, op return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -622,8 +645,8 @@ type InstalmentScheduleUpdateParams struct { // Update // Updates an instalment schedule. This accepts only the metadata parameter. -func (s *InstalmentScheduleService) Update(ctx context.Context, identity string, p InstalmentScheduleUpdateParams, opts ...RequestOption) (*InstalmentSchedule, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/instalment_schedules/%v", +func (s *InstalmentScheduleServiceImpl) Update(ctx context.Context, identity string, p InstalmentScheduleUpdateParams, opts ...RequestOption) (*InstalmentSchedule, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/instalment_schedules/%v", identity)) if err != nil { return nil, err @@ -658,10 +681,10 @@ func (s *InstalmentScheduleService) Update(ctx context.Context, identity string, return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -670,7 +693,7 @@ func (s *InstalmentScheduleService) Update(ctx context.Context, identity string, req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -715,7 +738,8 @@ func (s *InstalmentScheduleService) Update(ctx context.Context, identity string, } // InstalmentScheduleCancelParams parameters -type InstalmentScheduleCancelParams map[string]interface{} +type InstalmentScheduleCancelParams struct { +} // Cancel // Immediately cancels an instalment schedule; no further payments will be @@ -723,8 +747,8 @@ type InstalmentScheduleCancelParams map[string]interface{} // // This will fail with a `cancellation_failed` error if the instalment schedule // is already cancelled or has completed. -func (s *InstalmentScheduleService) Cancel(ctx context.Context, identity string, p InstalmentScheduleCancelParams, opts ...RequestOption) (*InstalmentSchedule, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/instalment_schedules/%v/actions/cancel", +func (s *InstalmentScheduleServiceImpl) Cancel(ctx context.Context, identity string, p InstalmentScheduleCancelParams, opts ...RequestOption) (*InstalmentSchedule, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/instalment_schedules/%v/actions/cancel", identity)) if err != nil { return nil, err @@ -759,10 +783,10 @@ func (s *InstalmentScheduleService) Cancel(ctx context.Context, identity string, return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -771,7 +795,7 @@ func (s *InstalmentScheduleService) Cancel(ctx context.Context, identity string, req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/institution_service.go b/institution_service.go index 660670c..578c4e8 100644 --- a/institution_service.go +++ b/institution_service.go @@ -19,19 +19,22 @@ var _ = json.NewDecoder var _ = errors.New // InstitutionService manages institutions -type InstitutionService struct { - endpoint string - token string - client *http.Client +type InstitutionServiceImpl struct { + config Config } // Institution model type Institution struct { - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - IconUrl string `url:"icon_url,omitempty" json:"icon_url,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - LogoUrl string `url:"logo_url,omitempty" json:"logo_url,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + IconUrl string `url:"icon_url,omitempty" json:"icon_url,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + LogoUrl string `url:"logo_url,omitempty" json:"logo_url,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + Roles []string `url:"roles,omitempty" json:"roles,omitempty"` +} + +type InstitutionService interface { + List(ctx context.Context, p InstitutionListParams, opts ...RequestOption) (*InstitutionListResult, error) } // InstitutionListParams parameters @@ -39,22 +42,25 @@ type InstitutionListParams struct { CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` } -// InstitutionListResult response including pagination metadata +type InstitutionListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type InstitutionListResultMeta struct { + Cursors *InstitutionListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + type InstitutionListResult struct { - Institutions []Institution `json:"institutions"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Institutions []Institution `json:"institutions"` + Meta InstitutionListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List -// Returns a list of all supported institutions. -func (s *InstitutionService) List(ctx context.Context, p InstitutionListParams, opts ...RequestOption) (*InstitutionListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/institutions")) +// Returns a list of supported institutions. +func (s *InstitutionServiceImpl) List(ctx context.Context, p InstitutionListParams, opts ...RequestOption) (*InstitutionListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/institutions")) if err != nil { return nil, err } @@ -82,17 +88,17 @@ func (s *InstitutionService) List(ctx context.Context, p InstitutionListParams, return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/mandate_import_entry_service.go b/mandate_import_entry_service.go index 1fbb314..881c544 100644 --- a/mandate_import_entry_service.go +++ b/mandate_import_entry_service.go @@ -19,60 +19,74 @@ var _ = json.NewDecoder var _ = errors.New // MandateImportEntryService manages mandate_import_entries -type MandateImportEntryService struct { - endpoint string - token string - client *http.Client +type MandateImportEntryServiceImpl struct { + config Config +} + +type MandateImportEntryLinks struct { + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + MandateImport string `url:"mandate_import,omitempty" json:"mandate_import,omitempty"` } // MandateImportEntry model type MandateImportEntry struct { - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Links struct { - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - MandateImport string `url:"mandate_import,omitempty" json:"mandate_import,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - RecordIdentifier string `url:"record_identifier,omitempty" json:"record_identifier,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Links *MandateImportEntryLinks `url:"links,omitempty" json:"links,omitempty"` + RecordIdentifier string `url:"record_identifier,omitempty" json:"record_identifier,omitempty"` +} + +type MandateImportEntryService interface { + Create(ctx context.Context, p MandateImportEntryCreateParams, opts ...RequestOption) (*MandateImportEntry, error) + List(ctx context.Context, p MandateImportEntryListParams, opts ...RequestOption) (*MandateImportEntryListResult, error) + All(ctx context.Context, p MandateImportEntryListParams, opts ...RequestOption) *MandateImportEntryListPagingIterator +} + +type MandateImportEntryCreateParamsAmendment struct { + OriginalCreditorId string `url:"original_creditor_id,omitempty" json:"original_creditor_id,omitempty"` + OriginalCreditorName string `url:"original_creditor_name,omitempty" json:"original_creditor_name,omitempty"` + OriginalMandateReference string `url:"original_mandate_reference,omitempty" json:"original_mandate_reference,omitempty"` +} + +type MandateImportEntryCreateParamsBankAccount struct { + 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"` +} + +type MandateImportEntryCreateParamsCustomer struct { + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` + Email string `url:"email,omitempty" json:"email,omitempty"` + FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` + GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` + Language string `url:"language,omitempty" json:"language,omitempty"` + PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` +} + +type MandateImportEntryCreateParamsLinks struct { + MandateImport string `url:"mandate_import,omitempty" json:"mandate_import,omitempty"` } // MandateImportEntryCreateParams parameters type MandateImportEntryCreateParams struct { - Amendment struct { - OriginalCreditorId string `url:"original_creditor_id,omitempty" json:"original_creditor_id,omitempty"` - OriginalCreditorName string `url:"original_creditor_name,omitempty" json:"original_creditor_name,omitempty"` - OriginalMandateReference string `url:"original_mandate_reference,omitempty" json:"original_mandate_reference,omitempty"` - } `url:"amendment,omitempty" json:"amendment,omitempty"` - BankAccount struct { - 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"` - } `url:"bank_account,omitempty" json:"bank_account,omitempty"` - Customer struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` - Email string `url:"email,omitempty" json:"email,omitempty"` - FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` - GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` - Language string `url:"language,omitempty" json:"language,omitempty"` - PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` - } `url:"customer,omitempty" json:"customer,omitempty"` - Links struct { - MandateImport string `url:"mandate_import,omitempty" json:"mandate_import,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - RecordIdentifier string `url:"record_identifier,omitempty" json:"record_identifier,omitempty"` + Amendment *MandateImportEntryCreateParamsAmendment `url:"amendment,omitempty" json:"amendment,omitempty"` + BankAccount MandateImportEntryCreateParamsBankAccount `url:"bank_account,omitempty" json:"bank_account,omitempty"` + Customer MandateImportEntryCreateParamsCustomer `url:"customer,omitempty" json:"customer,omitempty"` + Links MandateImportEntryCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + RecordIdentifier string `url:"record_identifier,omitempty" json:"record_identifier,omitempty"` } // Create @@ -83,8 +97,8 @@ type MandateImportEntryCreateParams struct { // You can add no more than 30,000 rows to a single mandate import. // If you attempt to go over this limit, the API will return a // `record_limit_exceeded` error. -func (s *MandateImportEntryService) Create(ctx context.Context, p MandateImportEntryCreateParams, opts ...RequestOption) (*MandateImportEntry, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/mandate_import_entries")) +func (s *MandateImportEntryServiceImpl) Create(ctx context.Context, p MandateImportEntryCreateParams, opts ...RequestOption) (*MandateImportEntry, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/mandate_import_entries")) if err != nil { return nil, err } @@ -118,10 +132,10 @@ func (s *MandateImportEntryService) Create(ctx context.Context, p MandateImportE return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -130,7 +144,7 @@ func (s *MandateImportEntryService) Create(ctx context.Context, p MandateImportE req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -182,16 +196,19 @@ type MandateImportEntryListParams struct { MandateImport string `url:"mandate_import,omitempty" json:"mandate_import,omitempty"` } -// MandateImportEntryListResult response including pagination metadata +type MandateImportEntryListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type MandateImportEntryListResultMeta struct { + Cursors *MandateImportEntryListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + type MandateImportEntryListResult struct { - MandateImportEntries []MandateImportEntry `json:"mandate_import_entries"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + MandateImportEntries []MandateImportEntry `json:"mandate_import_entries"` + Meta MandateImportEntryListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List @@ -204,8 +221,8 @@ type MandateImportEntryListResult struct { // the // mandate import). // -func (s *MandateImportEntryService) List(ctx context.Context, p MandateImportEntryListParams, opts ...RequestOption) (*MandateImportEntryListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/mandate_import_entries")) +func (s *MandateImportEntryServiceImpl) List(ctx context.Context, p MandateImportEntryListParams, opts ...RequestOption) (*MandateImportEntryListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/mandate_import_entries")) if err != nil { return nil, err } @@ -233,17 +250,17 @@ func (s *MandateImportEntryService) List(ctx context.Context, p MandateImportEnt return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -291,7 +308,7 @@ type MandateImportEntryListPagingIterator struct { cursor string response *MandateImportEntryListResult params MandateImportEntryListParams - service *MandateImportEntryService + service *MandateImportEntryServiceImpl requestOptions []RequestOption } @@ -312,7 +329,7 @@ func (c *MandateImportEntryListPagingIterator) Value(ctx context.Context) (*Mand p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/mandate_import_entries")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/mandate_import_entries")) if err != nil { return nil, err @@ -342,16 +359,16 @@ func (c *MandateImportEntryListPagingIterator) Value(ctx context.Context) (*Mand } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -398,7 +415,7 @@ func (c *MandateImportEntryListPagingIterator) Value(ctx context.Context) (*Mand return c.response, nil } -func (s *MandateImportEntryService) All(ctx context.Context, +func (s *MandateImportEntryServiceImpl) All(ctx context.Context, p MandateImportEntryListParams, opts ...RequestOption) *MandateImportEntryListPagingIterator { return &MandateImportEntryListPagingIterator{ diff --git a/mandate_import_service.go b/mandate_import_service.go index 2878dc4..81fa60e 100644 --- a/mandate_import_service.go +++ b/mandate_import_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // MandateImportService manages mandate_imports -type MandateImportService struct { - endpoint string - token string - client *http.Client +type MandateImportServiceImpl struct { + config Config } // MandateImport model @@ -33,6 +31,13 @@ type MandateImport struct { Status string `url:"status,omitempty" json:"status,omitempty"` } +type MandateImportService interface { + Create(ctx context.Context, p MandateImportCreateParams, opts ...RequestOption) (*MandateImport, error) + Get(ctx context.Context, identity string, p MandateImportGetParams, opts ...RequestOption) (*MandateImport, error) + Submit(ctx context.Context, identity string, p MandateImportSubmitParams, opts ...RequestOption) (*MandateImport, error) + Cancel(ctx context.Context, identity string, p MandateImportCancelParams, opts ...RequestOption) (*MandateImport, error) +} + // MandateImportCreateParams parameters type MandateImportCreateParams struct { Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` @@ -45,8 +50,8 @@ type MandateImportCreateParams struct { // finished // adding entries to an import, you should // [submit](#mandate-imports-submit-a-mandate-import) it. -func (s *MandateImportService) Create(ctx context.Context, p MandateImportCreateParams, opts ...RequestOption) (*MandateImport, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/mandate_imports")) +func (s *MandateImportServiceImpl) Create(ctx context.Context, p MandateImportCreateParams, opts ...RequestOption) (*MandateImport, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/mandate_imports")) if err != nil { return nil, err } @@ -80,10 +85,10 @@ func (s *MandateImportService) Create(ctx context.Context, p MandateImportCreate return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -92,7 +97,7 @@ func (s *MandateImportService) Create(ctx context.Context, p MandateImportCreate req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -137,12 +142,13 @@ func (s *MandateImportService) Create(ctx context.Context, p MandateImportCreate } // MandateImportGetParams parameters -type MandateImportGetParams map[string]interface{} +type MandateImportGetParams struct { +} // Get // Returns a single mandate import. -func (s *MandateImportService) Get(ctx context.Context, identity string, p MandateImportGetParams, opts ...RequestOption) (*MandateImport, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/mandate_imports/%v", +func (s *MandateImportServiceImpl) Get(ctx context.Context, identity string, p MandateImportGetParams, opts ...RequestOption) (*MandateImport, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/mandate_imports/%v", identity)) if err != nil { return nil, err @@ -165,17 +171,17 @@ func (s *MandateImportService) Get(ctx context.Context, identity string, p Manda return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -220,7 +226,8 @@ func (s *MandateImportService) Get(ctx context.Context, identity string, p Manda } // MandateImportSubmitParams parameters -type MandateImportSubmitParams map[string]interface{} +type MandateImportSubmitParams struct { +} // Submit // Submits the mandate import, which allows it to be processed by a member of @@ -235,8 +242,8 @@ type MandateImportSubmitParams map[string]interface{} // you to // test both the "submitted" response and wait for the webhook to confirm the // processing has begun. -func (s *MandateImportService) Submit(ctx context.Context, identity string, p MandateImportSubmitParams, opts ...RequestOption) (*MandateImport, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/mandate_imports/%v/actions/submit", +func (s *MandateImportServiceImpl) Submit(ctx context.Context, identity string, p MandateImportSubmitParams, opts ...RequestOption) (*MandateImport, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/mandate_imports/%v/actions/submit", identity)) if err != nil { return nil, err @@ -271,10 +278,10 @@ func (s *MandateImportService) Submit(ctx context.Context, identity string, p Ma return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -283,7 +290,7 @@ func (s *MandateImportService) Submit(ctx context.Context, identity string, p Ma req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -328,7 +335,8 @@ func (s *MandateImportService) Submit(ctx context.Context, identity string, p Ma } // MandateImportCancelParams parameters -type MandateImportCancelParams map[string]interface{} +type MandateImportCancelParams struct { +} // Cancel // Cancels the mandate import, which aborts the import process and stops the @@ -338,8 +346,8 @@ type MandateImportCancelParams map[string]interface{} // entries added to it. Mandate imports which have already been submitted or // processed // cannot be cancelled. -func (s *MandateImportService) Cancel(ctx context.Context, identity string, p MandateImportCancelParams, opts ...RequestOption) (*MandateImport, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/mandate_imports/%v/actions/cancel", +func (s *MandateImportServiceImpl) Cancel(ctx context.Context, identity string, p MandateImportCancelParams, opts ...RequestOption) (*MandateImport, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/mandate_imports/%v/actions/cancel", identity)) if err != nil { return nil, err @@ -374,10 +382,10 @@ func (s *MandateImportService) Cancel(ctx context.Context, identity string, p Ma return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -386,7 +394,7 @@ func (s *MandateImportService) Cancel(ctx context.Context, identity string, p Ma req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/mandate_pdf_service.go b/mandate_pdf_service.go index 4e126dd..668214f 100644 --- a/mandate_pdf_service.go +++ b/mandate_pdf_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // MandatePdfService manages mandate_pdfs -type MandatePdfService struct { - endpoint string - token string - client *http.Client +type MandatePdfServiceImpl struct { + config Config } // MandatePdf model @@ -31,34 +29,40 @@ type MandatePdf struct { Url string `url:"url,omitempty" json:"url,omitempty"` } +type MandatePdfService interface { + Create(ctx context.Context, p MandatePdfCreateParams, opts ...RequestOption) (*MandatePdf, error) +} + +type MandatePdfCreateParamsLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` +} + // MandatePdfCreateParams parameters type MandatePdfCreateParams struct { - AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` - AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` - AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - BankCode string `url:"bank_code,omitempty" json:"bank_code,omitempty"` - Bic string `url:"bic,omitempty" json:"bic,omitempty"` - BranchCode string `url:"branch_code,omitempty" json:"branch_code,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` - Iban string `url:"iban,omitempty" json:"iban,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - MandateReference string `url:"mandate_reference,omitempty" json:"mandate_reference,omitempty"` - PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` - PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - SignatureDate string `url:"signature_date,omitempty" json:"signature_date,omitempty"` - SubscriptionAmount int `url:"subscription_amount,omitempty" json:"subscription_amount,omitempty"` - SubscriptionFrequency string `url:"subscription_frequency,omitempty" json:"subscription_frequency,omitempty"` - SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` + AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` + AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` + AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + BankCode string `url:"bank_code,omitempty" json:"bank_code,omitempty"` + Bic string `url:"bic,omitempty" json:"bic,omitempty"` + BranchCode string `url:"branch_code,omitempty" json:"branch_code,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` + Iban string `url:"iban,omitempty" json:"iban,omitempty"` + Links *MandatePdfCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + MandateReference string `url:"mandate_reference,omitempty" json:"mandate_reference,omitempty"` + PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` + PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` + SignatureDate string `url:"signature_date,omitempty" json:"signature_date,omitempty"` + SubscriptionAmount int `url:"subscription_amount,omitempty" json:"subscription_amount,omitempty"` + SubscriptionFrequency string `url:"subscription_frequency,omitempty" json:"subscription_frequency,omitempty"` + SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` } // Create @@ -105,8 +109,8 @@ type MandatePdfCreateParams struct { // | SEPA Core | Danish (`da`), Dutch (`nl`), English (`en`), French // (`fr`), German (`de`), Italian (`it`), Portuguese (`pt`), Spanish (`es`), // Swedish (`sv`) | -func (s *MandatePdfService) Create(ctx context.Context, p MandatePdfCreateParams, opts ...RequestOption) (*MandatePdf, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/mandate_pdfs")) +func (s *MandatePdfServiceImpl) Create(ctx context.Context, p MandatePdfCreateParams, opts ...RequestOption) (*MandatePdf, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/mandate_pdfs")) if err != nil { return nil, err } @@ -140,10 +144,10 @@ func (s *MandatePdfService) Create(ctx context.Context, p MandatePdfCreateParams return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -152,7 +156,7 @@ func (s *MandatePdfService) Create(ctx context.Context, p MandatePdfCreateParams req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/mandate_service.go b/mandate_service.go index 0590e4d..e4d8074 100644 --- a/mandate_service.go +++ b/mandate_service.go @@ -19,22 +19,22 @@ var _ = json.NewDecoder var _ = errors.New // MandateService manages mandates -type MandateService struct { - endpoint string - token string - client *http.Client +type MandateServiceImpl struct { + config Config +} + +type MandateLinks struct { + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` + NewMandate string `url:"new_mandate,omitempty" json:"new_mandate,omitempty"` } // Mandate model type Mandate struct { - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` - NewMandate string `url:"new_mandate,omitempty" json:"new_mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *MandateLinks `url:"links,omitempty" json:"links,omitempty"` Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` NextPossibleChargeDate string `url:"next_possible_charge_date,omitempty" json:"next_possible_charge_date,omitempty"` PaymentsRequireApproval bool `url:"payments_require_approval,omitempty" json:"payments_require_approval,omitempty"` @@ -43,22 +43,34 @@ type Mandate struct { Status string `url:"status,omitempty" json:"status,omitempty"` } +type MandateService interface { + Create(ctx context.Context, p MandateCreateParams, opts ...RequestOption) (*Mandate, error) + List(ctx context.Context, p MandateListParams, opts ...RequestOption) (*MandateListResult, error) + All(ctx context.Context, p MandateListParams, opts ...RequestOption) *MandateListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*Mandate, error) + Update(ctx context.Context, identity string, p MandateUpdateParams, opts ...RequestOption) (*Mandate, error) + Cancel(ctx context.Context, identity string, p MandateCancelParams, opts ...RequestOption) (*Mandate, error) + Reinstate(ctx context.Context, identity string, p MandateReinstateParams, opts ...RequestOption) (*Mandate, error) +} + +type MandateCreateParamsLinks struct { + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` +} + // MandateCreateParams parameters type MandateCreateParams struct { - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` + Links MandateCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` } // Create // Creates a new mandate object. -func (s *MandateService) Create(ctx context.Context, p MandateCreateParams, opts ...RequestOption) (*Mandate, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/mandates")) +func (s *MandateServiceImpl) Create(ctx context.Context, p MandateCreateParams, opts ...RequestOption) (*Mandate, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/mandates")) if err != nil { return nil, err } @@ -92,10 +104,10 @@ func (s *MandateService) Create(ctx context.Context, p MandateCreateParams, opts return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -104,7 +116,7 @@ func (s *MandateService) Create(ctx context.Context, p MandateCreateParams, opts req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -148,42 +160,47 @@ func (s *MandateService) Create(ctx context.Context, p MandateCreateParams, opts return result.Mandate, nil } +type MandateListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // MandateListParams parameters type MandateListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - Scheme []string `url:"scheme,omitempty" json:"scheme,omitempty"` - Status []string `url:"status,omitempty" json:"status,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *MandateListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + Scheme []string `url:"scheme,omitempty" json:"scheme,omitempty"` + Status []string `url:"status,omitempty" json:"status,omitempty"` +} + +type MandateListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type MandateListResultMeta struct { + Cursors *MandateListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// MandateListResult response including pagination metadata type MandateListResult struct { - Mandates []Mandate `json:"mandates"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Mandates []Mandate `json:"mandates"` + Meta MandateListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // mandates. -func (s *MandateService) List(ctx context.Context, p MandateListParams, opts ...RequestOption) (*MandateListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/mandates")) +func (s *MandateServiceImpl) List(ctx context.Context, p MandateListParams, opts ...RequestOption) (*MandateListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/mandates")) if err != nil { return nil, err } @@ -211,17 +228,17 @@ func (s *MandateService) List(ctx context.Context, p MandateListParams, opts ... return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -269,7 +286,7 @@ type MandateListPagingIterator struct { cursor string response *MandateListResult params MandateListParams - service *MandateService + service *MandateServiceImpl requestOptions []RequestOption } @@ -290,7 +307,7 @@ func (c *MandateListPagingIterator) Value(ctx context.Context) (*MandateListResu p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/mandates")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/mandates")) if err != nil { return nil, err @@ -320,16 +337,16 @@ func (c *MandateListPagingIterator) Value(ctx context.Context) (*MandateListResu } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -376,7 +393,7 @@ func (c *MandateListPagingIterator) Value(ctx context.Context) (*MandateListResu return c.response, nil } -func (s *MandateService) All(ctx context.Context, +func (s *MandateServiceImpl) All(ctx context.Context, p MandateListParams, opts ...RequestOption) *MandateListPagingIterator { return &MandateListPagingIterator{ @@ -388,8 +405,8 @@ func (s *MandateService) All(ctx context.Context, // Get // Retrieves the details of an existing mandate. -func (s *MandateService) Get(ctx context.Context, identity string, opts ...RequestOption) (*Mandate, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/mandates/%v", +func (s *MandateServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*Mandate, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/mandates/%v", identity)) if err != nil { return nil, err @@ -412,17 +429,17 @@ func (s *MandateService) Get(ctx context.Context, identity string, opts ...Reque return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -473,8 +490,8 @@ type MandateUpdateParams struct { // Update // Updates a mandate object. This accepts only the metadata parameter. -func (s *MandateService) Update(ctx context.Context, identity string, p MandateUpdateParams, opts ...RequestOption) (*Mandate, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/mandates/%v", +func (s *MandateServiceImpl) Update(ctx context.Context, identity string, p MandateUpdateParams, opts ...RequestOption) (*Mandate, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/mandates/%v", identity)) if err != nil { return nil, err @@ -509,10 +526,10 @@ func (s *MandateService) Update(ctx context.Context, identity string, p MandateU return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -521,7 +538,7 @@ func (s *MandateService) Update(ctx context.Context, identity string, p MandateU req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -577,8 +594,8 @@ type MandateCancelParams struct { // // This will fail with a `cancellation_failed` error if the mandate is already // cancelled. -func (s *MandateService) Cancel(ctx context.Context, identity string, p MandateCancelParams, opts ...RequestOption) (*Mandate, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/mandates/%v/actions/cancel", +func (s *MandateServiceImpl) Cancel(ctx context.Context, identity string, p MandateCancelParams, opts ...RequestOption) (*Mandate, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/mandates/%v/actions/cancel", identity)) if err != nil { return nil, err @@ -613,10 +630,10 @@ func (s *MandateService) Cancel(ctx context.Context, identity string, p MandateC return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -625,7 +642,7 @@ func (s *MandateService) Cancel(ctx context.Context, identity string, p MandateC req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -687,8 +704,8 @@ type MandateReinstateParams struct { // being submitted, or is active. // // Mandates can be resubmitted up to 10 times. -func (s *MandateService) Reinstate(ctx context.Context, identity string, p MandateReinstateParams, opts ...RequestOption) (*Mandate, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/mandates/%v/actions/reinstate", +func (s *MandateServiceImpl) Reinstate(ctx context.Context, identity string, p MandateReinstateParams, opts ...RequestOption) (*Mandate, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/mandates/%v/actions/reinstate", identity)) if err != nil { return nil, err @@ -723,10 +740,10 @@ func (s *MandateService) Reinstate(ctx context.Context, identity string, p Manda return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -735,7 +752,7 @@ func (s *MandateService) Reinstate(ctx context.Context, identity string, p Manda req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/options.go b/options.go index 06c5d6d..f139e26 100644 --- a/options.go +++ b/options.go @@ -6,34 +6,89 @@ import ( "net/url" ) -// Option used to initialise the client -type Option func(*options) error +const ( -type options struct { + // Live environment + LiveEndpoint = "https://api.gocardless.com" + + // Sandbox environment + SandboxEndpoint = "https://api-sandbox.gocardless.com" +) + +// ConfigOption used to initialise the client +type ConfigOption func(Config) error + +type Config interface { + Token() string + Endpoint() string + Client() *http.Client +} + +type config struct { + token string endpoint string client *http.Client } +func (c *config) Token() string { + return c.token +} + +func (c *config) Endpoint() string { + return c.endpoint +} + +func (c *config) Client() *http.Client { + return c.client +} + // WithEndpoint configures the endpoint hosting the API -func WithEndpoint(endpoint string) Option { - return func(opts *options) error { +func WithEndpoint(endpoint string) ConfigOption { + return func(cfg Config) error { u, err := url.Parse(endpoint) if err != nil { return err } - opts.endpoint = u.String() + if c, ok := cfg.(*config); ok { + c.endpoint = u.String() + } else { + return errors.New("invalid input, input is not of type config") + } return nil } } // WithClient configures the net/http client -func WithClient(c *http.Client) Option { - return func(opts *options) error { - opts.client = c +func WithClient(client *http.Client) ConfigOption { + return func(cfg Config) error { + if c, ok := cfg.(*config); ok { + c.client = client + } else { + return errors.New("invalid input, input is not of type config") + } return nil } } +func NewConfig(token string, configOpts ...ConfigOption) (Config, error) { + if token == "" { + return nil, errors.New("token required") + } + + config := &config{ + token: token, + endpoint: LiveEndpoint, + } + + for _, configOpt := range configOpts { + if err := configOpt(config); err != nil { + return nil, err + } + } + + return config, nil +} + // RequestOption is used to configure a given request type RequestOption func(*requestOptions) error diff --git a/options_test.go b/options_test.go new file mode 100644 index 0000000..55d4f06 --- /dev/null +++ b/options_test.go @@ -0,0 +1,52 @@ +package gocardless + +import "testing" + +func TestEndpointForToken(t *testing.T) { + tests := []struct { + token string + wantErr bool + }{ + {"", true}, + {"dummy_token", false}, + } + + for _, tt := range tests { + _, err := NewConfig(tt.token) + if tt.wantErr { + if err == nil { + t.Fatalf("expected error if token is invalid, got nil for token: %v", tt.token) + } + continue + } + + if err != nil { + t.Fatalf("unexepcted error if token is valid, got token: %v, err: %v", tt.token, err) + } + } +} + +func TestEndpointForConfig(t *testing.T) { + tests := []struct { + endpoint string + wantErr bool + }{ + {"http://foo.com", false}, + {"1http://foo.com", true}, + } + + for _, tt := range tests { + token := "dummy_token" + _, err := NewConfig(token, WithEndpoint(tt.endpoint)) + if tt.wantErr { + if err == nil { + t.Fatalf("expected error if endpoint is invalid, got nil for endpoint: %v", tt.endpoint) + } + continue + } + + if err != nil { + t.Fatalf("unexepcted error if endpoint is valid, got endpoint: %v, err: %v", tt.endpoint, err) + } + } +} diff --git a/payer_authorisation_service.go b/payer_authorisation_service.go index f5d4919..35b507b 100644 --- a/payer_authorisation_service.go +++ b/payer_authorisation_service.go @@ -19,70 +19,86 @@ var _ = json.NewDecoder var _ = errors.New // PayerAuthorisationService manages payer_authorisations -type PayerAuthorisationService struct { - endpoint string - token string - client *http.Client +type PayerAuthorisationServiceImpl struct { + config Config +} + +type PayerAuthorisationBankAccount struct { + AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` + AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` + AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` + AccountNumberSuffix string `url:"account_number_suffix,omitempty" json:"account_number_suffix,omitempty"` + AccountType string `url:"account_type,omitempty" json:"account_type,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"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Iban string `url:"iban,omitempty" json:"iban,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` +} + +type PayerAuthorisationCustomer struct { + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` + Email string `url:"email,omitempty" json:"email,omitempty"` + FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` + GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` + Locale string `url:"locale,omitempty" json:"locale,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` +} + +type PayerAuthorisationIncompleteFields struct { + Field string `url:"field,omitempty" json:"field,omitempty"` + Message string `url:"message,omitempty" json:"message,omitempty"` + RequestPointer string `url:"request_pointer,omitempty" json:"request_pointer,omitempty"` +} + +type PayerAuthorisationLinks struct { + BankAccount string `url:"bank_account,omitempty" json:"bank_account,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` +} + +type PayerAuthorisationMandate struct { + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` } // PayerAuthorisation model type PayerAuthorisation struct { - BankAccount struct { - AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` - AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` - AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` - AccountNumberSuffix string `url:"account_number_suffix,omitempty" json:"account_number_suffix,omitempty"` - AccountType string `url:"account_type,omitempty" json:"account_type,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"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Iban string `url:"iban,omitempty" json:"iban,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - } `url:"bank_account,omitempty" json:"bank_account,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Customer struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` - Email string `url:"email,omitempty" json:"email,omitempty"` - FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` - GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` - Locale string `url:"locale,omitempty" json:"locale,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` - } `url:"customer,omitempty" json:"customer,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - IncompleteFields []struct { - Field string `url:"field,omitempty" json:"field,omitempty"` - Message string `url:"message,omitempty" json:"message,omitempty"` - RequestPointer string `url:"request_pointer,omitempty" json:"request_pointer,omitempty"` - } `url:"incomplete_fields,omitempty" json:"incomplete_fields,omitempty"` - Links struct { - BankAccount string `url:"bank_account,omitempty" json:"bank_account,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Mandate struct { - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - } `url:"mandate,omitempty" json:"mandate,omitempty"` - Status string `url:"status,omitempty" json:"status,omitempty"` + BankAccount *PayerAuthorisationBankAccount `url:"bank_account,omitempty" json:"bank_account,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Customer *PayerAuthorisationCustomer `url:"customer,omitempty" json:"customer,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + IncompleteFields []PayerAuthorisationIncompleteFields `url:"incomplete_fields,omitempty" json:"incomplete_fields,omitempty"` + Links *PayerAuthorisationLinks `url:"links,omitempty" json:"links,omitempty"` + Mandate *PayerAuthorisationMandate `url:"mandate,omitempty" json:"mandate,omitempty"` + Status string `url:"status,omitempty" json:"status,omitempty"` +} + +type PayerAuthorisationService interface { + Get(ctx context.Context, identity string, opts ...RequestOption) (*PayerAuthorisation, error) + Create(ctx context.Context, p PayerAuthorisationCreateParams, opts ...RequestOption) (*PayerAuthorisation, error) + Update(ctx context.Context, identity string, p PayerAuthorisationUpdateParams, opts ...RequestOption) (*PayerAuthorisation, error) + Submit(ctx context.Context, identity string, opts ...RequestOption) (*PayerAuthorisation, error) + Confirm(ctx context.Context, identity string, opts ...RequestOption) (*PayerAuthorisation, error) } // Get // Retrieves the details of a single existing Payer Authorisation. It can be // used for polling the status of a Payer Authorisation. -func (s *PayerAuthorisationService) Get(ctx context.Context, identity string, opts ...RequestOption) (*PayerAuthorisation, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payer_authorisations/%v", +func (s *PayerAuthorisationServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*PayerAuthorisation, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payer_authorisations/%v", identity)) if err != nil { return nil, err @@ -105,17 +121,17 @@ func (s *PayerAuthorisationService) Get(ctx context.Context, identity string, op return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -159,44 +175,50 @@ func (s *PayerAuthorisationService) Get(ctx context.Context, identity string, op return result.PayerAuthorisation, nil } +type PayerAuthorisationCreateParamsBankAccount struct { + AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` + AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` + AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` + AccountNumberSuffix string `url:"account_number_suffix,omitempty" json:"account_number_suffix,omitempty"` + AccountType string `url:"account_type,omitempty" json:"account_type,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"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Iban string `url:"iban,omitempty" json:"iban,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` +} + +type PayerAuthorisationCreateParamsCustomer struct { + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` + Email string `url:"email,omitempty" json:"email,omitempty"` + FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` + GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` + Locale string `url:"locale,omitempty" json:"locale,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` +} + +type PayerAuthorisationCreateParamsMandate struct { + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` +} + // PayerAuthorisationCreateParams parameters type PayerAuthorisationCreateParams struct { - BankAccount struct { - AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` - AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` - AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` - AccountNumberSuffix string `url:"account_number_suffix,omitempty" json:"account_number_suffix,omitempty"` - AccountType string `url:"account_type,omitempty" json:"account_type,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"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Iban string `url:"iban,omitempty" json:"iban,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - } `url:"bank_account,omitempty" json:"bank_account,omitempty"` - Customer struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` - Email string `url:"email,omitempty" json:"email,omitempty"` - FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` - GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` - Locale string `url:"locale,omitempty" json:"locale,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` - } `url:"customer,omitempty" json:"customer,omitempty"` - Mandate struct { - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - } `url:"mandate,omitempty" json:"mandate,omitempty"` + BankAccount PayerAuthorisationCreateParamsBankAccount `url:"bank_account,omitempty" json:"bank_account,omitempty"` + Customer PayerAuthorisationCreateParamsCustomer `url:"customer,omitempty" json:"customer,omitempty"` + Mandate PayerAuthorisationCreateParamsMandate `url:"mandate,omitempty" json:"mandate,omitempty"` } // Create @@ -206,8 +228,8 @@ type PayerAuthorisationCreateParams struct { // has been designed this way so you do not need to save any payer data on your // servers or the browser while still being able to implement a progressive // solution, such as a multi-step form. -func (s *PayerAuthorisationService) Create(ctx context.Context, p PayerAuthorisationCreateParams, opts ...RequestOption) (*PayerAuthorisation, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/payer_authorisations")) +func (s *PayerAuthorisationServiceImpl) Create(ctx context.Context, p PayerAuthorisationCreateParams, opts ...RequestOption) (*PayerAuthorisation, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/payer_authorisations")) if err != nil { return nil, err } @@ -241,10 +263,10 @@ func (s *PayerAuthorisationService) Create(ctx context.Context, p PayerAuthorisa return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -253,7 +275,7 @@ func (s *PayerAuthorisationService) Create(ctx context.Context, p PayerAuthorisa req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -297,44 +319,50 @@ func (s *PayerAuthorisationService) Create(ctx context.Context, p PayerAuthorisa return result.PayerAuthorisation, nil } +type PayerAuthorisationUpdateParamsBankAccount struct { + AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` + AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` + AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` + AccountNumberSuffix string `url:"account_number_suffix,omitempty" json:"account_number_suffix,omitempty"` + AccountType string `url:"account_type,omitempty" json:"account_type,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"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Iban string `url:"iban,omitempty" json:"iban,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` +} + +type PayerAuthorisationUpdateParamsCustomer struct { + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` + Email string `url:"email,omitempty" json:"email,omitempty"` + FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` + GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` + Locale string `url:"locale,omitempty" json:"locale,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` +} + +type PayerAuthorisationUpdateParamsMandate struct { + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` +} + // PayerAuthorisationUpdateParams parameters type PayerAuthorisationUpdateParams struct { - BankAccount struct { - AccountHolderName string `url:"account_holder_name,omitempty" json:"account_holder_name,omitempty"` - AccountNumber string `url:"account_number,omitempty" json:"account_number,omitempty"` - AccountNumberEnding string `url:"account_number_ending,omitempty" json:"account_number_ending,omitempty"` - AccountNumberSuffix string `url:"account_number_suffix,omitempty" json:"account_number_suffix,omitempty"` - AccountType string `url:"account_type,omitempty" json:"account_type,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"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Iban string `url:"iban,omitempty" json:"iban,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - } `url:"bank_account,omitempty" json:"bank_account,omitempty"` - Customer struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` - Email string `url:"email,omitempty" json:"email,omitempty"` - FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` - GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` - Locale string `url:"locale,omitempty" json:"locale,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` - } `url:"customer,omitempty" json:"customer,omitempty"` - Mandate struct { - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PayerIpAddress string `url:"payer_ip_address,omitempty" json:"payer_ip_address,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - } `url:"mandate,omitempty" json:"mandate,omitempty"` + BankAccount PayerAuthorisationUpdateParamsBankAccount `url:"bank_account,omitempty" json:"bank_account,omitempty"` + Customer PayerAuthorisationUpdateParamsCustomer `url:"customer,omitempty" json:"customer,omitempty"` + Mandate PayerAuthorisationUpdateParamsMandate `url:"mandate,omitempty" json:"mandate,omitempty"` } // Update @@ -347,8 +375,8 @@ type PayerAuthorisationUpdateParams struct { // class="notice"> Note that in order to update the `metadata` attribute values // it must be sent completely as it overrides the previously existing values. //

-func (s *PayerAuthorisationService) Update(ctx context.Context, identity string, p PayerAuthorisationUpdateParams, opts ...RequestOption) (*PayerAuthorisation, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payer_authorisations/%v", +func (s *PayerAuthorisationServiceImpl) Update(ctx context.Context, identity string, p PayerAuthorisationUpdateParams, opts ...RequestOption) (*PayerAuthorisation, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payer_authorisations/%v", identity)) if err != nil { return nil, err @@ -383,10 +411,10 @@ func (s *PayerAuthorisationService) Update(ctx context.Context, identity string, return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -395,7 +423,7 @@ func (s *PayerAuthorisationService) Update(ctx context.Context, identity string, req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -444,8 +472,8 @@ func (s *PayerAuthorisationService) Update(ctx context.Context, identity string, // verification. This time, a 200 HTTP status is returned if the resource is // valid and a 422 error response in case of validation errors. After it is // successfully submitted, the Payer Authorisation can no longer be edited. -func (s *PayerAuthorisationService) Submit(ctx context.Context, identity string, opts ...RequestOption) (*PayerAuthorisation, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payer_authorisations/%v/actions/submit", +func (s *PayerAuthorisationServiceImpl) Submit(ctx context.Context, identity string, opts ...RequestOption) (*PayerAuthorisation, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payer_authorisations/%v/actions/submit", identity)) if err != nil { return nil, err @@ -471,10 +499,10 @@ func (s *PayerAuthorisationService) Submit(ctx context.Context, identity string, return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -483,7 +511,7 @@ func (s *PayerAuthorisationService) Submit(ctx context.Context, identity string, req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -539,8 +567,8 @@ func (s *PayerAuthorisationService) Submit(ctx context.Context, identity string, // go through our flow or make them go through the necessary verification // mechanism (upcoming feature). //

-func (s *PayerAuthorisationService) Confirm(ctx context.Context, identity string, opts ...RequestOption) (*PayerAuthorisation, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payer_authorisations/%v/actions/confirm", +func (s *PayerAuthorisationServiceImpl) Confirm(ctx context.Context, identity string, opts ...RequestOption) (*PayerAuthorisation, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payer_authorisations/%v/actions/confirm", identity)) if err != nil { return nil, err @@ -566,10 +594,10 @@ func (s *PayerAuthorisationService) Confirm(ctx context.Context, identity string return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -578,7 +606,7 @@ func (s *PayerAuthorisationService) Confirm(ctx context.Context, identity string req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/payment_service.go b/payment_service.go index 2c4e2d5..2ec8503 100644 --- a/payment_service.go +++ b/payment_service.go @@ -19,53 +19,67 @@ var _ = json.NewDecoder var _ = errors.New // PaymentService manages payments -type PaymentService struct { - endpoint string - token string - client *http.Client +type PaymentServiceImpl struct { + config Config +} + +type PaymentFx struct { + EstimatedExchangeRate string `url:"estimated_exchange_rate,omitempty" json:"estimated_exchange_rate,omitempty"` + ExchangeRate string `url:"exchange_rate,omitempty" json:"exchange_rate,omitempty"` + FxAmount int `url:"fx_amount,omitempty" json:"fx_amount,omitempty"` + FxCurrency string `url:"fx_currency,omitempty" json:"fx_currency,omitempty"` +} + +type PaymentLinks struct { + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + InstalmentSchedule string `url:"instalment_schedule,omitempty" json:"instalment_schedule,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + Payout string `url:"payout,omitempty" json:"payout,omitempty"` + Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` } // Payment model type Payment struct { - Amount int `url:"amount,omitempty" json:"amount,omitempty"` - AmountRefunded int `url:"amount_refunded,omitempty" json:"amount_refunded,omitempty"` - ChargeDate string `url:"charge_date,omitempty" json:"charge_date,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Description string `url:"description,omitempty" json:"description,omitempty"` - Fx struct { - EstimatedExchangeRate string `url:"estimated_exchange_rate,omitempty" json:"estimated_exchange_rate,omitempty"` - ExchangeRate string `url:"exchange_rate,omitempty" json:"exchange_rate,omitempty"` - FxAmount int `url:"fx_amount,omitempty" json:"fx_amount,omitempty"` - FxCurrency string `url:"fx_currency,omitempty" json:"fx_currency,omitempty"` - } `url:"fx,omitempty" json:"fx,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - InstalmentSchedule string `url:"instalment_schedule,omitempty" json:"instalment_schedule,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - Payout string `url:"payout,omitempty" json:"payout,omitempty"` - Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` + Amount int `url:"amount,omitempty" json:"amount,omitempty"` + AmountRefunded int `url:"amount_refunded,omitempty" json:"amount_refunded,omitempty"` + ChargeDate string `url:"charge_date,omitempty" json:"charge_date,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Description string `url:"description,omitempty" json:"description,omitempty"` + Fx *PaymentFx `url:"fx,omitempty" json:"fx,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *PaymentLinks `url:"links,omitempty" json:"links,omitempty"` Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` Reference string `url:"reference,omitempty" json:"reference,omitempty"` RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"` } +type PaymentService interface { + Create(ctx context.Context, p PaymentCreateParams, opts ...RequestOption) (*Payment, error) + List(ctx context.Context, p PaymentListParams, opts ...RequestOption) (*PaymentListResult, error) + All(ctx context.Context, p PaymentListParams, opts ...RequestOption) *PaymentListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*Payment, error) + Update(ctx context.Context, identity string, p PaymentUpdateParams, opts ...RequestOption) (*Payment, error) + Cancel(ctx context.Context, identity string, p PaymentCancelParams, opts ...RequestOption) (*Payment, error) + Retry(ctx context.Context, identity string, p PaymentRetryParams, opts ...RequestOption) (*Payment, error) +} + +type PaymentCreateParamsLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` +} + // PaymentCreateParams parameters type PaymentCreateParams struct { - Amount int `url:"amount,omitempty" json:"amount,omitempty"` - AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` - ChargeDate string `url:"charge_date,omitempty" json:"charge_date,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Description string `url:"description,omitempty" json:"description,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` + Amount int `url:"amount,omitempty" json:"amount,omitempty"` + AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` + ChargeDate string `url:"charge_date,omitempty" json:"charge_date,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Description string `url:"description,omitempty" json:"description,omitempty"` + Links PaymentCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` } // Create @@ -75,8 +89,8 @@ type PaymentCreateParams struct { // [mandate](#core-endpoints-mandates) is cancelled or has failed. Payments can // be created against mandates with status of: `pending_customer_approval`, // `pending_submission`, `submitted`, and `active`. -func (s *PaymentService) Create(ctx context.Context, p PaymentCreateParams, opts ...RequestOption) (*Payment, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/payments")) +func (s *PaymentServiceImpl) Create(ctx context.Context, p PaymentCreateParams, opts ...RequestOption) (*Payment, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/payments")) if err != nil { return nil, err } @@ -110,10 +124,10 @@ func (s *PaymentService) Create(ctx context.Context, p PaymentCreateParams, opts return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -122,7 +136,7 @@ func (s *PaymentService) Create(ctx context.Context, p PaymentCreateParams, opts req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -166,50 +180,57 @@ func (s *PaymentService) Create(ctx context.Context, p PaymentCreateParams, opts return result.Payment, nil } +type PaymentListParamsChargeDate struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + +type PaymentListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // PaymentListParams parameters type PaymentListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - ChargeDate struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"charge_date,omitempty" json:"charge_date,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - SortDirection string `url:"sort_direction,omitempty" json:"sort_direction,omitempty"` - SortField string `url:"sort_field,omitempty" json:"sort_field,omitempty"` - Status string `url:"status,omitempty" json:"status,omitempty"` - Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + ChargeDate *PaymentListParamsChargeDate `url:"charge_date,omitempty" json:"charge_date,omitempty"` + CreatedAt *PaymentListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + SortDirection string `url:"sort_direction,omitempty" json:"sort_direction,omitempty"` + SortField string `url:"sort_field,omitempty" json:"sort_field,omitempty"` + Status string `url:"status,omitempty" json:"status,omitempty"` + Subscription string `url:"subscription,omitempty" json:"subscription,omitempty"` +} + +type PaymentListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type PaymentListResultMeta struct { + Cursors *PaymentListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// PaymentListResult response including pagination metadata type PaymentListResult struct { - Payments []Payment `json:"payments"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Payments []Payment `json:"payments"` + Meta PaymentListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // payments. -func (s *PaymentService) List(ctx context.Context, p PaymentListParams, opts ...RequestOption) (*PaymentListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/payments")) +func (s *PaymentServiceImpl) List(ctx context.Context, p PaymentListParams, opts ...RequestOption) (*PaymentListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/payments")) if err != nil { return nil, err } @@ -237,17 +258,17 @@ func (s *PaymentService) List(ctx context.Context, p PaymentListParams, opts ... return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -295,7 +316,7 @@ type PaymentListPagingIterator struct { cursor string response *PaymentListResult params PaymentListParams - service *PaymentService + service *PaymentServiceImpl requestOptions []RequestOption } @@ -316,7 +337,7 @@ func (c *PaymentListPagingIterator) Value(ctx context.Context) (*PaymentListResu p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/payments")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/payments")) if err != nil { return nil, err @@ -346,16 +367,16 @@ func (c *PaymentListPagingIterator) Value(ctx context.Context) (*PaymentListResu } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -402,7 +423,7 @@ func (c *PaymentListPagingIterator) Value(ctx context.Context) (*PaymentListResu return c.response, nil } -func (s *PaymentService) All(ctx context.Context, +func (s *PaymentServiceImpl) All(ctx context.Context, p PaymentListParams, opts ...RequestOption) *PaymentListPagingIterator { return &PaymentListPagingIterator{ @@ -414,8 +435,8 @@ func (s *PaymentService) All(ctx context.Context, // Get // Retrieves the details of a single existing payment. -func (s *PaymentService) Get(ctx context.Context, identity string, opts ...RequestOption) (*Payment, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payments/%v", +func (s *PaymentServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*Payment, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payments/%v", identity)) if err != nil { return nil, err @@ -438,17 +459,17 @@ func (s *PaymentService) Get(ctx context.Context, identity string, opts ...Reque return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -500,8 +521,8 @@ type PaymentUpdateParams struct { // Update // Updates a payment object. This accepts only the metadata parameter. -func (s *PaymentService) Update(ctx context.Context, identity string, p PaymentUpdateParams, opts ...RequestOption) (*Payment, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payments/%v", +func (s *PaymentServiceImpl) Update(ctx context.Context, identity string, p PaymentUpdateParams, opts ...RequestOption) (*Payment, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payments/%v", identity)) if err != nil { return nil, err @@ -536,10 +557,10 @@ func (s *PaymentService) Update(ctx context.Context, identity string, p PaymentU return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -548,7 +569,7 @@ func (s *PaymentService) Update(ctx context.Context, identity string, p PaymentU req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -604,8 +625,8 @@ type PaymentCancelParams struct { // // This will fail with a `cancellation_failed` error unless the payment's status // is `pending_submission`. -func (s *PaymentService) Cancel(ctx context.Context, identity string, p PaymentCancelParams, opts ...RequestOption) (*Payment, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payments/%v/actions/cancel", +func (s *PaymentServiceImpl) Cancel(ctx context.Context, identity string, p PaymentCancelParams, opts ...RequestOption) (*Payment, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payments/%v/actions/cancel", identity)) if err != nil { return nil, err @@ -640,10 +661,10 @@ func (s *PaymentService) Cancel(ctx context.Context, identity string, p PaymentC return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -652,7 +673,7 @@ func (s *PaymentService) Cancel(ctx context.Context, identity string, p PaymentC req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -713,8 +734,8 @@ type PaymentRetryParams struct { // This will return a `retry_failed` error if the payment has not failed. // // Payments can be retried up to 3 times. -func (s *PaymentService) Retry(ctx context.Context, identity string, p PaymentRetryParams, opts ...RequestOption) (*Payment, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payments/%v/actions/retry", +func (s *PaymentServiceImpl) Retry(ctx context.Context, identity string, p PaymentRetryParams, opts ...RequestOption) (*Payment, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payments/%v/actions/retry", identity)) if err != nil { return nil, err @@ -749,10 +770,10 @@ func (s *PaymentService) Retry(ctx context.Context, identity string, p PaymentRe return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -761,7 +782,7 @@ func (s *PaymentService) Retry(ctx context.Context, identity string, p PaymentRe req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/payout_item_service.go b/payout_item_service.go index 8cd398a..0d6b535 100644 --- a/payout_item_service.go +++ b/payout_item_service.go @@ -19,29 +19,36 @@ var _ = json.NewDecoder var _ = errors.New // PayoutItemService manages payout_items -type PayoutItemService struct { - endpoint string - token string - client *http.Client +type PayoutItemServiceImpl struct { + config Config +} + +type PayoutItemLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + Payment string `url:"payment,omitempty" json:"payment,omitempty"` + Refund string `url:"refund,omitempty" json:"refund,omitempty"` +} + +type PayoutItemTaxes struct { + Amount string `url:"amount,omitempty" json:"amount,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + DestinationAmount string `url:"destination_amount,omitempty" json:"destination_amount,omitempty"` + DestinationCurrency string `url:"destination_currency,omitempty" json:"destination_currency,omitempty"` + ExchangeRate string `url:"exchange_rate,omitempty" json:"exchange_rate,omitempty"` + TaxRateId string `url:"tax_rate_id,omitempty" json:"tax_rate_id,omitempty"` } // PayoutItem model type PayoutItem struct { - Amount string `url:"amount,omitempty" json:"amount,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - Payment string `url:"payment,omitempty" json:"payment,omitempty"` - Refund string `url:"refund,omitempty" json:"refund,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Taxes []struct { - Amount string `url:"amount,omitempty" json:"amount,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - DestinationAmount string `url:"destination_amount,omitempty" json:"destination_amount,omitempty"` - DestinationCurrency string `url:"destination_currency,omitempty" json:"destination_currency,omitempty"` - ExchangeRate string `url:"exchange_rate,omitempty" json:"exchange_rate,omitempty"` - TaxRateId string `url:"tax_rate_id,omitempty" json:"tax_rate_id,omitempty"` - } `url:"taxes,omitempty" json:"taxes,omitempty"` - Type string `url:"type,omitempty" json:"type,omitempty"` + Amount string `url:"amount,omitempty" json:"amount,omitempty"` + Links *PayoutItemLinks `url:"links,omitempty" json:"links,omitempty"` + Taxes []PayoutItemTaxes `url:"taxes,omitempty" json:"taxes,omitempty"` + Type string `url:"type,omitempty" json:"type,omitempty"` +} + +type PayoutItemService interface { + List(ctx context.Context, p PayoutItemListParams, opts ...RequestOption) (*PayoutItemListResult, error) + All(ctx context.Context, p PayoutItemListParams, opts ...RequestOption) *PayoutItemListPagingIterator } // PayoutItemListParams parameters @@ -53,24 +60,27 @@ type PayoutItemListParams struct { Payout string `url:"payout,omitempty" json:"payout,omitempty"` } -// PayoutItemListResult response including pagination metadata +type PayoutItemListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type PayoutItemListResultMeta struct { + Cursors *PayoutItemListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + type PayoutItemListResult struct { - PayoutItems []PayoutItem `json:"payout_items"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + PayoutItems []PayoutItem `json:"payout_items"` + Meta PayoutItemListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of items in // the payout. // -func (s *PayoutItemService) List(ctx context.Context, p PayoutItemListParams, opts ...RequestOption) (*PayoutItemListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/payout_items")) +func (s *PayoutItemServiceImpl) List(ctx context.Context, p PayoutItemListParams, opts ...RequestOption) (*PayoutItemListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/payout_items")) if err != nil { return nil, err } @@ -98,17 +108,17 @@ func (s *PayoutItemService) List(ctx context.Context, p PayoutItemListParams, op return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -156,7 +166,7 @@ type PayoutItemListPagingIterator struct { cursor string response *PayoutItemListResult params PayoutItemListParams - service *PayoutItemService + service *PayoutItemServiceImpl requestOptions []RequestOption } @@ -177,7 +187,7 @@ func (c *PayoutItemListPagingIterator) Value(ctx context.Context) (*PayoutItemLi p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/payout_items")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/payout_items")) if err != nil { return nil, err @@ -207,16 +217,16 @@ func (c *PayoutItemListPagingIterator) Value(ctx context.Context) (*PayoutItemLi } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -263,7 +273,7 @@ func (c *PayoutItemListPagingIterator) Value(ctx context.Context) (*PayoutItemLi return c.response, nil } -func (s *PayoutItemService) All(ctx context.Context, +func (s *PayoutItemServiceImpl) All(ctx context.Context, p PayoutItemListParams, opts ...RequestOption) *PayoutItemListPagingIterator { return &PayoutItemListPagingIterator{ diff --git a/payout_service.go b/payout_service.go index 5f40479..c2279d2 100644 --- a/payout_service.go +++ b/payout_service.go @@ -19,74 +19,88 @@ var _ = json.NewDecoder var _ = errors.New // PayoutService manages payouts -type PayoutService struct { - endpoint string - token string - client *http.Client +type PayoutServiceImpl struct { + config Config +} + +type PayoutFx struct { + EstimatedExchangeRate string `url:"estimated_exchange_rate,omitempty" json:"estimated_exchange_rate,omitempty"` + ExchangeRate string `url:"exchange_rate,omitempty" json:"exchange_rate,omitempty"` + FxAmount int `url:"fx_amount,omitempty" json:"fx_amount,omitempty"` + FxCurrency string `url:"fx_currency,omitempty" json:"fx_currency,omitempty"` +} + +type PayoutLinks struct { + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + CreditorBankAccount string `url:"creditor_bank_account,omitempty" json:"creditor_bank_account,omitempty"` } // Payout model type Payout struct { - Amount int `url:"amount,omitempty" json:"amount,omitempty"` - ArrivalDate string `url:"arrival_date,omitempty" json:"arrival_date,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - DeductedFees int `url:"deducted_fees,omitempty" json:"deducted_fees,omitempty"` - Fx struct { - EstimatedExchangeRate string `url:"estimated_exchange_rate,omitempty" json:"estimated_exchange_rate,omitempty"` - ExchangeRate string `url:"exchange_rate,omitempty" json:"exchange_rate,omitempty"` - FxAmount int `url:"fx_amount,omitempty" json:"fx_amount,omitempty"` - FxCurrency string `url:"fx_currency,omitempty" json:"fx_currency,omitempty"` - } `url:"fx,omitempty" json:"fx,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - CreditorBankAccount string `url:"creditor_bank_account,omitempty" json:"creditor_bank_account,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PayoutType string `url:"payout_type,omitempty" json:"payout_type,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - Status string `url:"status,omitempty" json:"status,omitempty"` - TaxCurrency string `url:"tax_currency,omitempty" json:"tax_currency,omitempty"` + Amount int `url:"amount,omitempty" json:"amount,omitempty"` + ArrivalDate string `url:"arrival_date,omitempty" json:"arrival_date,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + DeductedFees int `url:"deducted_fees,omitempty" json:"deducted_fees,omitempty"` + Fx *PayoutFx `url:"fx,omitempty" json:"fx,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *PayoutLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PayoutType string `url:"payout_type,omitempty" json:"payout_type,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + Status string `url:"status,omitempty" json:"status,omitempty"` + TaxCurrency string `url:"tax_currency,omitempty" json:"tax_currency,omitempty"` +} + +type PayoutService interface { + List(ctx context.Context, p PayoutListParams, opts ...RequestOption) (*PayoutListResult, error) + All(ctx context.Context, p PayoutListParams, opts ...RequestOption) *PayoutListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*Payout, error) + Update(ctx context.Context, identity string, p PayoutUpdateParams, opts ...RequestOption) (*Payout, error) +} + +type PayoutListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` } // PayoutListParams parameters type PayoutListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - CreditorBankAccount string `url:"creditor_bank_account,omitempty" json:"creditor_bank_account,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PayoutType string `url:"payout_type,omitempty" json:"payout_type,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - Status string `url:"status,omitempty" json:"status,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *PayoutListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + CreditorBankAccount string `url:"creditor_bank_account,omitempty" json:"creditor_bank_account,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PayoutType string `url:"payout_type,omitempty" json:"payout_type,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + Status string `url:"status,omitempty" json:"status,omitempty"` +} + +type PayoutListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type PayoutListResultMeta struct { + Cursors *PayoutListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// PayoutListResult response including pagination metadata type PayoutListResult struct { - Payouts []Payout `json:"payouts"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Payouts []Payout `json:"payouts"` + Meta PayoutListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // payouts. -func (s *PayoutService) List(ctx context.Context, p PayoutListParams, opts ...RequestOption) (*PayoutListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/payouts")) +func (s *PayoutServiceImpl) List(ctx context.Context, p PayoutListParams, opts ...RequestOption) (*PayoutListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/payouts")) if err != nil { return nil, err } @@ -114,17 +128,17 @@ func (s *PayoutService) List(ctx context.Context, p PayoutListParams, opts ...Re return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -172,7 +186,7 @@ type PayoutListPagingIterator struct { cursor string response *PayoutListResult params PayoutListParams - service *PayoutService + service *PayoutServiceImpl requestOptions []RequestOption } @@ -193,7 +207,7 @@ func (c *PayoutListPagingIterator) Value(ctx context.Context) (*PayoutListResult p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/payouts")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/payouts")) if err != nil { return nil, err @@ -223,16 +237,16 @@ func (c *PayoutListPagingIterator) Value(ctx context.Context) (*PayoutListResult } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -279,7 +293,7 @@ func (c *PayoutListPagingIterator) Value(ctx context.Context) (*PayoutListResult return c.response, nil } -func (s *PayoutService) All(ctx context.Context, +func (s *PayoutServiceImpl) All(ctx context.Context, p PayoutListParams, opts ...RequestOption) *PayoutListPagingIterator { return &PayoutListPagingIterator{ @@ -293,8 +307,8 @@ func (s *PayoutService) All(ctx context.Context, // Retrieves the details of a single payout. For an example of how to reconcile // the transactions in a payout, see [this // guide](#events-reconciling-payouts-with-events). -func (s *PayoutService) Get(ctx context.Context, identity string, opts ...RequestOption) (*Payout, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payouts/%v", +func (s *PayoutServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*Payout, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payouts/%v", identity)) if err != nil { return nil, err @@ -317,17 +331,17 @@ func (s *PayoutService) Get(ctx context.Context, identity string, opts ...Reques return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -378,8 +392,8 @@ type PayoutUpdateParams struct { // Update // Updates a payout object. This accepts only the metadata parameter. -func (s *PayoutService) Update(ctx context.Context, identity string, p PayoutUpdateParams, opts ...RequestOption) (*Payout, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/payouts/%v", +func (s *PayoutServiceImpl) Update(ctx context.Context, identity string, p PayoutUpdateParams, opts ...RequestOption) (*Payout, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/payouts/%v", identity)) if err != nil { return nil, err @@ -414,10 +428,10 @@ func (s *PayoutService) Update(ctx context.Context, identity string, p PayoutUpd return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -426,7 +440,7 @@ func (s *PayoutService) Update(ctx context.Context, identity string, p PayoutUpd req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/redirect_flow_service.go b/redirect_flow_service.go index 5c1de03..a592180 100644 --- a/redirect_flow_service.go +++ b/redirect_flow_service.go @@ -19,24 +19,25 @@ var _ = json.NewDecoder var _ = errors.New // RedirectFlowService manages redirect_flows -type RedirectFlowService struct { - endpoint string - token string - client *http.Client +type RedirectFlowServiceImpl struct { + config Config +} + +type RedirectFlowLinks struct { + BillingRequest string `url:"billing_request,omitempty" json:"billing_request,omitempty"` + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` } // RedirectFlow model type RedirectFlow struct { - ConfirmationUrl string `url:"confirmation_url,omitempty" json:"confirmation_url,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Description string `url:"description,omitempty" json:"description,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - CustomerBankAccount string `url:"customer_bank_account,omitempty" json:"customer_bank_account,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` + ConfirmationUrl string `url:"confirmation_url,omitempty" json:"confirmation_url,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Description string `url:"description,omitempty" json:"description,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *RedirectFlowLinks `url:"links,omitempty" json:"links,omitempty"` MandateReference string `url:"mandate_reference,omitempty" json:"mandate_reference,omitempty"` Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` RedirectUrl string `url:"redirect_url,omitempty" json:"redirect_url,omitempty"` @@ -45,43 +46,55 @@ type RedirectFlow struct { SuccessRedirectUrl string `url:"success_redirect_url,omitempty" json:"success_redirect_url,omitempty"` } +type RedirectFlowService interface { + Create(ctx context.Context, p RedirectFlowCreateParams, opts ...RequestOption) (*RedirectFlow, error) + Get(ctx context.Context, identity string, opts ...RequestOption) (*RedirectFlow, error) + Complete(ctx context.Context, identity string, p RedirectFlowCompleteParams, opts ...RequestOption) (*RedirectFlow, error) +} + +type RedirectFlowCreateParamsLinks struct { + Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` +} + +type RedirectFlowCreateParamsPrefilledBankAccount struct { + AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` +} + +type RedirectFlowCreateParamsPrefilledCustomer struct { + AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` + AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` + AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` + City string `url:"city,omitempty" json:"city,omitempty"` + CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` + CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` + DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` + Email string `url:"email,omitempty" json:"email,omitempty"` + FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` + GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` + Language string `url:"language,omitempty" json:"language,omitempty"` + PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` + PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` + Region string `url:"region,omitempty" json:"region,omitempty"` + SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` +} + // RedirectFlowCreateParams parameters type RedirectFlowCreateParams struct { - Description string `url:"description,omitempty" json:"description,omitempty"` - Links struct { - Creditor string `url:"creditor,omitempty" json:"creditor,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - PrefilledBankAccount struct { - AccountType string `url:"account_type,omitempty" json:"account_type,omitempty"` - } `url:"prefilled_bank_account,omitempty" json:"prefilled_bank_account,omitempty"` - PrefilledCustomer struct { - AddressLine1 string `url:"address_line1,omitempty" json:"address_line1,omitempty"` - AddressLine2 string `url:"address_line2,omitempty" json:"address_line2,omitempty"` - AddressLine3 string `url:"address_line3,omitempty" json:"address_line3,omitempty"` - City string `url:"city,omitempty" json:"city,omitempty"` - CompanyName string `url:"company_name,omitempty" json:"company_name,omitempty"` - CountryCode string `url:"country_code,omitempty" json:"country_code,omitempty"` - DanishIdentityNumber string `url:"danish_identity_number,omitempty" json:"danish_identity_number,omitempty"` - Email string `url:"email,omitempty" json:"email,omitempty"` - FamilyName string `url:"family_name,omitempty" json:"family_name,omitempty"` - GivenName string `url:"given_name,omitempty" json:"given_name,omitempty"` - Language string `url:"language,omitempty" json:"language,omitempty"` - PhoneNumber string `url:"phone_number,omitempty" json:"phone_number,omitempty"` - PostalCode string `url:"postal_code,omitempty" json:"postal_code,omitempty"` - Region string `url:"region,omitempty" json:"region,omitempty"` - SwedishIdentityNumber string `url:"swedish_identity_number,omitempty" json:"swedish_identity_number,omitempty"` - } `url:"prefilled_customer,omitempty" json:"prefilled_customer,omitempty"` - Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` - SessionToken string `url:"session_token,omitempty" json:"session_token,omitempty"` - SuccessRedirectUrl string `url:"success_redirect_url,omitempty" json:"success_redirect_url,omitempty"` + Description string `url:"description,omitempty" json:"description,omitempty"` + Links *RedirectFlowCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + PrefilledBankAccount *RedirectFlowCreateParamsPrefilledBankAccount `url:"prefilled_bank_account,omitempty" json:"prefilled_bank_account,omitempty"` + PrefilledCustomer *RedirectFlowCreateParamsPrefilledCustomer `url:"prefilled_customer,omitempty" json:"prefilled_customer,omitempty"` + Scheme string `url:"scheme,omitempty" json:"scheme,omitempty"` + SessionToken string `url:"session_token,omitempty" json:"session_token,omitempty"` + SuccessRedirectUrl string `url:"success_redirect_url,omitempty" json:"success_redirect_url,omitempty"` } // Create // Creates a redirect flow object which can then be used to redirect your // customer to the GoCardless hosted payment pages. -func (s *RedirectFlowService) Create(ctx context.Context, p RedirectFlowCreateParams, opts ...RequestOption) (*RedirectFlow, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/redirect_flows")) +func (s *RedirectFlowServiceImpl) Create(ctx context.Context, p RedirectFlowCreateParams, opts ...RequestOption) (*RedirectFlow, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/redirect_flows")) if err != nil { return nil, err } @@ -115,10 +128,10 @@ func (s *RedirectFlowService) Create(ctx context.Context, p RedirectFlowCreatePa return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -127,7 +140,7 @@ func (s *RedirectFlowService) Create(ctx context.Context, p RedirectFlowCreatePa req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -173,8 +186,8 @@ func (s *RedirectFlowService) Create(ctx context.Context, p RedirectFlowCreatePa // Get // Returns all details about a single redirect flow -func (s *RedirectFlowService) Get(ctx context.Context, identity string, opts ...RequestOption) (*RedirectFlow, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/redirect_flows/%v", +func (s *RedirectFlowServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*RedirectFlow, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/redirect_flows/%v", identity)) if err != nil { return nil, err @@ -197,17 +210,17 @@ func (s *RedirectFlowService) Get(ctx context.Context, identity string, opts ... return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -268,8 +281,8 @@ type RedirectFlowCompleteParams struct { // completed this flow. It will return a `bad_request` error if the // `session_token` differs to the one supplied when the redirect flow was // created. -func (s *RedirectFlowService) Complete(ctx context.Context, identity string, p RedirectFlowCompleteParams, opts ...RequestOption) (*RedirectFlow, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/redirect_flows/%v/actions/complete", +func (s *RedirectFlowServiceImpl) Complete(ctx context.Context, identity string, p RedirectFlowCompleteParams, opts ...RequestOption) (*RedirectFlow, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/redirect_flows/%v/actions/complete", identity)) if err != nil { return nil, err @@ -304,10 +317,10 @@ func (s *RedirectFlowService) Complete(ctx context.Context, identity string, p R return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -316,7 +329,7 @@ func (s *RedirectFlowService) Complete(ctx context.Context, identity string, p R req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/refund_service.go b/refund_service.go index 0869ef3..49885aa 100644 --- a/refund_service.go +++ b/refund_service.go @@ -19,43 +19,55 @@ var _ = json.NewDecoder var _ = errors.New // RefundService manages refunds -type RefundService struct { - endpoint string - token string - client *http.Client +type RefundServiceImpl struct { + config Config +} + +type RefundFx struct { + EstimatedExchangeRate string `url:"estimated_exchange_rate,omitempty" json:"estimated_exchange_rate,omitempty"` + ExchangeRate string `url:"exchange_rate,omitempty" json:"exchange_rate,omitempty"` + FxAmount int `url:"fx_amount,omitempty" json:"fx_amount,omitempty"` + FxCurrency string `url:"fx_currency,omitempty" json:"fx_currency,omitempty"` +} + +type RefundLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + Payment string `url:"payment,omitempty" json:"payment,omitempty"` } // Refund model type Refund struct { - Amount int `url:"amount,omitempty" json:"amount,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - Fx struct { - EstimatedExchangeRate string `url:"estimated_exchange_rate,omitempty" json:"estimated_exchange_rate,omitempty"` - ExchangeRate string `url:"exchange_rate,omitempty" json:"exchange_rate,omitempty"` - FxAmount int `url:"fx_amount,omitempty" json:"fx_amount,omitempty"` - FxCurrency string `url:"fx_currency,omitempty" json:"fx_currency,omitempty"` - } `url:"fx,omitempty" json:"fx,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - Payment string `url:"payment,omitempty" json:"payment,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` + Amount int `url:"amount,omitempty" json:"amount,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + Fx *RefundFx `url:"fx,omitempty" json:"fx,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Links *RefundLinks `url:"links,omitempty" json:"links,omitempty"` Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` Reference string `url:"reference,omitempty" json:"reference,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"` } +type RefundService interface { + Create(ctx context.Context, p RefundCreateParams, opts ...RequestOption) (*Refund, error) + List(ctx context.Context, p RefundListParams, opts ...RequestOption) (*RefundListResult, error) + All(ctx context.Context, p RefundListParams, opts ...RequestOption) *RefundListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*Refund, error) + Update(ctx context.Context, identity string, p RefundUpdateParams, opts ...RequestOption) (*Refund, error) +} + +type RefundCreateParamsLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + Payment string `url:"payment,omitempty" json:"payment,omitempty"` +} + // RefundCreateParams parameters type RefundCreateParams struct { - Amount int `url:"amount,omitempty" json:"amount,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - Payment string `url:"payment,omitempty" json:"payment,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - Reference string `url:"reference,omitempty" json:"reference,omitempty"` - TotalAmountConfirmation int `url:"total_amount_confirmation,omitempty" json:"total_amount_confirmation,omitempty"` + Amount int `url:"amount,omitempty" json:"amount,omitempty"` + Links RefundCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Reference string `url:"reference,omitempty" json:"reference,omitempty"` + TotalAmountConfirmation int `url:"total_amount_confirmation,omitempty" json:"total_amount_confirmation,omitempty"` } // Create @@ -76,8 +88,8 @@ type RefundCreateParams struct { // sufficient balance for refunds available to cover the cost of the requested // refund. // -func (s *RefundService) Create(ctx context.Context, p RefundCreateParams, opts ...RequestOption) (*Refund, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/refunds")) +func (s *RefundServiceImpl) Create(ctx context.Context, p RefundCreateParams, opts ...RequestOption) (*Refund, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/refunds")) if err != nil { return nil, err } @@ -111,10 +123,10 @@ func (s *RefundService) Create(ctx context.Context, p RefundCreateParams, opts . return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -123,7 +135,7 @@ func (s *RefundService) Create(ctx context.Context, p RefundCreateParams, opts . req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -167,39 +179,44 @@ func (s *RefundService) Create(ctx context.Context, p RefundCreateParams, opts . return result.Refund, nil } +type RefundListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // RefundListParams parameters type RefundListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - Payment string `url:"payment,omitempty" json:"payment,omitempty"` - RefundType string `url:"refund_type,omitempty" json:"refund_type,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *RefundListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + Payment string `url:"payment,omitempty" json:"payment,omitempty"` + RefundType string `url:"refund_type,omitempty" json:"refund_type,omitempty"` +} + +type RefundListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type RefundListResultMeta struct { + Cursors *RefundListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// RefundListResult response including pagination metadata type RefundListResult struct { - Refunds []Refund `json:"refunds"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Refunds []Refund `json:"refunds"` + Meta RefundListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // refunds. -func (s *RefundService) List(ctx context.Context, p RefundListParams, opts ...RequestOption) (*RefundListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/refunds")) +func (s *RefundServiceImpl) List(ctx context.Context, p RefundListParams, opts ...RequestOption) (*RefundListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/refunds")) if err != nil { return nil, err } @@ -227,17 +244,17 @@ func (s *RefundService) List(ctx context.Context, p RefundListParams, opts ...Re return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -285,7 +302,7 @@ type RefundListPagingIterator struct { cursor string response *RefundListResult params RefundListParams - service *RefundService + service *RefundServiceImpl requestOptions []RequestOption } @@ -306,7 +323,7 @@ func (c *RefundListPagingIterator) Value(ctx context.Context) (*RefundListResult p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/refunds")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/refunds")) if err != nil { return nil, err @@ -336,16 +353,16 @@ func (c *RefundListPagingIterator) Value(ctx context.Context) (*RefundListResult } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -392,7 +409,7 @@ func (c *RefundListPagingIterator) Value(ctx context.Context) (*RefundListResult return c.response, nil } -func (s *RefundService) All(ctx context.Context, +func (s *RefundServiceImpl) All(ctx context.Context, p RefundListParams, opts ...RequestOption) *RefundListPagingIterator { return &RefundListPagingIterator{ @@ -404,8 +421,8 @@ func (s *RefundService) All(ctx context.Context, // Get // Retrieves all details for a single refund -func (s *RefundService) Get(ctx context.Context, identity string, opts ...RequestOption) (*Refund, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/refunds/%v", +func (s *RefundServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*Refund, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/refunds/%v", identity)) if err != nil { return nil, err @@ -428,17 +445,17 @@ func (s *RefundService) Get(ctx context.Context, identity string, opts ...Reques return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -489,8 +506,8 @@ type RefundUpdateParams struct { // Update // Updates a refund object. -func (s *RefundService) Update(ctx context.Context, identity string, p RefundUpdateParams, opts ...RequestOption) (*Refund, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/refunds/%v", +func (s *RefundServiceImpl) Update(ctx context.Context, identity string, p RefundUpdateParams, opts ...RequestOption) (*Refund, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/refunds/%v", identity)) if err != nil { return nil, err @@ -525,10 +542,10 @@ func (s *RefundService) Update(ctx context.Context, identity string, p RefundUpd return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -537,7 +554,7 @@ func (s *RefundService) Update(ctx context.Context, identity string, p RefundUpd req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/retries.go b/retries.go index 8103dfb..ef3ed92 100644 --- a/retries.go +++ b/retries.go @@ -69,6 +69,10 @@ func (r *responseError) Cause() error { return r.err } +func (r *responseError) Unwrap() error { + return r.err +} + func (r *responseError) Error() string { return r.res.Status } diff --git a/scenario_simulator_service.go b/scenario_simulator_service.go index 6ee30c2..6850ef5 100644 --- a/scenario_simulator_service.go +++ b/scenario_simulator_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // ScenarioSimulatorService manages scenario_simulators -type ScenarioSimulatorService struct { - endpoint string - token string - client *http.Client +type ScenarioSimulatorServiceImpl struct { + config Config } // ScenarioSimulator model @@ -30,17 +28,23 @@ type ScenarioSimulator struct { Id string `url:"id,omitempty" json:"id,omitempty"` } +type ScenarioSimulatorService interface { + Run(ctx context.Context, identity string, p ScenarioSimulatorRunParams, opts ...RequestOption) (*ScenarioSimulator, error) +} + +type ScenarioSimulatorRunParamsLinks struct { + Resource string `url:"resource,omitempty" json:"resource,omitempty"` +} + // ScenarioSimulatorRunParams parameters type ScenarioSimulatorRunParams struct { - Links struct { - Resource string `url:"resource,omitempty" json:"resource,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` + Links *ScenarioSimulatorRunParamsLinks `url:"links,omitempty" json:"links,omitempty"` } // Run // Runs the specific scenario simulator against the specific resource -func (s *ScenarioSimulatorService) Run(ctx context.Context, identity string, p ScenarioSimulatorRunParams, opts ...RequestOption) (*ScenarioSimulator, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/scenario_simulators/%v/actions/run", +func (s *ScenarioSimulatorServiceImpl) Run(ctx context.Context, identity string, p ScenarioSimulatorRunParams, opts ...RequestOption) (*ScenarioSimulator, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/scenario_simulators/%v/actions/run", identity)) if err != nil { return nil, err @@ -75,10 +79,10 @@ func (s *ScenarioSimulatorService) Run(ctx context.Context, identity string, p S return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -87,7 +91,7 @@ func (s *ScenarioSimulatorService) Run(ctx context.Context, identity string, p S req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/subscription_service.go b/subscription_service.go index a7dcb3f..f114864 100644 --- a/subscription_service.go +++ b/subscription_service.go @@ -19,66 +19,81 @@ var _ = json.NewDecoder var _ = errors.New // SubscriptionService manages subscriptions -type SubscriptionService struct { - endpoint string - token string - client *http.Client +type SubscriptionServiceImpl struct { + config Config +} + +type SubscriptionLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` +} + +type SubscriptionUpcomingPayments struct { + Amount int `url:"amount,omitempty" json:"amount,omitempty"` + ChargeDate string `url:"charge_date,omitempty" json:"charge_date,omitempty"` } // Subscription model type Subscription struct { - Amount int `url:"amount,omitempty" json:"amount,omitempty"` - AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` - Count int `url:"count,omitempty" json:"count,omitempty"` - CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - DayOfMonth int `url:"day_of_month,omitempty" json:"day_of_month,omitempty"` - EarliestChargeDateAfterResume string `url:"earliest_charge_date_after_resume,omitempty" json:"earliest_charge_date_after_resume,omitempty"` - EndDate string `url:"end_date,omitempty" json:"end_date,omitempty"` - Id string `url:"id,omitempty" json:"id,omitempty"` - Interval int `url:"interval,omitempty" json:"interval,omitempty"` - IntervalUnit string `url:"interval_unit,omitempty" json:"interval_unit,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - Month string `url:"month,omitempty" json:"month,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` - PaymentReference string `url:"payment_reference,omitempty" json:"payment_reference,omitempty"` - RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` - StartDate string `url:"start_date,omitempty" json:"start_date,omitempty"` - Status string `url:"status,omitempty" json:"status,omitempty"` - UpcomingPayments []struct { - Amount int `url:"amount,omitempty" json:"amount,omitempty"` - ChargeDate string `url:"charge_date,omitempty" json:"charge_date,omitempty"` - } `url:"upcoming_payments,omitempty" json:"upcoming_payments,omitempty"` + Amount int `url:"amount,omitempty" json:"amount,omitempty"` + AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` + Count int `url:"count,omitempty" json:"count,omitempty"` + CreatedAt string `url:"created_at,omitempty" json:"created_at,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + DayOfMonth int `url:"day_of_month,omitempty" json:"day_of_month,omitempty"` + EarliestChargeDateAfterResume string `url:"earliest_charge_date_after_resume,omitempty" json:"earliest_charge_date_after_resume,omitempty"` + EndDate string `url:"end_date,omitempty" json:"end_date,omitempty"` + Id string `url:"id,omitempty" json:"id,omitempty"` + Interval int `url:"interval,omitempty" json:"interval,omitempty"` + IntervalUnit string `url:"interval_unit,omitempty" json:"interval_unit,omitempty"` + Links *SubscriptionLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Month string `url:"month,omitempty" json:"month,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + PaymentReference string `url:"payment_reference,omitempty" json:"payment_reference,omitempty"` + RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` + StartDate string `url:"start_date,omitempty" json:"start_date,omitempty"` + Status string `url:"status,omitempty" json:"status,omitempty"` + UpcomingPayments []SubscriptionUpcomingPayments `url:"upcoming_payments,omitempty" json:"upcoming_payments,omitempty"` +} + +type SubscriptionService interface { + Create(ctx context.Context, p SubscriptionCreateParams, opts ...RequestOption) (*Subscription, error) + List(ctx context.Context, p SubscriptionListParams, opts ...RequestOption) (*SubscriptionListResult, error) + All(ctx context.Context, p SubscriptionListParams, opts ...RequestOption) *SubscriptionListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*Subscription, error) + Update(ctx context.Context, identity string, p SubscriptionUpdateParams, opts ...RequestOption) (*Subscription, error) + Pause(ctx context.Context, identity string, p SubscriptionPauseParams, opts ...RequestOption) (*Subscription, error) + Resume(ctx context.Context, identity string, p SubscriptionResumeParams, opts ...RequestOption) (*Subscription, error) + Cancel(ctx context.Context, identity string, p SubscriptionCancelParams, opts ...RequestOption) (*Subscription, error) +} + +type SubscriptionCreateParamsLinks struct { + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` } // SubscriptionCreateParams parameters type SubscriptionCreateParams struct { - Amount int `url:"amount,omitempty" json:"amount,omitempty"` - AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` - Count int `url:"count,omitempty" json:"count,omitempty"` - Currency string `url:"currency,omitempty" json:"currency,omitempty"` - DayOfMonth int `url:"day_of_month,omitempty" json:"day_of_month,omitempty"` - EndDate string `url:"end_date,omitempty" json:"end_date,omitempty"` - Interval int `url:"interval,omitempty" json:"interval,omitempty"` - IntervalUnit string `url:"interval_unit,omitempty" json:"interval_unit,omitempty"` - Links struct { - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - } `url:"links,omitempty" json:"links,omitempty"` - Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` - Month string `url:"month,omitempty" json:"month,omitempty"` - Name string `url:"name,omitempty" json:"name,omitempty"` - PaymentReference string `url:"payment_reference,omitempty" json:"payment_reference,omitempty"` - RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` - StartDate string `url:"start_date,omitempty" json:"start_date,omitempty"` + Amount int `url:"amount,omitempty" json:"amount,omitempty"` + AppFee int `url:"app_fee,omitempty" json:"app_fee,omitempty"` + Count int `url:"count,omitempty" json:"count,omitempty"` + Currency string `url:"currency,omitempty" json:"currency,omitempty"` + DayOfMonth int `url:"day_of_month,omitempty" json:"day_of_month,omitempty"` + EndDate string `url:"end_date,omitempty" json:"end_date,omitempty"` + Interval int `url:"interval,omitempty" json:"interval,omitempty"` + IntervalUnit string `url:"interval_unit,omitempty" json:"interval_unit,omitempty"` + Links SubscriptionCreateParamsLinks `url:"links,omitempty" json:"links,omitempty"` + Metadata map[string]interface{} `url:"metadata,omitempty" json:"metadata,omitempty"` + Month string `url:"month,omitempty" json:"month,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + PaymentReference string `url:"payment_reference,omitempty" json:"payment_reference,omitempty"` + RetryIfPossible bool `url:"retry_if_possible,omitempty" json:"retry_if_possible,omitempty"` + StartDate string `url:"start_date,omitempty" json:"start_date,omitempty"` } // Create // Creates a new subscription object -func (s *SubscriptionService) Create(ctx context.Context, p SubscriptionCreateParams, opts ...RequestOption) (*Subscription, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/subscriptions")) +func (s *SubscriptionServiceImpl) Create(ctx context.Context, p SubscriptionCreateParams, opts ...RequestOption) (*Subscription, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/subscriptions")) if err != nil { return nil, err } @@ -112,10 +127,10 @@ func (s *SubscriptionService) Create(ctx context.Context, p SubscriptionCreatePa return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -124,7 +139,7 @@ func (s *SubscriptionService) Create(ctx context.Context, p SubscriptionCreatePa req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -168,39 +183,44 @@ func (s *SubscriptionService) Create(ctx context.Context, p SubscriptionCreatePa return result.Subscription, nil } +type SubscriptionListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // SubscriptionListParams parameters type SubscriptionListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - Customer string `url:"customer,omitempty" json:"customer,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` - Status []string `url:"status,omitempty" json:"status,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *SubscriptionListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + Customer string `url:"customer,omitempty" json:"customer,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + Mandate string `url:"mandate,omitempty" json:"mandate,omitempty"` + Status []string `url:"status,omitempty" json:"status,omitempty"` +} + +type SubscriptionListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type SubscriptionListResultMeta struct { + Cursors *SubscriptionListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// SubscriptionListResult response including pagination metadata type SubscriptionListResult struct { - Subscriptions []Subscription `json:"subscriptions"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Subscriptions []Subscription `json:"subscriptions"` + Meta SubscriptionListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // subscriptions. -func (s *SubscriptionService) List(ctx context.Context, p SubscriptionListParams, opts ...RequestOption) (*SubscriptionListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/subscriptions")) +func (s *SubscriptionServiceImpl) List(ctx context.Context, p SubscriptionListParams, opts ...RequestOption) (*SubscriptionListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/subscriptions")) if err != nil { return nil, err } @@ -228,17 +248,17 @@ func (s *SubscriptionService) List(ctx context.Context, p SubscriptionListParams return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -286,7 +306,7 @@ type SubscriptionListPagingIterator struct { cursor string response *SubscriptionListResult params SubscriptionListParams - service *SubscriptionService + service *SubscriptionServiceImpl requestOptions []RequestOption } @@ -307,7 +327,7 @@ func (c *SubscriptionListPagingIterator) Value(ctx context.Context) (*Subscripti p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/subscriptions")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/subscriptions")) if err != nil { return nil, err @@ -337,16 +357,16 @@ func (c *SubscriptionListPagingIterator) Value(ctx context.Context) (*Subscripti } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -393,7 +413,7 @@ func (c *SubscriptionListPagingIterator) Value(ctx context.Context) (*Subscripti return c.response, nil } -func (s *SubscriptionService) All(ctx context.Context, +func (s *SubscriptionServiceImpl) All(ctx context.Context, p SubscriptionListParams, opts ...RequestOption) *SubscriptionListPagingIterator { return &SubscriptionListPagingIterator{ @@ -405,8 +425,8 @@ func (s *SubscriptionService) All(ctx context.Context, // Get // Retrieves the details of a single subscription. -func (s *SubscriptionService) Get(ctx context.Context, identity string, opts ...RequestOption) (*Subscription, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/subscriptions/%v", +func (s *SubscriptionServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*Subscription, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/subscriptions/%v", identity)) if err != nil { return nil, err @@ -429,17 +449,17 @@ func (s *SubscriptionService) Get(ctx context.Context, identity string, opts ... return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -519,8 +539,8 @@ type SubscriptionUpdateParams struct { // subscription was created by an app other than the app you are authenticated // as // -func (s *SubscriptionService) Update(ctx context.Context, identity string, p SubscriptionUpdateParams, opts ...RequestOption) (*Subscription, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/subscriptions/%v", +func (s *SubscriptionServiceImpl) Update(ctx context.Context, identity string, p SubscriptionUpdateParams, opts ...RequestOption) (*Subscription, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/subscriptions/%v", identity)) if err != nil { return nil, err @@ -555,10 +575,10 @@ func (s *SubscriptionService) Update(ctx context.Context, identity string, p Sub return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -567,7 +587,7 @@ func (s *SubscriptionService) Update(ctx context.Context, identity string, p Sub req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -659,8 +679,8 @@ type SubscriptionPauseParams struct { // - `pause_cycles_must_be_greater_than_or_equal_to` if the provided value for // `pause_cycles` cannot be satisfied. // -func (s *SubscriptionService) Pause(ctx context.Context, identity string, p SubscriptionPauseParams, opts ...RequestOption) (*Subscription, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/subscriptions/%v/actions/pause", +func (s *SubscriptionServiceImpl) Pause(ctx context.Context, identity string, p SubscriptionPauseParams, opts ...RequestOption) (*Subscription, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/subscriptions/%v/actions/pause", identity)) if err != nil { return nil, err @@ -695,10 +715,10 @@ func (s *SubscriptionService) Pause(ctx context.Context, identity string, p Subs return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -707,7 +727,7 @@ func (s *SubscriptionService) Pause(ctx context.Context, identity string, p Subs req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -774,8 +794,8 @@ type SubscriptionResumeParams struct { // // - `subscription_not_paused` if the subscription is not paused. // -func (s *SubscriptionService) Resume(ctx context.Context, identity string, p SubscriptionResumeParams, opts ...RequestOption) (*Subscription, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/subscriptions/%v/actions/resume", +func (s *SubscriptionServiceImpl) Resume(ctx context.Context, identity string, p SubscriptionResumeParams, opts ...RequestOption) (*Subscription, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/subscriptions/%v/actions/resume", identity)) if err != nil { return nil, err @@ -810,10 +830,10 @@ func (s *SubscriptionService) Resume(ctx context.Context, identity string, p Sub return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -822,7 +842,7 @@ func (s *SubscriptionService) Resume(ctx context.Context, identity string, p Sub req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -878,8 +898,8 @@ type SubscriptionCancelParams struct { // // This will fail with a cancellation_failed error if the subscription is // already cancelled or finished. -func (s *SubscriptionService) Cancel(ctx context.Context, identity string, p SubscriptionCancelParams, opts ...RequestOption) (*Subscription, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/subscriptions/%v/actions/cancel", +func (s *SubscriptionServiceImpl) Cancel(ctx context.Context, identity string, p SubscriptionCancelParams, opts ...RequestOption) (*Subscription, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/subscriptions/%v/actions/cancel", identity)) if err != nil { return nil, err @@ -914,10 +934,10 @@ func (s *SubscriptionService) Cancel(ctx context.Context, identity string, p Sub return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -926,7 +946,7 @@ func (s *SubscriptionService) Cancel(ctx context.Context, identity string, p Sub req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/tax_rate_service.go b/tax_rate_service.go index 41cde59..e6e1dcb 100644 --- a/tax_rate_service.go +++ b/tax_rate_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // TaxRateService manages tax_rates -type TaxRateService struct { - endpoint string - token string - client *http.Client +type TaxRateServiceImpl struct { + config Config } // TaxRate model @@ -35,6 +33,12 @@ type TaxRate struct { Type string `url:"type,omitempty" json:"type,omitempty"` } +type TaxRateService interface { + List(ctx context.Context, p TaxRateListParams, opts ...RequestOption) (*TaxRateListResult, error) + All(ctx context.Context, p TaxRateListParams, opts ...RequestOption) *TaxRateListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*TaxRate, error) +} + // TaxRateListParams parameters type TaxRateListParams struct { After string `url:"after,omitempty" json:"after,omitempty"` @@ -42,23 +46,26 @@ type TaxRateListParams struct { Jurisdiction string `url:"jurisdiction,omitempty" json:"jurisdiction,omitempty"` } -// TaxRateListResult response including pagination metadata +type TaxRateListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type TaxRateListResultMeta struct { + Cursors *TaxRateListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` +} + type TaxRateListResult struct { - TaxRates []TaxRate `json:"tax_rates"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + TaxRates []TaxRate `json:"tax_rates"` + Meta TaxRateListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of all tax // rates. -func (s *TaxRateService) List(ctx context.Context, p TaxRateListParams, opts ...RequestOption) (*TaxRateListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/tax_rates")) +func (s *TaxRateServiceImpl) List(ctx context.Context, p TaxRateListParams, opts ...RequestOption) (*TaxRateListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/tax_rates")) if err != nil { return nil, err } @@ -86,17 +93,17 @@ func (s *TaxRateService) List(ctx context.Context, p TaxRateListParams, opts ... return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -144,7 +151,7 @@ type TaxRateListPagingIterator struct { cursor string response *TaxRateListResult params TaxRateListParams - service *TaxRateService + service *TaxRateServiceImpl requestOptions []RequestOption } @@ -165,7 +172,7 @@ func (c *TaxRateListPagingIterator) Value(ctx context.Context) (*TaxRateListResu p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/tax_rates")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/tax_rates")) if err != nil { return nil, err @@ -195,16 +202,16 @@ func (c *TaxRateListPagingIterator) Value(ctx context.Context) (*TaxRateListResu } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -251,7 +258,7 @@ func (c *TaxRateListPagingIterator) Value(ctx context.Context) (*TaxRateListResu return c.response, nil } -func (s *TaxRateService) All(ctx context.Context, +func (s *TaxRateServiceImpl) All(ctx context.Context, p TaxRateListParams, opts ...RequestOption) *TaxRateListPagingIterator { return &TaxRateListPagingIterator{ @@ -263,8 +270,8 @@ func (s *TaxRateService) All(ctx context.Context, // Get // Retrieves the details of a tax rate. -func (s *TaxRateService) Get(ctx context.Context, identity string, opts ...RequestOption) (*TaxRate, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/tax_rates/%v", +func (s *TaxRateServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*TaxRate, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/tax_rates/%v", identity)) if err != nil { return nil, err @@ -287,17 +294,17 @@ func (s *TaxRateService) Get(ctx context.Context, identity string, opts ...Reque return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } diff --git a/testdata/bank_authorisations.json b/testdata/bank_authorisations.json index 362dbe3..e2994dd 100644 --- a/testdata/bank_authorisations.json +++ b/testdata/bank_authorisations.json @@ -1,8 +1,8 @@ { "get": { - "body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 8081","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2022-01-12T10:16:43.390Z","expires_at":"2022-01-12T10:16:43.390Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}} + "body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 8081","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2022-03-23T10:25:45.985Z","expires_at":"2022-03-23T10:25:45.985Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}} }, "create": { - "body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 7887","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2022-01-12T10:16:43.390Z","expires_at":"2022-01-12T10:16:43.390Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}} + "body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 7887","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2022-03-23T10:25:45.985Z","expires_at":"2022-03-23T10:25:45.985Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}} } } \ No newline at end of file diff --git a/testdata/billing_request_flows.json b/testdata/billing_request_flows.json index 2ae4a76..1b00a7b 100644 --- a/testdata/billing_request_flows.json +++ b/testdata/billing_request_flows.json @@ -1,8 +1,8 @@ { "create": { - "body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":true,"created_at":"2022-01-12T10:16:43.394Z","exit_uri":"https://my-website.com/abc/callback","expires_at":"2022-01-12T10:16:43.394Z","id":"BRF123","links":{"billing_request":"BRQ123"},"lock_bank_account":true,"lock_customer_details":true,"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123"}} + "body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":true,"created_at":"2022-03-23T10:25:45.988Z","exit_uri":"https://my-website.com/abc/callback","expires_at":"2022-03-23T10:25:45.988Z","id":"BRF123","links":{"billing_request":"BRQ123"},"lock_bank_account":true,"lock_customer_details":true,"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":true}} }, "initialise": { - "body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":true,"created_at":"2022-01-12T10:16:43.394Z","exit_uri":"https://my-website.com/abc/callback","expires_at":"2022-01-12T10:16:43.394Z","id":"BRF123","links":{"billing_request":"BRQ123"},"lock_bank_account":false,"lock_customer_details":true,"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123"}} + "body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":false,"created_at":"2022-03-23T10:25:45.988Z","exit_uri":"https://my-website.com/abc/callback","expires_at":"2022-03-23T10:25:45.988Z","id":"BRF123","links":{"billing_request":"BRQ123"},"lock_bank_account":false,"lock_customer_details":false,"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":true}} } } \ No newline at end of file diff --git a/testdata/billing_request_templates.json b/testdata/billing_request_templates.json index 22b9131..fef7b8f 100644 --- a/testdata/billing_request_templates.json +++ b/testdata/billing_request_templates.json @@ -1,6 +1,6 @@ { "list": { - "body": {"billing_request_templates":[{"authorisation_url":"https://pay.gocardless.com/BRT123","created_at":"2021-01-01T12:00:00.000Z","id":"BRT123","mandate_request_currency":"GBP","mandate_request_metadata":{},"mandate_request_scheme":"bacs","mandate_request_verify":null,"metadata":{},"name":"12 Month Gold Plan","payment_request_amount":1000,"payment_request_currency":"GBP","payment_request_description":"Top-up Payment","payment_request_metadata":{},"payment_request_scheme":"faster_payments","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"},{"authorisation_url":"https://pay.gocardless.com/BRT123","created_at":"2021-01-01T12:00:00.000Z","id":"BRT123","mandate_request_currency":"GBP","mandate_request_metadata":{},"mandate_request_scheme":"bacs","mandate_request_verify":null,"metadata":{},"name":"12 Month Gold Plan","payment_request_amount":1000,"payment_request_currency":"GBP","payment_request_description":"Top-up Payment","payment_request_metadata":{},"payment_request_scheme":"faster_payments","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 3632","before":"example before 8590"},"limit":50}} + "body": {"billing_request_templates":[{"authorisation_url":"https://pay.gocardless.com/BRT123","created_at":"2021-01-01T12:00:00.000Z","id":"BRT123","mandate_request_currency":"GBP","mandate_request_metadata":{},"mandate_request_scheme":"bacs","mandate_request_verify":null,"metadata":{},"name":"12 Month Gold Plan","payment_request_amount":1000,"payment_request_currency":"GBP","payment_request_description":"Top-up Payment","payment_request_metadata":{},"payment_request_scheme":"faster_payments","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"},{"authorisation_url":"https://pay.gocardless.com/BRT123","created_at":"2021-01-01T12:00:00.000Z","id":"BRT123","mandate_request_currency":"GBP","mandate_request_metadata":{},"mandate_request_scheme":"bacs","mandate_request_verify":null,"metadata":{},"name":"12 Month Gold Plan","payment_request_amount":1000,"payment_request_currency":"GBP","payment_request_description":"Top-up Payment","payment_request_metadata":{},"payment_request_scheme":"faster_payments","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 8553","before":"example before 3098"},"limit":50}} }, "get": { "body": {"billing_request_templates":{"authorisation_url":"https://pay.gocardless.com/BRT123","created_at":"2021-01-01T12:00:00.000Z","id":"BRT123","mandate_request_currency":"GBP","mandate_request_metadata":{},"mandate_request_scheme":"bacs","mandate_request_verify":null,"metadata":{},"name":"12 Month Gold Plan","payment_request_amount":1000,"payment_request_currency":"GBP","payment_request_description":"Top-up Payment","payment_request_metadata":{},"payment_request_scheme":"faster_payments","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"}} diff --git a/testdata/billing_requests.json b/testdata/billing_requests.json index e934e5a..cad4262 100644 --- a/testdata/billing_requests.json +++ b/testdata/billing_requests.json @@ -1,29 +1,29 @@ { "list": { - "body": {"billing_requests":[{"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1318","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 4425","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 4059"},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 2081"},"scheme":"faster_payments"},"status":"pending"},{"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 456","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 2540","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 694"},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 8511"},"scheme":"faster_payments"},"status":"pending"}],"meta":{"cursors":{"after":"example after 5089","before":"example before 8162"},"limit":50}} + "body": {"billing_requests":[{"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1318","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 4425","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 4059"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 2081"},"metadata":{},"scheme":"faster_payments"},"status":"pending"},{"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 694","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 8511","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 456"},"metadata":{},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 3300"},"metadata":{},"scheme":"faster_payments"},"status":"pending"}],"meta":{"cursors":{"after":"example after 5089","before":"example before 8162"},"limit":50}} }, "create": { - "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 1528","authorisation_type":"example authorisation_type 6258","requires_institution":false},"collect_customer_details":{"default_country_code":"example default_country_code 8047"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1445","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 3237","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 9106"},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 4728"},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 1211"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 3274"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 3237","authorisation_type":"example authorisation_type 9106","requires_institution":false},"collect_customer_details":{"default_country_code":"example default_country_code 495"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 3274","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 4728","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 1528"},"metadata":{},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 1211"},"metadata":{},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 8047"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 6258"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "get": { - "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 2790","authorisation_type":"example authorisation_type 3015","requires_institution":false},"collect_customer_details":{"default_country_code":"example default_country_code 5541"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 5356","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 5429","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 8287"},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 6831"},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 7387"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 408"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 7387","authorisation_type":"example authorisation_type 6831","requires_institution":true},"collect_customer_details":{"default_country_code":"example default_country_code 5356"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 408","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 5541","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 8287"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 2888"},"metadata":{},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 3015"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 2790"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "collect_customer_details": { - "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 2433","authorisation_type":"example authorisation_type 4147","requires_institution":false},"collect_customer_details":{"default_country_code":"example default_country_code 563"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 5026","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 6413","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 5194"},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 1485"},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 1737"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 631"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 1485","authorisation_type":"example authorisation_type 5026","requires_institution":false},"collect_customer_details":{"default_country_code":"example default_country_code 3090"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 563","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 5194","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 2433"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 4078"},"metadata":{},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 631"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 1737"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "collect_bank_account": { - "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 7189","authorisation_type":"example authorisation_type 2199","requires_institution":true},"collect_customer_details":{"default_country_code":"example default_country_code 8705"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1353","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 6159","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 1957"},"scheme":"bacs","verify":"recommended"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 4324"},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4538"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 2888"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 7189","authorisation_type":"example authorisation_type 2199","requires_institution":true},"collect_customer_details":{"default_country_code":"example default_country_code 8705"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 6159","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 4324","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 3721"},"metadata":{},"scheme":"bacs","verify":"recommended"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 1353"},"metadata":{},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4538"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 2888"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "fulfil": { - "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 8510","authorisation_type":"example authorisation_type 2605","requires_institution":true},"collect_customer_details":{"default_country_code":"example default_country_code 8266"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 7202","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 4783","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 2451"},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 9703"},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 5561"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 9828"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 156","authorisation_type":"example authorisation_type 8266","requires_institution":false},"collect_customer_details":{"default_country_code":"example default_country_code 5561"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 9703","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 9355","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 8510"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 2605"},"metadata":{},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4783"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 7202"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "confirm_payer_details": { - "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 7463","authorisation_type":"example authorisation_type 7996","requires_institution":true},"collect_customer_details":{"default_country_code":"example default_country_code 6420"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 5746","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 1563","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 9002"},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 5094"},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 5447"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 9718"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 9718","authorisation_type":"example authorisation_type 5447","requires_institution":true},"collect_customer_details":{"default_country_code":"example default_country_code 1577"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 9002","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 4376","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 1563"},"metadata":{},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 7463"},"metadata":{},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 6420"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 7996"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "cancel": { - "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 59","authorisation_type":"example authorisation_type 3033","requires_institution":true},"collect_customer_details":{"default_country_code":"example default_country_code 3891"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 8878","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 2002","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 9241"},"scheme":"bacs","verify":"recommended"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 1137"},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 8623"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 953"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 953","authorisation_type":"example authorisation_type 1137","requires_institution":true},"collect_customer_details":{"default_country_code":"example default_country_code 9241"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 8878","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 2002","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 3891"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 8623"},"metadata":{},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 3033"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 59"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "notify": { - "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 552","authorisation_type":"example authorisation_type 7940","requires_institution":false},"collect_customer_details":{"default_country_code":"example default_country_code 9843"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1351","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 7425","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 1598"},"scheme":"bacs","verify":"recommended"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 9336"},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 9107"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 2546"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"bank_authorisation":{"adapter":"example adapter 9107","authorisation_type":"example authorisation_type 9336","requires_institution":false},"collect_customer_details":{"default_country_code":"example default_country_code 7940"},"completes_actions":["collect_bank_account"],"required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 2205","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 9843","mandate_request":"MRQ123","mandate_request_mandate":"MD123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"currency":"GBP","links":{"mandate":"example mandate 552"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 1351"},"metadata":{},"scheme":"faster_payments"},"resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 7425"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 1598"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} } } \ No newline at end of file diff --git a/testdata/blocks.json b/testdata/blocks.json index 4c0baa4..0cbba33 100644 --- a/testdata/blocks.json +++ b/testdata/blocks.json @@ -1,20 +1,20 @@ { "create": { - "body": {"blocks":{"active":true,"block_type":"example block_type 3098","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 8591","reason_type":"example reason_type 8553","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}} + "body": {"blocks":{"active":true,"block_type":"example block_type 5384","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 8582","reason_type":"example reason_type 8591","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}} }, "get": { - "body": {"blocks":{"active":true,"block_type":"example block_type 8582","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 1297","reason_type":"example reason_type 5384","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}} + "body": {"blocks":{"active":true,"block_type":"example block_type 1297","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 6137","reason_type":"example reason_type 9267","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}} }, "list": { - "body": {"blocks":[{"active":true,"block_type":"example block_type 9271","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 7726","reason_type":"example reason_type 5894","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"},{"active":true,"block_type":"example block_type 3981","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 5802","reason_type":"example reason_type 2079","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 6137","before":"example before 9267"},"limit":50}} + "body": {"blocks":[{"active":true,"block_type":"example block_type 9271","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 7726","reason_type":"example reason_type 5894","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"},{"active":true,"block_type":"example block_type 3981","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 5802","reason_type":"example reason_type 2079","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 1270","before":"example before 2066"},"limit":50}} }, "disable": { - "body": {"blocks":{"active":true,"block_type":"example block_type 2066","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 493","reason_type":"example reason_type 1270","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}} + "body": {"blocks":{"active":true,"block_type":"example block_type 493","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 9819","reason_type":"example reason_type 3086","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}} }, "enable": { - "body": {"blocks":{"active":true,"block_type":"example block_type 3086","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 8981","reason_type":"example reason_type 9819","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}} + "body": {"blocks":{"active":true,"block_type":"example block_type 8981","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 7175","reason_type":"example reason_type 6052","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}} }, "block_by_ref": { - "body": {"blocks":[{"active":true,"block_type":"example block_type 4885","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 1387","reason_type":"example reason_type 5710","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"},{"active":true,"block_type":"example block_type 2818","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 1528","reason_type":"example reason_type 3749","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 7175","before":"example before 6052"},"limit":50}} + "body": {"blocks":[{"active":true,"block_type":"example block_type 5710","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 4885","reason_type":"example reason_type 1387","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"},{"active":true,"block_type":"example block_type 3749","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 2818","reason_type":"example reason_type 1528","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 7903","before":"example before 4384"},"limit":50}} } } \ No newline at end of file diff --git a/testdata/creditor_bank_accounts.json b/testdata/creditor_bank_accounts.json index 65777f4..4600019 100644 --- a/testdata/creditor_bank_accounts.json +++ b/testdata/creditor_bank_accounts.json @@ -3,7 +3,7 @@ "body": {"creditor_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}} }, "list": { - "body": {"creditor_bank_accounts":[{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}},{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}],"meta":{"cursors":{"after":"example after 3231","before":"example before 3767"},"limit":50}} + "body": {"creditor_bank_accounts":[{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}},{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}],"meta":{"cursors":{"after":"example after 8154","before":"example before 7578"},"limit":50}} }, "get": { "body": {"creditor_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}} diff --git a/testdata/creditors.json b/testdata/creditors.json index fbafe5f..dc8cc1b 100644 --- a/testdata/creditors.json +++ b/testdata/creditors.json @@ -1,14 +1,14 @@ { "create": { - "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 7903","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 4384","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 1224","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 4547","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"}} + "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 3612","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 1532","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 1224","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 4547","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"}} }, "list": { - "body": {"creditors":[{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 3612","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 1532","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 3616","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 7839","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"},{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 540","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 8076","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 7051","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 5786","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"}],"meta":{"cursors":{"after":"example after 7351","before":"example before 3640"},"limit":50}} + "body": {"creditors":[{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 540","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 8076","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 7051","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 5786","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"},{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 7351","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 3640","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 364","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 8844","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"}],"meta":{"cursors":{"after":"example after 3616","before":"example before 7839"},"limit":50}} }, "get": { - "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 8844","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 364","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 9183","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 2305","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"}} + "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 2305","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 9183","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 90","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 4801","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"}} }, "update": { - "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 4801","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 2258","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 1602","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 90","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"}} + "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 3231","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Nude Wines","postal_code":"EC1V 7LQ","region":"example region 1602","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","currency":"EUR","email":"user@example.com","minimum_advance_notice":3,"name":"example name 2258","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 3767","region":"Greater London","scheme":"bacs"}],"verification_status":"action_required"}} } } \ No newline at end of file diff --git a/testdata/currency_exchange_rates.json b/testdata/currency_exchange_rates.json index bb253ed..57caabd 100644 --- a/testdata/currency_exchange_rates.json +++ b/testdata/currency_exchange_rates.json @@ -1,5 +1,5 @@ { "list": { - "body": {"currency_exchange_rates":[{"rate":"1.1234567890","source":"GBP","target":"EUR","time":"2014-01-01T12:00:00Z"},{"rate":"1.1234567890","source":"GBP","target":"EUR","time":"2014-01-01T12:00:00Z"}],"meta":{"cursors":{"after":"example after 8154","before":"example before 7578"},"limit":50}} + "body": {"currency_exchange_rates":[{"rate":"1.1234567890","source":"GBP","target":"EUR","time":"2014-01-01T12:00:00Z"},{"rate":"1.1234567890","source":"GBP","target":"EUR","time":"2014-01-01T12:00:00Z"}],"meta":{"cursors":{"after":"example after 1223","before":"example before 7822"},"limit":50}} } } \ No newline at end of file diff --git a/testdata/customer_bank_accounts.json b/testdata/customer_bank_accounts.json index 1fdcb00..76ffd5d 100644 --- a/testdata/customer_bank_accounts.json +++ b/testdata/customer_bank_accounts.json @@ -1,17 +1,17 @@ { "create": { - "body": {"customer_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 7342"},"metadata":{}}} + "body": {"customer_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 7743"},"metadata":{}}} }, "list": { - "body": {"customer_bank_accounts":[{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4208"},"metadata":{}},{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 7743"},"metadata":{}}],"meta":{"cursors":{"after":"example after 1968","before":"example before 1166"},"limit":50}} + "body": {"customer_bank_accounts":[{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 1968"},"metadata":{}},{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 1166"},"metadata":{}}],"meta":{"cursors":{"after":"example after 4535","before":"example before 3710"},"limit":50}} }, "get": { - "body": {"customer_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 3710"},"metadata":{}}} + "body": {"customer_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 440"},"metadata":{}}} }, "update": { - "body": {"customer_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4535"},"metadata":{}}} + "body": {"customer_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4904"},"metadata":{}}} }, "disable": { - "body": {"customer_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 440"},"metadata":{}}} + "body": {"customer_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 3162"},"metadata":{}}} } } \ No newline at end of file diff --git a/testdata/customer_notifications.json b/testdata/customer_notifications.json index 5481de7..12be960 100644 --- a/testdata/customer_notifications.json +++ b/testdata/customer_notifications.json @@ -1,5 +1,5 @@ { "handle": { - "body": {"customer_notifications":{"action_taken":"example action_taken 4904","action_taken_at":"2022-01-12T10:16:43.401Z","action_taken_by":"example action_taken_by 3162","id":"PCN123","links":{"customer":"CU123","event":"EV123","mandate":"MD123","payment":"PM123","refund":"RF123","subscription":"SB123"},"type":"payment_created"}} + "body": {"customer_notifications":{"action_taken":"example action_taken 4657","action_taken_at":"2022-03-23T10:25:45.997Z","action_taken_by":"example action_taken_by 4415","id":"PCN123","links":{"customer":"CU123","event":"EV123","mandate":"MD123","payment":"PM123","refund":"RF123","subscription":"SB123"},"type":"payment_created"}} } } \ No newline at end of file diff --git a/testdata/customers.json b/testdata/customers.json index 0548e8c..f14731b 100644 --- a/testdata/customers.json +++ b/testdata/customers.json @@ -3,7 +3,7 @@ "body": {"customers":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"}} }, "list": { - "body": {"customers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"}],"meta":{"cursors":{"after":"example after 1223","before":"example before 7822"},"limit":50}} + "body": {"customers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"}],"meta":{"cursors":{"after":"example after 7342","before":"example before 4208"},"limit":50}} }, "get": { "body": {"customers":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"}} diff --git a/testdata/events.json b/testdata/events.json index 2df0e4f..2198ad7 100644 --- a/testdata/events.json +++ b/testdata/events.json @@ -1,8 +1,8 @@ { "list": { - "body": {"events":[{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2022-01-12T10:16:43.401Z","id":"PCN123","mandatory":true,"type":"payment_created"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","subscription":"SB123"},"metadata":{},"resource_type":"mandates"},{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2022-01-12T10:16:43.401Z","id":"PCN123","mandatory":true,"type":"payment_created"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","subscription":"SB123"},"metadata":{},"resource_type":"mandates"}],"meta":{"cursors":{"after":"example after 3039","before":"example before 9371"},"limit":50}} + "body": {"events":[{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2022-03-23T10:25:45.998Z","id":"PCN123","mandatory":false,"type":"payment_created"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","subscription":"SB123"},"metadata":{},"resource_type":"mandates"},{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2022-03-23T10:25:45.998Z","id":"PCN123","mandatory":false,"type":"payment_created"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","subscription":"SB123"},"metadata":{},"resource_type":"mandates"}],"meta":{"cursors":{"after":"example after 3039","before":"example before 9371"},"limit":50}} }, "get": { - "body": {"events":{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2022-01-12T10:16:43.401Z","id":"PCN123","mandatory":false,"type":"payment_created"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","subscription":"SB123"},"metadata":{},"resource_type":"mandates"}} + "body": {"events":{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2022-03-23T10:25:45.998Z","id":"PCN123","mandatory":false,"type":"payment_created"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","subscription":"SB123"},"metadata":{},"resource_type":"mandates"}} } } \ No newline at end of file diff --git a/testdata/instalment_schedules.json b/testdata/instalment_schedules.json index 77c5cf8..87726de 100644 --- a/testdata/instalment_schedules.json +++ b/testdata/instalment_schedules.json @@ -6,7 +6,7 @@ "body": {"instalment_schedules":{"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"IS123","links":{"customer":"CU123","mandate":"MD123","payments":["PM123","PM456"]},"metadata":{},"name":"Invoice 4404","payment_errors":{"0":[],"1":{"field":"charge_date","message":"must be on or after mandate's next_possible_customer_charge_date"}},"status":"active","total_amount":1000}} }, "list": { - "body": {"instalment_schedules":[{"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"IS123","links":{"customer":"CU123","mandate":"MD123","payments":["PM123","PM456"]},"metadata":{},"name":"Invoice 4404","payment_errors":{"0":[],"1":{"field":"charge_date","message":"must be on or after mandate's next_possible_customer_charge_date"}},"status":"active","total_amount":1000},{"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"IS123","links":{"customer":"CU123","mandate":"MD123","payments":["PM123","PM456"]},"metadata":{},"name":"Invoice 4404","payment_errors":{"0":[],"1":{"field":"charge_date","message":"must be on or after mandate's next_possible_customer_charge_date"}},"status":"active","total_amount":1000}],"meta":{"cursors":{"after":"example after 9700","before":"example before 9513"},"limit":50}} + "body": {"instalment_schedules":[{"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"IS123","links":{"customer":"CU123","mandate":"MD123","payments":["PM123","PM456"]},"metadata":{},"name":"Invoice 4404","payment_errors":{"0":[],"1":{"field":"charge_date","message":"must be on or after mandate's next_possible_customer_charge_date"}},"status":"active","total_amount":1000},{"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"IS123","links":{"customer":"CU123","mandate":"MD123","payments":["PM123","PM456"]},"metadata":{},"name":"Invoice 4404","payment_errors":{"0":[],"1":{"field":"charge_date","message":"must be on or after mandate's next_possible_customer_charge_date"}},"status":"active","total_amount":1000}],"meta":{"cursors":{"after":"example after 6720","before":"example before 1359"},"limit":50}} }, "get": { "body": {"instalment_schedules":{"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"IS123","links":{"customer":"CU123","mandate":"MD123","payments":["PM123","PM456"]},"metadata":{},"name":"Invoice 4404","payment_errors":{"0":[],"1":{"field":"charge_date","message":"must be on or after mandate's next_possible_customer_charge_date"}},"status":"active","total_amount":1000}} diff --git a/testdata/institutions.json b/testdata/institutions.json index 63e6cee..acd26d0 100644 --- a/testdata/institutions.json +++ b/testdata/institutions.json @@ -1,5 +1,5 @@ { "list": { - "body": {"institutions":[{"country_code":"GB","icon_url":"https://gocardless/assets/icons/monzo","id":"monzo","logo_url":"https://gocardless/assets/logos/monzo","name":"VAT"},{"country_code":"GB","icon_url":"https://gocardless/assets/icons/monzo","id":"monzo","logo_url":"https://gocardless/assets/logos/monzo","name":"VAT"}],"meta":{"cursors":{"after":"example after 6720","before":"example before 1359"},"limit":50}} + "body": {"institutions":[{"country_code":"GB","icon_url":"https://gocardless/assets/icons/monzo","id":"monzo","logo_url":"https://gocardless/assets/logos/monzo","name":"VAT","roles":["institutions_list","heartbeat","read_refund_account"]},{"country_code":"GB","icon_url":"https://gocardless/assets/icons/monzo","id":"monzo","logo_url":"https://gocardless/assets/logos/monzo","name":"VAT","roles":["institutions_list","heartbeat","read_refund_account"]}],"meta":{"cursors":{"after":"example after 870","before":"example before 783"},"limit":50}} } } \ No newline at end of file diff --git a/testdata/mandate_import_entries.json b/testdata/mandate_import_entries.json index b6ef63d..4058b11 100644 --- a/testdata/mandate_import_entries.json +++ b/testdata/mandate_import_entries.json @@ -3,6 +3,6 @@ "body": {"mandate_import_entries":{"created_at":"2014-01-01T12:00:00.000Z","links":{"customer":"CU123","customer_bank_account":"BA123","mandate":"MD123","mandate_import":"IM0000AAAAAAA"},"record_identifier":"bank-file.xml/line-1"}} }, "list": { - "body": {"mandate_import_entries":[{"created_at":"2014-01-01T12:00:00.000Z","links":{"customer":"CU123","customer_bank_account":"BA123","mandate":"MD123","mandate_import":"IM0000AAAAAAA"},"record_identifier":"bank-file.xml/line-1"},{"created_at":"2014-01-01T12:00:00.000Z","links":{"customer":"CU123","customer_bank_account":"BA123","mandate":"MD123","mandate_import":"IM0000AAAAAAA"},"record_identifier":"bank-file.xml/line-1"}],"meta":{"cursors":{"after":"example after 8247","before":"example before 2984"},"limit":50}} + "body": {"mandate_import_entries":[{"created_at":"2014-01-01T12:00:00.000Z","links":{"customer":"CU123","customer_bank_account":"BA123","mandate":"MD123","mandate_import":"IM0000AAAAAAA"},"record_identifier":"bank-file.xml/line-1"},{"created_at":"2014-01-01T12:00:00.000Z","links":{"customer":"CU123","customer_bank_account":"BA123","mandate":"MD123","mandate_import":"IM0000AAAAAAA"},"record_identifier":"bank-file.xml/line-1"}],"meta":{"cursors":{"after":"example after 8010","before":"example before 565"},"limit":50}} } } \ No newline at end of file diff --git a/testdata/mandates.json b/testdata/mandates.json index 3d8b8f4..fd7bf2f 100644 --- a/testdata/mandates.json +++ b/testdata/mandates.json @@ -3,7 +3,7 @@ "body": {"mandates":{"created_at":"2014-01-01T12:00:00.000Z","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission"}} }, "list": { - "body": {"mandates":[{"created_at":"2014-01-01T12:00:00.000Z","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission"},{"created_at":"2014-01-01T12:00:00.000Z","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission"}],"meta":{"cursors":{"after":"example after 870","before":"example before 783"},"limit":50}} + "body": {"mandates":[{"created_at":"2014-01-01T12:00:00.000Z","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission"},{"created_at":"2014-01-01T12:00:00.000Z","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission"}],"meta":{"cursors":{"after":"example after 8247","before":"example before 2984"},"limit":50}} }, "get": { "body": {"mandates":{"created_at":"2014-01-01T12:00:00.000Z","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission"}} diff --git a/testdata/payer_authorisations.json b/testdata/payer_authorisations.json index 245cf29..95dde36 100644 --- a/testdata/payer_authorisations.json +++ b/testdata/payer_authorisations.json @@ -1,17 +1,17 @@ { "get": { - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 8010","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 6829","message":"example message 565","request_pointer":"example request_pointer 4162"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 4162","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 7920","message":"example message 2048","request_pointer":"example request_pointer 6829"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} }, "create": { - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 5695","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 7920","message":"example message 2048","request_pointer":"example request_pointer 6756"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 6756","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 8666","message":"example message 6200","request_pointer":"example request_pointer 5695"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} }, "update": { - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 8666","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 9456","message":"example message 6629","request_pointer":"example request_pointer 6200"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 8831","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 9456","message":"example message 6629","request_pointer":"example request_pointer 1092"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} }, "submit": { - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 1092","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 8831","message":"example message 7577","request_pointer":"example request_pointer 7886"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 7577","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 7886","message":"example message 5320","request_pointer":"example request_pointer 5399"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} }, "confirm": { - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 5320","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 3447","message":"example message 5399","request_pointer":"example request_pointer 1162"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 1162","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 3447","message":"example message 292","request_pointer":"example request_pointer 1888"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} } } \ No newline at end of file diff --git a/testdata/payments.json b/testdata/payments.json index a1793c4..6e090e4 100644 --- a/testdata/payments.json +++ b/testdata/payments.json @@ -3,10 +3,10 @@ "body": {"payments":{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":true,"status":"submitted"}} }, "list": { - "body": {"meta":{"cursors":{"after":"example after 9888","before":"example before 9103"},"limit":50},"payments":[{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":false,"status":"submitted"},{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":true,"status":"submitted"}]} + "body": {"meta":{"cursors":{"after":"example after 3756","before":"example before 8318"},"limit":50},"payments":[{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":false,"status":"submitted"},{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":false,"status":"submitted"}]} }, "get": { - "body": {"payments":{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":false,"status":"submitted"}} + "body": {"payments":{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":true,"status":"submitted"}} }, "update": { "body": {"payments":{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":false,"status":"submitted"}} @@ -15,6 +15,6 @@ "body": {"payments":{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":true,"status":"submitted"}} }, "retry": { - "body": {"payments":{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":false,"status":"submitted"}} + "body": {"payments":{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":true,"status":"submitted"}} } } \ No newline at end of file diff --git a/testdata/payout_items.json b/testdata/payout_items.json index e502e8f..c4fe69d 100644 --- a/testdata/payout_items.json +++ b/testdata/payout_items.json @@ -1,5 +1,5 @@ { "list": { - "body": {"meta":{"cursors":{"after":"example after 2181","before":"example before 8675"},"limit":10},"payout_items":[{"amount":"45.0","links":{"mandate":"MD123","payment":"PM123","refund":"RF123"},"taxes":[{"amount":"1.1","currency":"EUR","destination_amount":"1.1","destination_currency":"EUR","exchange_rate":"1.11205","tax_rate_id":"GB_VAT_1"}],"type":"payment_paid_out"},{"amount":"45.0","links":{"mandate":"MD123","payment":"PM123","refund":"RF123"},"taxes":[{"amount":"1.1","currency":"EUR","destination_amount":"1.1","destination_currency":"EUR","exchange_rate":"1.11205","tax_rate_id":"GB_VAT_1"}],"type":"payment_paid_out"}]} + "body": {"meta":{"cursors":{"after":"example after 8795","before":"example before 1853"},"limit":10},"payout_items":[{"amount":"45.0","links":{"mandate":"MD123","payment":"PM123","refund":"RF123"},"taxes":[{"amount":"1.1","currency":"EUR","destination_amount":"1.1","destination_currency":"EUR","exchange_rate":"1.11205","tax_rate_id":"GB_VAT_1"}],"type":"payment_paid_out"},{"amount":"45.0","links":{"mandate":"MD123","payment":"PM123","refund":"RF123"},"taxes":[{"amount":"1.1","currency":"EUR","destination_amount":"1.1","destination_currency":"EUR","exchange_rate":"1.11205","tax_rate_id":"GB_VAT_1"}],"type":"payment_paid_out"}]} } } \ No newline at end of file diff --git a/testdata/payouts.json b/testdata/payouts.json index d6266a8..1a8c3bd 100644 --- a/testdata/payouts.json +++ b/testdata/payouts.json @@ -1,6 +1,6 @@ { "list": { - "body": {"meta":{"cursors":{"after":"example after 8652","before":"example before 6157"},"limit":50},"payouts":[{"amount":1000,"arrival_date":"2014-01-01","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","deducted_fees":20,"fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PO123","links":{"creditor":"CR123","creditor_bank_account":"BA123"},"metadata":{"salesforce_id":"ABCD1234"},"payout_type":"merchant","reference":"ref-1","status":"pending","tax_currency":"EUR"},{"amount":1000,"arrival_date":"2014-01-01","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","deducted_fees":20,"fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PO123","links":{"creditor":"CR123","creditor_bank_account":"BA123"},"metadata":{"salesforce_id":"ABCD1234"},"payout_type":"merchant","reference":"ref-1","status":"pending","tax_currency":"EUR"}]} + "body": {"meta":{"cursors":{"after":"example after 8675","before":"example before 2181"},"limit":50},"payouts":[{"amount":1000,"arrival_date":"2014-01-01","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","deducted_fees":20,"fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PO123","links":{"creditor":"CR123","creditor_bank_account":"BA123"},"metadata":{"salesforce_id":"ABCD1234"},"payout_type":"merchant","reference":"ref-1","status":"pending","tax_currency":"EUR"},{"amount":1000,"arrival_date":"2014-01-01","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","deducted_fees":20,"fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PO123","links":{"creditor":"CR123","creditor_bank_account":"BA123"},"metadata":{"salesforce_id":"ABCD1234"},"payout_type":"merchant","reference":"ref-1","status":"pending","tax_currency":"EUR"}]} }, "get": { "body": {"payouts":{"amount":1000,"arrival_date":"2014-01-01","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","deducted_fees":20,"fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PO123","links":{"creditor":"CR123","creditor_bank_account":"BA123"},"metadata":{"salesforce_id":"ABCD1234"},"payout_type":"merchant","reference":"ref-1","status":"pending","tax_currency":"EUR"}} diff --git a/testdata/redirect_flows.json b/testdata/redirect_flows.json index 4d2acc7..44a4afa 100644 --- a/testdata/redirect_flows.json +++ b/testdata/redirect_flows.json @@ -1,11 +1,11 @@ { "create": { - "body": {"redirect_flows":{"confirmation_url":"https://pay.gocardless.com/flow/RE123/success","created_at":"2014-01-01T12:00:00.000Z","description":"Standard subscription","id":"RE123456","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","mandate":"MD123"},"mandate_reference":"example mandate_reference 1853","metadata":{"salesforce_id":"ABCD1234"},"redirect_url":"http://pay.gocardless.com/flow/RE123","scheme":"bacs","session_token":"SESS_wSs0uGYMISxzqOBq","success_redirect_url":"https://example.com/pay/confirm"}} + "body": {"redirect_flows":{"confirmation_url":"https://pay.gocardless.com/flow/RE123/success","created_at":"2014-01-01T12:00:00.000Z","description":"Standard subscription","id":"RE123456","links":{"billing_request":"BR123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","mandate":"MD123"},"mandate_reference":"example mandate_reference 417","metadata":{"salesforce_id":"ABCD1234"},"redirect_url":"http://pay.gocardless.com/flow/RE123","scheme":"bacs","session_token":"SESS_wSs0uGYMISxzqOBq","success_redirect_url":"https://example.com/pay/confirm"}} }, "get": { - "body": {"redirect_flows":{"confirmation_url":"https://pay.gocardless.com/flow/RE123/success","created_at":"2014-01-01T12:00:00.000Z","description":"Standard subscription","id":"RE123456","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","mandate":"MD123"},"mandate_reference":"example mandate_reference 8795","metadata":{"salesforce_id":"ABCD1234"},"redirect_url":"http://pay.gocardless.com/flow/RE123","scheme":"bacs","session_token":"SESS_wSs0uGYMISxzqOBq","success_redirect_url":"https://example.com/pay/confirm"}} + "body": {"redirect_flows":{"confirmation_url":"https://pay.gocardless.com/flow/RE123/success","created_at":"2014-01-01T12:00:00.000Z","description":"Standard subscription","id":"RE123456","links":{"billing_request":"BR123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","mandate":"MD123"},"mandate_reference":"example mandate_reference 1393","metadata":{"salesforce_id":"ABCD1234"},"redirect_url":"http://pay.gocardless.com/flow/RE123","scheme":"bacs","session_token":"SESS_wSs0uGYMISxzqOBq","success_redirect_url":"https://example.com/pay/confirm"}} }, "complete": { - "body": {"redirect_flows":{"confirmation_url":"https://pay.gocardless.com/flow/RE123/success","created_at":"2014-01-01T12:00:00.000Z","description":"Standard subscription","id":"RE123456","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","mandate":"MD123"},"mandate_reference":"example mandate_reference 417","metadata":{"salesforce_id":"ABCD1234"},"redirect_url":"http://pay.gocardless.com/flow/RE123","scheme":"bacs","session_token":"SESS_wSs0uGYMISxzqOBq","success_redirect_url":"https://example.com/pay/confirm"}} + "body": {"redirect_flows":{"confirmation_url":"https://pay.gocardless.com/flow/RE123/success","created_at":"2014-01-01T12:00:00.000Z","description":"Standard subscription","id":"RE123456","links":{"billing_request":"BR123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","mandate":"MD123"},"mandate_reference":"example mandate_reference 8470","metadata":{"salesforce_id":"ABCD1234"},"redirect_url":"http://pay.gocardless.com/flow/RE123","scheme":"bacs","session_token":"SESS_wSs0uGYMISxzqOBq","success_redirect_url":"https://example.com/pay/confirm"}} } } \ No newline at end of file diff --git a/testdata/refunds.json b/testdata/refunds.json index 282ac47..89dffcd 100644 --- a/testdata/refunds.json +++ b/testdata/refunds.json @@ -3,7 +3,7 @@ "body": {"refunds":{"amount":150,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"RF123","links":{"mandate":"MD123","payment":"PM123"},"metadata":{},"reference":"WINEBOX001","status":"submitted"}} }, "list": { - "body": {"meta":{"cursors":{"after":"example after 8470","before":"example before 1393"},"limit":50},"refunds":[{"amount":150,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"RF123","links":{"mandate":"MD123","payment":"PM123"},"metadata":{},"reference":"WINEBOX001","status":"submitted"},{"amount":150,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"RF123","links":{"mandate":"MD123","payment":"PM123"},"metadata":{},"reference":"WINEBOX001","status":"submitted"}]} + "body": {"meta":{"cursors":{"after":"example after 9386","before":"example before 8996"},"limit":50},"refunds":[{"amount":150,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"RF123","links":{"mandate":"MD123","payment":"PM123"},"metadata":{},"reference":"WINEBOX001","status":"submitted"},{"amount":150,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"RF123","links":{"mandate":"MD123","payment":"PM123"},"metadata":{},"reference":"WINEBOX001","status":"submitted"}]} }, "get": { "body": {"refunds":{"amount":150,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"RF123","links":{"mandate":"MD123","payment":"PM123"},"metadata":{},"reference":"WINEBOX001","status":"submitted"}} diff --git a/testdata/subscriptions.json b/testdata/subscriptions.json index a3fffde..5cc5b95 100644 --- a/testdata/subscriptions.json +++ b/testdata/subscriptions.json @@ -3,16 +3,16 @@ "body": {"subscriptions":{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":true,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}} }, "list": { - "body": {"meta":{"cursors":{"after":"example after 2520","before":"example before 260"},"limit":50},"subscriptions":[{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":false,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]},{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":true,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}]} + "body": {"meta":{"cursors":{"after":"example after 260","before":"example before 2520"},"limit":50},"subscriptions":[{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":true,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]},{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":true,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}]} }, "get": { - "body": {"subscriptions":{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":true,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}} + "body": {"subscriptions":{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":false,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}} }, "update": { "body": {"subscriptions":{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":true,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}} }, "pause": { - "body": {"subscriptions":{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":false,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}} + "body": {"subscriptions":{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":true,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}} }, "resume": { "body": {"subscriptions":{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":true,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}} diff --git a/testdata/tax_rates.json b/testdata/tax_rates.json index 599b761..e988fe5 100644 --- a/testdata/tax_rates.json +++ b/testdata/tax_rates.json @@ -1,6 +1,6 @@ { "list": { - "body": {"meta":{"cursors":{"after":"example after 2954","before":"example before 1079"},"limit":50},"tax_rates":[{"end_date":"2014-01-01","id":"GB_VAT_1","jurisdiction":"GBP","percentage":"20.0","start_date":"2014-01-01","type":"VAT"},{"end_date":"2014-01-01","id":"GB_VAT_1","jurisdiction":"GBP","percentage":"20.0","start_date":"2014-01-01","type":"VAT"}]} + "body": {"meta":{"cursors":{"after":"example after 2060","before":"example before 1464"},"limit":50},"tax_rates":[{"end_date":"2014-01-01","id":"GB_VAT_1","jurisdiction":"GBP","percentage":"20.0","start_date":"2014-01-01","type":"VAT"},{"end_date":"2014-01-01","id":"GB_VAT_1","jurisdiction":"GBP","percentage":"20.0","start_date":"2014-01-01","type":"VAT"}]} }, "get": { "body": {"tax_rates":{"end_date":"2014-01-01","id":"GB_VAT_1","jurisdiction":"GBP","percentage":"20.0","start_date":"2014-01-01","type":"VAT"}} diff --git a/testdata/webhooks.json b/testdata/webhooks.json index a329bf6..5412c88 100644 --- a/testdata/webhooks.json +++ b/testdata/webhooks.json @@ -1,11 +1,11 @@ { "list": { - "body": {"meta":{"cursors":{"after":"example after 1040","before":"example before 5014"},"limit":50},"webhooks":[{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":true,"request_body":"example request_body 1757","request_headers":{},"response_body":"example response_body 1181","response_body_truncated":true,"response_code":9551,"response_headers":{},"response_headers_content_truncated":true,"response_headers_count_truncated":false,"successful":true,"url":"https://example.com/webhooks"},{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":false,"request_body":"example request_body 5561","request_headers":{},"response_body":"example response_body 1509","response_body_truncated":false,"response_code":1719,"response_headers":{},"response_headers_content_truncated":true,"response_headers_count_truncated":true,"successful":false,"url":"https://example.com/webhooks"}]} + "body": {"meta":{"cursors":{"after":"example after 5740","before":"example before 8662"},"limit":50},"webhooks":[{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":true,"request_body":"example request_body 1757","request_headers":{},"response_body":"example response_body 4637","response_body_truncated":false,"response_code":600,"response_headers":{},"response_headers_content_truncated":true,"response_headers_count_truncated":false,"successful":true,"url":"https://example.com/webhooks"},{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":true,"request_body":"example request_body 1509","request_headers":{},"response_body":"example response_body 1719","response_body_truncated":false,"response_code":5561,"response_headers":{},"response_headers_content_truncated":false,"response_headers_count_truncated":true,"successful":true,"url":"https://example.com/webhooks"}]} }, "get": { - "body": {"webhooks":{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":true,"request_body":"example request_body 8662","request_headers":{},"response_body":"example response_body 5740","response_body_truncated":true,"response_code":6443,"response_headers":{},"response_headers_content_truncated":false,"response_headers_count_truncated":false,"successful":false,"url":"https://example.com/webhooks"}} + "body": {"webhooks":{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":false,"request_body":"example request_body 9284","request_headers":{},"response_body":"example response_body 421","response_body_truncated":false,"response_code":3173,"response_headers":{},"response_headers_content_truncated":true,"response_headers_count_truncated":false,"successful":true,"url":"https://example.com/webhooks"}} }, "retry": { - "body": {"webhooks":{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":true,"request_body":"example request_body 2390","request_headers":{},"response_body":"example response_body 1544","response_body_truncated":false,"response_code":2869,"response_headers":{},"response_headers_content_truncated":true,"response_headers_count_truncated":false,"successful":false,"url":"https://example.com/webhooks"}} + "body": {"webhooks":{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":false,"request_body":"example request_body 2869","request_headers":{},"response_body":"example response_body 8070","response_body_truncated":true,"response_code":6336,"response_headers":{},"response_headers_content_truncated":true,"response_headers_count_truncated":false,"successful":false,"url":"https://example.com/webhooks"}} } } \ No newline at end of file diff --git a/testing.go b/testing.go index cf59ade..9dae1ea 100644 --- a/testing.go +++ b/testing.go @@ -38,9 +38,12 @@ func runServer(t *testing.T, fixtureFile string, method string) *httptest.Server } func getClient(t *testing.T, url string) (*Service, error) { - opts := WithEndpoint(url) token := "dummy_token" - service, err := New(token, opts) + config, err := NewConfig(token, WithEndpoint(url)) + if err != nil { + t.Fatal(err) + } + service, err := New(config) if err != nil { t.Fatal(err) } diff --git a/useragent.go b/useragent.go index 8dd218e..3690005 100644 --- a/useragent.go +++ b/useragent.go @@ -7,7 +7,7 @@ import ( const ( // client library version - clientLibVersion = "1.0.0" + clientLibVersion = "2.0.0" ) var userAgent string diff --git a/webhook_service.go b/webhook_service.go index 17e570b..934f4b1 100644 --- a/webhook_service.go +++ b/webhook_service.go @@ -19,10 +19,8 @@ var _ = json.NewDecoder var _ = errors.New // WebhookService manages webhooks -type WebhookService struct { - endpoint string - token string - client *http.Client +type WebhookServiceImpl struct { + config Config } // Webhook model @@ -42,38 +40,50 @@ type Webhook struct { Url string `url:"url,omitempty" json:"url,omitempty"` } +type WebhookService interface { + List(ctx context.Context, p WebhookListParams, opts ...RequestOption) (*WebhookListResult, error) + All(ctx context.Context, p WebhookListParams, opts ...RequestOption) *WebhookListPagingIterator + Get(ctx context.Context, identity string, opts ...RequestOption) (*Webhook, error) + Retry(ctx context.Context, identity string, opts ...RequestOption) (*Webhook, error) +} + +type WebhookListParamsCreatedAt struct { + Gt string `url:"gt,omitempty" json:"gt,omitempty"` + Gte string `url:"gte,omitempty" json:"gte,omitempty"` + Lt string `url:"lt,omitempty" json:"lt,omitempty"` + Lte string `url:"lte,omitempty" json:"lte,omitempty"` +} + // WebhookListParams parameters type WebhookListParams struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - CreatedAt struct { - Gt string `url:"gt,omitempty" json:"gt,omitempty"` - Gte string `url:"gte,omitempty" json:"gte,omitempty"` - Lt string `url:"lt,omitempty" json:"lt,omitempty"` - Lte string `url:"lte,omitempty" json:"lte,omitempty"` - } `url:"created_at,omitempty" json:"created_at,omitempty"` - IsTest bool `url:"is_test,omitempty" json:"is_test,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - Successful bool `url:"successful,omitempty" json:"successful,omitempty"` + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` + CreatedAt *WebhookListParamsCreatedAt `url:"created_at,omitempty" json:"created_at,omitempty"` + IsTest bool `url:"is_test,omitempty" json:"is_test,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` + Successful bool `url:"successful,omitempty" json:"successful,omitempty"` +} + +type WebhookListResultMetaCursors struct { + After string `url:"after,omitempty" json:"after,omitempty"` + Before string `url:"before,omitempty" json:"before,omitempty"` +} + +type WebhookListResultMeta struct { + Cursors *WebhookListResultMetaCursors `url:"cursors,omitempty" json:"cursors,omitempty"` + Limit int `url:"limit,omitempty" json:"limit,omitempty"` } -// WebhookListResult response including pagination metadata type WebhookListResult struct { - Webhooks []Webhook `json:"webhooks"` - Meta struct { - Cursors struct { - After string `url:"after,omitempty" json:"after,omitempty"` - Before string `url:"before,omitempty" json:"before,omitempty"` - } `url:"cursors,omitempty" json:"cursors,omitempty"` - Limit int `url:"limit,omitempty" json:"limit,omitempty"` - } `json:"meta"` + Webhooks []Webhook `json:"webhooks"` + Meta WebhookListResultMeta `url:"meta,omitempty" json:"meta,omitempty"` } // List // Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your // webhooks. -func (s *WebhookService) List(ctx context.Context, p WebhookListParams, opts ...RequestOption) (*WebhookListResult, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/webhooks")) +func (s *WebhookServiceImpl) List(ctx context.Context, p WebhookListParams, opts ...RequestOption) (*WebhookListResult, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/webhooks")) if err != nil { return nil, err } @@ -101,17 +111,17 @@ func (s *WebhookService) List(ctx context.Context, p WebhookListParams, opts ... return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -159,7 +169,7 @@ type WebhookListPagingIterator struct { cursor string response *WebhookListResult params WebhookListParams - service *WebhookService + service *WebhookServiceImpl requestOptions []RequestOption } @@ -180,7 +190,7 @@ func (c *WebhookListPagingIterator) Value(ctx context.Context) (*WebhookListResu p := c.params p.After = c.cursor - uri, err := url.Parse(fmt.Sprintf(s.endpoint + "/webhooks")) + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint() + "/webhooks")) if err != nil { return nil, err @@ -210,16 +220,16 @@ func (c *WebhookListPagingIterator) Value(ctx context.Context) (*WebhookListResu } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -266,7 +276,7 @@ func (c *WebhookListPagingIterator) Value(ctx context.Context) (*WebhookListResu return c.response, nil } -func (s *WebhookService) All(ctx context.Context, +func (s *WebhookServiceImpl) All(ctx context.Context, p WebhookListParams, opts ...RequestOption) *WebhookListPagingIterator { return &WebhookListPagingIterator{ @@ -278,8 +288,8 @@ func (s *WebhookService) All(ctx context.Context, // Get // Retrieves the details of an existing webhook. -func (s *WebhookService) Get(ctx context.Context, identity string, opts ...RequestOption) (*Webhook, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/webhooks/%v", +func (s *WebhookServiceImpl) Get(ctx context.Context, identity string, opts ...RequestOption) (*Webhook, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/webhooks/%v", identity)) if err != nil { return nil, err @@ -302,17 +312,17 @@ func (s *WebhookService) Get(ctx context.Context, identity string, opts ...Reque return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) for key, value := range o.headers { req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient } @@ -358,8 +368,8 @@ func (s *WebhookService) Get(ctx context.Context, identity string, opts ...Reque // Retry // Requests for a previous webhook to be sent again -func (s *WebhookService) Retry(ctx context.Context, identity string, opts ...RequestOption) (*Webhook, error) { - uri, err := url.Parse(fmt.Sprintf(s.endpoint+"/webhooks/%v/actions/retry", +func (s *WebhookServiceImpl) Retry(ctx context.Context, identity string, opts ...RequestOption) (*Webhook, error) { + uri, err := url.Parse(fmt.Sprintf(s.config.Endpoint()+"/webhooks/%v/actions/retry", identity)) if err != nil { return nil, err @@ -385,10 +395,10 @@ func (s *WebhookService) Retry(ctx context.Context, identity string, opts ...Req return nil, err } req.WithContext(ctx) - req.Header.Set("Authorization", "Bearer "+s.token) + 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", "1.0.0") + req.Header.Set("GoCardless-Client-Version", "2.0.0") req.Header.Set("User-Agent", userAgent) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", o.idempotencyKey) @@ -397,7 +407,7 @@ func (s *WebhookService) Retry(ctx context.Context, identity string, opts ...Req req.Header.Set(key, value) } - client := s.client + client := s.config.Client() if client == nil { client = http.DefaultClient }