Categorygithub.com/hyperworks/stripe-go
modulepackage
4.4.3+incompatible
Repository: https://github.com/hyperworks/stripe-go.git
Documentation: pkg.go.dev

# README

Go Stripe GoDoc Build Status

Summary

The official Stripe Go client library.

Versioning

Each revision of the binding is tagged and the version is updated accordingly.

Given Go's lack of built-in versioning, it is highly recommended you use a package management tool in order to ensure a newer version of the binding does not affect backwards compatibility.

To see the list of past versions, run git tag. To manually get an older version of the client, clone this repo, checkout the specific tag and build the library:

git clone https://github.com/stripe/stripe-go.git
cd stripe
git checkout api_version_tag
make build

For more details on changes between versions, see the binding changelog and API changelog.

Installation

go get github.com/stripe/stripe-go

Documentation

For a comprehensive list of examples, check out the API documentation.

For details on all the functionality in this library, see the GoDoc documentation.

Below are a few simple examples:

Customers

params := &stripe.CustomerParams{
		Balance: -123,
		Card: &stripe.CardParams{
			Name:   "Go Stripe",
			Number: "378282246310005",
			Month:  "06",
			Year:   "15",
		},
		Desc:  "Stripe Developer",
		Email: "[email protected]",
	}

customer, err := customer.New(params)

Charges

params := &stripe.ChargeListParams{Customer: customer.Id}
params.Filters.AddFilter("include[]", "", "total_count")

// set this so you can easily retry your request in case of a timeout
params.Params.IdempotencyKey = stripe.NewIdempotencyKey()

i := charge.List(params)
for i.Next() {
  charge := i.Charge()
}

if err := i.Err(); err != nil {
  // handle
}

Events

i := event.List(nil)
for i.Next() {
  e := i.Event()

  // access event data via e.GetObjValue("resource_name_based_on_type", "resource_property_name")
  // alternatively you can access values via e.Data.Obj["resource_name_based_on_type"].(map[string]interface{})["resource_property_name"]

  // access previous attributes via e.GetPrevValue("resource_name_based_on_type", "resource_property_name")
  // alternatively you can access values via e.Data.Prev["resource_name_based_on_type"].(map[string]interface{})["resource_property_name"]
}

Alternatively, you can use the even.Data.Raw property to unmarshal to the appropriate struct.

Connect Flows

If you're using an access token you will need to use a client. Simply pass the access token value as the tok when initializing the client.


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

stripe := &client.API{}
stripe.Init("access_token", nil)

Google AppEngine

If you're running the client in a Google AppEngine environment, you can override the HTTP client used internally since the http.DefaultClient is not available:

stripe.SetHTTPClient(urlfetch.Client(appengine.NewContext(req)))

Usage

While some resources may contain more/less APIs, the following pattern is applied throughout the library for a given $resource$:

Without a Client

If you're only dealing with a single key, you can simply import the packages required for the resources you're interacting with without the need to create a client.

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

// Setup
stripe.Key = "sk_key"

stripe.SetBackend("api", backend) // optional, useful for mocking

// Create
$resource$, err := $resource$.New(stripe.$Resource$Params)

// Get
$resource$, err := $resource$.Get(id, stripe.$Resource$Params)

// Update
$resource$, err := $resource$.Update(stripe.$Resource$Params)

// Delete
err := $resource$.Del(id)

// List
i := $resource$.List(stripe.$Resource$ListParams)
for i.Next() {
  $resource$ := i.$Resource$()
}

if err := i.Err(); err != nil {
  // handle
}


With a Client

If you're dealing with multiple keys, it is recommended you use the client.API. This allows you to create as many clients as needed, each with their own individual key.

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

// Setup
sc := &client.API{}
sc.Init("sk_key", nil) // the second parameter overrides the backends used if needed for mocking

// Create
$resource$, err := sc.$Resource$s.New(stripe.$Resource$Params)

// Get
$resource$, err := sc.$Resource$s.Get(id, stripe.$Resource$Params)

// Update
$resource$, err := sc.$Resource$s.Update(stripe.$Resource$Params)

// Delete
err := sc.$Resource$s.Del(id)

// List
i := sc.$Resource$s.List(stripe.$Resource$ListParams)
for i.Next() {
  resource := i.$Resource$()
}

if err := i.Err(); err != nil {
  // handle
}

Development

Pull requests from the community are welcome. If you submit one, please keep the following guidelines in mind:

  1. Code must be go fmt compliant.
  2. All types, structs and funcs should be documented.
  3. Ensure that make test succeeds.

