Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stripe-go v71 #1055

Merged
merged 11 commits into from
Apr 17, 2020
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cache:
env:
global:
# If changing this number, please also change it in `testing/testing.go`.
- STRIPE_MOCK_VERSION=0.86.0
- STRIPE_MOCK_VERSION=0.87.0

go:
- "1.9.x"
Expand Down
78 changes: 24 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,8 @@ Then, import it using:

``` go
import (
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/customer"
)
```

### Go Module Support

The library currently *does not* ship with first-class support for Go
modules. We put in support for it before, but ran into compatibility problems
for existing installations using Dep (see discussion in [closer to the bottom
of this thread][gomodvsdep]), and [reverted support][gomodrevert]. Our current
plan is to wait for better module compatibility in Dep (see a [preliminary
patch here][depgomodsupport]), give the release a little grace time to become
more widely distributed, then bring support back.

For now, require stripe-go in `go.mod` with a version but without a *version
suffix* in the path like so:

``` go
module github.com/my/package

require (
github.com/stripe/stripe-go v70.15.0
)
```

And use the same style of import paths as above:

``` go
import (
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/customer"
"github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/customer"
)
```

Expand Down Expand Up @@ -139,8 +109,8 @@ To use a key, pass it to `API`'s `Init` function:
```go

import (
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/client"
"github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/client"
)

stripe := &client.API{}
Expand All @@ -161,8 +131,8 @@ import (
"google.golang.org/appengine"
"google.golang.org/appengine/urlfetch"

"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/client"
"github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/client"
)

func handler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -196,8 +166,8 @@ client.

```go
import (
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/$resource$"
"github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/$resource$"
)

// Setup
Expand Down Expand Up @@ -236,8 +206,8 @@ individual key.

```go
import (
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/client"
"github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/client"
)

// Setup
Expand Down Expand Up @@ -267,19 +237,24 @@ if err := i.Err(); err != nil {
}
```

### Configuring Automatic Retries
### Automatic Retries

The library automatically retries requests on intermittent failures like on a
connection error, timeout, or on certain API responses like a status `409
Conflict`. [Idempotency keys][idempotency-keys] are always added to requests to
make any such subsequent retries safe.

You can enable automatic retries on requests that fail due to a transient
problem by configuring the maximum number of retries:
By default, it will perform up to two retries. That number can be configured
with `MaxNetworkRetries`:

```go
import (
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/client"
"github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/client"
)

config := &stripe.BackendConfig{
MaxNetworkRetries: 2,
MaxNetworkRetries: stripe.Int64(0), // Zero retries
}

sc := &client.API{}
Expand All @@ -291,15 +266,10 @@ sc.Init("sk_key", &stripe.Backends{
coupon, err := sc.Coupons.New(...)
```

Various errors can trigger a retry, like a connection error or a timeout, and
also certain API responses like HTTP status `409 Conflict`.

[Idempotency keys][idempotency-keys] are added to requests to guarantee that
retries are safe.

### Configuring Logging

Configure logging using the global `DefaultLeveledLogger` variable:
By default, the library logs error messages only (which are sent to `stderr`).
Configure default logging using the global `DefaultLeveledLogger` variable:

