stripe

package module
v0.0.0-...-832208e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2014 License: MIT Imports: 10 Imported by: 3

README

go.stripe

a simple Credit Card processing library for Go using the Stripe API

go get github.com/drone/go.stripe

Examples

In order to use the go.stripe API you will need to create an account with stripe.com, and obtain an Secret Key. You must set this key by invoking the following function:

stripe.SetKey("vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE")

Or you can specify your Secret Key in environment variable STRIPE_API_KEY, and then invoke the following function:

stripe.SetKeyEnv()
Create Customer
params := stripe.CustomerParams{
	Email:  "george.costanza@mail.com",
	Desc:   "short, bald",
	Card:   &stripe.CardParams {
		Name     : "George Costanza",
		Number   : "4242424242424242",
		ExpYear  : 2012,
		ExpMonth : 5,
		CVC      : "26726",
	},
}

customer, err := stripe.Customers.Create(&params)
Charge Card
params := stripe.ChargeParams{
	Desc:     "Calzone",
	Amount:   400,
	Currency: "usd",
	Card:     &stripe.CardParams {
		Name     : "George Costanza",
		Number   : "4242424242424242",
		ExpYear  : 2012,
		ExpMonth : 5,
		CVC      : "26726",
	},
}

charge, err := stripe.Charges.Create(&params)

Note: the amount charged is $4.00, but is specified in cents (400 cents == $4)

Documentation

You can also have a look at the Godocs.

Unit Tests

In order to run the unit tests, you must have a Stripe account and a Test Secret Key. The Test Secret Key must be set in environment variable STRIPE_API_KEY:

export STRIPE_API_KEY="vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE"
go test -v

The unit tests attempt to cleanup after themselves whenever possible. You can manually clear all test data from the Stripe console by navigating to: Your Account » Account Settings » Test Data. Then click the "Remove All Test Data" button.

Documentation

Index

Constants

View Source
const (
	AmericanExpress = "American Express"
	DinersClub      = "Diners Club"
	Discover        = "Discover"
	JCB             = "JCB"
	MasterCard      = "MasterCard"
	Visa            = "Visa"
	UnknownCard     = "Unknown"
)

Credit Card Types accepted by the Stripe API.

View Source
const (
	USD = "usd" // US Dollar ($)
	EUR = "eur" // Euro (€)
	GBP = "gbp" // British Pound Sterling (UK£)
	JPY = "jpy" // Japanese Yen (¥)
	CAD = "cad" // Canadian Dollar (CA$)
	HKD = "hkd" // Hong Kong Dollar (HK$)
	CNY = "cny" // Chinese Yuan (CN¥)
	AUD = "aud" // Australian Dollar (A$)
)

ISO 3-digit Currency Codes for major currencies (not the full list).

View Source
const (
	DurationForever   = "forever"
	DurationOnce      = "once"
	DurationRepeating = "repeating"
)

Coupon Durations

View Source
const (
	ErrTypeInvalidRequest = "invalid_request_error"
	ErrTypeAPI            = "api_error"
	ErrTypeCard           = "card_error"

	ErrCodeIncorrectNumber    = "incorrect_number"
	ErrCodeInvalidNumber      = "invalid_number"
	ErrCodeInvalidExpiryMonth = "invalid_expiry_month"
	ErrCodeInvalidExpiryYear  = "invalid_expiry_year"
	ErrCodeInvalidCVC         = "invalid_cvc"
	ErrCodeExpiredCard        = "expired_card"
	ErrCodeIncorrectCVC       = "incorrect_cvc"
	ErrCodeIncorrectZIP       = "incorrect_zip"
	ErrCodeCardDeclined       = "card_declined"
	ErrCodeMissing            = "missing"
	ErrCodeProcessingError    = "processing_error"
)

Stripe-provided error codes and types See https://stripe.com/docs/api#errors

View Source
const (
	IntervalMonth = "month"
	IntervalYear  = "year"
)

Plan Intervals

View Source
const (
	SubscriptionTrialing = "trialing"
	SubscriptionActive   = "active"
	SubscriptionPastDue  = "past_due"
	SubscriptionCanceled = "canceled"
	SubscriptionUnpaid   = "unpaid"
)

