├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── events ├── register.go └── register_test.go ├── main.go ├── rename.sh └── vendor └── github.com └── stripe └── stripe-go ├── account.go ├── account ├── client.go └── client_test.go ├── balance.go ├── balance ├── client.go └── client_test.go ├── bankaccount.go ├── bankaccount ├── client.go └── client_test.go ├── bitcoin_receiver.go ├── bitcoin_transaction.go ├── bitcoinreceiver ├── client.go └── client_test.go ├── bitcointransaction ├── client.go └── client_test.go ├── card.go ├── card ├── client.go └── client_test.go ├── charge.go ├── charge ├── client.go └── client_test.go ├── client ├── api.go ├── checkin_test.go └── error_test.go ├── coupon.go ├── coupon ├── client.go └── client_test.go ├── currency └── currency.go ├── customer.go ├── customer ├── client.go └── client_test.go ├── discount └── client.go ├── discounts.go ├── dispute.go ├── dispute ├── client.go └── client_test.go ├── error.go ├── event.go ├── event ├── client.go └── client_test.go ├── example_test.go ├── fee.go ├── fee └── client.go ├── feerefund.go ├── feerefund └── client.go ├── fileupload.go ├── fileupload ├── client.go ├── client_test.go └── test_data.pdf ├── invoice.go ├── invoice ├── client.go └── client_test.go ├── invoiceitem.go ├── invoiceitem └── client.go ├── iter.go ├── iter_test.go ├── order.go ├── order ├── client.go └── client_test.go ├── order_item.go ├── orderitem └── order_item.go ├── params.go ├── params_test.go ├── payment_source.go ├── paymentsource ├── client.go └── client_test.go ├── plan.go ├── plan ├── client.go └── client_test.go ├── product.go ├── product ├── client.go └── client_test.go ├── recipient.go ├── recipient ├── client.go └── client_test.go ├── refund.go ├── refund ├── client.go └── client_test.go ├── reversal.go ├── reversal ├── client.go └── client_test.go ├── sku.go ├── sku ├── client.go └── client_test.go ├── stripe.go ├── sub.go ├── sub ├── client.go └── client_test.go ├── token.go ├── token ├── client.go └── client_test.go ├── transfer.go ├── transfer ├── client.go └── client_test.go └── utils └── key.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.5.3 4 | - tip 5 | before_install: ./rename.sh 6 | script: 7 | - go vet main.go 8 | - go vet ./events 9 | - go test ./events -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Teamwork.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/Teamwork/stripehooks.svg?branch=master)](https://travis-ci.org/Teamwork/stripehooks) 2 | 3 | # stripehooks 4 | 5 | A server to handle [Stripe webhooks](https://stripe.com/docs/webhooks). Add your own custom event handlers. 6 | 7 | ## Run 8 | `go get github.com/teamwork/stripehooks` 9 | 10 | `go run main.go` or `go build && ./stripehooks` 11 | 12 | This accepts a port and a path part for configuring the endpoint e.g. `./stripehooks --help` 13 | 14 | ``` 15 | Usage of ./stripehooks: 16 | -path="stripe": the endpoint to recieve webhooks on e.g. 'stripe' would be http://localhost:/stripe 17 | -port=8080: port number to bind the server to e.g. '8080' would be http://localhost:8080/ 18 | ``` 19 | 20 | ## Example 21 | 22 | In `events/register.go` add your event handlers to `RegisterEventHandlers()` function for any of the various events that Stripe send to your endpoint. You can see the list of events Stripe sends [here](https://stripe.com/docs/api#event_types). Here is an example of handling an `invoice.payment_succeeded` event. 23 | 24 | ```go 25 | // Example handle incoming hook for invoice.payment_succeeded event 26 | registerEventHandler("invoice.payment_succeeded", func(event *stripe.Event) error { 27 | fmt.Printf("Event %s handled, type %s\n", event.ID, event.Type) 28 | return nil 29 | }) 30 | ``` 31 | 32 | `eventHandlers` is a `map[string]eventHandler` that holds all the events you register. There is also a `validationHandler` for checking the event Stripe sends down. This is typically either checking the event back with Stripe (extra step for security) or to use the event as-is and trust it. Examples of both are provided 33 | 34 | ```go 35 | func VerifyEventWithStripe(hook StripeWebhook) (*stripe.Event, error) { 36 | if !hook.LiveMode { 37 | return &stripe.Event{ 38 | Data: &hook.Data, 39 | Live: hook.LiveMode, 40 | Type: hook.Type, 41 | ID: hook.ID, 42 | }, nil 43 | } 44 | stripe.Key = "" // your private stripe api key goes here 45 | return event.Get(hook.ID) 46 | } 47 | ``` 48 | 49 | ```go 50 | validationHandler = func(hook StripeWebhook) (*stripe.Event, error) { 51 | return &stripe.Event{ 52 | Data: &hook.Data, 53 | Live: hook.LiveMode, 54 | Type: hook.Type, 55 | ID: hook.Id, 56 | }, nil 57 | } 58 | ``` 59 | 60 | ## Dependencies 61 | The only dependecies outside of the standard library are 62 | * "github.com/stripe/stripe-go" 63 | * "github.com/stripe/stripe-go/event" 64 | 65 | I would recommend vendoring the stripe dependencies. 66 | -------------------------------------------------------------------------------- /events/register.go: -------------------------------------------------------------------------------- 1 | package events 2 | 3 | // registerEventHandlers is the place to add your handlers for different Stripe hooks 4 | import ( 5 | "errors" 6 | "fmt" 7 | 8 | "github.com/stripe/stripe-go" 9 | "github.com/stripe/stripe-go/event" 10 | ) 11 | 12 | type eventHandler func(hook *stripe.Event) (err error) 13 | type validateHandler func(hook *stripe.Event) (event *stripe.Event, err error) 14 | 15 | // EventHandlers is a mapping of stripe events to their handleEvent functions 16 | var EventHandlers = make(map[string]eventHandler) 17 | 18 | // ValidationHandler is an 19 | var ValidationHandler validateHandler 20 | 21 | // RegisterEventHandlers is the place to add your handlers for each 22 | // event type you want to support from Stripe webhooks 23 | func RegisterEventHandlers() { 24 | // Example handle incoming hook for invoice.payment_succeeded event 25 | // Shows how to get the data safely out of the map[string]interface{} 26 | RegisterEventHandler("invoice.payment_succeeded", func(event *stripe.Event) error { 27 | customer, ok := event.Data.Obj["customer"] 28 | if !ok { 29 | return errors.New("Could not find customer in event") 30 | } 31 | customer, ok = customer.(string) 32 | if !ok { 33 | return errors.New("Customer field was not expected type") 34 | } 35 | 36 | fmt.Printf("Event %s handled, type %s for customer %s\n", event.ID, event.Type, customer) 37 | return nil 38 | }) 39 | 40 | RegisterEventHandler("invoice.payment_failed", func(event *stripe.Event) error { 41 | // Example, send email to customer 42 | return nil 43 | }) 44 | } 45 | 46 | // RegisterEventHandler adds the handler to the list of handlers 47 | // It will overwrite handler if one exists for event already 48 | func RegisterEventHandler(event string, handleFunc eventHandler) { 49 | EventHandlers[event] = handleFunc 50 | } 51 | 52 | // RegisterValidationHandler allows you to add your validation handler function here 53 | // A typical validation is to call back to Stripe 54 | // and verify and use the event that check returns. 55 | // 56 | // If you want no validation with Stripe, then just use the original event data e.g. 57 | // validationHandler = func(hook *stripe.Event) (*stripe.Event, error) { 58 | // return &stripe.Event{ 59 | // Data: &hook.Data, 60 | // Live: hook.LiveMode, 61 | // Type: hook.Type, 62 | // ID: hook.Id, 63 | // }, nil 64 | // } 65 | func RegisterValidationHandler(handleFunc validateHandler) { 66 | ValidationHandler = handleFunc 67 | } 68 | 69 | // VerifyEventWithStripe verifies the event received via webhook with Stripe 70 | // using the ID to confirm webhook is legit - extra security step 71 | // Note: If the stripe webhook is not Livemode then this bypasses the call to Stripe 72 | // and uses the event we have from the original webhook. 73 | // Without that bypass, a testmode hook would always fail this callback 74 | func VerifyEventWithStripe(hook *stripe.Event) (*stripe.Event, error) { 75 | if !hook.Live { 76 | return hook, nil 77 | } 78 | stripe.Key = "" // your private stripe api key goes here 79 | return event.Get(hook.ID) 80 | } 81 | -------------------------------------------------------------------------------- /events/register_test.go: -------------------------------------------------------------------------------- 1 | package events 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stripe/stripe-go" 7 | ) 8 | 9 | func TestVerifyEventWithStripeWithTestMode(t *testing.T) { 10 | e := &stripe.Event{ 11 | Type: "invoice", 12 | ID: "in_123456789", 13 | Live: false, 14 | Data: &stripe.EventData{}, 15 | } 16 | 17 | event, err := VerifyEventWithStripe(e) 18 | if err != nil { 19 | t.Fail() 20 | } 21 | if event.ID != e.ID && event.Type != e.Type { 22 | t.Errorf("Expected eventID to be %s but was %s", e.ID, event.ID) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "flag" 6 | "fmt" 7 | "io" 8 | "io/ioutil" 9 | "log" 10 | "net/http" 11 | "strconv" 12 | 13 | "github.com/stripe/stripe-go" 14 | "github.com/teamwork/stripehooks/events" 15 | ) 16 | 17 | var ( 18 | port int 19 | path string 20 | ) 21 | 22 | func main() { 23 | 24 | parseCommandLineArgs() 25 | 26 | events.RegisterValidationHandler(events.VerifyEventWithStripe) 27 | events.RegisterEventHandlers() 28 | 29 | http.HandleFunc("/"+path, stripeHandler) 30 | 31 | fmt.Println("Listening...") 32 | log.Fatal(http.ListenAndServe(":"+strconv.Itoa(port), nil)) 33 | } 34 | 35 | // stripeHandler is responsible for receiving the stripe webhook 36 | // and then taking that request through verification and event handlers 37 | // and return 200 OK to Stripe or some other HTTP response code in the event 38 | // of an error. Note: Stripe will retry any events returned outside of 2XX. 39 | func stripeHandler(w http.ResponseWriter, r *http.Request) { 40 | if r.Method != "POST" { 41 | http.Error(w, "route only supports POST", http.StatusBadRequest) 42 | return 43 | } 44 | 45 | hook, err := parseBody(r.Body) 46 | if err != nil { 47 | http.Error(w, err.Error(), http.StatusBadRequest) 48 | return 49 | } 50 | 51 | handler, ok := events.EventHandlers[hook.Type] 52 | if !ok { 53 | fmt.Fprintf(w, "No handler for this event %s", hook.Type) 54 | return 55 | } 56 | 57 | event, err := events.ValidationHandler(hook) 58 | if err != nil { 59 | http.Error(w, fmt.Sprintf("Verifying with stripe failed for event %s", hook.ID), http.StatusInternalServerError) 60 | return 61 | } 62 | 63 | err = handler(event) 64 | if err != nil { 65 | http.Error(w, "Something went wrong", http.StatusInternalServerError) 66 | return 67 | } 68 | 69 | fmt.Fprintf(w, "Event handled successfully %s", event.ID) 70 | return 71 | } 72 | 73 | // parseBody unmarshals the payload from Stripe to our StripeWebhook struct 74 | func parseBody(body io.Reader) (event *stripe.Event, err error) { 75 | b, err := ioutil.ReadAll(body) 76 | if err != nil { 77 | return 78 | } 79 | err = json.Unmarshal(b, &event) 80 | return event, err 81 | } 82 | 83 | func parseCommandLineArgs() { 84 | flag.IntVar( 85 | &port, 86 | "port", 87 | 8080, `port number to bind the server to e.g. '8080' would be http://localhost:8080/`, 88 | ) 89 | flag.StringVar( 90 | &path, 91 | "path", 92 | "stripe", 93 | "the endpoint to recieve webhooks on e.g. 'stripe' would be http://localhost:/stripe", 94 | ) 95 | flag.Parse() 96 | } 97 | -------------------------------------------------------------------------------- /rename.sh: -------------------------------------------------------------------------------- 1 | #/usr/bin/env sh 2 | mv $HOME/gopath/src/github.com/Teamwork/ $HOME/gopath/src/github.com/teamwork/ -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/balance.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // TransactionStatus is the list of allowed values for the transaction's status. 6 | // Allowed values are "available", "pending". 7 | type TransactionStatus string 8 | 9 | // TransactionType is the list of allowed values for the transaction's type. 10 | // Allowed values are "charge", "refund", "adjustment", "application_fee", 11 | // "application_fee_refund", "transfer", "transfer_cancel", "transfer_failure". 12 | type TransactionType string 13 | 14 | // BalanceParams is the set of parameters that can be used when retrieving a balance. 15 | // For more details see https://stripe.com/docs/api#balance. 16 | type BalanceParams struct { 17 | Params 18 | } 19 | 20 | // TxParams is the set of parameters that can be used when retrieving a transaction. 21 | // For more details see https://stripe.com/docs/api#retrieve_balance_transaction. 22 | type TxParams struct { 23 | Params 24 | } 25 | 26 | // TxListParams is the set of parameters that can be used when listing balance transactions. 27 | // For more details see https://stripe.com/docs/api/#balance_history. 28 | type TxListParams struct { 29 | ListParams 30 | Created, Available int64 31 | Currency, Src, Transfer string 32 | Type TransactionType 33 | } 34 | 35 | // Balance is the resource representing your Stripe balance. 36 | // For more details see https://stripe.com/docs/api/#balance. 37 | type Balance struct { 38 | // Live indicates the live mode. 39 | Live bool `json:"livemode"` 40 | Available []Amount `json:"available"` 41 | Pending []Amount `json:"pending"` 42 | } 43 | 44 | // Transaction is the resource representing the balance transaction. 45 | // For more details see https://stripe.com/docs/api/#balance. 46 | type Transaction struct { 47 | ID string `json:"id"` 48 | Amount int64 `json:"amount"` 49 | Currency Currency `json:"currency"` 50 | Available int64 `json:"available_on"` 51 | Created int64 `json:"created"` 52 | Fee int64 `json:"fee"` 53 | FeeDetails []TxFee `json:"fee_details"` 54 | Net int64 `json:"net"` 55 | Status TransactionStatus `json:"status"` 56 | Type TransactionType `json:"type"` 57 | Desc string `json:"description"` 58 | Src string `json:"source"` 59 | Recipient string `json:"recipient"` 60 | } 61 | 62 | // Amount is a structure wrapping an amount value and its currency. 63 | type Amount struct { 64 | Value int64 `json:"amount"` 65 | Currency Currency `json:"currency"` 66 | } 67 | 68 | // TxFee is a structure that breaks down the fees in a transaction. 69 | type TxFee struct { 70 | Amount int64 `json:"amount"` 71 | Currency Currency `json:"currency"` 72 | Type string `json:"type"` 73 | Desc string `json:"description"` 74 | Application string `json:"application"` 75 | } 76 | 77 | // UnmarshalJSON handles deserialization of a Transaction. 78 | // This custom unmarshaling is needed because the resulting 79 | // property may be an id or the full struct if it was expanded. 80 | func (t *Transaction) UnmarshalJSON(data []byte) error { 81 | type transaction Transaction 82 | var tt transaction 83 | err := json.Unmarshal(data, &tt) 84 | if err == nil { 85 | *t = Transaction(tt) 86 | } else { 87 | // the id is surrounded by "\" characters, so strip them 88 | t.ID = string(data[1 : len(data)-1]) 89 | } 90 | 91 | return nil 92 | } 93 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/balance/client.go: -------------------------------------------------------------------------------- 1 | // Package balance provides the /balance APIs 2 | package balance 3 | 4 | import ( 5 | "net/url" 6 | "strconv" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | ) 10 | 11 | const ( 12 | TxAvailable stripe.TransactionStatus = "available" 13 | TxPending stripe.TransactionStatus = "pending" 14 | 15 | TxCharge stripe.TransactionType = "charge" 16 | TxRefund stripe.TransactionType = "refund" 17 | TxAdjust stripe.TransactionType = "adjustment" 18 | TxAppFee stripe.TransactionType = "application_fee" 19 | TxFeeRefund stripe.TransactionType = "application_fee_refund" 20 | TxTransfer stripe.TransactionType = "transfer" 21 | TxTransferCancel stripe.TransactionType = "transfer_cancel" 22 | TxTransferFail stripe.TransactionType = "transfer_failure" 23 | ) 24 | 25 | // Client is used to invoke /balance and transaction-related APIs. 26 | type Client struct { 27 | B stripe.Backend 28 | Key string 29 | } 30 | 31 | // Get returns the details of your balance. 32 | // For more details see https://stripe.com/docs/api#retrieve_balance. 33 | func Get(params *stripe.BalanceParams) (*stripe.Balance, error) { 34 | return getC().Get(params) 35 | } 36 | 37 | func (c Client) Get(params *stripe.BalanceParams) (*stripe.Balance, error) { 38 | var body *url.Values 39 | var commonParams *stripe.Params 40 | 41 | if params != nil { 42 | commonParams = ¶ms.Params 43 | body = &url.Values{} 44 | params.AppendTo(body) 45 | } 46 | 47 | balance := &stripe.Balance{} 48 | err := c.B.Call("GET", "/balance", c.Key, body, commonParams, balance) 49 | 50 | return balance, err 51 | } 52 | 53 | // GetTx returns the details of a balance transaction. 54 | // For more details see https://stripe.com/docs/api#retrieve_balance_transaction. 55 | func GetTx(id string, params *stripe.TxParams) (*stripe.Transaction, error) { 56 | return getC().GetTx(id, params) 57 | } 58 | 59 | func (c Client) GetTx(id string, params *stripe.TxParams) (*stripe.Transaction, error) { 60 | var body *url.Values 61 | var commonParams *stripe.Params 62 | 63 | if params != nil { 64 | commonParams = ¶ms.Params 65 | body = &url.Values{} 66 | params.AppendTo(body) 67 | } 68 | 69 | balance := &stripe.Transaction{} 70 | err := c.B.Call("GET", "/balance/history/"+id, c.Key, body, commonParams, balance) 71 | 72 | return balance, err 73 | } 74 | 75 | // List returns a list of balance transactions. 76 | // For more details see https://stripe.com/docs/api#balance_history. 77 | func List(params *stripe.TxListParams) *Iter { 78 | return getC().List(params) 79 | } 80 | 81 | func (c Client) List(params *stripe.TxListParams) *Iter { 82 | var body *url.Values 83 | var lp *stripe.ListParams 84 | 85 | if params != nil { 86 | body = &url.Values{} 87 | 88 | if params.Created > 0 { 89 | body.Add("created", strconv.FormatInt(params.Created, 10)) 90 | } 91 | 92 | if params.Available > 0 { 93 | body.Add("available_on", strconv.FormatInt(params.Available, 10)) 94 | } 95 | 96 | if len(params.Currency) > 0 { 97 | body.Add("currency", params.Currency) 98 | } 99 | 100 | if len(params.Src) > 0 { 101 | body.Add("source", params.Src) 102 | } 103 | 104 | if len(params.Transfer) > 0 { 105 | body.Add("transfer", params.Transfer) 106 | } 107 | 108 | if len(params.Type) > 0 { 109 | body.Add("type", string(params.Type)) 110 | } 111 | 112 | params.AppendTo(body) 113 | lp = ¶ms.ListParams 114 | } 115 | 116 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 117 | type transactionList struct { 118 | stripe.ListMeta 119 | Values []*stripe.Transaction `json:"data"` 120 | } 121 | 122 | list := &transactionList{} 123 | err := c.B.Call("GET", "/balance/history", c.Key, &b, nil, list) 124 | 125 | ret := make([]interface{}, len(list.Values)) 126 | for i, v := range list.Values { 127 | ret[i] = v 128 | } 129 | 130 | return ret, list.ListMeta, err 131 | })} 132 | } 133 | 134 | // Iter is an iterator for lists of Transactions. 135 | // The embedded Iter carries methods with it; 136 | // see its documentation for details. 137 | type Iter struct { 138 | *stripe.Iter 139 | } 140 | 141 | // Charge returns the most recent Transaction 142 | // visited by a call to Next. 143 | func (i *Iter) Transaction() *stripe.Transaction { 144 | return i.Current().(*stripe.Transaction) 145 | } 146 | 147 | func getC() Client { 148 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 149 | } 150 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/balance/client_test.go: -------------------------------------------------------------------------------- 1 | package balance 2 | 3 | import ( 4 | "testing" 5 | 6 | stripe "github.com/stripe/stripe-go" 7 | "github.com/stripe/stripe-go/charge" 8 | "github.com/stripe/stripe-go/currency" 9 | . "github.com/stripe/stripe-go/utils" 10 | ) 11 | 12 | func init() { 13 | stripe.Key = GetTestKey() 14 | } 15 | 16 | func TestBalanceGet(t *testing.T) { 17 | target, err := Get(nil) 18 | 19 | if err != nil { 20 | t.Error(err) 21 | } 22 | 23 | if len(target.Available[0].Currency) == 0 { 24 | t.Errorf("Available currency is not set\n") 25 | } 26 | 27 | if len(target.Pending[0].Currency) == 0 { 28 | t.Errorf("Pending currency is not set\n") 29 | } 30 | } 31 | 32 | func TestBalanceGetTx(t *testing.T) { 33 | chargeParams := &stripe.ChargeParams{ 34 | Amount: 1002, 35 | Currency: currency.USD, 36 | Desc: "charge transaction", 37 | } 38 | chargeParams.SetSource(&stripe.CardParams{ 39 | Number: "378282246310005", 40 | Month: "06", 41 | Year: "20", 42 | }) 43 | 44 | res, _ := charge.New(chargeParams) 45 | 46 | target, err := GetTx(res.Tx.ID, nil) 47 | 48 | if err != nil { 49 | t.Error(err) 50 | } 51 | 52 | if uint64(target.Amount) != chargeParams.Amount { 53 | t.Errorf("Amount %v does not match expected amount %v\n", target.Amount, chargeParams.Amount) 54 | } 55 | 56 | if target.Currency != chargeParams.Currency { 57 | t.Errorf("Currency %q does not match expected currency %q\n", target.Currency, chargeParams.Currency) 58 | } 59 | 60 | if target.Desc != chargeParams.Desc { 61 | t.Errorf("Description %q does not match expected description %q\n", target.Desc, chargeParams.Desc) 62 | } 63 | 64 | if target.Available == 0 { 65 | t.Errorf("Available date is not set\n") 66 | } 67 | 68 | if target.Created == 0 { 69 | t.Errorf("Created date is not set\n") 70 | } 71 | 72 | if target.Fee == 0 { 73 | t.Errorf("Fee is not set\n") 74 | } 75 | 76 | if target.FeeDetails == nil || len(target.FeeDetails) != 1 { 77 | t.Errorf("Fee details are not set") 78 | } 79 | 80 | if target.FeeDetails[0].Amount == 0 { 81 | t.Errorf("Fee detail amount is not set\n") 82 | } 83 | 84 | if len(target.FeeDetails[0].Currency) == 0 { 85 | t.Errorf("Fee detail currency is not set\n") 86 | } 87 | 88 | if len(target.FeeDetails[0].Desc) == 0 { 89 | t.Errorf("Fee detail description is not set\n") 90 | } 91 | 92 | if target.Net == 0 { 93 | t.Errorf("Net is not set\n") 94 | } 95 | 96 | if target.Status != TxPending { 97 | t.Errorf("Status %v does not match expected value\n", target.Status) 98 | } 99 | 100 | if target.Type != TxCharge { 101 | t.Errorf("Type %v does not match expected value\n", target.Type) 102 | } 103 | 104 | if target.Src != res.ID { 105 | t.Errorf("Source %q does not match expeted value %q\n", target.Src, res.ID) 106 | } 107 | } 108 | 109 | func TestBalanceList(t *testing.T) { 110 | params := &stripe.TxListParams{} 111 | params.Filters.AddFilter("limit", "", "5") 112 | params.Single = true 113 | 114 | i := List(params) 115 | for i.Next() { 116 | if i.Transaction() == nil { 117 | t.Error("No nil values expected") 118 | } 119 | 120 | if i.Meta() == nil { 121 | t.Error("No metadata returned") 122 | } 123 | } 124 | if err := i.Err(); err != nil { 125 | t.Error(err) 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/bankaccount.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/url" 7 | ) 8 | 9 | // BankAccountStatus is the list of allowed values for the bank account's status. 10 | // Allowed values are "new", "verified", "validated", "errored". 11 | type BankAccountStatus string 12 | 13 | // BankAccountParams is the set of parameters that can be used when creating or updating a bank account. 14 | type BankAccountParams struct { 15 | Params 16 | 17 | // The identifier of the parent account under which bank accounts are 18 | // nested. 19 | AccountID string 20 | 21 | // A token referencing an external account like one returned from 22 | // Stripe.js. 23 | Token string 24 | 25 | // Information on an external account to reference. Only used if `Token` 26 | // is not provided. 27 | Account, Country, Currency, Routing string 28 | 29 | Default bool 30 | Customer string 31 | } 32 | 33 | // BankAccountListParams is the set of parameters that can be used when listing bank accounts. 34 | type BankAccountListParams struct { 35 | ListParams 36 | AccountID string 37 | } 38 | 39 | // BankAccount represents a Stripe bank account. 40 | type BankAccount struct { 41 | ID string `json:"id"` 42 | Name string `json:"bank_name"` 43 | Country string `json:"country"` 44 | Currency Currency `json:"currency"` 45 | LastFour string `json:"last4"` 46 | Fingerprint string `json:"fingerprint"` 47 | Status BankAccountStatus `json:"status"` 48 | Routing string `json:"routing_number"` 49 | Deleted bool `json:"deleted"` 50 | Customer *Customer `json:"customer"` 51 | } 52 | 53 | // BankAccountList is a list object for bank accounts. 54 | type BankAccountList struct { 55 | ListMeta 56 | Values []*BankAccount `json:"data"` 57 | } 58 | 59 | func (ba *BankAccount) Display() string { 60 | return fmt.Sprintf("Bank account ending in %s", ba.LastFour) 61 | } 62 | 63 | // AppendDetails adds the bank account's details to the query string values. 64 | func (b *BankAccountParams) AppendDetails(values *url.Values) { 65 | values.Add("bank_account[country]", b.Country) 66 | values.Add("bank_account[routing_number]", b.Routing) 67 | values.Add("bank_account[account_number]", b.Account) 68 | 69 | if len(b.Currency) > 0 { 70 | values.Add("bank_account[currency]", b.Currency) 71 | } 72 | } 73 | 74 | // UnmarshalJSON handles deserialization of a BankAccount. 75 | // This custom unmarshaling is needed because the resulting 76 | // property may be an id or the full struct if it was expanded. 77 | func (b *BankAccount) UnmarshalJSON(data []byte) error { 78 | type bankAccount BankAccount 79 | var bb bankAccount 80 | err := json.Unmarshal(data, &bb) 81 | if err == nil { 82 | *b = BankAccount(bb) 83 | } else { 84 | // the id is surrounded by "\" characters, so strip them 85 | b.ID = string(data[1 : len(data)-1]) 86 | } 87 | 88 | return nil 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/bankaccount/client.go: -------------------------------------------------------------------------------- 1 | // Package bankaccount provides the /bank_accounts APIs 2 | package bankaccount 3 | 4 | import ( 5 | "errors" 6 | "fmt" 7 | "net/url" 8 | "strconv" 9 | 10 | stripe "github.com/stripe/stripe-go" 11 | ) 12 | 13 | // Client is used to invoke /bank_accounts APIs. 14 | type Client struct { 15 | B stripe.Backend 16 | Key string 17 | } 18 | 19 | const ( 20 | NewAccount stripe.BankAccountStatus = "new" 21 | VerifiedAccount stripe.BankAccountStatus = "verified" 22 | ValidatedAccount stripe.BankAccountStatus = "validated" 23 | ErroredAccount stripe.BankAccountStatus = "errored" 24 | ) 25 | 26 | // New POSTs a new bank account. 27 | func New(params *stripe.BankAccountParams) (*stripe.BankAccount, error) { 28 | return getC().New(params) 29 | } 30 | 31 | func (c Client) New(params *stripe.BankAccountParams) (*stripe.BankAccount, error) { 32 | 33 | body := &url.Values{} 34 | 35 | // Use token (if exists) or a dictionary containing a user’s bank account details. 36 | if len(params.Token) > 0 { 37 | body.Add("external_account", params.Token) 38 | } else { 39 | body.Add("external_account[object]", "bank_account") 40 | body.Add("external_account[country]", params.Country) 41 | body.Add("external_account[account_number]", params.Account) 42 | body.Add("external_account[routing_number]", params.Routing) 43 | body.Add("external_account[currency]", params.Currency) 44 | 45 | if params.Default { 46 | body.Add("external_account[default_for_currency]", strconv.FormatBool(params.Default)) 47 | } 48 | } 49 | params.AppendTo(body) 50 | 51 | ba := &stripe.BankAccount{} 52 | err := c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts", params.AccountID), c.Key, body, ¶ms.Params, ba) 53 | 54 | return ba, err 55 | } 56 | 57 | // Get returns the details of a bank account. 58 | func Get(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { 59 | return getC().Get(id, params) 60 | } 61 | 62 | func (c Client) Get(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { 63 | var body *url.Values 64 | var commonParams *stripe.Params 65 | 66 | if params != nil { 67 | commonParams = ¶ms.Params 68 | body = &url.Values{} 69 | params.AppendTo(body) 70 | } 71 | 72 | ba := &stripe.BankAccount{} 73 | err := c.B.Call("GET", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba) 74 | 75 | return ba, err 76 | } 77 | 78 | // Update updates a bank account. 79 | func Update(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { 80 | return getC().Update(id, params) 81 | } 82 | 83 | func (c Client) Update(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { 84 | var body *url.Values 85 | var commonParams *stripe.Params 86 | 87 | if params != nil { 88 | commonParams = ¶ms.Params 89 | body = &url.Values{} 90 | 91 | if params.Default { 92 | body.Add("default_for_currency", strconv.FormatBool(params.Default)) 93 | } 94 | 95 | params.AppendTo(body) 96 | } 97 | 98 | ba := &stripe.BankAccount{} 99 | err := c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba) 100 | 101 | return ba, err 102 | } 103 | 104 | // Del removes a bank account. 105 | func Del(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { 106 | return getC().Del(id, params) 107 | } 108 | 109 | func (c Client) Del(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) { 110 | ba := &stripe.BankAccount{} 111 | var err error 112 | 113 | if len(params.Customer) > 0 { 114 | err = c.B.Call("DELETE", fmt.Sprintf("/customers/%v/bank_accounts/%v", params.Customer, id), c.Key, nil, nil, ba) 115 | } else if len(params.AccountID) > 0 { 116 | err = c.B.Call("DELETE", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, nil, nil, ba) 117 | } else { 118 | err = errors.New("Invalid bank account params: either customer or AccountID need to be set") 119 | } 120 | 121 | return ba, err 122 | } 123 | 124 | // List returns a list of bank accounts. 125 | func List(params *stripe.BankAccountListParams) *Iter { 126 | return getC().List(params) 127 | } 128 | 129 | func (c Client) List(params *stripe.BankAccountListParams) *Iter { 130 | body := &url.Values{} 131 | var lp *stripe.ListParams 132 | 133 | params.AppendTo(body) 134 | lp = ¶ms.ListParams 135 | 136 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 137 | list := &stripe.BankAccountList{} 138 | err := c.B.Call("GET", fmt.Sprintf("/accounts/%v/bank_accounts", params.AccountID), c.Key, &b, nil, list) 139 | 140 | ret := make([]interface{}, len(list.Values)) 141 | for i, v := range list.Values { 142 | ret[i] = v 143 | } 144 | 145 | return ret, list.ListMeta, err 146 | })} 147 | } 148 | 149 | // Iter is an iterator for lists of BankAccount. 150 | // The embedded Iter carries methods with it; 151 | // see its documentation for details. 152 | type Iter struct { 153 | *stripe.Iter 154 | } 155 | 156 | // BankAccount returns the most recent BankAccount 157 | // visited by a call to Next. 158 | func (i *Iter) BankAccount() *stripe.BankAccount { 159 | return i.Current().(*stripe.BankAccount) 160 | } 161 | 162 | func getC() Client { 163 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 164 | } 165 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/bankaccount/client_test.go: -------------------------------------------------------------------------------- 1 | package bankaccount 2 | 3 | import ( 4 | "testing" 5 | 6 | stripe "github.com/stripe/stripe-go" 7 | "github.com/stripe/stripe-go/customer" 8 | "github.com/stripe/stripe-go/token" 9 | . "github.com/stripe/stripe-go/utils" 10 | ) 11 | 12 | func init() { 13 | stripe.Key = GetTestKey() 14 | } 15 | 16 | func TestBankAccountDel(t *testing.T) { 17 | baTok, err := token.New(&stripe.TokenParams{ 18 | Bank: &stripe.BankAccountParams{ 19 | Country: "US", 20 | Currency: "usd", 21 | Routing: "110000000", 22 | Account: "000123456789", 23 | }, 24 | }) 25 | if err != nil { 26 | t.Error(err) 27 | } 28 | 29 | customerParams := &stripe.CustomerParams{} 30 | customerParams.SetSource(baTok.ID) 31 | cust, _ := customer.New(customerParams) 32 | if err != nil { 33 | t.Error(err) 34 | } 35 | 36 | baDel, err := Del(cust.DefaultSource.ID, &stripe.BankAccountParams{Customer: cust.ID}) 37 | if err != nil { 38 | t.Error(err) 39 | } 40 | 41 | if !baDel.Deleted { 42 | t.Errorf("Bank account id %q expected to be marked as deleted on the returned resource\n", baDel.ID) 43 | } 44 | 45 | customer.Del(cust.ID) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/bitcoin_receiver.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | // BitcoinReceiverListParams is the set of parameters that can be used when listing BitcoinReceivers. 9 | // For more details see https://stripe.com/docs/api/#list_bitcoin_receivers. 10 | type BitcoinReceiverListParams struct { 11 | ListParams 12 | NotFilled, NotActive, Uncaptured bool 13 | } 14 | 15 | // BitcoinReceiverParams is the set of parameters that can be used when creating a BitcoinReceiver. 16 | // For more details see https://stripe.com/docs/api/#create_bitcoin_receiver. 17 | type BitcoinReceiverParams struct { 18 | Params 19 | Amount uint64 20 | Currency Currency 21 | Desc, Email string 22 | } 23 | 24 | // BitcoinReceiverParams is the set of parameters that can be used when updating a BitcoinReceiver. 25 | // For more details see https://stripe.com/docs/api/#update_bitcoin_receiver. 26 | type BitcoinReceiverUpdateParams struct { 27 | Params 28 | Desc, Email, RefundAddr string 29 | } 30 | 31 | // BitcoinReceiver is the resource representing a Stripe bitcoin receiver. 32 | // For more details see https://stripe.com/docs/api/#bitcoin_receivers 33 | type BitcoinReceiver struct { 34 | ID string `json:"id"` 35 | Created int64 `json:"created"` 36 | Currency Currency `json:"currency"` 37 | Amount uint64 `json:"amount"` 38 | AmountReceived uint64 `json:"amount_received"` 39 | BitcoinAmount uint64 `json:"bitcoin_amount"` 40 | BitcoinAmountReceived uint64 `json:"bitcoin_amount_received"` 41 | Filled bool `json:"filled"` 42 | Active bool `json:"active"` 43 | RejectTransactions bool `json:"reject_transactions"` 44 | Desc string `json:"description"` 45 | InboundAddress string `json:"inbound_address"` 46 | RefundAddress string `json:"refund_address"` 47 | BitcoinUri string `json:"bitcoin_uri"` 48 | Meta map[string]string `json:"metadata"` 49 | Email string `json:"email"` 50 | Payment string `json:"payment"` 51 | Customer string `json:"customer"` 52 | Transactions *BitcoinTransactionList `json:"transactions"` 53 | } 54 | 55 | // Display human readable representation of a BitcoinReceiver. 56 | func (br *BitcoinReceiver) Display() string { 57 | var filled string 58 | if br.Filled { 59 | filled = "Filled" 60 | } else if br.BitcoinAmountReceived > 0 { 61 | filled = "Partially filled" 62 | } else { 63 | filled = "Unfilled" 64 | } 65 | return fmt.Sprintf("%s bitcoin receiver (%d/%d %s)", filled, br.AmountReceived, br.Amount, br.Currency) 66 | } 67 | 68 | // UnmarshalJSON handles deserialization of a BitcoinReceiver. 69 | // This custom unmarshaling is needed because the resulting 70 | // property may be an id or the full struct if it was expanded. 71 | func (br *BitcoinReceiver) UnmarshalJSON(data []byte) error { 72 | type bitcoinReceiver BitcoinReceiver 73 | var r bitcoinReceiver 74 | err := json.Unmarshal(data, &r) 75 | if err == nil { 76 | *br = BitcoinReceiver(r) 77 | } else { 78 | // the id is surrounded by "\" characters, so strip them 79 | br.ID = string(data[1 : len(data)-1]) 80 | } 81 | 82 | return nil 83 | } 84 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/bitcoin_transaction.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // BitcoinTransactionListParams is the set of parameters that can be used when listing BitcoinTransactions. 6 | type BitcoinTransactionListParams struct { 7 | ListParams 8 | Receiver, Customer string 9 | } 10 | 11 | // BitcoinTransactionList is a list object for BitcoinTransactions. 12 | // It is a child object of BitcoinRecievers 13 | // For more details see https://stripe.com/docs/api/#retrieve_bitcoin_receiver 14 | type BitcoinTransactionList struct { 15 | ListMeta 16 | Values []*BitcoinTransaction `json:"data"` 17 | } 18 | 19 | // BitcoinTransaction is the resource representing a Stripe bitcoin transaction. 20 | // For more details see https://stripe.com/docs/api/#bitcoin_receivers 21 | type BitcoinTransaction struct { 22 | ID string `json:"id"` 23 | Created int64 `json:"created"` 24 | Amount uint64 `json:"amount"` 25 | Currency Currency `json:"currency"` 26 | BitcoinAmount uint64 `json:"bitcoin_amount"` 27 | Receiver string `json:"receiver"` 28 | Customer string `json:"customer"` 29 | } 30 | 31 | // UnmarshalJSON handles deserialization of a BitcoinTransaction. 32 | // This custom unmarshaling is needed because the resulting 33 | // property may be an id or the full struct if it was expanded. 34 | func (bt *BitcoinTransaction) UnmarshalJSON(data []byte) error { 35 | type bitcoinTransaction BitcoinTransaction 36 | var t bitcoinTransaction 37 | err := json.Unmarshal(data, &t) 38 | if err == nil { 39 | *bt = BitcoinTransaction(t) 40 | } else { 41 | // the id is surrounded by "\" characters, so strip them 42 | bt.ID = string(data[1 : len(data)-1]) 43 | } 44 | 45 | return nil 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/bitcoinreceiver/client.go: -------------------------------------------------------------------------------- 1 | // Package bitcoinreceiver provides the /bitcoin/receivers APIs. 2 | package bitcoinreceiver 3 | 4 | import ( 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | 9 | stripe "github.com/stripe/stripe-go" 10 | ) 11 | 12 | // Client is used to invoke /bitcoin/receivers APIs. 13 | type Client struct { 14 | B stripe.Backend 15 | Key string 16 | } 17 | 18 | // New POSTs new bitcoin receivers. 19 | // For more details see https://stripe.com/docs/api/#create_bitcoin_receiver 20 | func New(params *stripe.BitcoinReceiverParams) (*stripe.BitcoinReceiver, error) { 21 | return getC().New(params) 22 | } 23 | 24 | func (c Client) New(params *stripe.BitcoinReceiverParams) (*stripe.BitcoinReceiver, error) { 25 | body := &url.Values{ 26 | "amount": {strconv.FormatUint(params.Amount, 10)}, 27 | "currency": {string(params.Currency)}, 28 | } 29 | 30 | if len(params.Desc) > 0 { 31 | body.Add("description", params.Desc) 32 | } 33 | 34 | if len(params.Email) > 0 { 35 | body.Add("email", params.Email) 36 | } 37 | 38 | token := c.Key 39 | 40 | params.AppendTo(body) 41 | 42 | receiver := &stripe.BitcoinReceiver{} 43 | err := c.B.Call("POST", "/bitcoin/receivers", token, body, ¶ms.Params, receiver) 44 | 45 | return receiver, err 46 | } 47 | 48 | // Get returns the details of a bitcoin receiver. 49 | // For more details see https://stripe.com/docs/api/#retrieve_bitcoin_receiver 50 | func Get(id string, params *stripe.BitcoinReceiverParams) (*stripe.BitcoinReceiver, error) { 51 | return getC().Get(id, params) 52 | } 53 | 54 | func (c Client) Get(id string, params *stripe.BitcoinReceiverParams) (*stripe.BitcoinReceiver, error) { 55 | var commonParams *stripe.Params 56 | 57 | if params != nil { 58 | commonParams = ¶ms.Params 59 | } 60 | 61 | bitcoinReceiver := &stripe.BitcoinReceiver{} 62 | err := c.B.Call("GET", "/bitcoin/receivers/"+id, c.Key, nil, commonParams, bitcoinReceiver) 63 | 64 | return bitcoinReceiver, err 65 | } 66 | 67 | // Update updates a bitcoin receiver's properties. 68 | // For more details see https://stripe.com/docs/api#update_bitcoin_receiver. 69 | func Update(id string, params *stripe.BitcoinReceiverUpdateParams) (*stripe.BitcoinReceiver, error) { 70 | return getC().Update(id, params) 71 | } 72 | 73 | func (c Client) Update(id string, params *stripe.BitcoinReceiverUpdateParams) (*stripe.BitcoinReceiver, error) { 74 | body := &url.Values{} 75 | 76 | if len(params.Desc) > 0 { 77 | body.Add("description", params.Desc) 78 | } 79 | 80 | if len(params.Email) > 0 { 81 | body.Add("email", params.Email) 82 | } 83 | 84 | if len(params.RefundAddr) > 0 { 85 | body.Add("refund_address", params.RefundAddr) 86 | } 87 | 88 | receiver := &stripe.BitcoinReceiver{} 89 | var err error 90 | 91 | err = c.B.Call("POST", fmt.Sprintf("/bitcoin/receivers/%v", id), c.Key, body, ¶ms.Params, receiver) 92 | 93 | return receiver, err 94 | } 95 | 96 | // List returns a list of bitcoin receivers. 97 | // For more details see https://stripe.com/docs/api/#list_bitcoin_receivers 98 | func List(params *stripe.BitcoinReceiverListParams) *Iter { 99 | return getC().List(params) 100 | } 101 | 102 | func (c Client) List(params *stripe.BitcoinReceiverListParams) *Iter { 103 | type receiverList struct { 104 | stripe.ListMeta 105 | Values []*stripe.BitcoinReceiver `json:"data"` 106 | } 107 | 108 | var body *url.Values 109 | var lp *stripe.ListParams 110 | 111 | if params != nil { 112 | body = &url.Values{} 113 | 114 | body.Add("filled", strconv.FormatBool(!params.NotFilled)) 115 | body.Add("active", strconv.FormatBool(!params.NotActive)) 116 | body.Add("uncaptured_funds", strconv.FormatBool(params.Uncaptured)) 117 | 118 | params.AppendTo(body) 119 | lp = ¶ms.ListParams 120 | } 121 | 122 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 123 | list := &receiverList{} 124 | err := c.B.Call("GET", "/bitcoin/receivers", c.Key, &b, nil, list) 125 | 126 | ret := make([]interface{}, len(list.Values)) 127 | for i, v := range list.Values { 128 | ret[i] = v 129 | } 130 | 131 | return ret, list.ListMeta, err 132 | })} 133 | } 134 | 135 | // Iter is an iterator for lists of BitcoinReceivers. 136 | // The embedded Iter carries methods with it; 137 | // see its documentation for details. 138 | type Iter struct { 139 | *stripe.Iter 140 | } 141 | 142 | // BitcoinReceiver returns the most recent BitcoinReceiver 143 | // visited by a call to Next. 144 | func (i *Iter) BitcoinReceiver() *stripe.BitcoinReceiver { 145 | return i.Current().(*stripe.BitcoinReceiver) 146 | } 147 | 148 | func getC() Client { 149 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 150 | } 151 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/bitcoinreceiver/client_test.go: -------------------------------------------------------------------------------- 1 | package bitcoinreceiver 2 | 3 | import ( 4 | "testing" 5 | 6 | stripe "github.com/stripe/stripe-go" 7 | "github.com/stripe/stripe-go/currency" 8 | . "github.com/stripe/stripe-go/utils" 9 | ) 10 | 11 | func init() { 12 | stripe.Key = GetTestKey() 13 | } 14 | 15 | func TestBitcoinReceiverNew(t *testing.T) { 16 | bitcoinReceiverParams := &stripe.BitcoinReceiverParams{ 17 | Amount: 1000, 18 | Currency: currency.USD, 19 | Email: "a@b.com", 20 | Desc: "some details", 21 | } 22 | 23 | target, err := New(bitcoinReceiverParams) 24 | 25 | if err != nil { 26 | t.Error(err) 27 | } 28 | 29 | if target.Amount != bitcoinReceiverParams.Amount { 30 | t.Errorf("Amount %v does not match expected amount %v\n", target.Amount, bitcoinReceiverParams.Amount) 31 | } 32 | 33 | if target.Currency != bitcoinReceiverParams.Currency { 34 | t.Errorf("Currency %q does not match expected currency %q\n", target.Currency, bitcoinReceiverParams.Currency) 35 | } 36 | 37 | if target.Desc != bitcoinReceiverParams.Desc { 38 | t.Errorf("Desc %q does not match expected description %v\n", target.Desc, bitcoinReceiverParams.Desc) 39 | } 40 | 41 | if target.Email != bitcoinReceiverParams.Email { 42 | t.Errorf("Email %q does not match expected email %v\n", target.Email, bitcoinReceiverParams.Email) 43 | } 44 | } 45 | 46 | func TestBitcoinReceiverGet(t *testing.T) { 47 | bitcoinReceiverParams := &stripe.BitcoinReceiverParams{ 48 | Amount: 1000, 49 | Currency: currency.USD, 50 | Email: "a@b.com", 51 | Desc: "some details", 52 | } 53 | 54 | res, _ := New(bitcoinReceiverParams) 55 | 56 | target, err := Get(res.ID, nil) 57 | 58 | if err != nil { 59 | t.Error(err) 60 | } 61 | 62 | if target.ID != res.ID { 63 | t.Errorf("BitcoinReceiver id %q does not match expected id %q\n", target.ID, res.ID) 64 | } 65 | } 66 | 67 | func TestBitcoinReceiverTransactionsGet(t *testing.T) { 68 | bitcoinReceiverParams := &stripe.BitcoinReceiverParams{ 69 | Amount: 1000, 70 | Currency: currency.USD, 71 | Email: "do+fill_now@stripe.com", 72 | Desc: "some details", 73 | } 74 | 75 | res, _ := New(bitcoinReceiverParams) 76 | 77 | target, err := Get(res.ID, nil) 78 | 79 | if err != nil { 80 | t.Error(err) 81 | } 82 | 83 | if target.ID != res.ID { 84 | t.Errorf("BitcoinReceiver id %q does not match expected id %q\n", target.ID, res.ID) 85 | } 86 | 87 | if target.Transactions == nil { 88 | t.Errorf("Expected BitcoinReceiver to have a BitcoinTransactionList") 89 | } 90 | 91 | if len(target.Transactions.Values) != 1 { 92 | t.Errorf("Bitcoin receiver should have 1 transaction") 93 | } 94 | } 95 | 96 | func TestBitcoinReceiverUpdate(t *testing.T) { 97 | bitcoinReceiverParams := &stripe.BitcoinReceiverParams{ 98 | Amount: 1000, 99 | Currency: currency.USD, 100 | Email: "do+fill_now@stripe.com", 101 | Desc: "some details", 102 | } 103 | 104 | receiver, err := New(bitcoinReceiverParams) 105 | 106 | if err != nil { 107 | t.Error(err) 108 | } 109 | 110 | updateParams := &stripe.BitcoinReceiverUpdateParams{ 111 | Desc: "some other details", 112 | } 113 | 114 | target, err := Update(receiver.ID, updateParams) 115 | 116 | if err != nil { 117 | t.Error(err) 118 | } 119 | 120 | if target.Desc != updateParams.Desc { 121 | t.Errorf("Description %q does not match expected name %q\n", target.Desc, updateParams.Desc) 122 | } 123 | } 124 | 125 | func TestBitcoinReceiverList(t *testing.T) { 126 | params := &stripe.BitcoinReceiverListParams{} 127 | params.Filters.AddFilter("limit", "", "5") 128 | params.Single = true 129 | 130 | i := List(params) 131 | for i.Next() { 132 | if i.BitcoinReceiver() == nil { 133 | t.Error("No nil values expected") 134 | } 135 | 136 | if i.Meta() == nil { 137 | t.Error("No metadata returned") 138 | } 139 | } 140 | if err := i.Err(); err != nil { 141 | t.Error(err) 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/bitcointransaction/client.go: -------------------------------------------------------------------------------- 1 | // Package bitcointransaction provides the /bitcoin/transactions APIs. 2 | package bitcointransaction 3 | 4 | import ( 5 | "fmt" 6 | "net/url" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | ) 10 | 11 | // Client is used to invoke /bitcoin/receivers/:receiver_id/transactions APIs. 12 | type Client struct { 13 | B stripe.Backend 14 | Key string 15 | } 16 | 17 | // List returns a list of bitcoin transactions. 18 | // For more details see https://stripe.com/docs/api#retrieve_bitcoin_receiver. 19 | func List(params *stripe.BitcoinTransactionListParams) *Iter { 20 | return getC().List(params) 21 | } 22 | 23 | func (c Client) List(params *stripe.BitcoinTransactionListParams) *Iter { 24 | type receiverList struct { 25 | stripe.ListMeta 26 | Values []*stripe.BitcoinTransaction `json:"data"` 27 | } 28 | 29 | var body *url.Values 30 | var lp *stripe.ListParams 31 | 32 | if params != nil { 33 | body = &url.Values{} 34 | 35 | if len(params.Customer) > 0 { 36 | body.Add("customer", params.Customer) 37 | } 38 | 39 | params.AppendTo(body) 40 | lp = ¶ms.ListParams 41 | } 42 | 43 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 44 | list := &receiverList{} 45 | err := c.B.Call("GET", fmt.Sprintf("/bitcoin/receivers/%v/transactions", params.Receiver), c.Key, &b, nil, list) 46 | 47 | ret := make([]interface{}, len(list.Values)) 48 | for i, v := range list.Values { 49 | ret[i] = v 50 | } 51 | 52 | return ret, list.ListMeta, err 53 | })} 54 | } 55 | 56 | // Iter is an iterator for lists of BitcoinTransactions. 57 | // The embedded Iter carries methods with it; 58 | // see its documentation for details. 59 | type Iter struct { 60 | *stripe.Iter 61 | } 62 | 63 | // BitcoinTransaction returns the most recent BitcoinTransaction 64 | // visited by a call to Next. 65 | func (i *Iter) BitcoinTransaction() *stripe.BitcoinTransaction { 66 | return i.Current().(*stripe.BitcoinTransaction) 67 | } 68 | 69 | func getC() Client { 70 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 71 | } 72 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/bitcointransaction/client_test.go: -------------------------------------------------------------------------------- 1 | package bitcointransaction 2 | 3 | import ( 4 | "testing" 5 | 6 | stripe "github.com/stripe/stripe-go" 7 | "github.com/stripe/stripe-go/bitcoinreceiver" 8 | "github.com/stripe/stripe-go/currency" 9 | . "github.com/stripe/stripe-go/utils" 10 | ) 11 | 12 | func init() { 13 | stripe.Key = GetTestKey() 14 | } 15 | 16 | func TestBitcoinTransactionList(t *testing.T) { 17 | bitcoinReceiverParams := &stripe.BitcoinReceiverParams{ 18 | Amount: 1000, 19 | Currency: currency.USD, 20 | Email: "do+fill_now@stripe.com", 21 | Desc: "some details", 22 | } 23 | 24 | r, _ := bitcoinreceiver.New(bitcoinReceiverParams) 25 | 26 | params := &stripe.BitcoinTransactionListParams{ 27 | Receiver: r.ID, 28 | } 29 | params.Filters.AddFilter("limit", "", "5") 30 | params.Single = true 31 | 32 | i := List(params) 33 | for i.Next() { 34 | if i.BitcoinTransaction() == nil { 35 | t.Error("No nil values expected") 36 | } 37 | 38 | if i.Meta() == nil { 39 | t.Error("No metadata returned") 40 | } 41 | } 42 | if err := i.Err(); err != nil { 43 | t.Error(err) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/card.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "fmt" 7 | "net/url" 8 | ) 9 | 10 | // CardBrand is the list of allowed values for the card's brand. 11 | // Allowed values are "Unknown", "Visa", "American Express", "MasterCard", "Discover" 12 | // "JCB", "Diners Club". 13 | type CardBrand string 14 | 15 | // Verification is the list of allowed verification responses. 16 | // Allowed values are "pass", "fail", "unchecked", "unavailabe". 17 | type Verification string 18 | 19 | // CardFunding is the list of allowed values for the card's funding. 20 | // Allowed values are "credit", "debit", "prepaid", "unknown". 21 | type CardFunding string 22 | 23 | // CardParams is the set of parameters that can be used when creating or updating a card. 24 | // For more details see https://stripe.com/docs/api#create_card and https://stripe.com/docs/api#update_card. 25 | type CardParams struct { 26 | Params 27 | Token string 28 | Customer, Recipient string 29 | Name, Number, Month, Year, CVC string 30 | Address1, Address2, City, State, Zip, Country string 31 | } 32 | 33 | // CardListParams is the set of parameters that can be used when listing cards. 34 | // For more details see https://stripe.com/docs/api#list_cards. 35 | type CardListParams struct { 36 | ListParams 37 | Customer, Recipient string 38 | } 39 | 40 | // Card is the resource representing a Stripe credit/debit card. 41 | // For more details see https://stripe.com/docs/api#cards. 42 | type Card struct { 43 | ID string `json:"id"` 44 | Month uint8 `json:"exp_month"` 45 | Year uint16 `json:"exp_year"` 46 | Fingerprint string `json:"fingerprint"` 47 | Funding CardFunding `json:"funding"` 48 | LastFour string `json:"last4"` 49 | Brand CardBrand `json:"brand"` 50 | City string `json:"address_city"` 51 | Country string `json:"address_country"` 52 | Address1 string `json:"address_line1"` 53 | Address1Check Verification `json:"address_line1_check"` 54 | Address2 string `json:"address_line2"` 55 | State string `json:"address_state"` 56 | Zip string `json:"address_zip"` 57 | ZipCheck Verification `json:"address_zip_check"` 58 | CardCountry string `json:"country"` 59 | Customer *Customer `json:"customer"` 60 | CVCCheck Verification `json:"cvc_check"` 61 | Name string `json:"name"` 62 | Recipient *Recipient `json:"recipient"` 63 | DynLastFour string `json:"dynamic_last4"` 64 | Deleted bool `json:"deleted"` 65 | } 66 | 67 | // CardList is a list object for cards. 68 | type CardList struct { 69 | ListMeta 70 | Values []*Card `json:"data"` 71 | } 72 | 73 | // AppendDetails adds the card's details to the query string values. 74 | // When creating a new card, the parameters are passed as a dictionary, but 75 | // on updates they are simply the parameter name. 76 | func (c *CardParams) AppendDetails(values *url.Values, creating bool) { 77 | if creating { 78 | if len(c.Token) > 0 { 79 | values.Add("card", c.Token) 80 | } else { 81 | values.Add("card[object]", "card") 82 | values.Add("card[number]", c.Number) 83 | values.Add("card[exp_month]", c.Month) 84 | values.Add("card[exp_year]", c.Year) 85 | 86 | if len(c.CVC) > 0 { 87 | values.Add("card[cvc]", c.CVC) 88 | } 89 | } 90 | } 91 | 92 | if len(c.Name) > 0 { 93 | if creating { 94 | values.Add("card[name]", c.Name) 95 | } else { 96 | values.Add("name", c.Name) 97 | } 98 | } 99 | 100 | if len(c.Address1) > 0 { 101 | if creating { 102 | values.Add("card[address_line1]", c.Address1) 103 | } else { 104 | values.Add("address_line1", c.Address1) 105 | } 106 | } 107 | 108 | if len(c.Address2) > 0 { 109 | if creating { 110 | values.Add("card[address_line2]", c.Address2) 111 | } else { 112 | values.Add("address_line2", c.Address2) 113 | } 114 | } 115 | 116 | if len(c.City) > 0 { 117 | if creating { 118 | values.Add("card[address_city]", c.City) 119 | } else { 120 | values.Add("address_city", c.City) 121 | } 122 | } 123 | 124 | if len(c.State) > 0 { 125 | if creating { 126 | values.Add("card[address_state]", c.State) 127 | } else { 128 | values.Add("address_state", c.State) 129 | } 130 | } 131 | 132 | if len(c.Zip) > 0 { 133 | if creating { 134 | values.Add("card[address_zip]", c.Zip) 135 | } else { 136 | values.Add("address_zip", c.Zip) 137 | } 138 | } 139 | 140 | if len(c.Country) > 0 { 141 | if creating { 142 | values.Add("card[address_country]", c.Country) 143 | } else { 144 | values.Add("address_country", c.Country) 145 | } 146 | } 147 | } 148 | 149 | // Display human readable representation of a Card. 150 | func (c *Card) Display() string { 151 | return fmt.Sprintf("%s ending in %s", c.Brand, c.LastFour) 152 | } 153 | 154 | // UnmarshalJSON handles deserialization of a Card. 155 | // This custom unmarshaling is needed because the resulting 156 | // property may be an id or the full struct if it was expanded. 157 | func (c *Card) UnmarshalJSON(data []byte) error { 158 | type card Card 159 | var cc card 160 | err := json.Unmarshal(data, &cc) 161 | if err == nil { 162 | *c = Card(cc) 163 | } else { 164 | // the id is surrounded by "\" characters, so strip them 165 | c.ID = string(data[1 : len(data)-1]) 166 | } 167 | 168 | return nil 169 | } 170 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/card/client_test.go: -------------------------------------------------------------------------------- 1 | package card 2 | 3 | import ( 4 | "testing" 5 | 6 | stripe "github.com/stripe/stripe-go" 7 | "github.com/stripe/stripe-go/customer" 8 | "github.com/stripe/stripe-go/recipient" 9 | . "github.com/stripe/stripe-go/utils" 10 | ) 11 | 12 | func init() { 13 | stripe.Key = GetTestKey() 14 | } 15 | 16 | func TestCardNew(t *testing.T) { 17 | customerParams := &stripe.CustomerParams{} 18 | customerParams.SetSource(&stripe.CardParams{ 19 | Number: "378282246310005", 20 | Month: "06", 21 | Year: "20", 22 | }) 23 | 24 | cust, _ := customer.New(customerParams) 25 | 26 | cardParams := &stripe.CardParams{ 27 | Number: "4242424242424242", 28 | Month: "10", 29 | Year: "20", 30 | Customer: cust.ID, 31 | CVC: "1234", 32 | } 33 | 34 | target, err := New(cardParams) 35 | 36 | if err != nil { 37 | t.Error(err) 38 | } 39 | 40 | if target.LastFour != "4242" { 41 | t.Errorf("Unexpected last four %q for card number %v\n", target.LastFour, cardParams.Number) 42 | } 43 | 44 | if target.CVCCheck != Pass { 45 | t.Errorf("CVC check %q does not match expected status\n", target.ZipCheck) 46 | } 47 | 48 | targetCust, err := customer.Get(cust.ID, nil) 49 | 50 | if err != nil { 51 | t.Error(err) 52 | } 53 | 54 | if targetCust.Sources.Count != 2 { 55 | t.Errorf("Unexpected number of sources %v\n", targetCust.Sources.Count) 56 | } 57 | 58 | customer.Del(cust.ID) 59 | } 60 | 61 | func TestCardGet(t *testing.T) { 62 | recipientParams := &stripe.RecipientParams{ 63 | Name: "Test Recipient", 64 | Type: recipient.Corp, 65 | Card: &stripe.CardParams{ 66 | Number: "5200828282828210", 67 | Month: "06", 68 | Year: "20", 69 | }, 70 | } 71 | 72 | rec, _ := recipient.New(recipientParams) 73 | 74 | target, err := Get(rec.DefaultCard.ID, &stripe.CardParams{Recipient: rec.ID}) 75 | 76 | if err != nil { 77 | t.Error(err) 78 | } 79 | 80 | if target.LastFour != "8210" { 81 | t.Errorf("Unexpected last four %q for card number %v\n", target.LastFour, recipientParams.Card.Number) 82 | } 83 | 84 | if target.Brand != MasterCard { 85 | t.Errorf("Card brand %q does not match expected value\n", target.Brand) 86 | } 87 | 88 | if target.Funding != Debit { 89 | t.Errorf("Card funding %q does not match expected value\n", target.Funding) 90 | } 91 | 92 | recipient.Del(rec.ID) 93 | } 94 | 95 | func TestCardDel(t *testing.T) { 96 | customerParams := &stripe.CustomerParams{} 97 | customerParams.SetSource(&stripe.CardParams{ 98 | Number: "378282246310005", 99 | Month: "06", 100 | Year: "20", 101 | }) 102 | 103 | cust, _ := customer.New(customerParams) 104 | 105 | cardDel, err := Del(cust.DefaultSource.ID, &stripe.CardParams{Customer: cust.ID}) 106 | if err != nil { 107 | t.Error(err) 108 | } 109 | 110 | if !cardDel.Deleted { 111 | t.Errorf("Card id %q expected to be marked as deleted on the returned resource\n", cardDel.ID) 112 | } 113 | 114 | customer.Del(cust.ID) 115 | } 116 | 117 | func TestCardUpdate(t *testing.T) { 118 | customerParams := &stripe.CustomerParams{} 119 | customerParams.SetSource(&stripe.CardParams{ 120 | Number: "378282246310005", 121 | Month: "06", 122 | Year: "20", 123 | Name: "Original Name", 124 | }) 125 | 126 | cust, err := customer.New(customerParams) 127 | 128 | if err != nil { 129 | t.Error(err) 130 | } 131 | 132 | cardParams := &stripe.CardParams{ 133 | Customer: cust.ID, 134 | Name: "Updated Name", 135 | } 136 | 137 | target, err := Update(cust.DefaultSource.ID, cardParams) 138 | 139 | if err != nil { 140 | t.Error(err) 141 | } 142 | 143 | if target.Name != cardParams.Name { 144 | t.Errorf("Card name %q does not match expected name %q\n", target.Name, cardParams.Name) 145 | } 146 | 147 | customer.Del(cust.ID) 148 | } 149 | 150 | func TestCardList(t *testing.T) { 151 | customerParams := &stripe.CustomerParams{} 152 | customerParams.SetSource(&stripe.CardParams{ 153 | Number: "378282246310005", 154 | Month: "06", 155 | Year: "20", 156 | }) 157 | 158 | cust, _ := customer.New(customerParams) 159 | 160 | card := &stripe.CardParams{ 161 | Number: "4242424242424242", 162 | Month: "10", 163 | Year: "20", 164 | Customer: cust.ID, 165 | } 166 | 167 | New(card) 168 | 169 | i := List(&stripe.CardListParams{Customer: cust.ID}) 170 | for i.Next() { 171 | if i.Card() == nil { 172 | t.Error("No nil values expected") 173 | } 174 | 175 | if i.Meta() == nil { 176 | t.Error("No metadata returned") 177 | } 178 | } 179 | if err := i.Err(); err != nil { 180 | t.Error(err) 181 | } 182 | 183 | customer.Del(cust.ID) 184 | } 185 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/charge.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "encoding/json" 5 | "net/url" 6 | ) 7 | 8 | // Currency is the list of supported currencies. 9 | // For more details see https://support.stripe.com/questions/which-currencies-does-stripe-support. 10 | type Currency string 11 | 12 | // FraudReport is the list of allowed values for reporting fraud. 13 | // Allowed values are "fraudulent", "safe". 14 | type FraudReport string 15 | 16 | // ChargeParams is the set of parameters that can be used when creating or updating a charge. 17 | // For more details see https://stripe.com/docs/api#create_charge and https://stripe.com/docs/api#update_charge. 18 | type ChargeParams struct { 19 | Params 20 | Amount uint64 21 | Currency Currency 22 | Customer, Token string 23 | Desc, Statement, Email, Dest string 24 | NoCapture bool 25 | Fee uint64 26 | Fraud FraudReport 27 | Source *SourceParams 28 | Shipping *ShippingDetails 29 | } 30 | 31 | // SetSource adds valid sources to a ChargeParams object, 32 | // returning an error for unsupported sources. 33 | func (cp *ChargeParams) SetSource(sp interface{}) error { 34 | source, err := SourceParamsFor(sp) 35 | cp.Source = source 36 | return err 37 | } 38 | 39 | // ChargeListParams is the set of parameters that can be used when listing charges. 40 | // For more details see https://stripe.com/docs/api#list_charges. 41 | type ChargeListParams struct { 42 | ListParams 43 | Created int64 44 | Customer string 45 | } 46 | 47 | // CaptureParams is the set of parameters that can be used when capturing a charge. 48 | // For more details see https://stripe.com/docs/api#charge_capture. 49 | type CaptureParams struct { 50 | Params 51 | Amount, Fee uint64 52 | Email string 53 | } 54 | 55 | // Charge is the resource representing a Stripe charge. 56 | // For more details see https://stripe.com/docs/api#charges. 57 | type Charge struct { 58 | ID string `json:"id"` 59 | Live bool `json:"livemode"` 60 | Amount uint64 `json:"amount"` 61 | Captured bool `json:"captured"` 62 | Created int64 `json:"created"` 63 | Currency Currency `json:"currency"` 64 | Paid bool `json:"paid"` 65 | Refunded bool `json:"refunded"` 66 | Refunds *RefundList `json:"refunds"` 67 | AmountRefunded uint64 `json:"amount_refunded"` 68 | Tx *Transaction `json:"balance_transaction"` 69 | Customer *Customer `json:"customer"` 70 | Desc string `json:"description"` 71 | Dispute *Dispute `json:"dispute"` 72 | FailMsg string `json:"failure_message"` 73 | FailCode string `json:"failure_code"` 74 | Invoice *Invoice `json:"invoice"` 75 | Meta map[string]string `json:"metadata"` 76 | Email string `json:"receipt_email"` 77 | Statement string `json:"statement_descriptor"` 78 | FraudDetails *FraudDetails `json:"fraud_details"` 79 | Status string `json:"status"` 80 | Source *PaymentSource `json:"source"` 81 | Shipping *ShippingDetails `json:"shipping"` 82 | Dest *Account `json:"destination"` 83 | Fee *Fee `json:"application_fee"` 84 | Transfer *Transfer `json:"transfer"` 85 | } 86 | 87 | // FraudDetails is the structure detailing fraud status. 88 | type FraudDetails struct { 89 | UserReport FraudReport `json:"user_report"` 90 | StripeReport FraudReport `json:"stripe_report"` 91 | } 92 | 93 | // ShippingDetails is the structure containing shipping information. 94 | type ShippingDetails struct { 95 | Name string `json:"name"` 96 | Address Address `json:"address"` 97 | Phone string `json:"phone"` 98 | Tracking string `json:"tracking_number"` 99 | Carrier string `json:"carrier"` 100 | } 101 | 102 | // AppendDetails adds the shipping details to the query string. 103 | func (s *ShippingDetails) AppendDetails(values *url.Values) { 104 | values.Add("shipping[name]", s.Name) 105 | 106 | values.Add("shipping[address][line1]", s.Address.Line1) 107 | if len(s.Address.Line2) > 0 { 108 | values.Add("shipping[address][line2]", s.Address.Line2) 109 | } 110 | if len(s.Address.City) > 0 { 111 | values.Add("shipping[address][city]", s.Address.City) 112 | } 113 | 114 | if len(s.Address.State) > 0 { 115 | values.Add("shipping[address][state]", s.Address.State) 116 | } 117 | 118 | if len(s.Address.Zip) > 0 { 119 | values.Add("shipping[address][postal_code]", s.Address.Zip) 120 | } 121 | 122 | if len(s.Phone) > 0 { 123 | values.Add("shipping[phone]", s.Phone) 124 | } 125 | 126 | if len(s.Tracking) > 0 { 127 | values.Add("shipping[tracking_number]", s.Tracking) 128 | } 129 | 130 | if len(s.Carrier) > 0 { 131 | values.Add("shipping[carrier]", s.Carrier) 132 | } 133 | } 134 | 135 | // UnmarshalJSON handles deserialization of a Charge. 136 | // This custom unmarshaling is needed because the resulting 137 | // property may be an id or the full struct if it was expanded. 138 | func (c *Charge) UnmarshalJSON(data []byte) error { 139 | type charge Charge 140 | var cc charge 141 | err := json.Unmarshal(data, &cc) 142 | if err == nil { 143 | *c = Charge(cc) 144 | } else { 145 | // the id is surrounded by "\" characters, so strip them 146 | c.ID = string(data[1 : len(data)-1]) 147 | } 148 | 149 | return nil 150 | } 151 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/client/checkin_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | stripe "github.com/stripe/stripe-go" 8 | "github.com/stripe/stripe-go/currency" 9 | "github.com/stripe/stripe-go/plan" 10 | ) 11 | 12 | const testKey = "tGN0bIwXnHdwOa85VABjPdSn8nWY7G7I" 13 | 14 | func TestCheckinIdempotency(t *testing.T) { 15 | c := &API{} 16 | c.Init(testKey, nil) 17 | 18 | charge := &stripe.ChargeParams{ 19 | Amount: 100, 20 | Currency: currency.USD, 21 | Source: &stripe.SourceParams{ 22 | Card: &stripe.CardParams{ 23 | Name: "Go Bindings Cardholder", 24 | Number: "4242424242424242", 25 | Month: "12", 26 | Year: "24", 27 | }, 28 | }, 29 | } 30 | 31 | charge.Params.IdempotencyKey = stripe.NewIdempotencyKey() 32 | 33 | first, err := c.Charges.New(charge) 34 | 35 | if err != nil { 36 | t.Error(err) 37 | } 38 | 39 | retry, err := c.Charges.New(charge) 40 | 41 | if err != nil { 42 | t.Error(err) 43 | } 44 | 45 | if first.ID != retry.ID { 46 | t.Errorf("First charge ID %q does not match retry charge ID %q", first.ID, retry.ID) 47 | } 48 | 49 | } 50 | 51 | func TestCheckinConnectivity(t *testing.T) { 52 | c := &API{} 53 | c.Init(testKey, nil) 54 | 55 | target, err := c.Account.Get() 56 | 57 | if err != nil { 58 | t.Error(err) 59 | } 60 | 61 | if target.ID != "cuD9Rwx8pgmRZRpVe02lsuR9cwp2Bzf7" { 62 | t.Errorf("Invalid account id: %q\n", target.ID) 63 | } 64 | 65 | if target.Name != "Stripe Test" { 66 | t.Errorf("Invalid account name: %q\n", target.Name) 67 | } 68 | 69 | if target.Email != "test+bindings@stripe.com" { 70 | t.Errorf("Invalid account email: %q\n", target.Email) 71 | } 72 | } 73 | 74 | func TestCheckinError(t *testing.T) { 75 | c := &API{} 76 | c.Init("bad_key", nil) 77 | 78 | _, err := c.Account.Get() 79 | 80 | if err == nil { 81 | t.Errorf("Expected an error") 82 | } 83 | 84 | stripeErr := err.(*stripe.Error) 85 | 86 | if stripeErr.Type != stripe.InvalidRequest { 87 | t.Errorf("Type %v does not match expected type\n", stripeErr.Type) 88 | } 89 | } 90 | 91 | func TestCheckinPost(t *testing.T) { 92 | c := &API{} 93 | c.Init(testKey, nil) 94 | 95 | charge := &stripe.ChargeParams{ 96 | Amount: 100, 97 | Currency: currency.USD, 98 | Source: &stripe.SourceParams{ 99 | Card: &stripe.CardParams{ 100 | Name: "Go Bindings Cardholder", 101 | Number: "4242424242424242", 102 | Month: "12", 103 | Year: "24", 104 | }, 105 | }, 106 | } 107 | 108 | target, err := c.Charges.New(charge) 109 | 110 | if err != nil { 111 | t.Error(err) 112 | } 113 | 114 | if target.Amount != charge.Amount { 115 | t.Errorf("Amount %v does not match expected amount %v\n", target.Amount, charge.Amount) 116 | } 117 | 118 | if target.Currency != charge.Currency { 119 | t.Errorf("Currency %q does not match expected currency %q\n", target.Currency, charge.Currency) 120 | } 121 | 122 | if target.Source.Card.Name != charge.Source.Card.Name { 123 | t.Errorf("Card name %q does not match expected name %q\n", target.Source.Card.Name, charge.Source.Card.Name) 124 | } 125 | } 126 | 127 | func TestCheckinDel(t *testing.T) { 128 | c := &API{} 129 | c.Init(testKey, nil) 130 | 131 | plan := &stripe.PlanParams{ 132 | ID: "go_binding", 133 | Name: "Go Test Plan", 134 | Amount: 100, 135 | Currency: currency.USD, 136 | Interval: plan.Month, 137 | } 138 | 139 | _, err := c.Plans.New(plan) 140 | 141 | if err != nil { 142 | t.Error(err) 143 | } 144 | 145 | _, err = c.Plans.Del(plan.ID) 146 | 147 | if err != nil { 148 | t.Error(err) 149 | } 150 | } 151 | 152 | func TestCheckinList(t *testing.T) { 153 | const runs = 4 154 | c := &API{} 155 | c.Init(testKey, nil) 156 | 157 | for i := 0; i < runs; i++ { 158 | plan := &stripe.PlanParams{ 159 | ID: fmt.Sprintf("go_binding_%v", i), 160 | Name: fmt.Sprintf("Go Test Plan %v", i), 161 | Amount: 100, 162 | Currency: currency.USD, 163 | Interval: plan.Month, 164 | } 165 | 166 | c.Plans.New(plan) 167 | } 168 | 169 | params := &stripe.PlanListParams{} 170 | params.Filters.AddFilter("limit", "", "2") 171 | params.Single = true 172 | 173 | i := c.Plans.List(params) 174 | for i.Next() { 175 | target := i.Plan() 176 | 177 | if i.Meta() == nil { 178 | t.Error("No metadata returned") 179 | } 180 | 181 | if target.Amount != 100 { 182 | t.Errorf("Amount %v does not match expected value\n", target.Amount) 183 | } 184 | } 185 | if err := i.Err(); err != nil { 186 | t.Error(err) 187 | } 188 | 189 | for i := 0; i < runs; i++ { 190 | c.Plans.Del(fmt.Sprintf("go_binding_%v", i)) 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/client/error_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "strings" 5 | "testing" 6 | 7 | . "github.com/stripe/stripe-go" 8 | ) 9 | 10 | func TestErrors(t *testing.T) { 11 | c := &API{} 12 | c.Init("bad_key", nil) 13 | 14 | _, err := c.Account.Get() 15 | 16 | if err == nil { 17 | t.Errorf("Expected an error") 18 | } 19 | 20 | stripeErr := err.(*Error) 21 | 22 | if stripeErr.Type != InvalidRequest { 23 | t.Errorf("Type %v does not match expected type\n", stripeErr.Type) 24 | } 25 | 26 | if !strings.HasPrefix(stripeErr.RequestID, "req_") { 27 | t.Errorf("Request ID %q does not start with 'req_'\n", stripeErr.RequestID) 28 | } 29 | 30 | if stripeErr.HTTPStatusCode != 401 { 31 | t.Errorf("HTTPStatusCode %q does not match expected value of \"401\"", stripeErr.HTTPStatusCode) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/coupon.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // CouponDuration is the list of allowed values for the coupon's duration. 6 | // Allowed values are "forever", "once", "repeating". 7 | type CouponDuration string 8 | 9 | // CouponParams is the set of parameters that can be used when creating a coupon. 10 | // For more details see https://stripe.com/docs/api#create_coupon. 11 | type CouponParams struct { 12 | Params 13 | Duration CouponDuration 14 | ID string 15 | Currency Currency 16 | Amount, Percent, DurationPeriod, Redemptions uint64 17 | RedeemBy int64 18 | } 19 | 20 | // CouponListParams is the set of parameters that can be used when listing coupons. 21 | // For more detail see https://stripe.com/docs/api#list_coupons. 22 | type CouponListParams struct { 23 | ListParams 24 | } 25 | 26 | // Coupon is the resource representing a Stripe coupon. 27 | // For more details see https://stripe.com/docs/api#coupons. 28 | type Coupon struct { 29 | ID string `json:"id"` 30 | Live bool `json:"livemode"` 31 | Created int64 `json:"created"` 32 | Duration CouponDuration `json:"duration"` 33 | Amount uint64 `json:"amount_off"` 34 | Currency Currency `json:"currency"` 35 | DurationPeriod uint64 `json:"duration_in_months"` 36 | Redemptions uint64 `json:"max_redemptions"` 37 | Meta map[string]string `json:"metadata"` 38 | Percent uint64 `json:"percent_off"` 39 | RedeemBy int64 `json:"redeem_by"` 40 | Redeemed uint64 `json:"times_redeemed"` 41 | Valid bool `json:"valid"` 42 | Deleted bool `json:"deleted"` 43 | } 44 | 45 | // UnmarshalJSON handles deserialization of a Coupon. 46 | // This custom unmarshaling is needed because the resulting 47 | // property may be an id or the full struct if it was expanded. 48 | func (c *Coupon) UnmarshalJSON(data []byte) error { 49 | type coupon Coupon 50 | var cc coupon 51 | err := json.Unmarshal(data, &cc) 52 | if err == nil { 53 | *c = Coupon(cc) 54 | } else { 55 | // the id is surrounded by "\" characters, so strip them 56 | c.ID = string(data[1 : len(data)-1]) 57 | } 58 | 59 | return nil 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/coupon/client.go: -------------------------------------------------------------------------------- 1 | // Package coupon provides the /coupons APIs 2 | package coupon 3 | 4 | import ( 5 | "errors" 6 | "net/url" 7 | "strconv" 8 | 9 | stripe "github.com/stripe/stripe-go" 10 | ) 11 | 12 | const ( 13 | Forever stripe.CouponDuration = "forever" 14 | Once stripe.CouponDuration = "once" 15 | Repeating stripe.CouponDuration = "repeating" 16 | ) 17 | 18 | // Client is used to invoke /coupons APIs. 19 | type Client struct { 20 | B stripe.Backend 21 | Key string 22 | } 23 | 24 | // New POSTs new coupons. 25 | // For more details see https://stripe.com/docs/api#create_coupon. 26 | func New(params *stripe.CouponParams) (*stripe.Coupon, error) { 27 | return getC().New(params) 28 | } 29 | 30 | func (c Client) New(params *stripe.CouponParams) (*stripe.Coupon, error) { 31 | // TODO: this doesn't check that the params are not nil. 32 | 33 | body := &url.Values{ 34 | "duration": {string(params.Duration)}, 35 | } 36 | 37 | if len(params.ID) > 0 { 38 | body.Add("id", params.ID) 39 | } 40 | 41 | if params.Percent > 0 { 42 | body.Add("percent_off", strconv.FormatUint(params.Percent, 10)) 43 | } else if params.Amount > 0 { 44 | body.Add("amount_off", strconv.FormatUint(params.Amount, 10)) 45 | body.Add("currency", string(params.Currency)) 46 | } else { 47 | err := errors.New("Invalid coupon params: either amount and currency or percent need to be set") 48 | return nil, err 49 | } 50 | 51 | if params.Duration == Repeating { 52 | body.Add("duration_in_months", strconv.FormatUint(params.DurationPeriod, 10)) 53 | } 54 | 55 | if params.Redemptions > 0 { 56 | body.Add("max_redemptions", strconv.FormatUint(params.Redemptions, 10)) 57 | } 58 | 59 | if params.RedeemBy > 0 { 60 | body.Add("redeem_by", strconv.FormatInt(params.RedeemBy, 10)) 61 | } 62 | 63 | params.AppendTo(body) 64 | 65 | coupon := &stripe.Coupon{} 66 | 67 | err := c.B.Call("POST", "/coupons", c.Key, body, ¶ms.Params, coupon) 68 | 69 | return coupon, err 70 | } 71 | 72 | // Get returns the details of a coupon. 73 | // For more details see https://stripe.com/docs/api#retrieve_coupon. 74 | func Get(id string, params *stripe.CouponParams) (*stripe.Coupon, error) { 75 | return getC().Get(id, params) 76 | } 77 | 78 | func (c Client) Get(id string, params *stripe.CouponParams) (*stripe.Coupon, error) { 79 | var body *url.Values 80 | var commonParams *stripe.Params 81 | 82 | if params != nil { 83 | commonParams = ¶ms.Params 84 | body = &url.Values{} 85 | params.AppendTo(body) 86 | } 87 | 88 | coupon := &stripe.Coupon{} 89 | 90 | err := c.B.Call("GET", "/coupons/"+id, c.Key, body, commonParams, coupon) 91 | 92 | return coupon, err 93 | } 94 | 95 | // Update updates a coupon's properties. 96 | // For more details see https://stripe.com/docs/api#update_coupon. 97 | func Update(id string, params *stripe.CouponParams) (*stripe.Coupon, error) { 98 | return getC().Update(id, params) 99 | } 100 | 101 | func (c Client) Update(id string, params *stripe.CouponParams) (*stripe.Coupon, error) { 102 | body := &url.Values{} 103 | 104 | params.AppendTo(body) 105 | 106 | coupon := &stripe.Coupon{} 107 | err := c.B.Call("POST", "/coupons/"+id, c.Key, body, ¶ms.Params, coupon) 108 | 109 | return coupon, err 110 | } 111 | 112 | // Del removes a coupon. 113 | // For more details see https://stripe.com/docs/api#delete_coupon. 114 | func Del(id string) (*stripe.Coupon, error) { 115 | return getC().Del(id) 116 | } 117 | 118 | func (c Client) Del(id string) (*stripe.Coupon, error) { 119 | coupon := &stripe.Coupon{} 120 | err := c.B.Call("DELETE", "/coupons/"+id, c.Key, nil, nil, coupon) 121 | 122 | return coupon, err 123 | } 124 | 125 | // List returns a list of coupons. 126 | // For more details see https://stripe.com/docs/api#list_coupons. 127 | func List(params *stripe.CouponListParams) *Iter { 128 | return getC().List(params) 129 | } 130 | 131 | func (c Client) List(params *stripe.CouponListParams) *Iter { 132 | type couponList struct { 133 | stripe.ListMeta 134 | Values []*stripe.Coupon `json:"data"` 135 | } 136 | 137 | var body *url.Values 138 | var lp *stripe.ListParams 139 | 140 | if params != nil { 141 | body = &url.Values{} 142 | 143 | params.AppendTo(body) 144 | lp = ¶ms.ListParams 145 | } 146 | 147 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 148 | list := &couponList{} 149 | err := c.B.Call("GET", "/coupons", c.Key, &b, nil, list) 150 | 151 | ret := make([]interface{}, len(list.Values)) 152 | for i, v := range list.Values { 153 | ret[i] = v 154 | } 155 | 156 | return ret, list.ListMeta, err 157 | })} 158 | } 159 | 160 | // Iter is an iterator for lists of Coupons. 161 | // The embedded Iter carries methods with it; 162 | // see its documentation for details. 163 | type Iter struct { 164 | *stripe.Iter 165 | } 166 | 167 | // Coupon returns the most recent Coupon 168 | // visited by a call to Next. 169 | func (i *Iter) Coupon() *stripe.Coupon { 170 | return i.Current().(*stripe.Coupon) 171 | } 172 | 173 | func getC() Client { 174 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 175 | } 176 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/coupon/client_test.go: -------------------------------------------------------------------------------- 1 | package coupon 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | "time" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | "github.com/stripe/stripe-go/currency" 10 | . "github.com/stripe/stripe-go/utils" 11 | ) 12 | 13 | func init() { 14 | stripe.Key = GetTestKey() 15 | } 16 | 17 | func TestCouponNew(t *testing.T) { 18 | couponParams := &stripe.CouponParams{ 19 | Amount: 99, 20 | Currency: currency.USD, 21 | Duration: Repeating, 22 | DurationPeriod: 3, 23 | Redemptions: 1, 24 | RedeemBy: time.Now().AddDate(0, 0, 30).Unix(), 25 | } 26 | 27 | target, err := New(couponParams) 28 | 29 | if err != nil { 30 | t.Error(err) 31 | } 32 | 33 | if target.Amount != couponParams.Amount { 34 | t.Errorf("Amount %v does not match expected amount %v\n", target.Amount, couponParams.Amount) 35 | } 36 | 37 | if target.Currency != couponParams.Currency { 38 | t.Errorf("Currency %q does not match expected currency %q\n", target.Currency, couponParams.Currency) 39 | } 40 | 41 | if target.Duration != couponParams.Duration { 42 | t.Errorf("Duration %q does not match expected duration %q\n", target.Duration, couponParams.Duration) 43 | } 44 | 45 | if target.DurationPeriod != couponParams.DurationPeriod { 46 | t.Errorf("Duration period %v does not match expected duration period %v\n", target.DurationPeriod, couponParams.DurationPeriod) 47 | } 48 | 49 | if target.Redemptions != couponParams.Redemptions { 50 | t.Errorf("Max redemptions %v does not match expected max redemptions %v\n", target.Redemptions, couponParams.Redemptions) 51 | } 52 | 53 | if target.RedeemBy != couponParams.RedeemBy { 54 | t.Errorf("Redeem by %v does not match expected redeem by %v\n", target.RedeemBy, couponParams.RedeemBy) 55 | } 56 | 57 | if !target.Valid { 58 | t.Errorf("Coupon is not valid, but was expecting it to be\n") 59 | } 60 | 61 | Del(target.ID) 62 | } 63 | 64 | func TestCouponGet(t *testing.T) { 65 | couponParams := &stripe.CouponParams{ 66 | ID: "test_coupon", 67 | Duration: Once, 68 | Percent: 50, 69 | } 70 | 71 | New(couponParams) 72 | target, err := Get(couponParams.ID, nil) 73 | 74 | if err != nil { 75 | t.Error(err) 76 | } 77 | 78 | if target.ID != couponParams.ID { 79 | t.Errorf("ID %q does not match expected id %q\n", target.ID, couponParams.ID) 80 | } 81 | 82 | if target.Percent != couponParams.Percent { 83 | t.Errorf("Percent %v does not match expected percent %v\n", target.Percent, couponParams.Percent) 84 | } 85 | 86 | Del(target.ID) 87 | } 88 | 89 | func TestCouponUpdate(t *testing.T) { 90 | couponParams := &stripe.CouponParams{ 91 | ID: "test_coupon", 92 | Duration: Once, 93 | Percent: 50, 94 | } 95 | 96 | New(couponParams) 97 | 98 | updateParams := &stripe.CouponParams{} 99 | updateParams.AddMeta("key", "value") 100 | target, err := Update(couponParams.ID, updateParams) 101 | 102 | if err != nil { 103 | t.Error(err) 104 | } 105 | 106 | if target.ID != couponParams.ID { 107 | t.Errorf("ID %q does not match expected id %q\n", target.ID, couponParams.ID) 108 | } 109 | 110 | if target.Meta["key"] != updateParams.Meta["key"] { 111 | t.Errorf("Meta %v does not match expected Meta %v\n", target.Meta, updateParams.Meta) 112 | } 113 | 114 | Del(target.ID) 115 | } 116 | 117 | func TestCouponList(t *testing.T) { 118 | for i := 0; i < 5; i++ { 119 | couponParams := &stripe.CouponParams{ 120 | ID: fmt.Sprintf("test_%v", i), 121 | Duration: Once, 122 | Percent: 50, 123 | } 124 | 125 | New(couponParams) 126 | } 127 | 128 | i := List(nil) 129 | for i.Next() { 130 | if i.Coupon() == nil { 131 | t.Error("No nil values expected") 132 | } 133 | 134 | if i.Meta() == nil { 135 | t.Error("No metadata returned") 136 | } 137 | } 138 | if err := i.Err(); err != nil { 139 | t.Error(err) 140 | } 141 | 142 | for i := 0; i < 5; i++ { 143 | Del(fmt.Sprintf("test_%v", i)) 144 | } 145 | } 146 | 147 | func TestCouponDel(t *testing.T) { 148 | couponParams := &stripe.CouponParams{ 149 | Duration: Once, 150 | Percent: 50, 151 | } 152 | 153 | target, err := New(couponParams) 154 | if err != nil { 155 | t.Error(err) 156 | } 157 | 158 | coupon, err := Del(target.ID) 159 | if !coupon.Deleted { 160 | t.Errorf("Coupon id %v expected to be marked as deleted on the returned resource\n", coupon.ID) 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/customer.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "encoding/json" 5 | "net/url" 6 | ) 7 | 8 | // CustomerParams is the set of parameters that can be used when creating or updating a customer. 9 | // For more details see https://stripe.com/docs/api#create_customer and https://stripe.com/docs/api#update_customer. 10 | type CustomerParams struct { 11 | Params 12 | Balance int64 13 | Token, Coupon string 14 | Source *SourceParams 15 | Desc, Email string 16 | Plan string 17 | Quantity uint64 18 | TrialEnd int64 19 | DefaultSource string 20 | Shipping *CustomerShippingDetails 21 | } 22 | 23 | // SetSource adds valid sources to a CustomerParams object, 24 | // returning an error for unsupported sources. 25 | func (cp *CustomerParams) SetSource(sp interface{}) error { 26 | source, err := SourceParamsFor(sp) 27 | cp.Source = source 28 | return err 29 | } 30 | 31 | // CustomerListParams is the set of parameters that can be used when listing customers. 32 | // For more details see https://stripe.com/docs/api#list_customers. 33 | type CustomerListParams struct { 34 | ListParams 35 | Created int64 36 | } 37 | 38 | // Customer is the resource representing a Stripe customer. 39 | // For more details see https://stripe.com/docs/api#customers. 40 | type Customer struct { 41 | ID string `json:"id"` 42 | Live bool `json:"livemode"` 43 | Sources *SourceList `json:"sources"` 44 | Created int64 `json:"created"` 45 | Balance int64 `json:"account_balance"` 46 | Currency Currency `json:"currency"` 47 | DefaultSource *PaymentSource `json:"default_source"` 48 | Delinquent bool `json:"delinquent"` 49 | Desc string `json:"description"` 50 | Discount *Discount `json:"discount"` 51 | Email string `json:"email"` 52 | Meta map[string]string `json:"metadata"` 53 | Subs *SubList `json:"subscriptions"` 54 | Deleted bool `json:"deleted"` 55 | Shipping *CustomerShippingDetails `json:"shipping"` 56 | } 57 | 58 | // ShippingDetails is the structure containing shipping information. 59 | type CustomerShippingDetails struct { 60 | Name string `json:"name"` 61 | Address Address `json:"address"` 62 | Phone string `json:"phone"` 63 | } 64 | 65 | // AppendDetails adds the shipping details to the query string. 66 | func (s *CustomerShippingDetails) AppendDetails(values *url.Values) { 67 | values.Add("shipping[name]", s.Name) 68 | 69 | values.Add("shipping[address][line1]", s.Address.Line1) 70 | if len(s.Address.Line2) > 0 { 71 | values.Add("shipping[address][line2]", s.Address.Line2) 72 | } 73 | if len(s.Address.City) > 0 { 74 | values.Add("shipping[address][city]", s.Address.City) 75 | } 76 | 77 | if len(s.Address.State) > 0 { 78 | values.Add("shipping[address][state]", s.Address.State) 79 | } 80 | 81 | if len(s.Address.Zip) > 0 { 82 | values.Add("shipping[address][postal_code]", s.Address.Zip) 83 | } 84 | 85 | if len(s.Phone) > 0 { 86 | values.Add("shipping[phone]", s.Phone) 87 | } 88 | } 89 | 90 | // UnmarshalJSON handles deserialization of a Customer. 91 | // This custom unmarshaling is needed because the resulting 92 | // property may be an id or the full struct if it was expanded. 93 | func (c *Customer) UnmarshalJSON(data []byte) error { 94 | type customer Customer 95 | var cc customer 96 | err := json.Unmarshal(data, &cc) 97 | if err == nil { 98 | *c = Customer(cc) 99 | } else { 100 | // the id is surrounded by "\" characters, so strip them 101 | c.ID = string(data[1 : len(data)-1]) 102 | } 103 | 104 | return nil 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/discount/client.go: -------------------------------------------------------------------------------- 1 | // Package discount provides the discount-related APIs 2 | package discount 3 | 4 | import ( 5 | "fmt" 6 | 7 | stripe "github.com/stripe/stripe-go" 8 | ) 9 | 10 | // Client is used to invoke discount-related APIs. 11 | type Client struct { 12 | B stripe.Backend 13 | Key string 14 | } 15 | 16 | // Del removes a discount from a customer. 17 | // For more details see https://stripe.com/docs/api#delete_discount. 18 | func Del(customerID string) (*stripe.Discount, error) { 19 | return getC().Del(customerID) 20 | } 21 | 22 | func (c Client) Del(customerID string) (*stripe.Discount, error) { 23 | discount := &stripe.Discount{} 24 | err := c.B.Call("DELETE", fmt.Sprintf("/customers/%v/discount", customerID), c.Key, nil, nil, discount) 25 | 26 | return discount, err 27 | } 28 | 29 | // DelSub removes a discount from a customer's subscription. 30 | // For more details see https://stripe.com/docs/api#delete_subscription_discount. 31 | func DelSub(customerID, subscriptionID string) (*stripe.Discount, error) { 32 | return getC().DelSub(customerID, subscriptionID) 33 | } 34 | 35 | func (c Client) DelSub(customerID, subscriptionID string) (*stripe.Discount, error) { 36 | discount := &stripe.Discount{} 37 | err := c.B.Call("DELETE", fmt.Sprintf("/customers/%v/subscriptions/%v/discount", customerID, subscriptionID), c.Key, nil, nil, discount) 38 | 39 | return discount, err 40 | } 41 | 42 | func getC() Client { 43 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/discounts.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | // Discount is the resource representing a Stripe discount. 4 | // For more details see https://stripe.com/docs/api#discounts. 5 | type Discount struct { 6 | Coupon *Coupon `json:"coupon"` 7 | Customer string `json:"customer"` 8 | Start int64 `json:"start"` 9 | End int64 `json:"end"` 10 | Sub string `json:"subscription"` 11 | Deleted bool `json:"deleted"` 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/dispute/client.go: -------------------------------------------------------------------------------- 1 | // Package dispute provides the dispute-related APIs 2 | package dispute 3 | 4 | import ( 5 | "fmt" 6 | "net/url" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | ) 10 | 11 | const ( 12 | Duplicate stripe.DisputeReason = "duplicate" 13 | Fraudulent stripe.DisputeReason = "fraudulent" 14 | SubCanceled stripe.DisputeReason = "subscription_canceled" 15 | Unacceptable stripe.DisputeReason = "product_unacceptable" 16 | NotReceived stripe.DisputeReason = "product_not_received" 17 | Unrecognized stripe.DisputeReason = "unrecognized" 18 | Credit stripe.DisputeReason = "credit_not_processed" 19 | General stripe.DisputeReason = "general" 20 | 21 | Won stripe.DisputeStatus = "won" 22 | Lost stripe.DisputeStatus = "lost" 23 | Response stripe.DisputeStatus = "needs_response" 24 | Review stripe.DisputeStatus = "under_review" 25 | WarningResponse stripe.DisputeStatus = "warning_needs_response" 26 | WarningReview stripe.DisputeStatus = "warning_under_review" 27 | ChargeRefunded stripe.DisputeStatus = "charge_refunded" 28 | WarningClosed stripe.DisputeStatus = "warning_closed" 29 | ) 30 | 31 | // Client is used to invoke dispute-related APIs. 32 | type Client struct { 33 | B stripe.Backend 34 | Key string 35 | } 36 | 37 | // Get returns the details of a dispute. 38 | // For more details see https://stripe.com/docs/api#retrieve_dispute. 39 | func Get(id string, params *stripe.DisputeParams) (*stripe.Dispute, error) { 40 | return getC().Get(id, params) 41 | } 42 | 43 | func (c Client) Get(id string, params *stripe.DisputeParams) (*stripe.Dispute, error) { 44 | var body *url.Values 45 | var commonParams *stripe.Params 46 | 47 | if params != nil { 48 | commonParams = ¶ms.Params 49 | body = &url.Values{} 50 | params.AppendTo(body) 51 | } 52 | 53 | dispute := &stripe.Dispute{} 54 | err := c.B.Call("GET", "/disputes/"+id, c.Key, body, commonParams, dispute) 55 | 56 | return dispute, err 57 | } 58 | 59 | // List returns a list of disputes. 60 | // For more details see https://stripe.com/docs/api#list_disputes. 61 | func List(params *stripe.DisputeListParams) *Iter { 62 | return getC().List(params) 63 | } 64 | 65 | func (c Client) List(params *stripe.DisputeListParams) *Iter { 66 | type disputeList struct { 67 | stripe.ListMeta 68 | Values []*stripe.Dispute `json:"data"` 69 | } 70 | 71 | var body *url.Values 72 | var lp *stripe.ListParams 73 | 74 | if params != nil { 75 | body = &url.Values{} 76 | 77 | params.AppendTo(body) 78 | lp = ¶ms.ListParams 79 | } 80 | 81 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 82 | list := &disputeList{} 83 | err := c.B.Call("GET", "/disputes", c.Key, &b, nil, list) 84 | 85 | ret := make([]interface{}, len(list.Values)) 86 | for i, v := range list.Values { 87 | ret[i] = v 88 | } 89 | 90 | return ret, list.ListMeta, err 91 | })} 92 | } 93 | 94 | // Iter is an iterator for lists of Disputes. 95 | // The embedded Iter carries methods with it; 96 | // see its documentation for details. 97 | type Iter struct { 98 | *stripe.Iter 99 | } 100 | 101 | // Dispute returns the most recent Dispute 102 | // visited by a call to Next. 103 | func (i *Iter) Dispute() *stripe.Dispute { 104 | return i.Current().(*stripe.Dispute) 105 | } 106 | 107 | // Update updates a dispute. 108 | // For more details see https://stripe.com/docs/api#update_dispute. 109 | func Update(id string, params *stripe.DisputeParams) (*stripe.Dispute, error) { 110 | return getC().Update(id, params) 111 | } 112 | 113 | func (c Client) Update(id string, params *stripe.DisputeParams) (*stripe.Dispute, error) { 114 | var body *url.Values 115 | var commonParams *stripe.Params 116 | 117 | if params != nil { 118 | commonParams = ¶ms.Params 119 | body = &url.Values{} 120 | 121 | if params.Evidence != nil { 122 | params.Evidence.AppendDetails(body) 123 | } 124 | params.AppendTo(body) 125 | } 126 | 127 | dispute := &stripe.Dispute{} 128 | err := c.B.Call("POST", fmt.Sprintf("/disputes/%v", id), c.Key, body, commonParams, dispute) 129 | 130 | return dispute, err 131 | } 132 | 133 | // Close dismisses a dispute in the customer's favor. 134 | // For more details see https://stripe.com/docs/api#close_dispute. 135 | func Close(id string) (*stripe.Dispute, error) { 136 | return getC().Close(id) 137 | } 138 | 139 | func (c Client) Close(id string) (*stripe.Dispute, error) { 140 | dispute := &stripe.Dispute{} 141 | err := c.B.Call("POST", fmt.Sprintf("/disputes/%v/close", id), c.Key, nil, nil, dispute) 142 | 143 | return dispute, err 144 | } 145 | 146 | func getC() Client { 147 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 148 | } 149 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/dispute/client_test.go: -------------------------------------------------------------------------------- 1 | package dispute 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | stripe "github.com/stripe/stripe-go" 8 | "github.com/stripe/stripe-go/charge" 9 | "github.com/stripe/stripe-go/currency" 10 | . "github.com/stripe/stripe-go/utils" 11 | ) 12 | 13 | func init() { 14 | stripe.Key = GetTestKey() 15 | } 16 | 17 | func newDisputedCharge() (*stripe.Charge, error) { 18 | chargeParams := &stripe.ChargeParams{ 19 | Amount: 1001, 20 | Currency: currency.USD, 21 | } 22 | 23 | chargeParams.SetSource(&stripe.CardParams{ 24 | Number: "4000000000000259", 25 | Month: "06", 26 | Year: "20", 27 | }) 28 | 29 | res, err := charge.New(chargeParams) 30 | if err != nil { 31 | return nil, err 32 | } 33 | 34 | target, err := charge.Get(res.ID, nil) 35 | 36 | if err != nil { 37 | return target, err 38 | } 39 | 40 | for target.Dispute == nil { 41 | time.Sleep(time.Second * 10) 42 | target, err = charge.Get(res.ID, nil) 43 | if err != nil { 44 | return target, err 45 | } 46 | } 47 | return target, err 48 | } 49 | 50 | // Use one large test here to avoid needing to create multiple disputed charges 51 | func TestDispute(t *testing.T) { 52 | ch, err := newDisputedCharge() 53 | if err != nil { 54 | t.Fatal(err) 55 | } 56 | 57 | CheckGet(t, ch.Dispute.ID) 58 | CheckUpdate(t, ch.Dispute.ID) 59 | 60 | ch, err = newDisputedCharge() 61 | if err != nil { 62 | t.Fatal(err) 63 | } 64 | CheckClose(t, ch.Dispute.ID) 65 | } 66 | 67 | func CheckGet(t *testing.T, id string) { 68 | dp, err := Get(id, nil) 69 | if err != nil { 70 | t.Error(err) 71 | } 72 | 73 | if dp.ID != id { 74 | t.Errorf("Dispute id %q does not match expected id %q\n", dp.ID, id) 75 | } 76 | } 77 | 78 | func CheckUpdate(t *testing.T, id string) { 79 | disputeParams := &stripe.DisputeParams{ 80 | Evidence: &stripe.DisputeEvidenceParams{ 81 | ProductDesc: "original description", 82 | }, 83 | } 84 | 85 | dp, err := Update(id, disputeParams) 86 | if err != nil { 87 | t.Error(err) 88 | } 89 | 90 | if dp.ID != id { 91 | t.Errorf("Dispute id %q does not match expected id %q\n", dp.ID, id) 92 | } 93 | 94 | if dp.Evidence.ProductDesc != disputeParams.Evidence.ProductDesc { 95 | t.Errorf("Original description %q does not match expected description %q\n", 96 | dp.Evidence.ProductDesc, disputeParams.Evidence.ProductDesc) 97 | } 98 | } 99 | 100 | func CheckClose(t *testing.T, id string) { 101 | dp, err := Close(id) 102 | if err != nil { 103 | t.Error(err) 104 | } 105 | 106 | if dp.ID != id { 107 | t.Errorf("Dispute id %q does not match expected id %q\n", dp.ID, id) 108 | } 109 | 110 | if dp.Status != "lost" { 111 | t.Errorf("Dispute status %q does not match expected status lost\n", dp.Status) 112 | } 113 | } 114 | 115 | func TestDisputeList(t *testing.T) { 116 | params := &stripe.DisputeListParams{} 117 | params.Filters.AddFilter("limit", "", "5") 118 | params.Single = true 119 | 120 | i := List(params) 121 | for i.Next() { 122 | if i.Dispute() == nil { 123 | t.Error("No nil values expected") 124 | } 125 | 126 | if i.Meta() == nil { 127 | t.Error("No metadata returned") 128 | } 129 | } 130 | if err := i.Err(); err != nil { 131 | t.Error(err) 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/error.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // ErrorType is the list of allowed values for the error's type. 6 | // Allowed values are "invalid_request_error", "api_error", "card_error". 7 | type ErrorType string 8 | 9 | // ErrorCode is the list of allowed values for the error's code. 10 | // Allowed values are "incorrect_number", "invalid_number", "invalid_expiry_month", 11 | // "invalid_expiry_year", "invalid_cvc", "expired_card", "incorrect_cvc", "incorrect_zip", 12 | // "card_declined", "missing", "processing_error", "rate_limit". 13 | type ErrorCode string 14 | 15 | const ( 16 | InvalidRequest ErrorType = "invalid_request_error" 17 | APIErr ErrorType = "api_error" 18 | CardErr ErrorType = "card_error" 19 | 20 | IncorrectNum ErrorCode = "incorrect_number" 21 | InvalidNum ErrorCode = "invalid_number" 22 | InvalidExpM ErrorCode = "invalid_expiry_month" 23 | InvalidExpY ErrorCode = "invalid_expiry_year" 24 | InvalidCvc ErrorCode = "invalid_cvc" 25 | ExpiredCard ErrorCode = "expired_card" 26 | IncorrectCvc ErrorCode = "incorrect_cvc" 27 | IncorrectZip ErrorCode = "incorrect_zip" 28 | CardDeclined ErrorCode = "card_declined" 29 | Missing ErrorCode = "missing" 30 | ProcessingErr ErrorCode = "processing_error" 31 | RateLimit ErrorCode = "rate_limit" 32 | ) 33 | 34 | // Error is the response returned when a call is unsuccessful. 35 | // For more details see https://stripe.com/docs/api#errors. 36 | type Error struct { 37 | Type ErrorType `json:"type"` 38 | Msg string `json:"message"` 39 | Code ErrorCode `json:"code,omitempty"` 40 | Param string `json:"param,omitempty"` 41 | RequestID string `json:"request_id,omitempty"` 42 | HTTPStatusCode int `json:"status,omitempty"` 43 | ChargeID string `json:"charge,omitempty"` 44 | } 45 | 46 | // Error serializes the Error object and prints the JSON string. 47 | func (e *Error) Error() string { 48 | ret, _ := json.Marshal(e) 49 | return string(ret) 50 | } 51 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/event.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | // Event is the resource representing a Stripe event. 9 | // For more details see https://stripe.com/docs/api#events. 10 | type Event struct { 11 | ID string `json:"id"` 12 | Live bool `json:"livemode"` 13 | Created int64 `json:"created"` 14 | Data *EventData `json:"data"` 15 | Webhooks uint64 `json:"pending_webhooks"` 16 | Type string `json:"type"` 17 | Req string `json:"request"` 18 | UserID string `json:"user_id"` 19 | } 20 | 21 | // EventData is the unmarshalled object as a map. 22 | type EventData struct { 23 | Raw json.RawMessage `json:"object"` 24 | Prev map[string]interface{} `json:"previous_attributes"` 25 | Obj map[string]interface{} 26 | } 27 | 28 | // EventListParams is the set of parameters that can be used when listing events. 29 | // For more details see https://stripe.com/docs/api#list_events. 30 | type EventListParams struct { 31 | ListParams 32 | Created int64 33 | // Type is one of the values documented at https://stripe.com/docs/api#event_types. 34 | Type string 35 | } 36 | 37 | // GetObjValue returns the value from the e.Data.Obj bag based on the keys hierarchy. 38 | func (e *Event) GetObjValue(keys ...string) string { 39 | return getValue(e.Data.Obj, keys) 40 | } 41 | 42 | // GetPrevValue returns the value from the e.Data.Prev bag based on the keys hierarchy. 43 | func (e *Event) GetPrevValue(keys ...string) string { 44 | return getValue(e.Data.Prev, keys) 45 | } 46 | 47 | // UnmarshalJSON handles deserialization of the EventData. 48 | // This custom unmarshaling exists so that we can keep both the map and raw data. 49 | func (e *EventData) UnmarshalJSON(data []byte) error { 50 | type eventdata EventData 51 | var ee eventdata 52 | err := json.Unmarshal(data, &ee) 53 | if err != nil { 54 | return err 55 | } 56 | 57 | *e = EventData(ee) 58 | return json.Unmarshal(e.Raw, &e.Obj) 59 | } 60 | 61 | // getValue returns the value from the m map based on the keys. 62 | func getValue(m map[string]interface{}, keys []string) string { 63 | node := m[keys[0]] 64 | 65 | for i := 1; i < len(keys); i++ { 66 | node = node.(map[string]interface{})[keys[i]] 67 | } 68 | 69 | if node == nil { 70 | return "" 71 | } 72 | 73 | return fmt.Sprintf("%v", node) 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/event/client.go: -------------------------------------------------------------------------------- 1 | // Package event provides the /events APIs 2 | package event 3 | 4 | import ( 5 | "net/url" 6 | "strconv" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | ) 10 | 11 | // Client is used to invoke /events APIs. 12 | type Client struct { 13 | B stripe.Backend 14 | Key string 15 | } 16 | 17 | // Get returns the details of an event 18 | // For more details see https://stripe.com/docs/api#retrieve_event. 19 | func Get(id string) (*stripe.Event, error) { 20 | return getC().Get(id) 21 | } 22 | 23 | func (c Client) Get(id string) (*stripe.Event, error) { 24 | event := &stripe.Event{} 25 | err := c.B.Call("GET", "/events/"+id, c.Key, nil, nil, event) 26 | 27 | return event, err 28 | } 29 | 30 | // List returns a list of events. 31 | // For more details see https://stripe.com/docs/api#list_events 32 | func List(params *stripe.EventListParams) *Iter { 33 | return getC().List(params) 34 | } 35 | 36 | func (c Client) List(params *stripe.EventListParams) *Iter { 37 | type eventList struct { 38 | stripe.ListMeta 39 | Values []*stripe.Event `json:"data"` 40 | } 41 | 42 | var body *url.Values 43 | var lp *stripe.ListParams 44 | 45 | if params != nil { 46 | body = &url.Values{} 47 | 48 | if params.Created > 0 { 49 | body.Add("created", strconv.FormatInt(params.Created, 10)) 50 | } 51 | 52 | if len(params.Type) > 0 { 53 | body.Add("type", params.Type) 54 | } 55 | 56 | params.AppendTo(body) 57 | lp = ¶ms.ListParams 58 | } 59 | 60 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 61 | list := &eventList{} 62 | err := c.B.Call("GET", "/events", c.Key, &b, nil, list) 63 | 64 | ret := make([]interface{}, len(list.Values)) 65 | for i, v := range list.Values { 66 | ret[i] = v 67 | } 68 | 69 | return ret, list.ListMeta, err 70 | })} 71 | } 72 | 73 | // Iter is an iterator for lists of Events. 74 | // The embedded Iter carries methods with it; 75 | // see its documentation for details. 76 | type Iter struct { 77 | *stripe.Iter 78 | } 79 | 80 | // Event returns the most recent Event 81 | // visited by a call to Next. 82 | func (i *Iter) Event() *stripe.Event { 83 | return i.Current().(*stripe.Event) 84 | } 85 | 86 | func getC() Client { 87 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/event/client_test.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import ( 4 | "testing" 5 | 6 | stripe "github.com/stripe/stripe-go" 7 | . "github.com/stripe/stripe-go/utils" 8 | ) 9 | 10 | func init() { 11 | stripe.Key = GetTestKey() 12 | } 13 | 14 | func TestEvent(t *testing.T) { 15 | params := &stripe.EventListParams{} 16 | params.Filters.AddFilter("limit", "", "5") 17 | params.Single = true 18 | params.Type = "charge.*" 19 | 20 | i := List(params) 21 | for i.Next() { 22 | e := i.Event() 23 | 24 | if e == nil { 25 | t.Error("No nil values expected") 26 | } 27 | 28 | if len(e.ID) == 0 { 29 | t.Errorf("ID is not set\n") 30 | } 31 | 32 | if e.Created == 0 { 33 | t.Errorf("Created date is not set\n") 34 | } 35 | 36 | if len(e.Type) == 0 { 37 | t.Errorf("Type is not set\n") 38 | } 39 | 40 | if len(e.Req) == 0 { 41 | t.Errorf("Request is not set\n") 42 | } 43 | 44 | if e.Data == nil { 45 | t.Errorf("Data is not set\n") 46 | } 47 | 48 | if len(e.Data.Obj) == 0 { 49 | t.Errorf("Object is empty\n") 50 | } 51 | 52 | target, err := Get(e.ID) 53 | 54 | if err != nil { 55 | t.Error(err) 56 | } 57 | 58 | if e.ID != target.ID { 59 | t.Errorf("ID %q does not match expected id %q\n", e.ID, target.ID) 60 | } 61 | 62 | var targetVal string 63 | var val string 64 | 65 | if e.GetObjValue("source", "object") == "card" { 66 | targetVal = e.GetObjValue("card", "last4") 67 | val = target.Data.Obj["card"].(map[string]interface{})["last4"].(string) 68 | } else { // is bitcoin receiver 69 | targetVal = e.GetObjValue("source", "currency") 70 | val = target.Data.Obj["source"].(map[string]interface{})["currency"].(string) 71 | } 72 | 73 | if targetVal != val { 74 | t.Errorf("Value %q does not match expected value %q\n", targetVal, val) 75 | } 76 | 77 | if len(target.Data.Raw) == 0 { 78 | t.Errorf("Raw data is nil\n") 79 | } 80 | 81 | // no need to actually check the value, we're just validating this doesn't bomb 82 | e.GetObjValue("does not exist") 83 | } 84 | 85 | if err := i.Err(); err != nil { 86 | t.Error(err) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/example_test.go: -------------------------------------------------------------------------------- 1 | package stripe_test 2 | 3 | import ( 4 | "log" 5 | 6 | stripe "github.com/stripe/stripe-go" 7 | "github.com/stripe/stripe-go/charge" 8 | "github.com/stripe/stripe-go/currency" 9 | "github.com/stripe/stripe-go/customer" 10 | "github.com/stripe/stripe-go/invoice" 11 | "github.com/stripe/stripe-go/plan" 12 | ) 13 | 14 | func ExampleCharge_new() { 15 | stripe.Key = "sk_key" 16 | 17 | params := &stripe.ChargeParams{ 18 | Amount: 1000, 19 | Currency: currency.USD, 20 | } 21 | params.SetSource(&stripe.CardParams{ 22 | Name: "Go Stripe", 23 | Number: "4242424242424242", 24 | Month: "10", 25 | Year: "20", 26 | }) 27 | params.AddMeta("key", "value") 28 | 29 | ch, err := charge.New(params) 30 | 31 | if err != nil { 32 | log.Fatal(err) 33 | } 34 | 35 | log.Printf("%v\n", ch.ID) 36 | } 37 | 38 | func ExampleCharge_get() { 39 | stripe.Key = "sk_key" 40 | 41 | params := &stripe.ChargeParams{} 42 | params.Expand("customer") 43 | params.Expand("balance_transaction") 44 | 45 | ch, err := charge.Get("ch_example_id", params) 46 | 47 | if err != nil { 48 | log.Fatal(err) 49 | } 50 | 51 | log.Printf("%v\n", ch.ID) 52 | } 53 | 54 | func ExampleInvoice_update() { 55 | stripe.Key = "sk_key" 56 | 57 | params := &stripe.InvoiceParams{ 58 | Desc: "updated description", 59 | } 60 | 61 | inv, err := invoice.Update("sub_example_id", params) 62 | 63 | if err != nil { 64 | log.Fatal(err) 65 | } 66 | 67 | log.Printf("%v\n", inv.Desc) 68 | } 69 | 70 | func ExampleCustomer_delete() { 71 | stripe.Key = "sk_key" 72 | 73 | customerDel, err := customer.Del("cus_example_id") 74 | 75 | if err != nil { 76 | log.Fatal(err) 77 | } 78 | 79 | if !customerDel.Deleted { 80 | log.Fatal("Customer doesn't appear deleted while it should be") 81 | } 82 | } 83 | 84 | func ExamplePlan_list() { 85 | stripe.Key = "sk_key" 86 | 87 | params := &stripe.PlanListParams{} 88 | params.Filters.AddFilter("limit", "", "3") 89 | params.Single = true 90 | 91 | it := plan.List(params) 92 | for it.Next() { 93 | log.Printf("%v ", it.Plan().Name) 94 | } 95 | if err := it.Err(); err != nil { 96 | log.Fatal(err) 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/fee.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // FeeParams is the set of parameters that can be used when refunding an application fee. 6 | // For more details see https://stripe.com/docs/api#refund_application_fee. 7 | type FeeParams struct { 8 | Params 9 | Amount uint64 10 | } 11 | 12 | // FeeListParams is the set of parameters that can be used when listing application fees. 13 | // For more details see https://stripe.com/docs/api#list_application_fees. 14 | type FeeListParams struct { 15 | ListParams 16 | Created int64 17 | Charge string 18 | } 19 | 20 | // Fee is the resource representing a Stripe application fee. 21 | // For more details see https://stripe.com/docs/api#application_fees. 22 | type Fee struct { 23 | ID string `json:"id"` 24 | Live bool `json:"livemode"` 25 | Account *Account `json:"account"` 26 | Amount uint64 `json:"amount"` 27 | App string `json:"application"` 28 | Tx *Transaction `json:"balance_transaction"` 29 | Charge *Charge `json:"charge"` 30 | Created int64 `json:"created"` 31 | Currency Currency `json:"currency"` 32 | Refunded bool `json:"refunded"` 33 | Refunds *FeeRefundList `json:"refunds"` 34 | AmountRefunded uint64 `json:"amount_refunded"` 35 | } 36 | 37 | // UnmarshalJSON handles deserialization of a Fee. 38 | // This custom unmarshaling is needed because the resulting 39 | // property may be an id or the full struct if it was expanded. 40 | func (f *Fee) UnmarshalJSON(data []byte) error { 41 | type appfee Fee 42 | var ff appfee 43 | err := json.Unmarshal(data, &ff) 44 | if err == nil { 45 | *f = Fee(ff) 46 | } else { 47 | // the id is surrounded by "\" characters, so strip them 48 | f.ID = string(data[1 : len(data)-1]) 49 | } 50 | 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/fee/client.go: -------------------------------------------------------------------------------- 1 | // Package fee provides the /application_fees APIs 2 | package fee 3 | 4 | import ( 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | 9 | stripe "github.com/stripe/stripe-go" 10 | ) 11 | 12 | // Client is used to invoke application_fees APIs. 13 | type Client struct { 14 | B stripe.Backend 15 | Key string 16 | } 17 | 18 | // Get returns the details of an application fee. 19 | // For more details see https://stripe.com/docs/api#retrieve_application_fee. 20 | func Get(id string, params *stripe.FeeParams) (*stripe.Fee, error) { 21 | return getC().Get(id, params) 22 | } 23 | 24 | func (c Client) Get(id string, params *stripe.FeeParams) (*stripe.Fee, error) { 25 | var body *url.Values 26 | var commonParams *stripe.Params 27 | 28 | if params != nil { 29 | commonParams = ¶ms.Params 30 | body = &url.Values{} 31 | params.AppendTo(body) 32 | } 33 | 34 | fee := &stripe.Fee{} 35 | err := c.B.Call("GET", fmt.Sprintf("application_fees/%v", id), c.Key, body, commonParams, fee) 36 | 37 | return fee, err 38 | } 39 | 40 | // List returns a list of application fees. 41 | // For more details see https://stripe.com/docs/api#list_application_fees. 42 | func List(params *stripe.FeeListParams) *Iter { 43 | return getC().List(params) 44 | } 45 | 46 | func (c Client) List(params *stripe.FeeListParams) *Iter { 47 | type feeList struct { 48 | stripe.ListMeta 49 | Values []*stripe.Fee `json:"data"` 50 | } 51 | 52 | var body *url.Values 53 | var lp *stripe.ListParams 54 | 55 | if params != nil { 56 | body = &url.Values{} 57 | 58 | if params.Created > 0 { 59 | body.Add("created", strconv.FormatInt(params.Created, 10)) 60 | } 61 | 62 | if len(params.Charge) > 0 { 63 | body.Add("charge", params.Charge) 64 | } 65 | 66 | params.AppendTo(body) 67 | lp = ¶ms.ListParams 68 | } 69 | 70 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 71 | list := &feeList{} 72 | err := c.B.Call("GET", "/application_fees", c.Key, &b, nil, list) 73 | 74 | ret := make([]interface{}, len(list.Values)) 75 | for i, v := range list.Values { 76 | ret[i] = v 77 | } 78 | 79 | return ret, list.ListMeta, err 80 | })} 81 | } 82 | 83 | // Iter is an iterator for lists of Fees. 84 | // The embedded Iter carries methods with it; 85 | // see its documentation for details. 86 | type Iter struct { 87 | *stripe.Iter 88 | } 89 | 90 | // Fee returns the most recent Fee 91 | // visited by a call to Next. 92 | func (i *Iter) Fee() *stripe.Fee { 93 | return i.Current().(*stripe.Fee) 94 | } 95 | 96 | func getC() Client { 97 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/feerefund.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // FeeRefundParams is the set of parameters that can be used when refunding a fee. 6 | // For more details see https://stripe.com/docs/api#fee_refund. 7 | type FeeRefundParams struct { 8 | Params 9 | Fee string 10 | Amount uint64 11 | Meta map[string]string 12 | } 13 | 14 | // FeeRefundListParams is the set of parameters that can be used when listing fee refunds. 15 | // For more details see https://stripe.com/docs/api#list_fee_refunds. 16 | type FeeRefundListParams struct { 17 | ListParams 18 | Fee string 19 | } 20 | 21 | // FeeRefund is the resource representing a Stripe fee refund. 22 | // For more details see https://stripe.com/docs/api#fee_refunds. 23 | type FeeRefund struct { 24 | ID string `json:"id"` 25 | Amount uint64 `json:"amount"` 26 | Created int64 `json:"created"` 27 | Currency Currency `json:"currency"` 28 | Tx *Transaction `json:"balance_transaction"` 29 | Fee string `json:"fee"` 30 | Meta map[string]string `json:"metadata"` 31 | } 32 | 33 | // FeeRefundList is a list object for fee refunds. 34 | type FeeRefundList struct { 35 | ListMeta 36 | Values []*FeeRefund `json:"data"` 37 | } 38 | 39 | // UnmarshalJSON handles deserialization of a FeeRefund. 40 | // This custom unmarshaling is needed because the resulting 41 | // property may be an id or the full struct if it was expanded. 42 | func (f *FeeRefund) UnmarshalJSON(data []byte) error { 43 | type feerefund FeeRefund 44 | var ff feerefund 45 | err := json.Unmarshal(data, &ff) 46 | if err == nil { 47 | *f = FeeRefund(ff) 48 | } else { 49 | // the id is surrounded by "\" characters, so strip them 50 | f.ID = string(data[1 : len(data)-1]) 51 | } 52 | 53 | return nil 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/feerefund/client.go: -------------------------------------------------------------------------------- 1 | // Package feerefund provides the /application_fees/refunds APIs 2 | package feerefund 3 | 4 | import ( 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | 9 | stripe "github.com/stripe/stripe-go" 10 | ) 11 | 12 | // Client is used to invoke /application_fees/refunds APIs. 13 | type Client struct { 14 | B stripe.Backend 15 | Key string 16 | } 17 | 18 | // New refunds the application fee collected. 19 | // For more details see https://stripe.com/docs/api#refund_application_fee. 20 | func New(params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) { 21 | return getC().New(params) 22 | } 23 | 24 | func (c Client) New(params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) { 25 | body := &url.Values{} 26 | 27 | if params.Amount > 0 { 28 | body.Add("amount", strconv.FormatUint(params.Amount, 10)) 29 | } 30 | 31 | params.AppendTo(body) 32 | 33 | refund := &stripe.FeeRefund{} 34 | err := c.B.Call("POST", fmt.Sprintf("application_fees/%v/refunds", params.Fee), c.Key, body, ¶ms.Params, refund) 35 | 36 | return refund, err 37 | } 38 | 39 | // Get returns the details of a fee refund. 40 | // For more details see https://stripe.com/docs/api#retrieve_fee_refund. 41 | func Get(id string, params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) { 42 | return getC().Get(id, params) 43 | } 44 | 45 | func (c Client) Get(id string, params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) { 46 | if params == nil { 47 | return nil, fmt.Errorf("params cannot be nil, and params.Fee must be set") 48 | } 49 | 50 | body := &url.Values{} 51 | params.AppendTo(body) 52 | 53 | refund := &stripe.FeeRefund{} 54 | err := c.B.Call("GET", fmt.Sprintf("/application_fees/%v/refunds/%v", params.Fee, id), c.Key, body, ¶ms.Params, refund) 55 | 56 | return refund, err 57 | } 58 | 59 | // Update updates a refund's properties. 60 | // For more details see https://stripe.com/docs/api#update_refund. 61 | func Update(id string, params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) { 62 | return getC().Update(id, params) 63 | } 64 | 65 | func (c Client) Update(id string, params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) { 66 | body := &url.Values{} 67 | params.AppendTo(body) 68 | 69 | refund := &stripe.FeeRefund{} 70 | err := c.B.Call("POST", fmt.Sprintf("/application_fees/%v/refunds/%v", params.Fee, id), c.Key, body, ¶ms.Params, refund) 71 | 72 | return refund, err 73 | } 74 | 75 | // List returns a list of fee refunds. 76 | // For more details see https://stripe.com/docs/api#list_fee_refunds. 77 | func List(params *stripe.FeeRefundListParams) *Iter { 78 | return getC().List(params) 79 | } 80 | 81 | func (c Client) List(params *stripe.FeeRefundListParams) *Iter { 82 | body := &url.Values{} 83 | var lp *stripe.ListParams 84 | 85 | params.AppendTo(body) 86 | lp = ¶ms.ListParams 87 | 88 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 89 | list := &stripe.FeeRefundList{} 90 | err := c.B.Call("GET", fmt.Sprintf("/application_fees/%v/refunds", params.Fee), c.Key, &b, nil, list) 91 | 92 | ret := make([]interface{}, len(list.Values)) 93 | for i, v := range list.Values { 94 | ret[i] = v 95 | } 96 | 97 | return ret, list.ListMeta, err 98 | })} 99 | } 100 | 101 | // Iter is an iterator for lists of FeeRefunds. 102 | // The embedded Iter carries methods with it; 103 | // see its documentation for details. 104 | type Iter struct { 105 | *stripe.Iter 106 | } 107 | 108 | // FeeRefund returns the most recent FeeRefund 109 | // visited by a call to Next. 110 | func (i *Iter) FeeRefund() *stripe.FeeRefund { 111 | return i.Current().(*stripe.FeeRefund) 112 | } 113 | 114 | func getC() Client { 115 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 116 | } 117 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/fileupload.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | "mime/multipart" 7 | "os" 8 | "path/filepath" 9 | ) 10 | 11 | // FileUploadParams is the set of parameters that can be used when creating a 12 | // file upload. 13 | // For more details see https://stripe.com/docs/api#create_file_upload. 14 | type FileUploadParams struct { 15 | Params 16 | Purpose FileUploadPurpose 17 | File *os.File 18 | } 19 | 20 | // FileUploadListParams is the set of parameters that can be used when listing 21 | // file uploads. For more details see https://stripe.com/docs/api#list_file_uploads. 22 | type FileUploadListParams struct { 23 | Purpose FileUploadPurpose 24 | ListParams 25 | } 26 | 27 | // FileUploadPurpose is the purpose of a particular file upload. Allowed values 28 | // are "dispute_evidence" and "identity_document". 29 | type FileUploadPurpose string 30 | 31 | // FileUpload is the resource representing a Stripe file upload. 32 | // For more details see https://stripe.com/docs/api#file_uploads. 33 | type FileUpload struct { 34 | ID string `json:"id"` 35 | Created int64 `json:"created"` 36 | Size int64 `json:"size"` 37 | Purpose FileUploadPurpose `json:"purpose"` 38 | URL string `json:"url"` 39 | Type string `json:"type"` 40 | } 41 | 42 | // AppendDetails adds the file upload details to an io.ReadWriter. It returns 43 | // the boundary string for a multipart/form-data request and an error (if one 44 | // exists). 45 | func (f *FileUploadParams) AppendDetails(body io.ReadWriter) (string, error) { 46 | writer := multipart.NewWriter(body) 47 | var err error 48 | 49 | if len(f.Purpose) > 0 { 50 | err = writer.WriteField("purpose", string(f.Purpose)) 51 | if err != nil { 52 | return "", err 53 | } 54 | } 55 | 56 | if f.File != nil { 57 | part, err := writer.CreateFormFile("file", filepath.Base(f.File.Name())) 58 | if err != nil { 59 | return "", err 60 | } 61 | 62 | _, err = io.Copy(part, f.File) 63 | if err != nil { 64 | return "", err 65 | } 66 | } 67 | 68 | err = writer.Close() 69 | if err != nil { 70 | return "", err 71 | } 72 | 73 | return writer.Boundary(), nil 74 | } 75 | 76 | // UnmarshalJSON handles deserialization of a FileUpload. 77 | // This custom unmarshaling is needed because the resulting 78 | // property may be an id or the full struct if it was expanded. 79 | func (f *FileUpload) UnmarshalJSON(data []byte) error { 80 | type file FileUpload 81 | var ff file 82 | err := json.Unmarshal(data, &ff) 83 | if err == nil { 84 | *f = FileUpload(ff) 85 | } else { 86 | // the id is surrounded by "\" characters, so strip them 87 | f.ID = string(data[1 : len(data)-1]) 88 | } 89 | 90 | return nil 91 | } 92 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/fileupload/client.go: -------------------------------------------------------------------------------- 1 | // Package fileupload provides the file upload related APIs 2 | package fileupload 3 | 4 | import ( 5 | "bytes" 6 | "fmt" 7 | "net/url" 8 | 9 | stripe "github.com/stripe/stripe-go" 10 | ) 11 | 12 | const ( 13 | DisputeEvidenceFile stripe.FileUploadPurpose = "dispute_evidence" 14 | IdentityDocFile stripe.FileUploadPurpose = "identity_document" 15 | ) 16 | 17 | // Client is used to invoke file upload APIs. 18 | type Client struct { 19 | B stripe.Backend 20 | Key string 21 | } 22 | 23 | // New POSTs new file uploads. 24 | // For more details see https://stripe.com/docs/api#create_file_upload. 25 | func New(params *stripe.FileUploadParams) (*stripe.FileUpload, error) { 26 | return getC().New(params) 27 | } 28 | 29 | func (c Client) New(params *stripe.FileUploadParams) (*stripe.FileUpload, error) { 30 | if params == nil { 31 | return nil, fmt.Errorf("params cannot be nil, and params.Purpose and params.File must be set") 32 | } 33 | 34 | body := &bytes.Buffer{} 35 | boundary, err := params.AppendDetails(body) 36 | if err != nil { 37 | return nil, err 38 | } 39 | 40 | upload := &stripe.FileUpload{} 41 | err = c.B.CallMultipart("POST", "/files", c.Key, boundary, body, ¶ms.Params, upload) 42 | 43 | return upload, err 44 | } 45 | 46 | // Get returns the details of a file upload. 47 | // For more details see https://stripe.com/docs/api#retrieve_file_upload. 48 | func Get(id string, params *stripe.FileUploadParams) (*stripe.FileUpload, error) { 49 | return getC().Get(id, params) 50 | 51 | } 52 | 53 | func (c Client) Get(id string, params *stripe.FileUploadParams) (*stripe.FileUpload, error) { 54 | var body *url.Values 55 | var commonParams *stripe.Params 56 | 57 | if params != nil { 58 | commonParams = ¶ms.Params 59 | 60 | body = &url.Values{} 61 | params.AppendTo(body) 62 | } 63 | 64 | upload := &stripe.FileUpload{} 65 | err := c.B.Call("GET", "/files/"+id, c.Key, body, commonParams, upload) 66 | 67 | return upload, err 68 | } 69 | 70 | // List returns a list of file uploads. 71 | // For more details see https://stripe.com/docs/api#list_file_uploads. 72 | func List(params *stripe.FileUploadListParams) *Iter { 73 | return getC().List(params) 74 | } 75 | 76 | func (c Client) List(params *stripe.FileUploadListParams) *Iter { 77 | type fileUploadList struct { 78 | stripe.ListMeta 79 | Values []*stripe.FileUpload `json:"data"` 80 | } 81 | 82 | var body *url.Values 83 | var lp *stripe.ListParams 84 | 85 | if params != nil { 86 | body = &url.Values{} 87 | 88 | if len(params.Purpose) > 0 { 89 | body.Add("purpose", string(params.Purpose)) 90 | } 91 | 92 | params.AppendTo(body) 93 | lp = ¶ms.ListParams 94 | } 95 | 96 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 97 | list := &fileUploadList{} 98 | err := c.B.Call("GET", "/files", c.Key, &b, nil, list) 99 | 100 | ret := make([]interface{}, len(list.Values)) 101 | for i, v := range list.Values { 102 | ret[i] = v 103 | } 104 | 105 | return ret, list.ListMeta, err 106 | })} 107 | } 108 | 109 | // Iter is an iterator for lists of FileUploads. 110 | // The embedded Iter carries methods with it; 111 | // see its documentation for details. 112 | type Iter struct { 113 | *stripe.Iter 114 | } 115 | 116 | // FileUpload returns the most recent FileUpload visited by a call to Next. 117 | func (i *Iter) FileUpload() *stripe.FileUpload { 118 | return i.Current().(*stripe.FileUpload) 119 | } 120 | 121 | func getC() Client { 122 | return Client{stripe.GetBackend(stripe.UploadsBackend), stripe.Key} 123 | } 124 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/fileupload/client_test.go: -------------------------------------------------------------------------------- 1 | package fileupload 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | stripe "github.com/stripe/stripe-go" 8 | . "github.com/stripe/stripe-go/utils" 9 | ) 10 | 11 | const ( 12 | expectedSize = 734 13 | expectedType = "pdf" 14 | ) 15 | 16 | func init() { 17 | stripe.Key = GetTestKey() 18 | } 19 | 20 | func TestFileUploadNewThenGet(t *testing.T) { 21 | f, err := os.Open("test_data.pdf") 22 | if err != nil { 23 | t.Errorf("Unable to open test file upload file %v\n", err) 24 | } 25 | 26 | uploadParams := &stripe.FileUploadParams{ 27 | Purpose: "dispute_evidence", 28 | File: f, 29 | } 30 | 31 | target, err := New(uploadParams) 32 | if err != nil { 33 | t.Error(err) 34 | } 35 | 36 | if target.Size != expectedSize { 37 | t.Errorf("(POST) Size %v does not match expected size %v\n", target.Size, expectedSize) 38 | } 39 | 40 | if target.Purpose != uploadParams.Purpose { 41 | t.Errorf("(POST) Purpose %v does not match expected purpose %v\n", target.Purpose, uploadParams.Purpose) 42 | } 43 | 44 | if target.Type != expectedType { 45 | t.Errorf("(POST) Type %v does not match expected type %v\n", target.Type, expectedType) 46 | } 47 | 48 | res, err := Get(target.ID, nil) 49 | 50 | if err != nil { 51 | t.Error(err) 52 | } 53 | 54 | if target.ID != res.ID { 55 | t.Errorf("(GET) File upload id %q does not match expected id %q\n", target.ID, res.ID) 56 | } 57 | } 58 | 59 | func TestFileUploadList(t *testing.T) { 60 | f, err := os.Open("test_data.pdf") 61 | if err != nil { 62 | t.Errorf("Unable to open test file upload file %v\n", err) 63 | } 64 | 65 | uploadParams := &stripe.FileUploadParams{ 66 | Purpose: "dispute_evidence", 67 | File: f, 68 | } 69 | 70 | _, err = New(uploadParams) 71 | if err != nil { 72 | t.Error(err) 73 | } 74 | 75 | params := &stripe.FileUploadListParams{} 76 | params.Filters.AddFilter("limit", "", "5") 77 | params.Single = true 78 | 79 | i := List(params) 80 | for i.Next() { 81 | if i.FileUpload() == nil { 82 | t.Error("No nil values expected") 83 | } 84 | 85 | if i.Meta() == nil { 86 | t.Error("No metadata returned") 87 | } 88 | } 89 | 90 | if err := i.Err(); err != nil { 91 | t.Error(err) 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/fileupload/test_data.pdf: -------------------------------------------------------------------------------- 1 | %PDF-1.1 2 | %¥±ë 3 | 4 | 1 0 obj 5 | << /Type /Catalog 6 | /Pages 2 0 R 7 | >> 8 | endobj 9 | 10 | 2 0 obj 11 | << /Type /Pages 12 | /Kids [3 0 R] 13 | /Count 1 14 | /MediaBox [0 0 300 144] 15 | >> 16 | endobj 17 | 18 | 3 0 obj 19 | << /Type /Page 20 | /Parent 2 0 R 21 | /Resources 22 | << /Font 23 | << /F1 24 | << /Type /Font 25 | /Subtype /Type1 26 | /BaseFont /Times-Roman 27 | >> 28 | >> 29 | >> 30 | /Contents 4 0 R 31 | >> 32 | endobj 33 | 34 | 4 0 obj 35 | << /Length 55 >> 36 | stream 37 | BT 38 | /F1 18 Tf 39 | 0 0 Td 40 | (Hello World) Tj 41 | ET 42 | endstream 43 | endobj 44 | 45 | xref 46 | 0 5 47 | 0000000000 65535 f 48 | 0000000018 00000 n 49 | 0000000077 00000 n 50 | 0000000178 00000 n 51 | 0000000457 00000 n 52 | trailer 53 | << /Root 1 0 R 54 | /Size 5 55 | >> 56 | startxref 57 | 565 58 | %%EOF 59 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/invoice.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // InvoiceLineType is the list of allowed values for the invoice line's type. 6 | // Allowed values are "invoiceitem", "subscription". 7 | type InvoiceLineType string 8 | 9 | // InvoiceParams is the set of parameters that can be used when creating or updating an invoice. 10 | // For more details see https://stripe.com/docs/api#create_invoice, https://stripe.com/docs/api#update_invoice. 11 | type InvoiceParams struct { 12 | Params 13 | Customer string 14 | Desc, Statement, Sub string 15 | Fee uint64 16 | Closed, Forgive bool 17 | TaxPercent float64 18 | } 19 | 20 | // InvoiceListParams is the set of parameters that can be used when listing invoices. 21 | // For more details see https://stripe.com/docs/api#list_customer_invoices. 22 | type InvoiceListParams struct { 23 | ListParams 24 | Date int64 25 | Customer string 26 | } 27 | 28 | // InvoiceLineListParams is the set of parameters that can be used when listing invoice line items. 29 | // For more details see https://stripe.com/docs/api#invoice_lines. 30 | type InvoiceLineListParams struct { 31 | ListParams 32 | ID string 33 | Customer, Sub string 34 | } 35 | 36 | // Invoice is the resource representing a Stripe invoice. 37 | // For more details see https://stripe.com/docs/api#invoice_object. 38 | type Invoice struct { 39 | ID string `json:"id"` 40 | Live bool `json:"livemode"` 41 | Amount int64 `json:"amount_due"` 42 | Attempts uint64 `json:"attempt_count"` 43 | Attempted bool `json:"attempted"` 44 | Closed bool `json:"closed"` 45 | Currency Currency `json:"currency"` 46 | Customer *Customer `json:"customer"` 47 | Date int64 `json:"date"` 48 | Forgive bool `json:"forgiven"` 49 | Lines *InvoiceLineList `json:"lines"` 50 | Paid bool `json:"paid"` 51 | End int64 `json:"period_end"` 52 | Start int64 `json:"period_start"` 53 | StartBalance int64 `json:"starting_balance"` 54 | Subtotal int64 `json:"subtotal"` 55 | Total int64 `json:"total"` 56 | Tax int64 `json:"tax"` 57 | TaxPercent float64 `json:"tax_percent"` 58 | Fee uint64 `json:"application_fee"` 59 | Charge *Charge `json:"charge"` 60 | Desc string `json:"description"` 61 | Discount *Discount `json:"discount"` 62 | EndBalance int64 `json:"ending_balance"` 63 | NextAttempt int64 `json:"next_payment_attempt"` 64 | Statement string `json:"statement_descriptor"` 65 | Sub string `json:"subscription"` 66 | Webhook int64 `json:"webhooks_delivered_at"` 67 | Meta map[string]string `json:"metadata"` 68 | } 69 | 70 | // InvoiceLine is the resource representing a Stripe invoice line item. 71 | // For more details see https://stripe.com/docs/api#invoice_line_item_object. 72 | type InvoiceLine struct { 73 | ID string `json:"id"` 74 | Live bool `json:"live_mode"` 75 | Amount int64 `json:"amount"` 76 | Currency Currency `json:"currency"` 77 | Period *Period `json:"period"` 78 | Proration bool `json:"proration"` 79 | Type InvoiceLineType `json:"type"` 80 | Desc string `json:"description"` 81 | Meta map[string]string `json:"metadata"` 82 | Plan *Plan `json:"plan"` 83 | Quantity int64 `json:"quantity"` 84 | Sub string `json:"subscription"` 85 | Discountable bool `json:"discountable"` 86 | } 87 | 88 | // Period is a structure representing a start and end dates. 89 | type Period struct { 90 | Start int64 `json:"start"` 91 | End int64 `json:"end"` 92 | } 93 | 94 | // InvoiceLineList is a list object for invoice line items. 95 | type InvoiceLineList struct { 96 | ListMeta 97 | Values []*InvoiceLine `json:"data"` 98 | } 99 | 100 | // UnmarshalJSON handles deserialization of an Invoice. 101 | // This custom unmarshaling is needed because the resulting 102 | // property may be an id or the full struct if it was expanded. 103 | func (i *Invoice) UnmarshalJSON(data []byte) error { 104 | type invoice Invoice 105 | var ii invoice 106 | err := json.Unmarshal(data, &ii) 107 | if err == nil { 108 | *i = Invoice(ii) 109 | } else { 110 | // the id is surrounded by "\" characters, so strip them 111 | i.ID = string(data[1 : len(data)-1]) 112 | } 113 | 114 | return nil 115 | } 116 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/invoiceitem.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // InvoiceItemParams is the set of parameters that can be used when creating or updating an invoice item. 6 | // For more details see https://stripe.com/docs/api#create_invoiceitem and https://stripe.com/docs/api#update_invoiceitem. 7 | type InvoiceItemParams struct { 8 | Params 9 | Customer string 10 | Amount int64 11 | Currency Currency 12 | Invoice, Desc, Sub string 13 | Discountable bool 14 | } 15 | 16 | // InvoiceItemListParams is the set of parameters that can be used when listing invoice items. 17 | // For more details see https://stripe.com/docs/api#list_invoiceitems. 18 | type InvoiceItemListParams struct { 19 | ListParams 20 | Created int64 21 | Customer string 22 | } 23 | 24 | // InvoiceItem is the resource represneting a Stripe invoice item. 25 | // For more details see https://stripe.com/docs/api#invoiceitems. 26 | type InvoiceItem struct { 27 | ID string `json:"id"` 28 | Live bool `json:"livemode"` 29 | Amount int64 `json:"amount"` 30 | Currency Currency `json:"currency"` 31 | Customer *Customer `json:"customer"` 32 | Date int64 `json:"date"` 33 | Proration bool `json:"proration"` 34 | Desc string `json:"description"` 35 | Invoice *Invoice `json:"invoice"` 36 | Meta map[string]string `json:"metadata"` 37 | Sub string `json:"subscription"` 38 | Discountable bool `json:"discountable"` 39 | Deleted bool `json:"deleted"` 40 | } 41 | 42 | // UnmarshalJSON handles deserialization of an InvoiceItem. 43 | // This custom unmarshaling is needed because the resulting 44 | // property may be an id or the full struct if it was expanded. 45 | func (i *InvoiceItem) UnmarshalJSON(data []byte) error { 46 | type invoiceitem InvoiceItem 47 | var ii invoiceitem 48 | err := json.Unmarshal(data, &ii) 49 | if err == nil { 50 | *i = InvoiceItem(ii) 51 | } else { 52 | // the id is surrounded by "\" characters, so strip them 53 | i.ID = string(data[1 : len(data)-1]) 54 | } 55 | 56 | return nil 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/invoiceitem/client.go: -------------------------------------------------------------------------------- 1 | // Package invoiceitem provides the /invoiceitems APIs 2 | package invoiceitem 3 | 4 | import ( 5 | "net/url" 6 | "strconv" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | ) 10 | 11 | // Client is used to invoke /invoiceitems APIs. 12 | type Client struct { 13 | B stripe.Backend 14 | Key string 15 | } 16 | 17 | // New POSTs new invoice items. 18 | // For more details see https://stripe.com/docs/api#create_invoiceitem. 19 | func New(params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error) { 20 | return getC().New(params) 21 | } 22 | 23 | func (c Client) New(params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error) { 24 | body := &url.Values{ 25 | "customer": {params.Customer}, 26 | "amount": {strconv.FormatInt(params.Amount, 10)}, 27 | "currency": {string(params.Currency)}, 28 | } 29 | 30 | if len(params.Invoice) > 0 { 31 | body.Add("invoice", params.Invoice) 32 | } 33 | 34 | if len(params.Desc) > 0 { 35 | body.Add("description", params.Desc) 36 | } 37 | 38 | if len(params.Sub) > 0 { 39 | body.Add("subscription", params.Sub) 40 | } 41 | 42 | if params.Discountable { 43 | body.Add("discountable", strconv.FormatBool(true)) 44 | } 45 | 46 | params.AppendTo(body) 47 | 48 | invoiceItem := &stripe.InvoiceItem{} 49 | err := c.B.Call("POST", "/invoiceitems", c.Key, body, ¶ms.Params, invoiceItem) 50 | 51 | return invoiceItem, err 52 | } 53 | 54 | // Get returns the details of an invoice item. 55 | // For more details see https://stripe.com/docs/api#retrieve_invoiceitem. 56 | func Get(id string, params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error) { 57 | return getC().Get(id, params) 58 | } 59 | 60 | func (c Client) Get(id string, params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error) { 61 | var body *url.Values 62 | var commonParams *stripe.Params 63 | 64 | if params != nil { 65 | commonParams = ¶ms.Params 66 | body = &url.Values{} 67 | params.AppendTo(body) 68 | } 69 | 70 | invoiceItem := &stripe.InvoiceItem{} 71 | err := c.B.Call("GET", "/invoiceitems/"+id, c.Key, body, commonParams, invoiceItem) 72 | 73 | return invoiceItem, err 74 | } 75 | 76 | // Update updates an invoice item's properties. 77 | // For more details see https://stripe.com/docs/api#update_invoiceitem. 78 | func Update(id string, params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error) { 79 | return getC().Update(id, params) 80 | } 81 | 82 | func (c Client) Update(id string, params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error) { 83 | var body *url.Values 84 | var commonParams *stripe.Params 85 | 86 | if params != nil { 87 | commonParams = ¶ms.Params 88 | body = &url.Values{} 89 | 90 | if params.Amount != 0 { 91 | body.Add("amount", strconv.FormatInt(params.Amount, 10)) 92 | } 93 | 94 | if len(params.Desc) > 0 { 95 | body.Add("description", params.Desc) 96 | } 97 | 98 | if params.Discountable { 99 | body.Add("discountable", strconv.FormatBool(true)) 100 | } 101 | 102 | params.AppendTo(body) 103 | } 104 | 105 | invoiceItem := &stripe.InvoiceItem{} 106 | err := c.B.Call("POST", "/invoiceitems/"+id, c.Key, body, commonParams, invoiceItem) 107 | 108 | return invoiceItem, err 109 | } 110 | 111 | // Del removes an invoice item. 112 | // For more details see https://stripe.com/docs/api#delete_invoiceitem. 113 | func Del(id string) (*stripe.InvoiceItem, error) { 114 | return getC().Del(id) 115 | } 116 | 117 | func (c Client) Del(id string) (*stripe.InvoiceItem, error) { 118 | ii := &stripe.InvoiceItem{} 119 | err := c.B.Call("DELETE", "/invoiceitems/"+id, c.Key, nil, nil, ii) 120 | 121 | return ii, err 122 | } 123 | 124 | // List returns a list of invoice items. 125 | // For more details see https://stripe.com/docs/api#list_invoiceitems. 126 | func List(params *stripe.InvoiceItemListParams) *Iter { 127 | return getC().List(params) 128 | } 129 | 130 | func (c Client) List(params *stripe.InvoiceItemListParams) *Iter { 131 | type invoiceItemList struct { 132 | stripe.ListMeta 133 | Values []*stripe.InvoiceItem `json:"data"` 134 | } 135 | 136 | var body *url.Values 137 | var lp *stripe.ListParams 138 | 139 | if params != nil { 140 | body = &url.Values{} 141 | 142 | if params.Created > 0 { 143 | body.Add("created", strconv.FormatInt(params.Created, 10)) 144 | } 145 | 146 | if len(params.Customer) > 0 { 147 | body.Add("customer", params.Customer) 148 | } 149 | 150 | params.AppendTo(body) 151 | lp = ¶ms.ListParams 152 | } 153 | 154 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 155 | list := &invoiceItemList{} 156 | err := c.B.Call("GET", "/invoiceitems", c.Key, &b, nil, list) 157 | 158 | ret := make([]interface{}, len(list.Values)) 159 | for i, v := range list.Values { 160 | ret[i] = v 161 | } 162 | 163 | return ret, list.ListMeta, err 164 | })} 165 | } 166 | 167 | // Iter is an iterator for lists of InvoiceItems. 168 | // The embedded Iter carries methods with it; 169 | // see its documentation for details. 170 | type Iter struct { 171 | *stripe.Iter 172 | } 173 | 174 | // InvoiceItem returns the most recent InvoiceItem 175 | // visited by a call to Next. 176 | func (i *Iter) InvoiceItem() *stripe.InvoiceItem { 177 | return i.Current().(*stripe.InvoiceItem) 178 | } 179 | 180 | func getC() Client { 181 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 182 | } 183 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/iter.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "net/url" 5 | "reflect" 6 | ) 7 | 8 | // Query is the function used to get a page listing. 9 | type Query func(url.Values) ([]interface{}, ListMeta, error) 10 | 11 | // Iter provides a convenient interface 12 | // for iterating over the elements 13 | // returned from paginated list API calls. 14 | // Successive calls to the Next method 15 | // will step through each item in the list, 16 | // fetching pages of items as needed. 17 | // Iterators are not thread-safe, so they should not be consumed 18 | // across multiple goroutines. 19 | type Iter struct { 20 | query Query 21 | qs url.Values 22 | values []interface{} 23 | meta ListMeta 24 | params ListParams 25 | err error 26 | cur interface{} 27 | } 28 | 29 | // GetIter returns a new Iter for a given query and its options. 30 | func GetIter(params *ListParams, qs *url.Values, query Query) *Iter { 31 | iter := &Iter{} 32 | iter.query = query 33 | 34 | p := params 35 | if p == nil { 36 | p = &ListParams{} 37 | } 38 | iter.params = *p 39 | 40 | q := qs 41 | if q == nil { 42 | q = &url.Values{} 43 | } 44 | iter.qs = *q 45 | 46 | iter.getPage() 47 | return iter 48 | } 49 | 50 | func (it *Iter) getPage() { 51 | it.values, it.meta, it.err = it.query(it.qs) 52 | if it.params.End != "" { 53 | // We are moving backward, 54 | // but items arrive in forward order. 55 | reverse(it.values) 56 | } 57 | } 58 | 59 | // Next advances the Iter to the next item in the list, 60 | // which will then be available 61 | // through the Current method. 62 | // It returns false when the iterator stops 63 | // at the end of the list. 64 | func (it *Iter) Next() bool { 65 | if len(it.values) == 0 && it.meta.More && !it.params.Single { 66 | // determine if we're moving forward or backwards in paging 67 | if it.params.End != "" { 68 | it.params.End = listItemID(it.cur) 69 | it.qs.Set(endbefore, it.params.End) 70 | } else { 71 | it.params.Start = listItemID(it.cur) 72 | it.qs.Set(startafter, it.params.Start) 73 | } 74 | it.getPage() 75 | } 76 | if len(it.values) == 0 { 77 | return false 78 | } 79 | it.cur = it.values[0] 80 | it.values = it.values[1:] 81 | return true 82 | } 83 | 84 | // Current returns the most recent item 85 | // visited by a call to Next. 86 | func (it *Iter) Current() interface{} { 87 | return it.cur 88 | } 89 | 90 | // Err returns the error, if any, 91 | // that caused the Iter to stop. 92 | // It must be inspected 93 | // after Next returns false. 94 | func (it *Iter) Err() error { 95 | return it.err 96 | } 97 | 98 | // Meta returns the list metadata. 99 | func (it *Iter) Meta() *ListMeta { 100 | return &it.meta 101 | } 102 | 103 | func listItemID(x interface{}) string { 104 | return reflect.ValueOf(x).Elem().FieldByName("ID").String() 105 | } 106 | 107 | func reverse(a []interface{}) { 108 | for i := 0; i < len(a)/2; i++ { 109 | a[i], a[len(a)-i-1] = a[len(a)-i-1], a[i] 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/order.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | // OrderStatus represents the statuses of an order object. 8 | type OrderStatus string 9 | 10 | const ( 11 | StatusCreated OrderStatus = "created" 12 | StatusPaid OrderStatus = "paid" 13 | StatusCanceled OrderStatus = "canceled" 14 | StatusFulfilled OrderStatus = "fulfilled" 15 | StatusReturned OrderStatus = "returned" 16 | ) 17 | 18 | type OrderParams struct { 19 | Params 20 | Currency Currency 21 | Customer string 22 | Email string 23 | Items []*OrderItemParams 24 | Shipping *ShippingParams 25 | } 26 | 27 | type ShippingParams struct { 28 | Name string 29 | Address *AddressParams 30 | Phone string 31 | } 32 | 33 | type AddressParams struct { 34 | Line1 string 35 | Line2 string 36 | City string 37 | State string 38 | PostalCode string 39 | Country string 40 | } 41 | 42 | type OrderUpdateParams struct { 43 | Params 44 | Coupon string 45 | SelectedShippingMethod string 46 | Status OrderStatus 47 | } 48 | 49 | type Shipping struct { 50 | Name string `json:"name"` 51 | Address Address `json:"address"` 52 | Phone string `json:"phone"` 53 | } 54 | 55 | type ShippingMethod struct { 56 | ID string `json:"id"` 57 | Amount int64 `json:"amount"` 58 | Currency Currency `json:"currency"` 59 | Description string `json:"description"` 60 | } 61 | 62 | type Order struct { 63 | ID string `json:"id"` 64 | Amount int64 `json:"amount"` 65 | Application string `json:"application"` 66 | ApplicationFee int64 `json:"application_fee"` 67 | Charge Charge `json:"charge"` 68 | Created int64 `json:"created"` 69 | Currency Currency `json:"currency"` 70 | Customer Customer `json:"customer"` 71 | Email string `json:"email"` 72 | Items []OrderItem `json:"items"` 73 | Meta map[string]string `json:"metadata"` 74 | SelectedShippingMethod *string `json:"selected_shipping_method"` 75 | Shipping Shipping `json:"shipping"` 76 | ShippingMethods []ShippingMethod `json:"shipping_methods"` 77 | Status OrderStatus `json:"status"` 78 | Updated int64 `json:"updated"` 79 | } 80 | 81 | // OrderListParams is the set of parameters that can be used when 82 | // listing orders. For more details, see: 83 | // https://stripe.com/docs/api#list_orders. 84 | type OrderListParams struct { 85 | ListParams 86 | IDs []string 87 | Status OrderStatus 88 | } 89 | 90 | // OrderPayParams is the set of parameters that can be used when 91 | // paying orders. For more details, see: 92 | // https://stripe.com/docs/api#pay_order. 93 | type OrderPayParams struct { 94 | Params 95 | Source *SourceParams 96 | Customer string 97 | ApplicationFee int64 98 | Email string 99 | } 100 | 101 | // SetSource adds valid sources to a OrderParams object, 102 | // returning an error for unsupported sources. 103 | func (op *OrderPayParams) SetSource(sp interface{}) error { 104 | source, err := SourceParamsFor(sp) 105 | op.Source = source 106 | return err 107 | } 108 | 109 | // UnmarshalJSON handles deserialization of an Order. 110 | // This custom unmarshaling is needed because the resulting 111 | // property may be an id or the full struct if it was expanded. 112 | func (o *Order) UnmarshalJSON(data []byte) error { 113 | type order Order 114 | var oo order 115 | err := json.Unmarshal(data, &oo) 116 | if err == nil { 117 | *o = Order(oo) 118 | { 119 | } 120 | } else { 121 | // the id is surrounded by "\" characters, so strip them 122 | o.ID = string(data[1 : len(data)-1]) 123 | } 124 | 125 | return nil 126 | } 127 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/order_item.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "github.com/stripe/stripe-go/orderitem" 4 | 5 | type OrderItemParams struct { 6 | Amount int64 7 | Currency Currency 8 | Description string 9 | Parent string 10 | Quantity *int64 11 | Type orderitem.ItemType 12 | } 13 | 14 | type OrderItem struct { 15 | Amount int64 `json:"amount"` 16 | Currency Currency `json:"currency"` 17 | Description string `json:"description"` 18 | Parent string `json:"parent"` 19 | Quantity int64 `json:"quantity"` 20 | Type orderitem.ItemType `json:"type"` 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/orderitem/order_item.go: -------------------------------------------------------------------------------- 1 | package orderitem 2 | 3 | // OrderItemType represents one of the possible types that an order's OrderItem 4 | // can have. 5 | type ItemType string 6 | 7 | const ( 8 | SKU ItemType = "sku" 9 | Tax ItemType = "tax" 10 | Shipping ItemType = "shipping" 11 | Discount ItemType = "discount" 12 | ) 13 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/params.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "crypto/rand" 5 | "encoding/base64" 6 | "fmt" 7 | "net/url" 8 | "strconv" 9 | "time" 10 | ) 11 | 12 | const ( 13 | startafter = "starting_after" 14 | endbefore = "ending_before" 15 | ) 16 | 17 | // Params is the structure that contains the common properties 18 | // of any *Params structure. 19 | type Params struct { 20 | Exp []string 21 | Meta map[string]string 22 | Extra url.Values 23 | IdempotencyKey, Account string 24 | } 25 | 26 | // ListParams is the structure that contains the common properties 27 | // of any *ListParams structure. 28 | type ListParams struct { 29 | Exp []string 30 | Start, End string 31 | Limit int 32 | Filters Filters 33 | // By default, listing through an iterator will automatically grab 34 | // additional pages as the query progresses. To change this behavior 35 | // and just load a single page, set this to true. 36 | Single bool 37 | } 38 | 39 | // ListMeta is the structure that contains the common properties 40 | // of List iterators. The Count property is only populated if the 41 | // total_count include option is passed in (see tests for example). 42 | type ListMeta struct { 43 | Count uint32 `json:"total_count"` 44 | More bool `json:"has_more"` 45 | URL string `json:"url"` 46 | } 47 | 48 | // Filters is a structure that contains a collection of filters for list-related APIs. 49 | type Filters struct { 50 | f []*filter 51 | } 52 | 53 | // filter is the structure that contains a filter for list-related APIs. 54 | // It ends up passing query string parameters in the format key[op]=value. 55 | type filter struct { 56 | Key, Op, Val string 57 | } 58 | 59 | // NewIdempotencyKey generates a new idempotency key that 60 | // can be used on a request. 61 | func NewIdempotencyKey() string { 62 | now := time.Now().UnixNano() 63 | buf := make([]byte, 4) 64 | rand.Read(buf) 65 | return fmt.Sprintf("%v_%v", now, base64.URLEncoding.EncodeToString(buf)[:6]) 66 | } 67 | 68 | // SetAccount sets a value for the Stripe-Account header. 69 | func (p *Params) SetAccount(val string) { 70 | p.Account = val 71 | } 72 | 73 | // Expand appends a new field to expand. 74 | func (p *Params) Expand(f string) { 75 | p.Exp = append(p.Exp, f) 76 | } 77 | 78 | // AddMeta adds a new key-value pair to the Metadata. 79 | func (p *Params) AddMeta(key, value string) { 80 | if p.Meta == nil { 81 | p.Meta = make(map[string]string) 82 | } 83 | 84 | p.Meta[key] = value 85 | } 86 | 87 | // AddExtra adds a new arbitrary key-value pair to the request data 88 | func (p *Params) AddExtra(key, value string) { 89 | if p.Extra == nil { 90 | p.Extra = make(url.Values) 91 | } 92 | 93 | p.Extra.Add(key, value) 94 | } 95 | 96 | // AddFilter adds a new filter with a given key, op and value. 97 | func (f *Filters) AddFilter(key, op, value string) { 98 | filter := &filter{Key: key, Op: op, Val: value} 99 | f.f = append(f.f, filter) 100 | } 101 | 102 | // AppendTo adds the common parameters to the query string values. 103 | func (p *Params) AppendTo(body *url.Values) { 104 | for k, v := range p.Meta { 105 | body.Add(fmt.Sprintf("metadata[%v]", k), v) 106 | } 107 | 108 | for _, v := range p.Exp { 109 | body.Add("expand[]", v) 110 | } 111 | 112 | for k, vs := range p.Extra { 113 | for _, v := range vs { 114 | body.Add(k, v) 115 | } 116 | } 117 | } 118 | 119 | // Expand appends a new field to expand. 120 | func (p *ListParams) Expand(f string) { 121 | p.Exp = append(p.Exp, f) 122 | } 123 | 124 | // AppendTo adds the common parameters to the query string values. 125 | func (p *ListParams) AppendTo(body *url.Values) { 126 | if len(p.Filters.f) > 0 { 127 | p.Filters.AppendTo(body) 128 | } 129 | 130 | if len(p.Start) > 0 { 131 | body.Add(startafter, p.Start) 132 | } 133 | 134 | if len(p.End) > 0 { 135 | body.Add(endbefore, p.End) 136 | } 137 | 138 | if p.Limit > 0 { 139 | if p.Limit > 100 { 140 | p.Limit = 100 141 | } 142 | 143 | body.Add("limit", strconv.Itoa(p.Limit)) 144 | } 145 | for _, v := range p.Exp { 146 | body.Add("expand[]", v) 147 | } 148 | } 149 | 150 | // AppendTo adds the list of filters to the query string values. 151 | func (f *Filters) AppendTo(values *url.Values) { 152 | for _, v := range f.f { 153 | if len(v.Op) > 0 { 154 | values.Add(fmt.Sprintf("%v[%v]", v.Key, v.Op), v.Val) 155 | } else { 156 | values.Add(v.Key, v.Val) 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/params_test.go: -------------------------------------------------------------------------------- 1 | package stripe_test 2 | 3 | import ( 4 | "net/url" 5 | "reflect" 6 | "testing" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | ) 10 | 11 | func TestParamsWithExtras(t *testing.T) { 12 | testCases := []struct { 13 | InitialBody url.Values 14 | Extras [][2]string 15 | ExpectedBody url.Values 16 | }{ 17 | { 18 | InitialBody: url.Values{"foo": {"bar"}}, 19 | Extras: [][2]string{}, 20 | ExpectedBody: url.Values{"foo": {"bar"}}, 21 | }, 22 | { 23 | InitialBody: url.Values{"foo": {"bar"}}, 24 | Extras: [][2]string{{"foo", "baz"}, {"other", "thing"}}, 25 | ExpectedBody: url.Values{"foo": {"bar", "baz"}, "other": {"thing"}}, 26 | }, 27 | } 28 | 29 | for _, testCase := range testCases { 30 | p := stripe.Params{} 31 | 32 | for _, extra := range testCase.Extras { 33 | p.AddExtra(extra[0], extra[1]) 34 | } 35 | 36 | body := testCase.InitialBody 37 | p.AppendTo(&body) 38 | 39 | if !reflect.DeepEqual(body, testCase.ExpectedBody) { 40 | t.Fatalf("Expected body of %v but got %v.", testCase.ExpectedBody, body) 41 | } 42 | } 43 | } 44 | 45 | func TestListParamsExpansion(t *testing.T) { 46 | testCases := []struct { 47 | InitialBody url.Values 48 | Expand []string 49 | ExpectedBody url.Values 50 | }{ 51 | { 52 | InitialBody: url.Values{"foo": {"bar"}}, 53 | Expand: []string{}, 54 | ExpectedBody: url.Values{"foo": {"bar"}}, 55 | }, 56 | { 57 | InitialBody: url.Values{"foo": {"bar"}}, 58 | Expand: []string{"data", "data.foo"}, 59 | ExpectedBody: url.Values{"foo": {"bar", "baz"}, "expand[]": {"data", "data.foo"}}, 60 | }, 61 | } 62 | 63 | for _, testCase := range testCases { 64 | p := stripe.ListParams{} 65 | 66 | for _, exp := range testCase.Expand { 67 | p.Expand(exp) 68 | } 69 | 70 | body := testCase.InitialBody 71 | p.AppendTo(&body) 72 | 73 | if !reflect.DeepEqual(body, testCase.ExpectedBody) { 74 | t.Fatalf("Expected body of %v but got %v.", testCase.ExpectedBody, body) 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/payment_source.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "net/url" 8 | ) 9 | 10 | // SourceParams is a union struct used to describe an 11 | // arbitrary payment source. 12 | type SourceParams struct { 13 | Token string 14 | Card *CardParams 15 | } 16 | 17 | // AppendDetails adds the source's details to the query string values. 18 | // For cards: when creating a new one, the parameters are passed as a dictionary, but 19 | // on updates they are simply the parameter name. 20 | func (sp *SourceParams) AppendDetails(values *url.Values, creating bool) { 21 | if len(sp.Token) > 0 { 22 | values.Add("source", sp.Token) 23 | } else if sp.Card != nil { 24 | sp.Card.AppendDetails(values, creating) 25 | } 26 | } 27 | 28 | // CustomerSourceParams are used to manipulate a given Stripe 29 | // Customer object's payment sources. 30 | // For more details see https://stripe.com/docs/api#sources 31 | type CustomerSourceParams struct { 32 | Params 33 | Customer string 34 | Source *SourceParams 35 | } 36 | 37 | // SourceVerifyParams are used to verify a customer source 38 | // For more details see https://stripe.com/docs/guides/ach-beta 39 | type SourceVerifyParams struct { 40 | Params 41 | Customer string 42 | Amounts [2]uint8 43 | } 44 | 45 | // SetSource adds valid sources to a CustomerSourceParams object, 46 | // returning an error for unsupported sources. 47 | func (cp *CustomerSourceParams) SetSource(sp interface{}) error { 48 | source, err := SourceParamsFor(sp) 49 | cp.Source = source 50 | return err 51 | } 52 | 53 | // SourceParamsFor creates SourceParams objects around supported 54 | // payment sources, returning errors if not. 55 | // 56 | // Currently supported source types are Card (CardParams) and 57 | // Tokens/IDs (string), where Tokens could be single use card 58 | // tokens or bitcoin receiver ids 59 | func SourceParamsFor(obj interface{}) (*SourceParams, error) { 60 | var sp *SourceParams 61 | var err error 62 | switch p := obj.(type) { 63 | case *CardParams: 64 | sp = &SourceParams{ 65 | Card: p, 66 | } 67 | case string: 68 | sp = &SourceParams{ 69 | Token: p, 70 | } 71 | default: 72 | err = errors.New(fmt.Sprintf("Unsupported source type %s", p)) 73 | } 74 | return sp, err 75 | } 76 | 77 | // Displayer provides a human readable representation of a struct 78 | type Displayer interface { 79 | Display() string 80 | } 81 | 82 | // PaymentSourceType consts represent valid payment sources 83 | type PaymentSourceType string 84 | 85 | const ( 86 | PaymentSourceBankAccount PaymentSourceType = "bank_account" 87 | PaymentSourceBitcoinReceiver PaymentSourceType = "bitcoin_receiver" 88 | PaymentSourceCard PaymentSourceType = "card" 89 | ) 90 | 91 | // PaymentSource describes the payment source used to make a Charge. 92 | // The Type should indicate which object is fleshed out (eg. BitcoinReceiver or Card) 93 | // For more details see https://stripe.com/docs/api#retrieve_charge 94 | type PaymentSource struct { 95 | Type PaymentSourceType `json:"object"` 96 | ID string `json:"id"` 97 | Card *Card `json:"-"` 98 | BitcoinReceiver *BitcoinReceiver `json:"-"` 99 | BankAccount *BankAccount `json:"-"` 100 | Deleted bool `json:"deleted"` 101 | } 102 | 103 | // SourceList is a list object for cards. 104 | type SourceList struct { 105 | ListMeta 106 | Values []*PaymentSource `json:"data"` 107 | } 108 | 109 | // PaymentSourceListParams are used to enumerate the payment sources 110 | // that are attached to a Customer. 111 | type SourceListParams struct { 112 | ListParams 113 | Customer string 114 | } 115 | 116 | // Display human readable representation of source. 117 | func (s *PaymentSource) Display() string { 118 | switch s.Type { 119 | case PaymentSourceBitcoinReceiver: 120 | return s.BitcoinReceiver.Display() 121 | case PaymentSourceCard: 122 | return s.Card.Display() 123 | case PaymentSourceBankAccount: 124 | return s.BankAccount.Display() 125 | } 126 | 127 | return "" 128 | } 129 | 130 | // UnmarshalJSON handles deserialization of a PaymentSource. 131 | // This custom unmarshaling is needed because the specific 132 | // type of payment instrument it refers to is specified in the JSON 133 | func (s *PaymentSource) UnmarshalJSON(data []byte) error { 134 | type source PaymentSource 135 | var ss source 136 | err := json.Unmarshal(data, &ss) 137 | if err == nil { 138 | *s = PaymentSource(ss) 139 | 140 | switch s.Type { 141 | case PaymentSourceBankAccount: 142 | json.Unmarshal(data, &s.BankAccount) 143 | case PaymentSourceBitcoinReceiver: 144 | json.Unmarshal(data, &s.BitcoinReceiver) 145 | case PaymentSourceCard: 146 | json.Unmarshal(data, &s.Card) 147 | } 148 | } else { 149 | // the id is surrounded by "\" characters, so strip them 150 | s.ID = string(data[1 : len(data)-1]) 151 | } 152 | 153 | return nil 154 | } 155 | 156 | // MarshalJSON handles serialization of a PaymentSource. 157 | // This custom marshaling is needed because the specific type 158 | // of payment instrument it represents is specified by the PaymentSourceType 159 | func (s *PaymentSource) MarshalJSON() ([]byte, error) { 160 | var target interface{} 161 | 162 | switch s.Type { 163 | case PaymentSourceBitcoinReceiver: 164 | target = struct { 165 | Type PaymentSourceType `json:"object"` 166 | *BitcoinReceiver 167 | }{ 168 | Type: s.Type, 169 | BitcoinReceiver: s.BitcoinReceiver, 170 | } 171 | case PaymentSourceCard: 172 | var customerID *string 173 | if s.Card.Customer != nil { 174 | customerID = &s.Card.Customer.ID 175 | } 176 | 177 | target = struct { 178 | Type PaymentSourceType `json:"object"` 179 | Customer *string `json:"customer"` 180 | *Card 181 | }{ 182 | Type: s.Type, 183 | Customer: customerID, 184 | Card: s.Card, 185 | } 186 | 187 | case "": 188 | target = s.ID 189 | } 190 | 191 | return json.Marshal(target) 192 | } 193 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/plan.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | // PlanInterval is the list of allowed values for a plan's interval. 4 | // Allowed values are "day", "week", "month", "year". 5 | type PlanInterval string 6 | 7 | // PlanParams is the set of parameters that can be used when creating or updating a plan. 8 | // For more details see https://stripe.com/docs/api#create_plan and https://stripe.com/docs/api#update_plan. 9 | type PlanParams struct { 10 | Params 11 | ID, Name string 12 | Currency Currency 13 | Amount uint64 14 | Interval PlanInterval 15 | IntervalCount, TrialPeriod uint64 16 | Statement string 17 | } 18 | 19 | // PlanListParams is the set of parameters that can be used when listing plans. 20 | // For more details see https://stripe.com/docs/api#list_plans. 21 | type PlanListParams struct { 22 | ListParams 23 | } 24 | 25 | // Plan is the resource representing a Stripe plan. 26 | // For more details see https://stripe.com/docs/api#plans. 27 | type Plan struct { 28 | ID string `json:"id"` 29 | Live bool `json:"livemode"` 30 | Amount uint64 `json:"amount"` 31 | Created int64 `json:"created"` 32 | Currency Currency `json:"currency"` 33 | Interval PlanInterval `json:"interval"` 34 | IntervalCount uint64 `json:"interval_count"` 35 | Name string `json:"name"` 36 | Meta map[string]string `json:"metadata"` 37 | TrialPeriod uint64 `json:"trial_period_days"` 38 | Statement string `json:"statement_descriptor"` 39 | Deleted bool `json:"deleted"` 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/plan/client.go: -------------------------------------------------------------------------------- 1 | // Package plan provides the /plans APIs 2 | package plan 3 | 4 | import ( 5 | "net/url" 6 | "strconv" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | ) 10 | 11 | const ( 12 | Day stripe.PlanInterval = "day" 13 | Week stripe.PlanInterval = "week" 14 | Month stripe.PlanInterval = "month" 15 | Year stripe.PlanInterval = "year" 16 | ) 17 | 18 | // Client is used to invoke /plans APIs. 19 | type Client struct { 20 | B stripe.Backend 21 | Key string 22 | } 23 | 24 | // New POSTs a new plan. 25 | // For more details see https://stripe.com/docs/api#create_plan. 26 | func New(params *stripe.PlanParams) (*stripe.Plan, error) { 27 | return getC().New(params) 28 | } 29 | 30 | func (c Client) New(params *stripe.PlanParams) (*stripe.Plan, error) { 31 | body := &url.Values{ 32 | "id": {params.ID}, 33 | "name": {params.Name}, 34 | "amount": {strconv.FormatUint(params.Amount, 10)}, 35 | "currency": {string(params.Currency)}, 36 | "interval": {string(params.Interval)}, 37 | } 38 | 39 | if params.IntervalCount > 0 { 40 | body.Add("interval_count", strconv.FormatUint(params.IntervalCount, 10)) 41 | } 42 | 43 | if params.TrialPeriod > 0 { 44 | body.Add("trial_period_days", strconv.FormatUint(params.TrialPeriod, 10)) 45 | } 46 | 47 | if len(params.Statement) > 0 { 48 | body.Add("statement_descriptor", params.Statement) 49 | } 50 | params.AppendTo(body) 51 | 52 | plan := &stripe.Plan{} 53 | err := c.B.Call("POST", "/plans", c.Key, body, ¶ms.Params, plan) 54 | 55 | return plan, err 56 | } 57 | 58 | // Get returns the details of a plan. 59 | // For more details see https://stripe.com/docs/api#retrieve_plan. 60 | func Get(id string, params *stripe.PlanParams) (*stripe.Plan, error) { 61 | return getC().Get(id, params) 62 | } 63 | 64 | func (c Client) Get(id string, params *stripe.PlanParams) (*stripe.Plan, error) { 65 | var body *url.Values 66 | var commonParams *stripe.Params 67 | 68 | if params != nil { 69 | commonParams = ¶ms.Params 70 | body = &url.Values{} 71 | params.AppendTo(body) 72 | } 73 | 74 | plan := &stripe.Plan{} 75 | err := c.B.Call("GET", "/plans/"+id, c.Key, body, commonParams, plan) 76 | 77 | return plan, err 78 | } 79 | 80 | // Update updates a plan's properties. 81 | // For more details see https://stripe.com/docs/api#update_plan. 82 | func Update(id string, params *stripe.PlanParams) (*stripe.Plan, error) { 83 | return getC().Update(id, params) 84 | } 85 | 86 | func (c Client) Update(id string, params *stripe.PlanParams) (*stripe.Plan, error) { 87 | var body *url.Values 88 | var commonParams *stripe.Params 89 | 90 | if params != nil { 91 | commonParams = ¶ms.Params 92 | body = &url.Values{} 93 | 94 | if len(params.Name) > 0 { 95 | body.Add("name", params.Name) 96 | } 97 | 98 | if len(params.Statement) > 0 { 99 | body.Add("statement_descriptor", params.Statement) 100 | } 101 | 102 | params.AppendTo(body) 103 | } 104 | 105 | plan := &stripe.Plan{} 106 | err := c.B.Call("POST", "/plans/"+id, c.Key, body, commonParams, plan) 107 | 108 | return plan, err 109 | } 110 | 111 | // Del removes a plan. 112 | // For more details see https://stripe.com/docs/api#delete_plan. 113 | func Del(id string) (*stripe.Plan, error) { 114 | return getC().Del(id) 115 | } 116 | 117 | func (c Client) Del(id string) (*stripe.Plan, error) { 118 | plan := &stripe.Plan{} 119 | err := c.B.Call("DELETE", "/plans/"+id, c.Key, nil, nil, plan) 120 | 121 | return plan, err 122 | } 123 | 124 | // List returns a list of plans. 125 | // For more details see https://stripe.com/docs/api#list_plans. 126 | func List(params *stripe.PlanListParams) *Iter { 127 | return getC().List(params) 128 | } 129 | 130 | func (c Client) List(params *stripe.PlanListParams) *Iter { 131 | type planList struct { 132 | stripe.ListMeta 133 | Values []*stripe.Plan `json:"data"` 134 | } 135 | 136 | var body *url.Values 137 | var lp *stripe.ListParams 138 | 139 | if params != nil { 140 | body = &url.Values{} 141 | 142 | params.AppendTo(body) 143 | lp = ¶ms.ListParams 144 | } 145 | 146 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 147 | list := &planList{} 148 | err := c.B.Call("GET", "/plans", c.Key, &b, nil, list) 149 | 150 | ret := make([]interface{}, len(list.Values)) 151 | for i, v := range list.Values { 152 | ret[i] = v 153 | } 154 | 155 | return ret, list.ListMeta, err 156 | })} 157 | } 158 | 159 | // Iter is an iterator for lists of Plans. 160 | // The embedded Iter carries methods with it; 161 | // see its documentation for details. 162 | type Iter struct { 163 | *stripe.Iter 164 | } 165 | 166 | // Plan returns the most recent Plan 167 | // visited by a call to Next. 168 | func (i *Iter) Plan() *stripe.Plan { 169 | return i.Current().(*stripe.Plan) 170 | } 171 | 172 | func getC() Client { 173 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 174 | } 175 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/plan/client_test.go: -------------------------------------------------------------------------------- 1 | package plan 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | stripe "github.com/stripe/stripe-go" 8 | "github.com/stripe/stripe-go/currency" 9 | . "github.com/stripe/stripe-go/utils" 10 | ) 11 | 12 | func init() { 13 | stripe.Key = GetTestKey() 14 | } 15 | 16 | func TestPlanNew(t *testing.T) { 17 | planParams := &stripe.PlanParams{ 18 | ID: "test_plan", 19 | Name: "Test Plan", 20 | Amount: 99, 21 | Currency: currency.USD, 22 | Interval: Month, 23 | IntervalCount: 3, 24 | TrialPeriod: 30, 25 | Statement: "Test Plan", 26 | } 27 | 28 | target, err := New(planParams) 29 | 30 | if err != nil { 31 | t.Error(err) 32 | } 33 | 34 | if target.ID != planParams.ID { 35 | t.Errorf("ID %q does not match expected id %q\n", target.ID, planParams.ID) 36 | } 37 | 38 | if target.Name != planParams.Name { 39 | t.Errorf("Name %q does not match expected name %q\n", target.Name, planParams.Name) 40 | } 41 | 42 | if target.Amount != planParams.Amount { 43 | t.Errorf("Amount %v does not match expected amount %v\n", target.Amount, planParams.Amount) 44 | } 45 | 46 | if target.Currency != planParams.Currency { 47 | t.Errorf("Currency %q does not match expected currency %q\n", target.Currency, planParams.Currency) 48 | } 49 | 50 | if target.Interval != planParams.Interval { 51 | t.Errorf("Interval %q does not match expected interval %q\n", target.Interval, planParams.Interval) 52 | } 53 | 54 | if target.IntervalCount != planParams.IntervalCount { 55 | t.Errorf("Interval count %v does not match expected interval count %v\n", target.IntervalCount, planParams.IntervalCount) 56 | } 57 | 58 | if target.TrialPeriod != planParams.TrialPeriod { 59 | t.Errorf("Trial period %v does not match expected trial period %v\n", target.TrialPeriod, planParams.TrialPeriod) 60 | } 61 | 62 | if target.Statement != planParams.Statement { 63 | t.Errorf("Statement %q does not match expected statement %q\n", target.Statement, planParams.Statement) 64 | } 65 | 66 | Del(planParams.ID) 67 | } 68 | 69 | func TestPlanGet(t *testing.T) { 70 | planParams := &stripe.PlanParams{ 71 | ID: "test_plan", 72 | Name: "Test Plan", 73 | Amount: 99, 74 | Currency: currency.USD, 75 | Interval: Month, 76 | } 77 | 78 | New(planParams) 79 | target, err := Get(planParams.ID, nil) 80 | 81 | if err != nil { 82 | t.Error(err) 83 | } 84 | 85 | if target.ID != planParams.ID { 86 | t.Errorf("Plan id %q does not match expected id %q\n", target.ID, planParams.ID) 87 | } 88 | 89 | Del(planParams.ID) 90 | } 91 | 92 | func TestPlanUpdate(t *testing.T) { 93 | planParams := &stripe.PlanParams{ 94 | ID: "test_plan", 95 | Name: "Original Name", 96 | Amount: 99, 97 | Currency: currency.USD, 98 | Interval: Month, 99 | IntervalCount: 3, 100 | TrialPeriod: 30, 101 | Statement: "Original Plan", 102 | } 103 | 104 | New(planParams) 105 | 106 | updatedPlan := &stripe.PlanParams{ 107 | Name: "Updated Name", 108 | Statement: "Updated Plan", 109 | } 110 | 111 | target, err := Update(planParams.ID, updatedPlan) 112 | 113 | if err != nil { 114 | t.Error(err) 115 | } 116 | 117 | if target.Name != updatedPlan.Name { 118 | t.Errorf("Name %q does not match expected name %q\n", target.Name, updatedPlan.Name) 119 | } 120 | 121 | if target.Statement != updatedPlan.Statement { 122 | t.Errorf("Statement %q does not match expected statement %q\n", target.Statement, updatedPlan.Statement) 123 | } 124 | 125 | Del(planParams.ID) 126 | } 127 | 128 | func TestPlanDel(t *testing.T) { 129 | planParams := &stripe.PlanParams{ 130 | ID: "test_plan", 131 | Name: "Test Plan", 132 | Amount: 99, 133 | Currency: currency.USD, 134 | Interval: Month, 135 | } 136 | 137 | New(planParams) 138 | 139 | planDel, err := Del(planParams.ID) 140 | if err != nil { 141 | t.Error(err) 142 | } 143 | 144 | if !planDel.Deleted { 145 | t.Errorf("Plan id %q expected to be marked as deleted on the returned resource\n", planDel.ID) 146 | } 147 | } 148 | 149 | func TestPlanList(t *testing.T) { 150 | const runs = 3 151 | for i := 0; i < runs; i++ { 152 | planParams := &stripe.PlanParams{ 153 | ID: fmt.Sprintf("test_%v", i), 154 | Name: fmt.Sprintf("test_%v", i), 155 | Amount: 99, 156 | Currency: currency.USD, 157 | Interval: Month, 158 | } 159 | 160 | New(planParams) 161 | } 162 | 163 | params := &stripe.PlanListParams{} 164 | params.Filters.AddFilter("limit", "", "1") 165 | 166 | plansChecked := 0 167 | i := List(params) 168 | for i.Next() && plansChecked < runs { 169 | target := i.Plan() 170 | 171 | if i.Meta() == nil { 172 | t.Error("No metadata returned") 173 | } 174 | 175 | if target.Amount != 99 { 176 | t.Errorf("Amount %v does not match expected value\n", target.Amount) 177 | } 178 | 179 | plansChecked += 1 180 | } 181 | if err := i.Err(); err != nil { 182 | t.Error(err) 183 | } 184 | 185 | for i := 0; i < runs; i++ { 186 | Del(fmt.Sprintf("test_%v", i)) 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/product.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // PackageDimensions represents the dimension of a product or a sku from the 6 | // perspective of shipping. 7 | type PackageDimensions struct { 8 | Height float64 `json:"height"` 9 | Length float64 `json:"length"` 10 | Width float64 `json:"width"` 11 | Weight float64 `json:"weight"` 12 | } 13 | 14 | // ProductParams is the set of parameters that can be used 15 | // when creating or updating a product. 16 | // For more details, see https://stripe.com/docs/api#create_product 17 | // and https://stripe.com/docs/api#update_product. 18 | type ProductParams struct { 19 | Params 20 | ID string 21 | Active *bool 22 | Name string 23 | Caption string 24 | Desc string 25 | Attrs []string 26 | Images []string 27 | URL string 28 | Shippable *bool 29 | PackageDimensions *PackageDimensions 30 | } 31 | 32 | // Product is the resource representing a Stripe product. 33 | // For more details see https://stripe.com/docs/api#products. 34 | type Product struct { 35 | ID string `json:"id"` 36 | Created int64 `json:"created"` 37 | Updated int64 `json:"updated"` 38 | Live bool `json:"livemode"` 39 | Active bool `json:"active"` 40 | Name string `json:"name"` 41 | Caption string `json:"caption"` 42 | Desc string `json:"description"` 43 | Attrs []string `json:"attributes"` 44 | Shippable bool `json:"shippable"` 45 | PackageDimensions *PackageDimensions `json:"package_dimensions"` 46 | Images []string `json:"images"` 47 | Meta map[string]string `json:"metadata"` 48 | URL string `json:"url"` 49 | Skus *SKUList `json:"skus"` 50 | } 51 | 52 | // ProductListParams is the set of parameters that can be used when 53 | // listing products. For more details, see: 54 | // https://stripe.com/docs/api#list_products. 55 | type ProductListParams struct { 56 | ListParams 57 | Active *bool 58 | IDs []string 59 | Shippable *bool 60 | URL string 61 | } 62 | 63 | // UnmarshalJSON handles deserialization of a Product. 64 | // This custom unmarshaling is needed because the resulting 65 | // property may be an id or the full struct if it was expanded. 66 | func (p *Product) UnmarshalJSON(data []byte) error { 67 | type product Product 68 | var pr product 69 | err := json.Unmarshal(data, &pr) 70 | if err == nil { 71 | *p = Product(pr) 72 | } else { 73 | p.ID = string(data[1 : len(data)-1]) 74 | } 75 | 76 | return nil 77 | } 78 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/product/client_test.go: -------------------------------------------------------------------------------- 1 | package product 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "testing" 7 | "time" 8 | 9 | stripe "github.com/stripe/stripe-go" 10 | . "github.com/stripe/stripe-go/utils" 11 | ) 12 | 13 | func init() { 14 | stripe.Key = GetTestKey() 15 | rand.Seed(time.Now().UTC().UnixNano()) 16 | } 17 | 18 | func TestProduct(t *testing.T) { 19 | active := true 20 | shippable := true 21 | 22 | p, err := New(&stripe.ProductParams{ 23 | Active: &active, 24 | Name: "test name", 25 | Desc: "This is a description", 26 | Caption: "This is a caption", 27 | Attrs: []string{"attr1", "attr2"}, 28 | URL: "http://example.com", 29 | Shippable: &shippable, 30 | PackageDimensions: &stripe.PackageDimensions{ 31 | Height: 2.234, 32 | Length: 5.10, 33 | Width: 6.50, 34 | Weight: 10, 35 | }, 36 | }) 37 | 38 | if err != nil { 39 | t.Fatalf("%+v", err) 40 | } 41 | 42 | if p.ID == "" { 43 | t.Errorf("ID is not set %v", p.ID) 44 | } 45 | 46 | if p.Created == 0 { 47 | t.Errorf("Created date is not set") 48 | } 49 | 50 | if p.Updated == 0 { 51 | t.Errorf("Updated is not set") 52 | } 53 | 54 | if p.Name != "test name" { 55 | t.Errorf("Name is invalid: %v", p.Name) 56 | } 57 | 58 | if p.Caption != "This is a caption" { 59 | t.Errorf("Caption is invalid: %v", p.Caption) 60 | } 61 | 62 | if !p.Shippable { 63 | t.Errorf("Product should be shippable, but is not") 64 | } 65 | 66 | if p.Desc != "This is a description" { 67 | t.Errorf("Description is invalid: %v", p.Desc) 68 | } 69 | 70 | if p.URL != "http://example.com" { 71 | t.Errorf("URL is invalid: %v", p.URL) 72 | } 73 | 74 | if p.PackageDimensions == nil || 75 | p.PackageDimensions.Height != 2.23 || 76 | p.PackageDimensions.Length != 5.10 || 77 | p.PackageDimensions.Width != 6.50 || 78 | p.PackageDimensions.Weight != 10 { 79 | t.Errorf("PackageDimensions is invalid: %v", p.PackageDimensions) 80 | } 81 | } 82 | 83 | func TestProductWithCustomID(t *testing.T) { 84 | randID := fmt.Sprintf("TEST-PRODUCT-%v", RandSeq(16)) 85 | p, err := New(&stripe.ProductParams{ 86 | ID: randID, 87 | Name: "Test product name", 88 | Desc: "Test description", 89 | }) 90 | 91 | if err != nil { 92 | t.Fatalf("%+v", err) 93 | } 94 | 95 | if p.ID != randID { 96 | t.Errorf("Expected ID to be %v, but got back %v", randID, p.ID) 97 | } 98 | } 99 | 100 | func TestProductWithoutDescription(t *testing.T) { 101 | name := RandSeq(16) 102 | p, err := New(&stripe.ProductParams{ 103 | Name: name, 104 | }) 105 | 106 | if err != nil { 107 | t.Fatalf("%+v", err) 108 | } 109 | 110 | if p.Name != name { 111 | t.Errorf("Expected name to be %v, but got back %v", name, p.Name) 112 | } 113 | } 114 | func TestProductUpdate(t *testing.T) { 115 | randID := fmt.Sprintf("TEST-PRODUCT-%v", RandSeq(16)) 116 | p, err := New(&stripe.ProductParams{ 117 | ID: randID, 118 | Name: "Test product name", 119 | Desc: "Test description", 120 | }) 121 | if err != nil { 122 | t.Fatalf("%+v", err) 123 | } 124 | p, err = Update(p.ID, &stripe.ProductParams{ 125 | Desc: "new description", 126 | }) 127 | if err != nil { 128 | t.Fatalf("%+v", err) 129 | } 130 | if p.Desc != "new description" { 131 | t.Errorf("Invalid description: %v", p.Desc) 132 | } 133 | } 134 | 135 | func TestProductList(t *testing.T) { 136 | const runs = 3 137 | randID := fmt.Sprintf("example.com/", RandSeq(16)) 138 | for i := 0; i < runs; i++ { 139 | shippable := i == 0 140 | active := i == 1 141 | prodParams := &stripe.ProductParams{ 142 | Name: fmt.Sprintf("test_%v", i), 143 | Shippable: &shippable, 144 | Active: &active, 145 | URL: randID, 146 | } 147 | 148 | New(prodParams) 149 | } 150 | 151 | params := &stripe.ProductListParams{} 152 | params.Shippable = new(bool) 153 | *params.Shippable = true 154 | params.URL = randID 155 | 156 | i := List(params) 157 | for i.Next() { 158 | target := i.Product() 159 | 160 | if i.Meta() == nil { 161 | t.Error("No metadata returned") 162 | } 163 | 164 | if target.Name != "test_0" { 165 | t.Errorf("Filtered product %v is not the expected\n", target.Name) 166 | } 167 | } 168 | if err := i.Err(); err != nil { 169 | t.Error(err) 170 | } 171 | 172 | params.Shippable = nil 173 | params.Active = new(bool) 174 | *params.Active = true 175 | 176 | i = List(params) 177 | for i.Next() { 178 | target := i.Product() 179 | 180 | if i.Meta() == nil { 181 | t.Error("No metadata returned") 182 | } 183 | 184 | if target.Name != "test_1" { 185 | t.Errorf("Filtered product %v is not the expected\n", target.Name) 186 | } 187 | } 188 | if err := i.Err(); err != nil { 189 | t.Error(err) 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/recipient.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // RecipientType is the list of allowed values for the recipient's type. 6 | // Allowed values are "individual", "corporation". 7 | type RecipientType string 8 | 9 | // RecipientParams is the set of parameters that can be used when creating or updating recipients. 10 | // For more details see https://stripe.com/docs/api#create_recipient and https://stripe.com/docs/api#update_recipient. 11 | type RecipientParams struct { 12 | Params 13 | Name string 14 | Type RecipientType 15 | TaxID, Token, Email, Desc string 16 | Bank *BankAccountParams 17 | Card *CardParams 18 | DefaultCard string 19 | } 20 | 21 | // RecipientListParams is the set of parameters that can be used when listing recipients. 22 | // For more details see https://stripe.com/docs/api#list_recipients. 23 | type RecipientListParams struct { 24 | ListParams 25 | Verified bool 26 | } 27 | 28 | // Recipient is the resource representing a Stripe recipient. 29 | // For more details see https://stripe.com/docs/api#recipients. 30 | type Recipient struct { 31 | ID string `json:"id"` 32 | Live bool `json:"livemode"` 33 | Created int64 `json:"created"` 34 | Type RecipientType `json:"type"` 35 | Bank *BankAccount `json:"active_account"` 36 | Desc string `json:"description"` 37 | Email string `json:"email"` 38 | Meta map[string]string `json:"metadata"` 39 | Name string `json:"name"` 40 | Cards *CardList `json:"cards"` 41 | DefaultCard *Card `json:"default_card"` 42 | Deleted bool `json:"deleted"` 43 | } 44 | 45 | // UnmarshalJSON handles deserialization of a Recipient. 46 | // This custom unmarshaling is needed because the resulting 47 | // property may be an id or the full struct if it was expanded. 48 | func (r *Recipient) UnmarshalJSON(data []byte) error { 49 | type recipient Recipient 50 | var rr recipient 51 | err := json.Unmarshal(data, &rr) 52 | if err == nil { 53 | *r = Recipient(rr) 54 | } else { 55 | // the id is surrounded by "\" characters, so strip them 56 | r.ID = string(data[1 : len(data)-1]) 57 | } 58 | 59 | return nil 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/recipient/client.go: -------------------------------------------------------------------------------- 1 | // Package recipient provides the /recipients APIs 2 | package recipient 3 | 4 | import ( 5 | "net/url" 6 | "strconv" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | ) 10 | 11 | const ( 12 | Individual stripe.RecipientType = "individual" 13 | Corp stripe.RecipientType = "corporation" 14 | ) 15 | 16 | // Client is used to invoke /recipients APIs. 17 | type Client struct { 18 | B stripe.Backend 19 | Key string 20 | } 21 | 22 | // New POSTs a new recipient. 23 | // For more details see https://stripe.com/docs/api#create_recipient. 24 | func New(params *stripe.RecipientParams) (*stripe.Recipient, error) { 25 | return getC().New(params) 26 | } 27 | 28 | func (c Client) New(params *stripe.RecipientParams) (*stripe.Recipient, error) { 29 | body := &url.Values{ 30 | "name": {params.Name}, 31 | "type": {string(params.Type)}, 32 | } 33 | 34 | if params.Bank != nil { 35 | if len(params.Bank.Token) > 0 { 36 | body.Add("bank_account", params.Bank.Token) 37 | } else { 38 | params.Bank.AppendDetails(body) 39 | } 40 | } 41 | 42 | if len(params.Token) > 0 { 43 | body.Add("card", params.Token) 44 | } else if params.Card != nil { 45 | params.Card.AppendDetails(body, true) 46 | } 47 | 48 | if len(params.TaxID) > 0 { 49 | body.Add("tax_id", params.TaxID) 50 | } 51 | 52 | if len(params.Email) > 0 { 53 | body.Add("email", params.Email) 54 | } 55 | 56 | if len(params.Desc) > 0 { 57 | body.Add("description", params.Desc) 58 | } 59 | params.AppendTo(body) 60 | 61 | recipient := &stripe.Recipient{} 62 | err := c.B.Call("POST", "/recipients", c.Key, body, ¶ms.Params, recipient) 63 | 64 | return recipient, err 65 | } 66 | 67 | // Get returns the details of a recipient. 68 | // For more details see https://stripe.com/docs/api#retrieve_recipient. 69 | func Get(id string, params *stripe.RecipientParams) (*stripe.Recipient, error) { 70 | return getC().Get(id, params) 71 | } 72 | 73 | func (c Client) Get(id string, params *stripe.RecipientParams) (*stripe.Recipient, error) { 74 | var body *url.Values 75 | var commonParams *stripe.Params 76 | 77 | if params != nil { 78 | commonParams = ¶ms.Params 79 | body = &url.Values{} 80 | params.AppendTo(body) 81 | } 82 | 83 | recipient := &stripe.Recipient{} 84 | err := c.B.Call("GET", "/recipients/"+id, c.Key, body, commonParams, recipient) 85 | 86 | return recipient, err 87 | } 88 | 89 | // Update updates a recipient's properties. 90 | // For more details see https://stripe.com/docs/api#update_recipient. 91 | func Update(id string, params *stripe.RecipientParams) (*stripe.Recipient, error) { 92 | return getC().Update(id, params) 93 | } 94 | 95 | func (c Client) Update(id string, params *stripe.RecipientParams) (*stripe.Recipient, error) { 96 | var body *url.Values 97 | var commonParams *stripe.Params 98 | 99 | if params != nil { 100 | commonParams = ¶ms.Params 101 | body = &url.Values{} 102 | 103 | if len(params.Name) > 0 { 104 | body.Add("name", params.Name) 105 | } 106 | 107 | if params.Bank != nil { 108 | params.Bank.AppendDetails(body) 109 | } 110 | 111 | if len(params.Token) > 0 { 112 | body.Add("card", params.Token) 113 | } else if params.Card != nil { 114 | params.Card.AppendDetails(body, true) 115 | } 116 | 117 | if len(params.TaxID) > 0 { 118 | body.Add("tax_id", params.TaxID) 119 | } 120 | 121 | if len(params.DefaultCard) > 0 { 122 | body.Add("default_card", params.DefaultCard) 123 | } 124 | 125 | if len(params.Email) > 0 { 126 | body.Add("email", params.Email) 127 | } 128 | 129 | if len(params.Desc) > 0 { 130 | body.Add("description", params.Desc) 131 | } 132 | 133 | params.AppendTo(body) 134 | } 135 | 136 | recipient := &stripe.Recipient{} 137 | err := c.B.Call("POST", "/recipients/"+id, c.Key, body, commonParams, recipient) 138 | 139 | return recipient, err 140 | } 141 | 142 | // Del removes a recipient. 143 | // For more details see https://stripe.com/docs/api#delete_recipient. 144 | func Del(id string) (*stripe.Recipient, error) { 145 | return getC().Del(id) 146 | } 147 | 148 | func (c Client) Del(id string) (*stripe.Recipient, error) { 149 | recipient := &stripe.Recipient{} 150 | err := c.B.Call("DELETE", "/recipients/"+id, c.Key, nil, nil, recipient) 151 | 152 | return recipient, err 153 | } 154 | 155 | // List returns a list of recipients. 156 | // For more details see https://stripe.com/docs/api#list_recipients. 157 | func List(params *stripe.RecipientListParams) *Iter { 158 | return getC().List(params) 159 | } 160 | 161 | func (c Client) List(params *stripe.RecipientListParams) *Iter { 162 | type recipientList struct { 163 | stripe.ListMeta 164 | Values []*stripe.Recipient `json:"data"` 165 | } 166 | 167 | var body *url.Values 168 | var lp *stripe.ListParams 169 | 170 | if params != nil { 171 | body = &url.Values{} 172 | 173 | if params.Verified { 174 | body.Add("verified", strconv.FormatBool(true)) 175 | } 176 | 177 | params.AppendTo(body) 178 | lp = ¶ms.ListParams 179 | } 180 | 181 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 182 | list := &recipientList{} 183 | err := c.B.Call("GET", "/recipients", c.Key, &b, nil, list) 184 | 185 | ret := make([]interface{}, len(list.Values)) 186 | for i, v := range list.Values { 187 | ret[i] = v 188 | } 189 | 190 | return ret, list.ListMeta, err 191 | })} 192 | } 193 | 194 | // Iter is an iterator for lists of Recipients. 195 | // The embedded Iter carries methods with it; 196 | // see its documentation for details. 197 | type Iter struct { 198 | *stripe.Iter 199 | } 200 | 201 | // Recipient returns the most recent Recipient 202 | // visited by a call to Next. 203 | func (i *Iter) Recipient() *stripe.Recipient { 204 | return i.Current().(*stripe.Recipient) 205 | } 206 | 207 | func getC() Client { 208 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 209 | } 210 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/refund.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // RefundReason, if set, is the reason the refund is being made--allowed values 6 | // are "fraudulent", "duplicate", and "requested_by_customer". 7 | type RefundReason string 8 | 9 | // RefundParams is the set of parameters that can be used when refunding a charge. 10 | // For more details see https://stripe.com/docs/api#refund. 11 | type RefundParams struct { 12 | Params 13 | Charge string 14 | Amount uint64 15 | Fee, Transfer bool 16 | Reason RefundReason 17 | } 18 | 19 | // RefundListParams is the set of parameters that can be used when listing refunds. 20 | // For more details see https://stripe.com/docs/api#list_refunds. 21 | type RefundListParams struct { 22 | ListParams 23 | } 24 | 25 | // Refund is the resource representing a Stripe refund. 26 | // For more details see https://stripe.com/docs/api#refunds. 27 | type Refund struct { 28 | ID string `json:"id"` 29 | Amount uint64 `json:"amount"` 30 | Created int64 `json:"created"` 31 | Currency Currency `json:"currency"` 32 | Tx *Transaction `json:"balance_transaction"` 33 | Charge string `json:"charge"` 34 | Meta map[string]string `json:"metadata"` 35 | Reason RefundReason `json:"reason"` 36 | } 37 | 38 | // RefundList is a list object for refunds. 39 | type RefundList struct { 40 | ListMeta 41 | Values []*Refund `json:"data"` 42 | } 43 | 44 | // UnmarshalJSON handles deserialization of a Refund. 45 | // This custom unmarshaling is needed because the resulting 46 | // property may be an id or the full struct if it was expanded. 47 | func (r *Refund) UnmarshalJSON(data []byte) error { 48 | type refund Refund 49 | var rr refund 50 | err := json.Unmarshal(data, &rr) 51 | if err == nil { 52 | *r = Refund(rr) 53 | } else { 54 | // the id is surrounded by "\" characters, so strip them 55 | r.ID = string(data[1 : len(data)-1]) 56 | } 57 | 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/refund/client.go: -------------------------------------------------------------------------------- 1 | // Package refund provides the /refunds APIs 2 | package refund 3 | 4 | import ( 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | 9 | stripe "github.com/stripe/stripe-go" 10 | ) 11 | 12 | const ( 13 | RefundFraudulent stripe.RefundReason = "fraudulent" 14 | RefundDuplicate stripe.RefundReason = "duplicate" 15 | RefundRequestedByCustomer stripe.RefundReason = "requested_by_customer" 16 | ) 17 | 18 | // Client is used to invoke /refunds APIs. 19 | type Client struct { 20 | B stripe.Backend 21 | Key string 22 | } 23 | 24 | // New refunds a charge previously created. 25 | // For more details see https://stripe.com/docs/api#refund_charge. 26 | func New(params *stripe.RefundParams) (*stripe.Refund, error) { 27 | return getC().New(params) 28 | } 29 | 30 | func (c Client) New(params *stripe.RefundParams) (*stripe.Refund, error) { 31 | body := &url.Values{} 32 | 33 | if params.Amount > 0 { 34 | body.Add("amount", strconv.FormatUint(params.Amount, 10)) 35 | } 36 | 37 | if params.Fee { 38 | body.Add("refund_application_fee", strconv.FormatBool(params.Fee)) 39 | } 40 | 41 | if params.Transfer { 42 | body.Add("reverse_transfer", strconv.FormatBool(params.Transfer)) 43 | } 44 | 45 | if len(params.Reason) > 0 { 46 | body.Add("reason", string(params.Reason)) 47 | } 48 | 49 | if len(params.Charge) > 0 { 50 | body.Add("charge", string(params.Charge)) 51 | } 52 | 53 | params.AppendTo(body) 54 | 55 | refund := &stripe.Refund{} 56 | err := c.B.Call("POST", fmt.Sprintf("/refunds"), c.Key, body, ¶ms.Params, refund) 57 | 58 | return refund, err 59 | } 60 | 61 | // Get returns the details of a refund. 62 | // For more details see https://stripe.com/docs/api#retrieve_refund. 63 | func Get(id string, params *stripe.RefundParams) (*stripe.Refund, error) { 64 | return getC().Get(id, params) 65 | } 66 | 67 | func (c Client) Get(id string, params *stripe.RefundParams) (*stripe.Refund, error) { 68 | body := &url.Values{} 69 | params.AppendTo(body) 70 | 71 | refund := &stripe.Refund{} 72 | err := c.B.Call("GET", fmt.Sprintf("/refunds/%v", id), c.Key, body, ¶ms.Params, refund) 73 | 74 | return refund, err 75 | } 76 | 77 | // Update updates a refund's properties. 78 | // For more details see https://stripe.com/docs/api#update_refund. 79 | func Update(id string, params *stripe.RefundParams) (*stripe.Refund, error) { 80 | return getC().Update(id, params) 81 | } 82 | 83 | func (c Client) Update(id string, params *stripe.RefundParams) (*stripe.Refund, error) { 84 | body := &url.Values{} 85 | 86 | params.AppendTo(body) 87 | 88 | refund := &stripe.Refund{} 89 | err := c.B.Call("POST", fmt.Sprintf("/refunds/%v", id), c.Key, body, ¶ms.Params, refund) 90 | 91 | return refund, err 92 | } 93 | 94 | // List returns a list of refunds. 95 | // For more details see https://stripe.com/docs/api#list_refunds. 96 | func List(params *stripe.RefundListParams) *Iter { 97 | return getC().List(params) 98 | } 99 | 100 | func (c Client) List(params *stripe.RefundListParams) *Iter { 101 | body := &url.Values{} 102 | var lp *stripe.ListParams 103 | 104 | params.AppendTo(body) 105 | lp = ¶ms.ListParams 106 | 107 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 108 | list := &stripe.RefundList{} 109 | err := c.B.Call("GET", fmt.Sprintf("/refunds"), c.Key, &b, nil, list) 110 | 111 | ret := make([]interface{}, len(list.Values)) 112 | for i, v := range list.Values { 113 | ret[i] = v 114 | } 115 | 116 | return ret, list.ListMeta, err 117 | })} 118 | } 119 | 120 | // Iter is an iterator for lists of Refunds. 121 | // The embedded Iter carries methods with it; 122 | // see its documentation for details. 123 | type Iter struct { 124 | *stripe.Iter 125 | } 126 | 127 | // Refund returns the most recent Refund 128 | // visited by a call to Next. 129 | func (i *Iter) Refund() *stripe.Refund { 130 | return i.Current().(*stripe.Refund) 131 | } 132 | 133 | func getC() Client { 134 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 135 | } 136 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/reversal.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // ReversalParams is the set of parameters that can be used when reversing a transfer. 6 | type ReversalParams struct { 7 | Params 8 | Transfer string 9 | Amount uint64 10 | Fee bool 11 | } 12 | 13 | // ReversalListParams is the set of parameters that can be used when listing reversals. 14 | type ReversalListParams struct { 15 | ListParams 16 | Transfer string 17 | } 18 | 19 | // Reversal represents a transfer reversal. 20 | type Reversal struct { 21 | ID string `json:"id"` 22 | Amount uint64 `json:"amount"` 23 | Created int64 `json:"created"` 24 | Currency Currency `json:"currency"` 25 | Transfer string `json:"transfer"` 26 | Meta map[string]string `json:"metadata"` 27 | Tx *Transaction `json:"balance_transaction"` 28 | } 29 | 30 | // ReversalList is a list of object for reversals. 31 | type ReversalList struct { 32 | ListMeta 33 | Values []*Reversal `json:"data"` 34 | } 35 | 36 | // UnmarshalJSON handles deserialization of a Reversal. 37 | // This custom unmarshaling is needed because the resulting 38 | // property may be an id or the full struct if it was expanded. 39 | func (r *Reversal) UnmarshalJSON(data []byte) error { 40 | type reversal Reversal 41 | var rr reversal 42 | err := json.Unmarshal(data, &rr) 43 | if err == nil { 44 | *r = Reversal(rr) 45 | } else { 46 | // the id is surrounded by "\" characters, so strip them 47 | r.ID = string(data[1 : len(data)-1]) 48 | } 49 | 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/reversal/client.go: -------------------------------------------------------------------------------- 1 | // Package reversal provides the /transfers/reversals APIs 2 | package reversal 3 | 4 | import ( 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | 9 | stripe "github.com/stripe/stripe-go" 10 | ) 11 | 12 | // Client is used to invoke /transfers/reversals APIs. 13 | type Client struct { 14 | B stripe.Backend 15 | Key string 16 | } 17 | 18 | // New POSTs a new transfer reversal. 19 | func New(params *stripe.ReversalParams) (*stripe.Reversal, error) { 20 | return getC().New(params) 21 | } 22 | 23 | func (c Client) New(params *stripe.ReversalParams) (*stripe.Reversal, error) { 24 | body := &url.Values{} 25 | 26 | if params.Amount > 0 { 27 | body.Add("amount", strconv.FormatUint(params.Amount, 10)) 28 | } 29 | 30 | if params.Fee { 31 | body.Add("refund_application_fee", strconv.FormatBool(params.Fee)) 32 | } 33 | 34 | params.AppendTo(body) 35 | 36 | reversal := &stripe.Reversal{} 37 | err := c.B.Call("POST", fmt.Sprintf("/transfers/%v/reversals", params.Transfer), c.Key, body, ¶ms.Params, reversal) 38 | 39 | return reversal, err 40 | } 41 | 42 | // Get returns the details of a transfer reversal. 43 | func Get(id string, params *stripe.ReversalParams) (*stripe.Reversal, error) { 44 | return getC().Get(id, params) 45 | } 46 | 47 | func (c Client) Get(id string, params *stripe.ReversalParams) (*stripe.Reversal, error) { 48 | if params == nil { 49 | return nil, fmt.Errorf("params cannot be nil, and params.Transfer must be set") 50 | } 51 | 52 | body := &url.Values{} 53 | params.AppendTo(body) 54 | 55 | reversal := &stripe.Reversal{} 56 | err := c.B.Call("GET", fmt.Sprintf("/transfers/%v/reversals/%v", params.Transfer, id), c.Key, body, ¶ms.Params, reversal) 57 | 58 | return reversal, err 59 | } 60 | 61 | // Update updates a transfer reversal's properties. 62 | func Update(id string, params *stripe.ReversalParams) (*stripe.Reversal, error) { 63 | return getC().Update(id, params) 64 | } 65 | 66 | func (c Client) Update(id string, params *stripe.ReversalParams) (*stripe.Reversal, error) { 67 | body := &url.Values{} 68 | 69 | params.AppendTo(body) 70 | 71 | reversal := &stripe.Reversal{} 72 | err := c.B.Call("POST", fmt.Sprintf("/transfers/%v/reversals/%v", params.Transfer, id), c.Key, body, ¶ms.Params, reversal) 73 | 74 | return reversal, err 75 | } 76 | 77 | // List returns a list of transfer reversals. 78 | func List(params *stripe.ReversalListParams) *Iter { 79 | return getC().List(params) 80 | } 81 | 82 | func (c Client) List(params *stripe.ReversalListParams) *Iter { 83 | body := &url.Values{} 84 | var lp *stripe.ListParams 85 | 86 | params.AppendTo(body) 87 | lp = ¶ms.ListParams 88 | 89 | return &Iter{stripe.GetIter(lp, body, func(b url.Values) ([]interface{}, stripe.ListMeta, error) { 90 | list := &stripe.ReversalList{} 91 | err := c.B.Call("GET", fmt.Sprintf("/transfers/%v/reversals", params.Transfer), c.Key, &b, nil, list) 92 | 93 | ret := make([]interface{}, len(list.Values)) 94 | for i, v := range list.Values { 95 | ret[i] = v 96 | } 97 | 98 | return ret, list.ListMeta, err 99 | })} 100 | } 101 | 102 | // Iter is an iterator for lists of Reversals. 103 | // The embedded Iter carries methods with it; 104 | // see its documentation for details. 105 | type Iter struct { 106 | *stripe.Iter 107 | } 108 | 109 | // Refund returns the most recent Reversals 110 | // visited by a call to Next. 111 | func (i *Iter) Reversal() *stripe.Reversal { 112 | return i.Current().(*stripe.Reversal) 113 | } 114 | 115 | func getC() Client { 116 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 117 | } 118 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/reversal/client_test.go: -------------------------------------------------------------------------------- 1 | package reversal 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | stripe "github.com/stripe/stripe-go" 8 | "github.com/stripe/stripe-go/charge" 9 | "github.com/stripe/stripe-go/currency" 10 | "github.com/stripe/stripe-go/recipient" 11 | "github.com/stripe/stripe-go/transfer" 12 | . "github.com/stripe/stripe-go/utils" 13 | ) 14 | 15 | func init() { 16 | stripe.Key = GetTestKey() 17 | } 18 | 19 | func TestReversalNew(t *testing.T) { 20 | chargeParams := &stripe.ChargeParams{ 21 | Amount: 1000, 22 | Currency: currency.USD, 23 | Source: &stripe.SourceParams{ 24 | Card: &stripe.CardParams{ 25 | Number: "4000000000000077", 26 | Month: "06", 27 | Year: "20", 28 | }, 29 | }, 30 | } 31 | 32 | charge.New(chargeParams) 33 | 34 | recipientParams := &stripe.RecipientParams{ 35 | Name: "Recipient Name", 36 | Type: recipient.Individual, 37 | Bank: &stripe.BankAccountParams{ 38 | Country: "US", 39 | Routing: "110000000", 40 | Account: "000123456789", 41 | }, 42 | } 43 | 44 | rec, _ := recipient.New(recipientParams) 45 | 46 | transferParams := &stripe.TransferParams{ 47 | Amount: 100, 48 | Currency: currency.USD, 49 | Recipient: rec.ID, 50 | Desc: "Transfer Desc", 51 | Statement: "Transfer", 52 | } 53 | 54 | trans, _ := transfer.New(transferParams) 55 | 56 | target, err := New(&stripe.ReversalParams{Transfer: trans.ID}) 57 | 58 | if err != nil { 59 | // TODO: replace this with t.Error when this can be tested 60 | fmt.Println(err) 61 | } 62 | 63 | fmt.Printf("%+v\n", target) 64 | } 65 | 66 | func TestReversalGet(t *testing.T) { 67 | chargeParams := &stripe.ChargeParams{ 68 | Amount: 1000, 69 | Currency: currency.USD, 70 | Source: &stripe.SourceParams{ 71 | Card: &stripe.CardParams{ 72 | Number: "4000000000000077", 73 | Month: "06", 74 | Year: "20", 75 | }, 76 | }, 77 | } 78 | 79 | charge.New(chargeParams) 80 | 81 | recipientParams := &stripe.RecipientParams{ 82 | Name: "Recipient Name", 83 | Type: recipient.Individual, 84 | Bank: &stripe.BankAccountParams{ 85 | Country: "US", 86 | Routing: "110000000", 87 | Account: "000123456789", 88 | }, 89 | } 90 | 91 | rec, _ := recipient.New(recipientParams) 92 | 93 | transferParams := &stripe.TransferParams{ 94 | Amount: 100, 95 | Currency: currency.USD, 96 | Recipient: rec.ID, 97 | Desc: "Transfer Desc", 98 | Statement: "Transfer", 99 | } 100 | 101 | trans, _ := transfer.New(transferParams) 102 | rev, _ := New(&stripe.ReversalParams{Transfer: trans.ID}) 103 | 104 | target, err := Get(rev.ID, &stripe.ReversalParams{Transfer: trans.ID}) 105 | 106 | if err != nil { 107 | // TODO: replace this with t.Error when this can be tested 108 | fmt.Println(err) 109 | } 110 | 111 | fmt.Printf("%+v\n", target) 112 | } 113 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/sku.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | type SKUParams struct { 6 | Params 7 | ID string 8 | Active *bool 9 | Desc string 10 | Name string 11 | Attrs map[string]string 12 | Price int64 13 | Currency string 14 | Image string 15 | Inventory Inventory 16 | Product string 17 | PackageDimensions *PackageDimensions 18 | } 19 | 20 | type Inventory struct { 21 | Type string `json:"type"` 22 | Quantity int64 `json:"quantity"` 23 | Value string `json:"value"` 24 | } 25 | 26 | type SKU struct { 27 | ID string `json:"id"` 28 | Created int64 `json:"created"` 29 | Updated int64 `json:"updated"` 30 | Live bool `json:"livemode"` 31 | Active bool `json:"active"` 32 | Name string `json:"name"` 33 | Desc string `json:"description"` 34 | Attrs map[string]string `json:"attributes"` 35 | Price int64 `json:"price"` 36 | Currency string `json:"currency"` 37 | PackageDimensions *PackageDimensions `json:"package_dimensions"` 38 | Image string `json:"image"` 39 | Inventory Inventory `json:"inventory"` 40 | Product Product `json:"product"` 41 | Meta map[string]string `json:"metadata"` 42 | } 43 | 44 | type SKUList struct { 45 | ListMeta 46 | Values []*SKU `json:"data"` 47 | } 48 | 49 | type SKUListParams struct { 50 | ListParams 51 | Active *bool 52 | Product string 53 | Attributes map[string]string 54 | IDs []string 55 | InStock *bool 56 | } 57 | 58 | func (s *SKU) UnmarshalJSON(data []byte) error { 59 | type sku SKU 60 | var sk sku 61 | err := json.Unmarshal(data, &sk) 62 | if err == nil { 63 | *s = SKU(sk) 64 | } else { 65 | s.ID = string(data[1 : len(data)-1]) 66 | } 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/sku/client_test.go: -------------------------------------------------------------------------------- 1 | package sku 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "testing" 7 | "time" 8 | 9 | stripe "github.com/stripe/stripe-go" 10 | "github.com/stripe/stripe-go/product" 11 | . "github.com/stripe/stripe-go/utils" 12 | ) 13 | 14 | func init() { 15 | stripe.Key = GetTestKey() 16 | rand.Seed(time.Now().UTC().UnixNano()) 17 | } 18 | 19 | func TestSKUUpdateInventory(t *testing.T) { 20 | active := true 21 | 22 | p, err := product.New(&stripe.ProductParams{ 23 | Active: &active, 24 | Name: "test name", 25 | Desc: "This is a description", 26 | Caption: "This is a caption", 27 | Attrs: []string{"attr1", "attr2"}, 28 | URL: "http://example.com", 29 | Shippable: &active, 30 | }) 31 | if err != nil { 32 | t.Fatalf("%+v", err) 33 | } 34 | 35 | randID := fmt.Sprintf("TEST-SKU-%v", RandSeq(16)) 36 | sku, err := New(&stripe.SKUParams{ 37 | ID: randID, 38 | Active: &active, 39 | Attrs: map[string]string{"attr1": "val1", "attr2": "val2"}, 40 | Price: 499, 41 | Currency: "usd", 42 | Inventory: stripe.Inventory{Type: "bucket", Value: "limited"}, 43 | Product: p.ID, 44 | Image: "http://example.com/foo.png", 45 | }) 46 | 47 | updatedSKU, err := Update(sku.ID, &stripe.SKUParams{ 48 | Inventory: stripe.Inventory{Type: "bucket", Value: "in_stock"}, 49 | }) 50 | if err != nil { 51 | t.Fatalf("%+v", err) 52 | } 53 | 54 | if updatedSKU.Inventory.Value != "in_stock" { 55 | t.Errorf("unable to update inventory for SKU") 56 | } 57 | } 58 | func TestSKUCreate(t *testing.T) { 59 | active := true 60 | 61 | p, err := product.New(&stripe.ProductParams{ 62 | Active: &active, 63 | Name: "test name", 64 | Desc: "This is a description", 65 | Caption: "This is a caption", 66 | Attrs: []string{"attr1", "attr2"}, 67 | URL: "http://example.com", 68 | Shippable: &active, 69 | }) 70 | if err != nil { 71 | t.Fatalf("%+v", err) 72 | } 73 | 74 | randID := fmt.Sprintf("TEST-SKU-%v", RandSeq(16)) 75 | sku, err := New(&stripe.SKUParams{ 76 | ID: randID, 77 | Active: &active, 78 | Attrs: map[string]string{"attr1": "val1", "attr2": "val2"}, 79 | Price: 499, 80 | Currency: "usd", 81 | Inventory: stripe.Inventory{Type: "bucket", Value: "limited"}, 82 | Product: p.ID, 83 | Image: "http://example.com/foo.png", 84 | }) 85 | 86 | if err != nil { 87 | t.Fatalf("%+v", err) 88 | } 89 | 90 | if sku.ID == "" { 91 | t.Errorf("ID is not set %v", sku.ID) 92 | } 93 | 94 | if sku.Created == 0 { 95 | t.Errorf("Created date is not set") 96 | } 97 | 98 | if sku.Updated == 0 { 99 | t.Errorf("Updated is not set") 100 | } 101 | 102 | if len(sku.Attrs) != 2 { 103 | t.Errorf("Invalid attributes: %v", sku.Attrs) 104 | } 105 | 106 | if sku.Attrs["attr1"] != "val1" { 107 | t.Errorf("Invalid attributes: %v", sku.Attrs) 108 | } 109 | 110 | if sku.Attrs["attr2"] != "val2" { 111 | t.Errorf("Invalid attributes: %v", sku.Attrs) 112 | } 113 | 114 | if sku.Inventory.Type != "bucket" { 115 | t.Errorf("Invalid inventory type: %v", sku.Inventory.Type) 116 | } 117 | 118 | if sku.Inventory.Value != "limited" { 119 | t.Errorf("Invalid inventory type: %v", sku.Inventory.Value) 120 | } 121 | 122 | if sku.Image != "http://example.com/foo.png" { 123 | t.Errorf("invalid image: %v", sku.Image) 124 | } 125 | 126 | if sku.PackageDimensions != nil { 127 | t.Errorf("package dimensions expected nil: %v", sku.PackageDimensions) 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/sub.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // SubStatus is the list of allowed values for the subscription's status. 6 | // Allowed values are "trialing", "active", "past_due", "canceled", "unpaid". 7 | type SubStatus string 8 | 9 | // SubParams is the set of parameters that can be used when creating or updating a subscription. 10 | // For more details see https://stripe.com/docs/api#create_subscription and https://stripe.com/docs/api#update_subscription. 11 | type SubParams struct { 12 | Params 13 | Customer, Plan string 14 | Coupon, Token string 15 | TrialEnd int64 16 | Card *CardParams 17 | Quantity uint64 18 | ProrationDate int64 19 | FeePercent, TaxPercent float64 20 | NoProrate, EndCancel, QuantityZero, TrialEndNow bool 21 | BillingCycleAnchor int64 22 | BillingCycleAnchorNow bool 23 | } 24 | 25 | // SubListParams is the set of parameters that can be used when listing active subscriptions. 26 | // For more details see https://stripe.com/docs/api#list_subscriptions. 27 | type SubListParams struct { 28 | ListParams 29 | Customer string 30 | } 31 | 32 | // Sub is the resource representing a Stripe subscription. 33 | // For more details see https://stripe.com/docs/api#subscriptions. 34 | type Sub struct { 35 | ID string `json:"id"` 36 | EndCancel bool `json:"cancel_at_period_end"` 37 | Customer *Customer `json:"customer"` 38 | Plan *Plan `json:"plan"` 39 | Quantity uint64 `json:"quantity"` 40 | Status SubStatus `json:"status"` 41 | FeePercent float64 `json:"application_fee_percent"` 42 | Canceled int64 `json:"canceled_at"` 43 | Start int64 `json:"start"` 44 | PeriodEnd int64 `json:"current_period_end"` 45 | PeriodStart int64 `json:"current_period_start"` 46 | Discount *Discount `json:"discount"` 47 | Ended int64 `json:"ended_at"` 48 | Meta map[string]string `json:"metadata"` 49 | TaxPercent float64 `json:"tax_percent"` 50 | TrialEnd int64 `json:"trial_end"` 51 | TrialStart int64 `json:"trial_start"` 52 | } 53 | 54 | // SubList is a list object for subscriptions. 55 | type SubList struct { 56 | ListMeta 57 | Values []*Sub `json:"data"` 58 | } 59 | 60 | // UnmarshalJSON handles deserialization of a Sub. 61 | // This custom unmarshaling is needed because the resulting 62 | // property may be an id or the full struct if it was expanded. 63 | func (s *Sub) UnmarshalJSON(data []byte) error { 64 | type sub Sub 65 | var ss sub 66 | err := json.Unmarshal(data, &ss) 67 | if err == nil { 68 | *s = Sub(ss) 69 | } else { 70 | // the id is surrounded by "\" characters, so strip them 71 | s.ID = string(data[1 : len(data)-1]) 72 | } 73 | 74 | return nil 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/token.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | // TokenType is the list of allowed values for a token's type. 4 | // Allowed values are "card", "bank_account". 5 | type TokenType string 6 | 7 | // TokenParams is the set of parameters that can be used when creating a token. 8 | // For more details see https://stripe.com/docs/api#create_card_token and https://stripe.com/docs/api#create_bank_account_token. 9 | type TokenParams struct { 10 | Params 11 | Card *CardParams 12 | Bank *BankAccountParams 13 | Customer string 14 | // Email is an undocumented parameter used by Stripe Checkout 15 | // It may be removed from the API without notice. 16 | Email string 17 | } 18 | 19 | // Token is the resource representing a Stripe token. 20 | // For more details see https://stripe.com/docs/api#tokens. 21 | type Token struct { 22 | ID string `json:"id"` 23 | Live bool `json:"livemode"` 24 | Created int64 `json:"created"` 25 | Type TokenType `json:"type"` 26 | Used bool `json:"used"` 27 | Bank *BankAccount `json:"bank_account"` 28 | Card *Card `json:"card"` 29 | ClientIP string `json:"client_ip"` 30 | // Email is an undocumented field but included for all tokens created 31 | // with Stripe Checkout. 32 | Email string `json:"email"` 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/token/client.go: -------------------------------------------------------------------------------- 1 | // Package token provides the /tokens APIs 2 | package token 3 | 4 | import ( 5 | "errors" 6 | "net/url" 7 | 8 | stripe "github.com/stripe/stripe-go" 9 | ) 10 | 11 | const ( 12 | Card stripe.TokenType = "card" 13 | Bank stripe.TokenType = "bank_account" 14 | ) 15 | 16 | // Client is used to invoke /tokens APIs. 17 | type Client struct { 18 | B stripe.Backend 19 | Key string 20 | } 21 | 22 | // New POSTs a new card or bank account. 23 | // For more details see https://stripe.com/docs/api#create_card_Token and https://stripe.com/docs/api#create_bank_account_token. 24 | func New(params *stripe.TokenParams) (*stripe.Token, error) { 25 | return getC().New(params) 26 | } 27 | 28 | func (c Client) New(params *stripe.TokenParams) (*stripe.Token, error) { 29 | body := &url.Values{} 30 | token := c.Key 31 | 32 | if len(params.Customer) > 0 { 33 | body.Add("customer", params.Customer) 34 | } 35 | 36 | if params.Card != nil { 37 | params.Card.AppendDetails(body, true) 38 | } else if params.Bank != nil { 39 | params.Bank.AppendDetails(body) 40 | } else if len(params.Customer) == 0 { 41 | err := errors.New("Invalid Token params: either Card or Bank need to be set") 42 | return nil, err 43 | } 44 | 45 | if len(params.Email) > 0 { 46 | body.Add("email", params.Email) 47 | } 48 | 49 | params.AppendTo(body) 50 | 51 | tok := &stripe.Token{} 52 | err := c.B.Call("POST", "/tokens", token, body, ¶ms.Params, tok) 53 | 54 | return tok, err 55 | } 56 | 57 | // Get returns the details of a token. 58 | // For more details see https://stripe.com/docs/api#retrieve_token. 59 | func Get(id string, params *stripe.TokenParams) (*stripe.Token, error) { 60 | return getC().Get(id, params) 61 | } 62 | 63 | func (c Client) Get(id string, params *stripe.TokenParams) (*stripe.Token, error) { 64 | var body *url.Values 65 | var commonParams *stripe.Params 66 | 67 | if params != nil { 68 | commonParams = ¶ms.Params 69 | body = &url.Values{} 70 | params.AppendTo(body) 71 | } 72 | 73 | token := &stripe.Token{} 74 | err := c.B.Call("GET", "/tokens/"+id, c.Key, body, commonParams, token) 75 | 76 | return token, err 77 | } 78 | 79 | func getC() Client { 80 | return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 81 | } 82 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/token/client_test.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import ( 4 | "testing" 5 | 6 | stripe "github.com/stripe/stripe-go" 7 | "github.com/stripe/stripe-go/bankaccount" 8 | . "github.com/stripe/stripe-go/utils" 9 | ) 10 | 11 | func init() { 12 | stripe.Key = GetTestKey() 13 | } 14 | 15 | func TestTokenNew(t *testing.T) { 16 | tokenParams := &stripe.TokenParams{ 17 | Card: &stripe.CardParams{ 18 | Number: "4242424242424242", 19 | Month: "10", 20 | Year: "20", 21 | }, 22 | } 23 | 24 | target, err := New(tokenParams) 25 | 26 | if err != nil { 27 | t.Error(err) 28 | } 29 | 30 | if target.Created == 0 { 31 | t.Errorf("Created date is not set\n") 32 | } 33 | 34 | if target.Type != Card { 35 | t.Errorf("Type %v does not match expected value\n", target.Type) 36 | } 37 | 38 | if target.Card == nil { 39 | t.Errorf("Card is not set\n") 40 | } 41 | 42 | if target.Card.LastFour != "4242" { 43 | t.Errorf("Unexpected last four %q for card number %v\n", target.Card.LastFour, tokenParams.Card.Number) 44 | } 45 | } 46 | 47 | func TestTokenGet(t *testing.T) { 48 | tokenParams := &stripe.TokenParams{ 49 | Bank: &stripe.BankAccountParams{ 50 | Country: "US", 51 | Routing: "110000000", 52 | Account: "000123456789", 53 | }, 54 | } 55 | 56 | tok, _ := New(tokenParams) 57 | 58 | target, err := Get(tok.ID, nil) 59 | 60 | if err != nil { 61 | t.Error(err) 62 | } 63 | 64 | if target.Type != Bank { 65 | t.Errorf("Type %v does not match expected value\n", target.Type) 66 | } 67 | 68 | if target.Bank == nil { 69 | t.Errorf("Bank account is not set\n") 70 | } 71 | 72 | if target.Bank.Status != bankaccount.NewAccount { 73 | t.Errorf("Bank account status %q does not match expected value\n", target.Bank.Status) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/transfer.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import "encoding/json" 4 | 5 | // TransferStatus is the list of allowed values for the transfer's status. 6 | // Allowed values are "paid", "pending", "in_transit", "failed", "canceled". 7 | type TransferStatus string 8 | 9 | // TransferType is the list of allowed values for the transfer's type. 10 | // Allowed values are "card", "bank_account". 11 | type TransferType string 12 | 13 | // TransferFailCode is the list of allowed values for the transfer's failure code. 14 | // Allowed values are "insufficient_funds", "account_closed", "no_account", 15 | // "invalid_account_number", "debit_not_authorized", "bank_ownership_changed", 16 | // "account_frozen", "could_not_process", "bank_account_restricted", "invalid_currency". 17 | type TransferFailCode string 18 | 19 | // TransferParams is the set of parameters that can be used when creating or updating a transfer. 20 | // For more details see https://stripe.com/docs/api#create_transfer and https://stripe.com/docs/api#update_transfer. 21 | type TransferParams struct { 22 | Params 23 | Amount int64 24 | Fee uint64 25 | Currency Currency 26 | Recipient, Desc, Statement, Bank, Card, SourceTx, Dest string 27 | } 28 | 29 | // TransferListParams is the set of parameters that can be used when listing transfers. 30 | // For more details see https://stripe.com/docs/api#list_transfers. 31 | type TransferListParams struct { 32 | ListParams 33 | Created, Date int64 34 | Recipient string 35 | Status TransferStatus 36 | } 37 | 38 | // Transfer is the resource representing a Stripe transfer. 39 | // For more details see https://stripe.com/docs/api#transfers. 40 | type Transfer struct { 41 | ID string `json:"id"` 42 | Live bool `json:"livemode"` 43 | Amount int64 `json:"amount"` 44 | Currency Currency `json:"currency"` 45 | Created int64 `json:"created"` 46 | Date int64 `json:"date"` 47 | Desc string `json:"description"` 48 | FailCode TransferFailCode `json:"failure_code"` 49 | FailMsg string `json:"failure_message"` 50 | Status TransferStatus `json:"status"` 51 | Type TransferType `json:"type"` 52 | Tx *Transaction `json:"balance_transaction"` 53 | Meta map[string]string `json:"metadata"` 54 | Bank *BankAccount `json:"bank_account"` 55 | Card *Card `json:"card"` 56 | Recipient *Recipient `json:"recipient"` 57 | Statement string `json:"statement_descriptor"` 58 | Reversals *ReversalList `json:"reversals"` 59 | } 60 | 61 | // UnmarshalJSON handles deserialization of a Transfer. 62 | // This custom unmarshaling is needed because the resulting 63 | // property may be an id or the full struct if it was expanded. 64 | func (t *Transfer) UnmarshalJSON(data []byte) error { 65 | type transfer Transfer 66 | var tb transfer 67 | err := json.Unmarshal(data, &tb) 68 | if err == nil { 69 | *t = Transfer(tb) 70 | } else { 71 | // the id is surrounded by "\" characters, so strip them 72 | t.ID = string(data[1 : len(data)-1]) 73 | } 74 | 75 | return nil 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/stripe/stripe-go/utils/key.go: -------------------------------------------------------------------------------- 1 | // Package utils provides internal utilities 2 | package utils 3 | 4 | import ( 5 | "math/rand" 6 | "os" 7 | "time" 8 | ) 9 | 10 | func init() { 11 | rand.Seed(time.Now().UTC().UnixNano()) 12 | } 13 | 14 | func GetTestKey() string { 15 | key := os.Getenv("STRIPE_KEY") 16 | 17 | if len(key) == 0 { 18 | panic("STRIPE_KEY environment variable is not set, but is needed to run tests!\n") 19 | } 20 | 21 | return key 22 | } 23 | 24 | // h/t: http://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang 25 | func RandSeq(n int) string { 26 | letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") 27 | 28 | b := make([]rune, n) 29 | for i := range b { 30 | b[i] = letters[rand.Intn(len(letters))] 31 | } 32 | return string(b) 33 | } 34 | --------------------------------------------------------------------------------