```go
stripe.DefaultLeveledLogger = &stripe.LeveledLogger{
Expand Down Expand Up @@ -360,7 +330,7 @@ You can disable this behavior if you prefer:

```go
config := &stripe.BackendConfig{
EnableTelemetry: false,
EnableTelemetry: stripe.Bool(false),
}
```

Expand Down
5 changes: 4 additions & 1 deletion account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package stripe
import (
"encoding/json"

"github.com/stripe/stripe-go/form"
"github.com/stripe/stripe-go/v70/form"
)

// AccountType is the type of an account.
Expand Down Expand Up @@ -461,6 +461,7 @@ type AccountTOSAcceptance struct {
// Account is the resource representing your Stripe account.
// For more details see https://stripe.com/docs/api/#account.
type Account struct {
APIResource
BusinessProfile *AccountBusinessProfile `json:"business_profile"`
BusinessType AccountBusinessType `json:"business_type"`
Capabilities *AccountCapabilities `json:"capabilities"`
Expand Down Expand Up @@ -505,13 +506,15 @@ func (a *Account) UnmarshalJSON(data []byte) error {

// AccountList is a list of accounts as returned from a list endpoint.
type AccountList struct {
APIResource
ListMeta
Data []*Account `json:"data"`
}

// ExternalAccountList is a list of external accounts that may be either bank
// accounts or cards.
type ExternalAccountList struct {
APIResource
ListMeta

// Values contains any external accounts (bank accounts and/or cards)
Expand Down
4 changes: 2 additions & 2 deletions account/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package account
import (
"net/http"

stripe "github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/form"
stripe "github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/form"
)

// Client is used to invoke APIs related to accounts.
Expand Down
4 changes: 2 additions & 2 deletions account/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

assert "github.com/stretchr/testify/require"
stripe "github.com/stripe/stripe-go"
_ "github.com/stripe/stripe-go/testing"
stripe "github.com/stripe/stripe-go/v70"
_ "github.com/stripe/stripe-go/v70/testing"
)

func TestAccountDel(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

assert "github.com/stretchr/testify/require"
"github.com/stripe/stripe-go/form"
"github.com/stripe/stripe-go/v70/form"
)

func TestAccountExternalAccountParams_AppendTo(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions accountlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type AccountLinkParams struct {
// AccountLink is the resource representing an account link.
// For more details see https://stripe.com/docs/api/#account_links.
type AccountLink struct {
APIResource
Created int64 `json:"created"`
ExpiresAt int64 `json:"expires_at"`
Object string `json:"object"`
Expand Down
2 changes: 1 addition & 1 deletion accountlink/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package accountlink
import (
"net/http"

stripe "github.com/stripe/stripe-go"
stripe "github.com/stripe/stripe-go/v70"
)

// Client is used to invoke APIs related to account links.
Expand Down
4 changes: 2 additions & 2 deletions accountlink/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

assert "github.com/stretchr/testify/require"
stripe "github.com/stripe/stripe-go"
_ "github.com/stripe/stripe-go/testing"
stripe "github.com/stripe/stripe-go/v70"
_ "github.com/stripe/stripe-go/v70/testing"
)

func TestAccountLinkNew(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions applepaydomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type ApplePayDomainParams struct {

// ApplePayDomain is the resource representing a Stripe ApplePayDomain object
type ApplePayDomain struct {
APIResource
Created int64 `json:"created"`
Deleted bool `json:"deleted"`
DomainName string `json:"domain_name"`
Expand All @@ -22,6 +23,7 @@ type ApplePayDomainListParams struct {

// ApplePayDomainList is a list of ApplePayDomains as returned from a list endpoint.
type ApplePayDomainList struct {
APIResource
ListMeta
Data []*ApplePayDomain `json:"data"`
}
4 changes: 2 additions & 2 deletions applepaydomain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package applepaydomain
import (
"net/http"

stripe "github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/form"
stripe "github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/form"
)

// Client is used to invoke /apple_pay/domains and Apple Pay domain-related APIs.
Expand Down
4 changes: 2 additions & 2 deletions applepaydomain/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

assert "github.com/stretchr/testify/require"
stripe "github.com/stripe/stripe-go"
_ "github.com/stripe/stripe-go/testing"
stripe "github.com/stripe/stripe-go/v70"
_ "github.com/stripe/stripe-go/v70/testing"
)

func TestApplePayDomainDel(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type BalanceParams struct {
// Balance is the resource representing your Stripe balance.
// For more details see https://stripe.com/docs/api/#balance.
type Balance struct {
APIResource
Available []*Amount `json:"available"`
ConnectReserved []*Amount `json:"connect_reserved"`
Livemode bool `json:"livemode"`
Expand Down
2 changes: 1 addition & 1 deletion balance/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package balance
import (
"net/http"

stripe "github.com/stripe/stripe-go"
stripe "github.com/stripe/stripe-go/v70"
)

// Client is used to invoke /balance and transaction-related APIs.
Expand Down
2 changes: 1 addition & 1 deletion balance/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

assert "github.com/stretchr/testify/require"
_ "github.com/stripe/stripe-go/testing"
_ "github.com/stripe/stripe-go/v70/testing"
)

func TestBalanceGet(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions balancetransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ type BalanceTransactionListParams struct {
// BalanceTransaction is the resource representing the balance transaction.
// For more details see https://stripe.com/docs/api/#balance.
type BalanceTransaction struct {
APIResource
Amount int64 `json:"amount"`
AvailableOn int64 `json:"available_on"`
Created int64 `json:"created"`
Expand All @@ -145,6 +146,7 @@ type BalanceTransaction struct {

// BalanceTransactionList is a list of transactions as returned from a list endpoint.
type BalanceTransactionList struct {
APIResource
ListMeta
Data []*BalanceTransaction `json:"data"`
}
Expand Down
4 changes: 2 additions & 2 deletions balancetransaction/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package balancetransaction
import (
"net/http"

stripe "github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/form"
stripe "github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/form"
)

// Client is used to invoke /balance_transactions APIs.
Expand Down
4 changes: 2 additions & 2 deletions balancetransaction/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

assert "github.com/stretchr/testify/require"
stripe "github.com/stripe/stripe-go"
_ "github.com/stripe/stripe-go/testing"
stripe "github.com/stripe/stripe-go/v70"
_ "github.com/stripe/stripe-go/v70/testing"
)

func TestBalanceTransactionGet(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion bankaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"strconv"

"github.com/stripe/stripe-go/form"
"github.com/stripe/stripe-go/v70/form"
)

// BankAccountStatus is the list of allowed values for the bank account's status.
Expand Down Expand Up @@ -141,6 +141,7 @@ func (p *BankAccountListParams) AppendTo(body *form.Values, keyParts []string) {

// BankAccount represents a Stripe bank account.
type BankAccount struct {
APIResource
Account *Account `json:"account"`
AccountHolderName string `json:"account_holder_name"`
AccountHolderType BankAccountAccountHolderType `json:"account_holder_type"`
Expand All @@ -160,6 +161,7 @@ type BankAccount struct {

// BankAccountList is a list object for bank accounts.
type BankAccountList struct {
APIResource
ListMeta
Data []*BankAccount `json:"data"`
}
Expand Down
4 changes: 2 additions & 2 deletions bankaccount/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"errors"
"net/http"

stripe "github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/form"
stripe "github.com/stripe/stripe-go/v70"
"github.com/stripe/stripe-go/v70/form"
)

// Client is used to invoke /bank_accounts APIs.
Expand Down
4 changes: 2 additions & 2 deletions bankaccount/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

assert "github.com/stretchr/testify/require"
stripe "github.com/stripe/stripe-go"
_ "github.com/stripe/stripe-go/testing"
stripe "github.com/stripe/stripe-go/v70"
_ "github.com/stripe/stripe-go/v70/testing"
)

func TestBankAccountDel_ByAccount(t *testing.T) {
Expand Down
Loading