Subscription Statuses

Variables

View Source
var (
	Charges       = new(ChargeClient)
	Coupons       = new(CouponClient)
	Customers     = new(CustomerClient)
	Invoices      = new(InvoiceClient)
	InvoiceItems  = new(InvoiceItemClient)
	Plans         = new(PlanClient)
	Subscriptions = new(SubscriptionClient)
	Tokens        = new(TokenClient)
)

Available APIs

Functions

func GetCardType

func GetCardType(card string) string

GetCardType is a simple algorithm to determine the Card Type (ie Visa, Discover) based on the Credit Card Number. If the Number is not recognized, a value of "Unknown" will be returned.

func IsLuhnValid

func IsLuhnValid(card string) (bool, error)

IsLuhnValid uses the Luhn Algorithm (also known as the Mod 10 algorithm) to verify a credit cards checksum, which helps flag accidental data entry errors.

see http://en.wikipedia.org/wiki/Luhn_algorithm

func SetKey

func SetKey(key string)

SetKey will set the default Stripe API key used to authenticate all Stripe API requests.

func SetKeyEnv

func SetKeyEnv() (err error)

SetKeyEnv retrieves the Stripe API key using the STRIPE_API_KEY environment variable.

func SetUrl

func SetUrl(url string)

SetUrl will override the default Stripe API URL. This is primarily used for unit testing.

Types

type Bool

type Bool bool

Bool is a special type of bool that can unmarshall a JSON value of "null", which cannot be parsed by the Go JSON parser as of Go v1.

see http://code.google.com/p/go/issues/detail?id=2540

func (*Bool) UnmarshalJSON

func (self *Bool) UnmarshalJSON(data []byte) error

type Card

type Card struct {
	Id                string `json:"id"`
	Name              String `json:"name,omitempty"`
	Type              string `json:"type"`
	ExpMonth          int    `json:"exp_month"`
	ExpYear           int    `json:"exp_year"`
	Last4             string `json:"last4"`
	Fingerprint       string `json:"fingerprint"`
	Country           String `json:"country,omitempty"`
	Address1          String `json:"address_line1,omitempty"`
	Address2          String `json:"address_line2,omitempty"`
	AddressCountry    String `json:"address_country,omitempty"`
	AddressState      String `json:"address_state,omitempty"`
	AddressZip        String `json:"address_zip,omitempty"`
	AddressCity       String `json:"address_city"`
	AddressLine1Check String `json:"address_line1_check,omitempty"`
	AddressZipCheck   String `json:"address_zip_check,omitempty"`
	CVCCheck          String `json:"cvc_check,omitempty"`
}

Card represents details about a Credit Card entered into Stripe.

type CardClient

type CardClient struct{}

CardClient encapsulates operations for creating, updating, deleting and querying cards using the Stripe REST API.

func (*CardClient) Create

func (self *CardClient) Create(c *CardParams, customerId string) (*Card, error)

func (*CardClient) Delete

func (self *CardClient) Delete(cardId string, customerId string) (*DeleteResp, error)

type CardData

type CardData struct {
	Object string  `json:"object"`
	Count  int     `json:"count"`
	Url    string  `json:"url"`
	Data   []*Card `json:"data"`
}

type CardParams

type CardParams struct {
	// (Optional) Cardholder's full name.
	Name string

	// The card number, as a string without any separators.
	Number string

	// Two digit number representing the card's expiration month.
	ExpMonth int

	// Four digit number representing the card's expiration year.
	ExpYear int

	// Card security code
	CVC string

	// (Optional) Billing address line 1
	Address1 string

	// (Optional) Billing address line 2
	Address2 string

	// (Optional) Billing address country
	AddressCountry string

	// (Optional) Billing address state
	AddressState string

	// (Optional) Billing address zip code
	AddressZip string
}

CardParams encapsulates options for Creating or Updating Credit Cards.

type Charge