Test

For running additional tests, follow the steps below:

Set the STRIPE_KEY environment variable to match your test private key, then run make test:

STRIPE_KEY=YOUR_API_KEY make test

For any requests, bug or comments, please open an issue or submit a pull request.

# Packages

Package account provides the /account APIs.
Package balance provides the /balance APIs.
Package bitcoinreceiver provides the /bitcoin/receivers APIs.
Package bitcointransaction provides the /bitcoin/transactions APIs.
Package card provides the /cards APIs.
Package charge provides the /charges APIs.
Package client provides a Stripe client for invoking APIs across all resources.
Package coupon provides the /coupons APIs.
Package currency provides the list of currency codes.
Package customer provides the /customes APIs.
Package discount provides the discount-related APIs.
Package dispute provides the dispute-related APIs.
Package event provides the /events APIs.
Package fee provides the /application_fees APIs.
Package feerefund provides the /application_fees/refunds APIs.
Package fileupload provides the file upload related APIs.
Package invoice provides the /invoices APIs.
Package invoiceitem provides the /invoiceitems APIs.
Package plan provides the /plans APIs.
Package recipient provides the /recipients APIs.
Package refund provides the /refunds APIs.
Package sub provides the /subscriptions APIs.
Package token provides the /tokens APIs.
Package transfer provides the /transfers APIs.
Package utils provides internal utilities.

# Functions

GetBackend returns the currently used backend in the binding.
GetIter returns a new Iter for a given query and its options.
NewIdempotencyKey generates a new idempotency key that can be used on a request.
SetBackend sets the backend used in the binding.
SetHTTPClient overrides the default HTTP client.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Totalbackends is the total number of Stripe API endpoints supported by the binding.
No description provided by the author

# Variables

Key is the Stripe API key used globally in the binding.
LogLevel is the logging level for this library.

# Structs

