Coder Social home page Coder Social logo

go.stripe's Introduction

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:  "[email protected]",
	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.

go.stripe's People

Contributors

ae0000 avatar avitex avatar boj avatar bradrydzewski avatar elithrar avatar freeeve avatar irwinb avatar purohit avatar tdburke avatar titanous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go.stripe's Issues

Delete return types

Delete functions should return a special struct, that use the following format:

{
  "deleted": true,
  "id": "cus_3Sndou3HZmZVOW"
}

Missing "data" field for Invoice.Data.Object.Lines type ?

Hi,

I think i spotted an error while using the webhooks. It returns an object which contains "lines". But it contains json field called "data" which is not present in the structure :(

Can you confirm it ?

JSON
Webhook payment_succeeded from stripe

  "period_start": 1406634003,
      "period_end": 1406634003,
      "lines": {
        "data": [       // <==== HERE
          {
            "id": "sub_4UY3vxOFvXGlQm",
            "object": "line_item",
            "type": "subscription",

Struct
https://github.com/drone/go.stripe/blob/master/invoice.go

....
    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"`
}

// InvoiceLines represents an individual line items that is part of an invoice.
type InvoiceLines struct {
    InvoiceItems  []*InvoiceItem      `json:"invoiceitems"`
    Prorations    []*InvoiceItem      `json:"prorations"`
    Subscriptions []*SubscriptionItem `json:"subscriptions"`
}

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

Implement HandlerFunc for Events

Implement an http.HandlerFunc so that a developer can easily handle Stripe Events.

i'm thinking something like this

type EventCallback func(Event);

func HandleEvent(callback EventCallback) {
    return func(req *http.Request, resp http.Response) {
         // parse the event in the incoming request
         event, err := json.Unmarshall(...)

         // return a 202 so that stripe knows we go it
         w.WriteHeader(http.StatusOK)

         // invoke EventCallback function
         go callback(event)
    }
}

Update Subscription, Attach New Card

When updating a subscription, the API gives the ability to attach a new Credit Card (or Card Token). This feature is currently not implemented.

No stripe.Cards?

In stripe.go there's a convenience constructor for most ...Client types, but there isn't one that says:

Cards = new(CardClient)

Any reason for that? I can submit a pull request fix if not.

Create Customer using Card Token

Per the Stripe API docs, we should be able to substitute a Token in place of any API call that sends an actual Credit Card. Need to implement this functionality, specifically in the Customers.Create and Customer.Update API implementations

Two incorrect checks in plan_test.go

Two checks in plan_test.go compare a value with itself, instead of with the expected value:

/src/github.com/drone/go.stripe/plan_test.go:53:5: identical expressions on the left and right side of the '!=' operator
/src/github.com/drone/go.stripe/plan_test.go:98:5: identical expressions on the left and right side of the '!=' operator

Status of the repo?

Hi there,

I'm just checking if the library is still being maintained, and if so, if we should use bradrydzewski's version or drone.io's version.

Thanks!

Cancel Subscription, At Period End

When cancelling a subscription need to enable the at_parameter_end flag:

If you set the at_parameter_end parameter to true, the subscription will remain active until the end of the period, at which point it will be cancelled and not renewed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.