type Charge struct {
	Id                   string        `json:"id"`
	Desc                 String        `json:"description"`
	Amount               int64         `json:"amount"`
	Card                 *Card         `json:"card"`
	Currency             string        `json:"currency"`
	Created              int64         `json:"created"`
	Customer             String        `json:"customer"`
	Invoice              String        `json:"invoice"`
	Fee                  int64         `json:"fee"`
	Paid                 bool          `json:"paid"`
	Details              []*FeeDetails `json:"fee_details"`
	Refunded             bool          `json:"refunded"`
	AmountRefunded       Int64         `json:"amount_refunded"`
	FailureMessage       String        `json:"failure_message"`
	Disputed             bool          `json:"disputed"`
	Livemode             bool          `json:"livemode"`
	StatementDescription string        `json:"statement_description"`
}

Charge represents details about a credit card charge in Stripe.

see https://stripe.com/docs/api#charge_object

type ChargeClient

type ChargeClient struct{}

ChargeClient encapsulates operations for creating, updating, deleting and querying charges using the Stripe REST API.

func (*ChargeClient) Create

func (self *ChargeClient) Create(params *ChargeParams) (*Charge, error)

Creates a new credit card Charge.

see https://stripe.com/docs/api#create_charge

func (*ChargeClient) CustomerList

func (self *ChargeClient) CustomerList(id string) ([]*Charge, error)

Returns a list of your Charges with the given Customer ID.

see https://stripe.com/docs/api#list_charges

func (*ChargeClient) CustomerListN

func (self *ChargeClient) CustomerListN(id string, count int, offset int) ([]*Charge, error)

Returns a list of your Charges with the given Customer ID and range.

see https://stripe.com/docs/api#list_charges

func (*ChargeClient) List

func (self *ChargeClient) List() ([]*Charge, error)

Returns a list of your Charges.

see https://stripe.com/docs/api#list_charges

func (*ChargeClient) ListN

func (self *ChargeClient) ListN(count int, offset int) ([]*Charge, error)

Returns a list of your Charges with the specified range.

see https://stripe.com/docs/api#list_charges

func (*ChargeClient) Refund

func (self *ChargeClient) Refund(id string) (*Charge, error)

Refunds a charge for the full amount.

see https://stripe.com/docs/api#refund_charge

func (*ChargeClient) RefundAmount

func (self *ChargeClient) RefundAmount(id string, amt int64) (*Charge, error)

Refunds a charge for the specified amount.

see https://stripe.com/docs/api#refund_charge

func (*ChargeClient) Retrieve

func (self *ChargeClient) Retrieve(id string) (*Charge, error)

Retrieves the details of a charge with the given ID.

see https://stripe.com/docs/api#retrieve_charge

type ChargeParams

type ChargeParams struct {
	// A positive integer in cents representing how much to charge the card.
	// The minimum amount is 50 cents.
	Amount int64

	// 3-letter ISO code for currency. Refer to the Stripe docs for currently
	// supported currencies: https://support.stripe.com/questions/which-currencies-does-stripe-support
	Currency string

	// (Optional) Either customer or card is required, but not both The ID of an
	// existing customer that will be charged in this request.
	Customer string

	// (Optional) Credit Card that should be charged.
	Card *CardParams

	// (Optional) Credit Card token that should be charged.
	Token string

	// An arbitrary string which you can attach to a charge object. It is
	// displayed when in the web interface alongside the charge. It's often a
	// good idea to use an email address as a description for tracking later.
	Desc string

	// An arbitrary string to be displayed alongside your company name on your
	// customer's credit card statement. This may be up to 15 characters. As an
	// example, if your website is RunClub and you specify 5K Race Ticket, the
	// user will see:
	//     RUNCLUB 5K RACE TICKET.
	// The statement description may not include <>"' characters. While most
	// banks display this information consistently, some may display it
	// incorrectly or not at all.
	StatementDescription string
}

ChargeParams encapsulates options for creating a new Charge.

type Coupon

type Coupon struct {
	Id               string `json:"id"`
	Duration         string `json:"duration"`
	PercentOff       int    `json:"percent_off"`
	DurationInMonths Int    `json:"duration_in_months,omitempty"`
	MaxRedemptions   Int    `json:"max_redemptions,omitempty"`
	RedeemBy         Int64  `json:"redeem_by,omitempty"`
	TimesRedeemed    int    `json:"times_redeemed,omitempty"`
	Livemode         bool   `json:"livemode"`
}

