-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Changes generated by 90afb7b0bfe8400aa172a0c41d12cc89cab3a0cb * Changes generated by d03f550064463c26c11345d6f913b82145c463e0 * Changes generated by 761a5f396ff8e06739254ec3d5994647745a2fa5 * Changes generated by 3f7e469a9ed21afa7425ef1f6ce0682c66f9ee84 * Changes generated by 9673ff362be6a2c82b88a34e52b61b6d0603c461 * Changes generated by 89d28f103fc65da5c9f4677e2b85b06c9c07b799 * Changes generated by 73fa74b77ef5f5b5e400b81a3563af6e74c2ac85 * Changes generated by 61d47cd4272cbfc368540ec736da14486b76b71c * Changes generated by 1ed5a6598f0c9a12807f982f379311f20ff11ef8 * Changes generated by 3331ffcbdfa84b6ac199045b0fb50f60c3641426 * Changes generated by d2ff61a58e5ba09526bcb19a0664e0d1442e91b3 * Changes generated by 976187b15a5e307bbe6d7c588f36530a45139186 * Changes generated by 79077ca0952a7a942c9316d617e923b73ddd1aa1 * Changes generated by 750627fba2f3ef092a26bd8227b6f4fa2f6bba96 * Changes generated by c59277736a2d0e40ac0f9d8a42e1b9463a39edef * Changes generated by 6d1a66b2decd2844457e4f635aa396041d4415dd * Changes generated by 96427efe0958d47a42deeed61d74dd839ff3b801 * Changes generated by 86653b3d64a2ebc708cad205f692c4ef4f6ff502 * Changes generated by 957c7b6a278d7bbc180d245e31cc075042869e54 * Changes generated by e5377575d33701f1530977ced9f07b992bece019 * Changes generated by b0985abebd47ede4bc75cec926b0c9cc5b5a7384 * Changes generated by 813e6acfab0094225dd4820af515683eed3bacb3 * Changes generated by 7f472b1ae11ec581267eca9b6564d29c2cd670fe * Changes generated by e4a1f03495fe9b2018c66096ede365a866b439ff * Changes generated by 5a05b83be196c2f03480373c45c6ec522bc55511 * Changes generated by 42926f644eb35ecfccc50067b295ee652e5eaf4d * Changes generated by 5a05b83be196c2f03480373c45c6ec522bc55511 Co-authored-by: Robot <[email protected]>
- Loading branch information
1 parent
8dc9253
commit 1ef31e7
Showing
63 changed files
with
2,647 additions
and
2,190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,23 +38,48 @@ 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; | ||
```go | ||
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 = "[email protected]" | ||
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: "[email protected]", | ||
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,15 +190,15 @@ 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 | ||
example, an `Idempotency-Key` header with a randomly-generated value or one you've configured | ||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.0 | ||
2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.