Account is the resource representing youe Stripe account.
Amount is a structure wrapping an amount value and its currency.
BackendConfiguration is the internal implementation for making HTTP calls to Stripe.
Backends are the currently supported endpoints.
Balance is the resource representing your Stripe balance.
BalanceParams is the set of parameters that can be used when retrieving a balance.
BankAccount represents a Stripe bank account.
BankAccountParams is the set of parameters that can be used when creating or updating a bank account.
BitcoinReceiver is the resource representing a Stripe bitcoin receiver.
BitcoinReceiverListParams is the set of parameters that can be used when listing BitcoinReceivers.
BitcoinReceiverParams is the set of parameters that can be used when creating a BitcoinReceiver.
BitcoinTransaction is the resource representing a Stripe bitcoin transaction.
BitcoinTransactionList is a list object for BitcoinTransactions.
BitcoinTransactionListParams is the set of parameters that can be used when listing BitcoinTransactions.
CaptureParams is the set of parameters that can be used when capturing a charge.
Card is the resource representing a Stripe credit/debit card.
CardList is a list object for cards.
CardListParams is the set of parameters that can be used when listing cards.
CardParams is the set of parameters that can be used when creating or updating a card.
Charge is the resource representing a Stripe charge.
ChargeListParams is the set of parameters that can be used when listing charges.
ChargeParams is the set of parameters that can be used when creating or updating a charge.
Coupon is the resource representing a Stripe coupon.
CouponListParams is the set of parameters that can be used when listing coupons.
CouponParams is the set of parameters that can be used when creating a coupon.
Customer is the resource representing a Stripe customer.
CustomerListParams is the set of parameters that can be used when listing customers.
CustomerParams is the set of parameters that can be used when creating or updating a customer.
Discount is the resource representing a Stripe discount.
Dispute is the resource representing a Stripe dispute.
DisputeEvidence is the structure that contains various details about the evidence submitted for the dispute.
DisputeEvidenceParams is the set of parameters that can be used when submitting evidence for disputes.
DisputeParams is the set of parameters that can be used when updating a dispute.
Error is the response returned when a call is unsuccessful.
Event is the resource representing a Stripe event.
EventData is the unmarshalled object as a map.
EventListParams is the set of parameters that can be used when listing events.
EvidenceDetails is the structure representing more details about the dispute.
Fee is the resource representing a Stripe application fee.
FeeListParams is the set of parameters that can be used when listing application fees.
FeeParams is the set of parameters that can be used when refunding an application fee.
FeeRefund is the resource representing a Stripe fee refund.
FeeRefundList is a list object for fee refunds.
FeeRefundListParams is the set of parameters that can be used when listing fee refunds.
FeeRefundParams is the set of parameters that can be used when refunding a fee.
File represents a link to downloadable content.
FileUpload is the resource representing a Stripe file upload.
FileUploadListParams is the set of parameters that can be used when listing file uploads.
FileUploadParams is the set of parameters that can be used when creating a file upload.
Filters is a structure that contains a collection of filters for list-related APIs.
FraudDetails is the structure detailing fraud status.
Invoice is the resource representing a Stripe invoice.
InvoiceItem is the resource represneting a Stripe invoice item.
InvoiceItemListParams is the set of parameters that can be used when listing invoice items.
InvoiceItemParams is the set of parameters that can be used when creating or updating an invoice item.
InvoiceLine is the resource representing a Stripe invoice line item.
InvoiceLineList is a list object for invoice line items.
InvoiceLineListParams is the set of parameters that can be used when listing invoice line items.
InvoiceListParams is the set of parameters that can be used when listing invoices.
InvoiceParams is the set of parameters that can be used when creating or updating an invoice.
Iter provides a convenient interface for iterating over the elements returned from paginated list API calls.
ListMeta is the structure that contains the common properties of List iterators.
ListParams is the structure that contains the common properties of any *ListParams structure.
Params is the structure that contains the common properties of any *Params structure.
PaymentSource describes the payment source used to make a Charge.
Period is a structure representing a start and end dates.
Plan is the resource representing a Stripe plan.
PlanListParams is the set of parameters that can be used when listing plans.
PlanParams is the set of parameters that can be used when creating or updating a plan.
Recipient is the resource representing a Stripe recipient.
RecipientListParams is the set of parameters that can be used when listing recipients.
RecipientParams is the set of parameters that can be used when creating or updating recipients.
Refund is the resource representing a Stripe refund.
RefundList is a list object for refunds.
RefundListParams is the set of parameters that can be used when listing refunds.
RefundParams is the set of parameters that can be used when refunding a charge.
SourceParams is the set of parameters that can be used to describe the source object used to make a Charge.
Sub is the resource representing a Stripe subscription.
SubList is a list object for subscriptions.
SubListParams is the set of parameters that can be used when listing active subscriptions.
SubParams is the set of parameters that can be used when creating or updating a subscription.
Token is the resource representing a Stripe token.
TokenParams is the set of parameters that can be used when creating a token.
Transaction is the resource representing the balance transaction.
Transfer is the resource representing a Stripe transfer.
TransferListParams is the set of parameters that can be used when listing transfers.
TransferParams is the set of parameters that can be used when creating or updating a transfer.
TxFee is a structure that breaks down the fees in a transaction.
TxListParams is the set of parameters that can be used when listing balance transactions.
TxParams is the set of parameters that can be used when retrieving a transaction.

# Interfaces

Backend is an interface for making calls against a Stripe service.
Displayer provides a human readable representation of a struct.

# Type aliases

BankAccountStatus is the list of allowed values for the bank account's status.
CardBrand is the list of allowed values for the card's brand.
CardFunding is the list of allowed values for the card's funding.
CouponDuration is the list of allowed values for the coupon's duration.
Currency is the list of supported currencies.
DisputeReason is the list of allowed values for a discount's reason.
DisputeStatus is the list of allowed values for a discount's status.
ErrorCode is the list of allowed values for the error's code.
ErrorType is the list of allowed values for the error's type.
FileUploadPurpose is the purpose of a particular file upload.
FraudReport is the list of allowed values for reporting fraud.
InvoiceLineType is the list of allowed values for the invoice line's type.
PaymentSourceType consts represent valid payment sources.
PlanInterval is the list of allowed values for a plan's interval.
Query is the function used to get a page listing.
RecipientType is the list of allowed values for the recipient's type.
RefundReason, if set, is the reason the refund is being made--allowed values are "fraudulent", "duplicate", and "requested_by_customer".
SubStatus is the list of allowed values for the subscription's status.
SupportedBackend is an enumeration of supported Stripe endpoints.
TokenType is the list of allowed values for a token's type.
TransactionStatus is the list of allowed values for the transaction's status.
TransactionType is the list of allowed values for the transaction's type.
TransferFailCode is the list of allowed values for the transfer's failure code.
TransferStatus is the list of allowed values for the transfer's status.
TransferType is the list of allowed values for the transfer's type.
Verification is the list of allowed verification responses.