Coupon represents percent-off discount you might want to apply to a customer.

see https://stripe.com/docs/api#coupon_object

type CouponClient

type CouponClient struct{}

CouponClient encapsulates operations for creating, updating, deleting and querying coupons using the Stripe REST API.

func (*CouponClient) Create

func (self *CouponClient) Create(params *CouponParams) (*Coupon, error)

Creates a new Coupon.

see https://stripe.com/docs/api#create_coupon

func (*CouponClient) Delete

func (self *CouponClient) Delete(id string) (bool, error)

Deletes the coupon with the given ID.

see https://stripe.com/docs/api#delete_coupon

func (*CouponClient) List

func (self *CouponClient) List() ([]*Coupon, error)

Returns a list of your coupons.

see https://stripe.com/docs/api#list_coupons

func (*CouponClient) ListN

func (self *CouponClient) ListN(count int, offset int) ([]*Coupon, error)

Returns a list of your coupons at the specified range.

see https://stripe.com/docs/api#list_coupons

func (*CouponClient) Retrieve

func (self *CouponClient) Retrieve(id string) (*Coupon, error)

Retrieves the coupon with the given ID.

see https://stripe.com/docs/api#retrieve_coupon

type CouponParams

type CouponParams struct {
	// (Optional) Unique string of your choice that will be used to identify
	// this coupon when applying it a customer.
	Id string

	// A positive integer between 1 and 100 that represents the discount the
	// coupon will apply.
	PercentOff int

	// Specifies how long the discount will be in effect. Can be forever, once,
	// or repeating.
	Duration string

	// (Optional) If duration is repeating, a positive integer that specifies
	// the number of months the discount will be in effect.
	DurationInMonths int

	// (Optional) A positive integer specifying the number of times the coupon
	// can be redeemed before it's no longer valid. For example, you might have
	// a 50% off coupon that the first 20 readers of your blog can use.
	MaxRedemptions int

	// (Optional) UTC timestamp specifying the last time at which the coupon can
	// be redeemed. After the redeem_by date, the coupon can no longer be
	// applied to new customers.
	RedeemBy int64
}

CouponParams encapsulates options for creating a new Coupon.

type Customer

type Customer struct {
	Id           string        `json:"id"`
	Desc         String        `json:"description,omitempty"`
	Email        String        `json:"email,omitempty"`
	Created      int64         `json:"created"`
	Balance      int64         `json:"account_balance"`
	Delinquent   bool          `json:"delinquent"`
	Cards        CardData      `json:"cards,omitempty"`
	Discount     *Discount     `json:"discount,omitempty"`
	Subscription *Subscription `json:"subscription,omitempty"`
	Livemode     bool          `json:"livemode"`
	DefaultCard  String        `json:"default_card"`
}

Customer encapsulates details about a Customer registered in Stripe.

see https://stripe.com/docs/api#customer_object

type CustomerClient

type CustomerClient struct{}

CustomerClient encapsulates operations for creating, updating, deleting and querying customers using the Stripe REST API.

func (*CustomerClient) Create

func (self *CustomerClient) Create(c *CustomerParams) (*Customer, error)

Creates a new Customer.

see https://stripe.com/docs/api#create_customer

func (*CustomerClient) Delete

func (self *CustomerClient) Delete(id string) (bool, error)

Deletes a Customer (permanently) with the given ID.

see https://stripe.com/docs/api#delete_customer

func (*CustomerClient) List

func (self *CustomerClient) List() ([]*Customer, error)

Returns a list of your Customers.

see https://stripe.com/docs/api#list_customers

func (*CustomerClient) ListN

func (self *CustomerClient) ListN(count int, offset int) ([]*Customer, error)

Returns a list of your Customers at the specified range.

see https://stripe.com/docs/api#list_customers

func (*CustomerClient) Retrieve

func (self *CustomerClient) Retrieve(id string) (*Customer, error)

Retrieves a Customer with the given ID.

see https://stripe.com/docs/api#retrieve_customer

func (*CustomerClient) Update

func (self *CustomerClient) Update(id string, c *CustomerParams) (*Customer, error)

Updates a Customer with the given ID.

see https://stripe.com/docs/api#update_customer

type CustomerParams

type CustomerParams struct {
	// (Optional) The customer's email address.
	Email string

	// (Optional) An arbitrary string which you can attach to a customer object.
	Desc string

	// (Optional) Customer's Active Credit Card
	Card *CardParams

	// (Optional) Customer's Active Credid Card, using a Card Token
	Token string

	// (Optional) If you provide a coupon code, the customer will have a
	// discount applied on all recurring charges.
	Coupon string

	// (Optional) The identifier of the plan to subscribe the customer to. If
	// provided, the returned customer object has a 'subscription' attribute
	// describing the state of the customer's subscription.
	Plan string

	// (Optional) UTC integer timestamp representing the end of the trial period
	// the customer will get before being charged for the first time.
	TrialEnd int64

	// (Optional) An integer amount in cents that is the starting account
	// balance for your customer.
	AccountBalance int64

	// (Optional) A set of key/value pairs that you can attach to a customer
	// object.
	Metadata map[string]string

	// (Optional) The quantity you’d like to apply to the subscription you’re
	// creating.
	Quantity int64
}

CustomerParams encapsulates options for creating and updating Customers.

type DeleteResp

type DeleteResp struct {
	// ID of the Object that was deleted
	Id string `json:"id"`
	// Boolean value indicating object was successfully deleted.
	Deleted bool `json:"deleted"`
}

Response to a Deletion request.

type Discount

type Discount struct {
	Id       string  `json:"id"`
	Customer string  `json:"customer"`
	Start    Int64   `json:"start"`
	End      Int64   `json:"end"`
	Coupon   *Coupon `json:"coupon"`
}

Discount represents the actual application of a coupon to a particular customer.

see https://stripe.com/docs/api#discount_object

type Error

type Error struct {
	Code   int
	Detail struct {
		Type    string `json:"type"`
		Message string `json:"message"`
		Code    string `json:"code,omitempty"`
		Param   string `json:"param,omitempty"`
	} `json:"error"`
}

Error encapsulates an error returned by the Stripe REST API. Detail.Code and Detail.Param may be empty.

func (*Error) Error

func (e *Error) Error() string

type FeeDetails

type FeeDetails struct {
	Amount      int64  `json:"amount"`
	Currency    string `json:"currency"`
	Type        string `json:"type"`
	Application String `json:"application"`
}

FeeDetails represents a single fee associated with a Charge.

type Int

type Int int

Int is a special type of integer that can unmarshall a JSON value of "null", which cannot be parsed by the Go JSON parser as of Go v1.

see http://code.google.com/p/go/issues/detail?id=2540

func (*Int) UnmarshalJSON

func (self *Int) UnmarshalJSON(data []byte) error

type Int64

type Int64 int64

Int64 is a special type of int64 that can unmarshall a JSON value of "null", which cannot be parsed by the Go JSON parser as of Go v1.

see http://code.google.com/p/go/issues/detail?id=2540

func (*Int64) UnmarshalJSON

func (self *Int64) UnmarshalJSON(data []byte) error

type Invoice

type Invoice struct {
	Id              string        `json:"id"`
	AmountDue       int64         `json:"amount_due"`
	AttemptCount    int           `json:"attempt_count"`
	Attempted       bool          `json:"attempted"`
	Closed          bool          `json:"closed"`
	Paid            bool          `json:"paid"`
	PeriodEnd       int64         `json:"period_end"`
	PeriodStart     int64         `json:"period_start"`
	Subtotal        int64         `json:"subtotal"`
	Total           int64         `json:"total"`
	Charge          String        `json:"charge"`
	Customer        string        `json:"customer"`
	Date            int64         `json:"date"`
	Discount        *Discount     `json:"discount"`
	Lines           *InvoiceLines `json:"lines"`
	StartingBalance int64         `json:"starting_balance"`
	EndingBalance   Int64         `json:"ending_balance"`
	NextPayment     Int64         `json:"next_payment_attempt"`
	Livemode        bool          `json:"livemode"`
}

Invoice represents statements of what a customer owes for a particular billing period, including subscriptions, invoice items, and any automatic proration adjustments if necessary.

see https://stripe.com/docs/api#invoice_object

type InvoiceClient

type InvoiceClient struct{}

InvoiceClient encapsulates operations for querying invoices using the Stripe REST API.

func (*InvoiceClient) CustomerList

func (self *InvoiceClient) CustomerList(id string) ([]*Invoice, error)

Returns a list of Invoices with the given Customer ID.

see https://stripe.com/docs/api#list_customer_invoices

func (*InvoiceClient) CustomerListN

func (self *InvoiceClient) CustomerListN(id string, count int, offset int) ([]*Invoice, error)

Returns a list of Invoices with the given Customer ID, at the specified range.

see https://stripe.com/docs/api#list_customer_invoices

func (*InvoiceClient) List

func (self *InvoiceClient) List() ([]*Invoice, error)

Returns a list of Invoices.

see https://stripe.com/docs/api#list_customer_invoices

func (*InvoiceClient) ListN

func (self *InvoiceClient) ListN(count int, offset int) ([]*Invoice, error)

Returns a list of Invoices at the specified range.

see https://stripe.com/docs/api#list_customer_invoices

func (*InvoiceClient) Retrieve

func (self *InvoiceClient) Retrieve(id string) (*Invoice, error)

Retrieves the invoice with the given ID.

see https://stripe.com/docs/api#retrieve_invoice

func (*InvoiceClient) RetrieveCustomer

func (self *InvoiceClient) RetrieveCustomer(cid string) (*Invoice, error)

Retrieves the upcoming invoice the given customer ID.

see https://stripe.com/docs/api#retrieve_customer_invoice

type InvoiceItem

type InvoiceItem struct {
	Id       string `json:"id"`
	Amount   int64  `json:"amount"`
	Currency string `json:"currency"`
	Customer string `json:"customer"`
	Date     int64  `json:"date"`
	Desc     String `json:"description"`
	Invoice  String `json:"invoice"`
	Livemode bool   `json:"livemode"`
}

InvoiceItem represents a charge (or credit) that should be applied to the customer at the end of a billing cycle.

see https://stripe.com/docs/api#invoiceitem_object

type InvoiceItemClient

type InvoiceItemClient struct{}

InvoiceItemClient encapsulates operations for creating, updating, deleting and querying invoices using the Stripe REST API.

func (*InvoiceItemClient) Create

func (self *InvoiceItemClient) Create(params *InvoiceItemParams) (*InvoiceItem, error)

Create adds an arbitrary charge or credit to the customer's upcoming invoice.

see https://stripe.com/docs/api#invoiceitem_object

func (*InvoiceItemClient) CustomerList

func (self *InvoiceItemClient) CustomerList(id string) ([]*InvoiceItem, error)

Returns a list of Invoice Items for the specified Customer ID.

see https://stripe.com/docs/api#list_invoiceitems

func (*InvoiceItemClient) CustomerListN

func (self *InvoiceItemClient) CustomerListN(id string, count int, offset int) ([]*InvoiceItem, error)

Returns a list of Invoice Items for the specified Customer ID, at the specified range.

see https://stripe.com/docs/api#list_invoiceitems

func (*InvoiceItemClient) Delete

func (self *InvoiceItemClient) Delete(id string) (bool, error)

Removes an Invoice Item with the given ID.

see https://stripe.com/docs/api#delete_invoiceitem

func (*InvoiceItemClient) List

func (self *InvoiceItemClient) List() ([]*InvoiceItem, error)

Returns a list of Invoice Items.

see https://stripe.com/docs/api#list_invoiceitems

func (*InvoiceItemClient) ListN

func (self *InvoiceItemClient) ListN(count int, offset int) ([]*InvoiceItem, error)

Returns a list of Invoice Items at the specified range.

see https://stripe.com/docs/api#list_invoiceitems

func (*InvoiceItemClient) Retrieve

func (self *InvoiceItemClient) Retrieve(id string) (*InvoiceItem, error)

Retrieves the Invoice Item with the given ID.

see https://stripe.com/docs/api#retrieve_invoiceitem

func (*InvoiceItemClient) Update

func (self *InvoiceItemClient) Update(id string, params *InvoiceItemParams) (*InvoiceItem, error)

Update changes the amount or description of an Invoice Item on an upcoming invoice, using the given Invoice Item ID.

see https://stripe.com/docs/api#update_invoiceitem

type InvoiceItemParams

type InvoiceItemParams struct {
	// The ID of the customer who will be billed when this invoice item is
	// billed.
	Customer string

	// The integer amount in cents of the charge to be applied to the upcoming
	// invoice. If you want to apply a credit to the customer's account, pass a
	// negative amount.
	Amount int64

	// 3-letter ISO code for currency. Currently, only 'usd' is supported.
	Currency string

	// (Optional) An arbitrary string which you can attach to the invoice item.
	// The description is displayed in the invoice for easy tracking.
	Desc string

	// (Optional) The ID of an existing invoice to add this invoice item to.
	// When left blank, the invoice item will be added to the next upcoming
	// scheduled invoice.
	Invoice string
}

InvoiceItemParams encapsulates options for creating a new Invoice Items.

type InvoiceLines

type InvoiceLines struct {
	InvoiceItems  []*InvoiceItem      `json:"invoiceitems"`
	Prorations    []*InvoiceItem      `json:"prorations"`
	Subscriptions []*SubscriptionItem `json:"subscriptions"`
}

InvoiceLines represents an individual line items that is part of an invoice.

type Period

type Period struct {
	Start int64 `json:"start"`
	End   int64 `json:"end"`
}

type Plan

type Plan struct {
	Id              string `json:"id"`
	Name            string `json:"name"`
	Amount          int64  `json:"amount"`
	Interval        string `json:"interval"`
	IntervalCount   int    `json:"interval_count"`
	Currency        string `json:"currency"`
	TrialPeriodDays Int    `json:"trial_period_days"`
	Livemode        bool   `json:"livemode"`
}

Plan holds details about pricing information for different products and feature levels on your site. For example, you might have a $10/month plan for basic features and a different $20/month plan for premium features.

see https://stripe.com/docs/api#plan_object

type PlanClient

type PlanClient struct{}

PlanClient encapsulates operations for creating, updating, deleting and querying plans using the Stripe REST API.

func (*PlanClient) Create

func (self *PlanClient) Create(params *PlanParams) (*Plan, error)

Creates a new Plan.

see https://stripe.com/docs/api#create_plan

func (*PlanClient) Delete

func (self *PlanClient) Delete(id string) (bool, error)

Deletes a plan with the given ID.

see https://stripe.com/docs/api#delete_plan

func (*PlanClient) List

func (self *PlanClient) List() ([]*Plan, error)

Returns a list of your Plans.

see https://stripe.com/docs/api#list_Plans

func (*PlanClient) ListN

func (self *PlanClient) ListN(count int, offset int) ([]*Plan, error)

Returns a list of your Plans at the specified range.

see https://stripe.com/docs/api#list_Plans

func (*PlanClient) Retrieve

func (self *PlanClient) Retrieve(id string) (*Plan, error)

Retrieves the plan with the given ID.

see https://stripe.com/docs/api#retrieve_plan

func (*PlanClient) Update

func (self *PlanClient) Update(id string, newName string) (*Plan, error)

Updates the name of a plan. Other plan details (price, interval, etc.) are, by design, not editable.

see https://stripe.com/docs/api#update_plan

type PlanParams

type PlanParams struct {
	// Unique string of your choice that will be used to identify this plan
	// when subscribing a customer.
	Id string

	// A positive integer in cents (or 0 for a free plan) representing how much
	// to charge (on a recurring basis)
	Amount int64

	// 3-letter ISO code for currency. Currently, only 'usd' is supported.
	Currency string

	// Specifies billing frequency. Either month or year.
	Interval string

	// Name of the plan, to be displayed on invoices and in the web interface.
	Name string

	// (Optional) Specifies a trial period in (an integer number of) days. If
	// you include a trial period, the customer won't be billed for the first
	// time until the trial period ends. If the customer cancels before the
	// trial period is over, she'll never be billed at all.
	TrialPeriodDays int
}

PlanParams encapsulates options for creating a new Plan.

type String

type String string

String is a special type of string that can unmarshall a JSON value of "null", which cannot be parsed by the Go JSON parser as of Go v1.

see http://code.google.com/p/go/issues/detail?id=2540

func (*String) UnmarshalJSON

func (self *String) UnmarshalJSON(data []byte) error

type Subscription

type Subscription struct {
	Customer           string `json:"customer"`
	Status             string `json:"status"`
	Plan               *Plan  `json:"plan"`
	Start              int64  `json:"start"`
	EndedAt            Int64  `json:"ended_at"`
	CurrentPeriodStart Int64  `json:"current_period_start"`
	CurrentPeriodEnd   Int64  `json:"current_period_end"`
	TrialStart         Int64  `json:"trial_start"`
	TrialEnd           Int64  `json:"trial_end"`
	CanceledAt         Int64  `json:"canceled_at"`
	CancelAtPeriodEnd  bool   `json:"cancel_at_period_end"`
	Quantity           int64  `json"quantity"`
}

Subscriptions represents a recurring charge a customer's card.

see https://stripe.com/docs/api#subscription_object

type SubscriptionClient

type SubscriptionClient struct{}

SubscriptionClient encapsulates operations for updating and canceling customer subscriptions using the Stripe REST API.

func (*SubscriptionClient) Cancel

func (self *SubscriptionClient) Cancel(customerId string) (*Subscription, error)

Cancels the customer's subscription if it exists. It cancels the subscription immediately.

see https://stripe.com/docs/api#cancel_subscription

func (*SubscriptionClient) CancelAtPeriodEnd

func (self *SubscriptionClient) CancelAtPeriodEnd(customerId string) (*Subscription, error)

Cancels the customer's subscription at the end of the billing period.

see https://stripe.com/docs/api#cancel_subscription

func (*SubscriptionClient) Update

func (self *SubscriptionClient) Update(customerId string, params *SubscriptionParams) (*Subscription, error)

Subscribes a customer to a new plan.

see https://stripe.com/docs/api#update_subscription

type SubscriptionItem

type SubscriptionItem struct {
	Amount int64   `json:"amount"`
	Period *Period `json:"period"`
	Plan   *Plan   `json:"plan"`
}

type SubscriptionParams

type SubscriptionParams struct {
	// The identifier of the plan to subscribe the customer to.
	Plan string

	// (Optional) The code of the coupon to apply to the customer if you would
	// like to apply it at the same time as creating the subscription.
	Coupon string

	// (Optional) Flag telling us whether to prorate switching plans during a
	// billing cycle
	Prorate bool

	// (Optional) UTC integer timestamp representing the end of the trial period
	// the customer will get before being charged for the first time. If set,
	// trial_end will override the default trial period of the plan the customer
	// is being subscribed to.
	TrialEnd int64

	// (Optional) A new card to attach to the customer.
	Card *CardParams

	// (Optional) A new card Token to attach to the customer.
	Token string

	// (Optional) The quantity you'd like to apply to the subscription you're creating.
	Quantity int64
}

SubscriptionParams encapsulates options for updating a Customer's subscription.

type Token

type Token struct {
	Id       string `json:"id"`
	Amount   int64  `json:"amount"`
	Currency string `json:"currency"`
	Created  int64  `json:"created"`
	Used     bool   `json:"used"`
	Livemode bool   `json:"livemode"`
	Type     string `json:"type"`
	Card     *Card  `json:"card"`
}

Token represents a unique identifier for a credit card that can be safely stored without having to hold sensitive card information on your own servers.

see https://stripe.com/docs/api#token_object

type TokenClient

type TokenClient struct{}

TokenClient encapsulates operations for creating and querying tokens using the Stripe REST API.

func (*TokenClient) Create

func (self *TokenClient) Create(params *TokenParams) (*Token, error)

Creates a single use token that wraps the details of a credit card. This token can be used in place of a credit card hash with any API method. These tokens can only be used once: by creating a new charge object, or attaching them to a customer.

see https://stripe.com/docs/api#create_token

func (*TokenClient) Retrieve

func (self *TokenClient) Retrieve(id string) (*Token, error)

Retrieves the card token with the given Id.

see https://stripe.com/docs/api#retrieve_token

type TokenParams

type TokenParams struct {
	//Currency string REMOVED! no longer part of the API
	Card *CardParams
}

TokenParams encapsulates options for creating a new Card Token.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL