Example #1
0
func (c Client) List(params *stripe.BitcoinTransactionListParams) *Iter {
	var body *stripe.RequestValues
	var lp *stripe.ListParams
	var p *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		if len(params.Customer) > 0 {
			body.Add("customer", params.Customer)
		}

		params.AppendTo(body)
		lp = &params.ListParams
		p = params.ToParams()
	}

	return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
		list := &stripe.BitcoinTransactionList{}
		err := c.B.Call("GET", fmt.Sprintf("/bitcoin/receivers/%v/transactions", params.Receiver), c.Key, b, p, list)

		ret := make([]interface{}, len(list.Values))
		for i, v := range list.Values {
			ret[i] = v
		}

		return ret, list.ListMeta, err
	})}
}
Example #2
0
func (c Client) List(params *stripe.SubListParams) *Iter {
	var body *stripe.RequestValues
	var lp *stripe.ListParams
	var p *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		if len(params.Customer) > 0 {
			body.Add("customer", params.Customer)
		}

		if len(params.Plan) > 0 {
			body.Add("plan", params.Plan)
		}

		params.AppendTo(body)

		lp = &params.ListParams
		p = params.ToParams()
	}

	return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
		list := &stripe.SubList{}
		err := c.B.Call("GET", "/subscriptions", c.Key, b, p, list)

		ret := make([]interface{}, len(list.Values))
		for i, v := range list.Values {
			ret[i] = v
		}

		return ret, list.ListMeta, err
	})}
}
Example #3
0
func (c Client) List(params *stripe.FileUploadListParams) *Iter {
	var body *stripe.RequestValues
	var lp *stripe.ListParams
	var p *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		if len(params.Purpose) > 0 {
			body.Add("purpose", string(params.Purpose))
		}

		params.AppendTo(body)
		lp = &params.ListParams
		p = params.ToParams()
	}

	return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
		list := &stripe.FileUploadList{}
		err := c.B.Call("GET", "/files", c.Key, b, p, list)

		ret := make([]interface{}, len(list.Values))
		for i, v := range list.Values {
			ret[i] = v
		}

		return ret, list.ListMeta, err
	})}
}
Example #4
0
func (c Client) Update(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &stripe.RequestValues{}

		if params.Default {
			body.Add("default_for_currency", strconv.FormatBool(params.Default))
		}

		params.AppendTo(body)
	}

	ba := &stripe.BankAccount{}
	var err error

	if len(params.Customer) > 0 {
		err = c.B.Call("POST", fmt.Sprintf("/customers/%v/bank_accounts/%v", params.Customer, id), c.Key, body, commonParams, ba)
	} else if len(params.AccountID) > 0 {
		err = c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba)
	} else {
		err = errors.New("Invalid bank account params: either Customer or AccountID need to be set")
	}

	return ba, err
}
Example #5
0
func (c Client) List(params *stripe.InvoiceItemListParams) *Iter {
	var body *stripe.RequestValues
	var lp *stripe.ListParams
	var p *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		if params.Created > 0 {
			body.Add("created", strconv.FormatInt(params.Created, 10))
		}

		if len(params.Customer) > 0 {
			body.Add("customer", params.Customer)
		}

		params.AppendTo(body)
		lp = &params.ListParams
		p = params.ToParams()
	}

	return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
		list := &stripe.InvoiceItemList{}
		err := c.B.Call("GET", "/invoiceitems", c.Key, b, p, list)

		ret := make([]interface{}, len(list.Values))
		for i, v := range list.Values {
			ret[i] = v
		}

		return ret, list.ListMeta, err
	})}
}
Example #6
0
func (c Client) List(params *stripe.RecipientListParams) *Iter {
	var body *stripe.RequestValues
	var lp *stripe.ListParams
	var p *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		if params.Verified {
			body.Add("verified", strconv.FormatBool(true))
		}

		params.AppendTo(body)
		lp = &params.ListParams
		p = params.ToParams()
	}

	return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
		list := &stripe.RecipientList{}
		err := c.B.Call("GET", "/recipients", c.Key, b, p, list)

		ret := make([]interface{}, len(list.Values))
		for i, v := range list.Values {
			ret[i] = v
		}

		return ret, list.ListMeta, err
	})}
}
Example #7
0
func (c Client) List(params *stripe.BitcoinReceiverListParams) *Iter {
	var body *stripe.RequestValues
	var lp *stripe.ListParams
	var p *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		body.Add("filled", strconv.FormatBool(!params.NotFilled))
		body.Add("active", strconv.FormatBool(!params.NotActive))
		body.Add("uncaptured_funds", strconv.FormatBool(params.Uncaptured))

		params.AppendTo(body)
		lp = &params.ListParams
		p = params.ToParams()
	}

	return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
		list := &stripe.BitcoinReceiverList{}
		err := c.B.Call("GET", "/bitcoin/receivers", c.Key, b, p, list)

		ret := make([]interface{}, len(list.Values))
		for i, v := range list.Values {
			ret[i] = v
		}

		return ret, list.ListMeta, err
	})}
}
Example #8
0
func (c Client) New(params *stripe.SubItemParams) (*stripe.SubItem, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params
	token := c.Key

	if params != nil {
		body = &stripe.RequestValues{}
		body.Add("subscription", params.Sub)

		if len(params.Plan) > 0 {
			body.Add("plan", params.Plan)
		}
		if params.Quantity > 0 {
			body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
		} else if params.QuantityZero {
			body.Add("quantity", "0")
		}

		commonParams = &params.Params
		params.AppendTo(body)
	}

	item := &stripe.SubItem{}
	err := c.B.Call("POST", "/subscription_items", token, body, commonParams, item)
	return item, err
}
Example #9
0
func (c Client) Update(id string, params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &stripe.RequestValues{}

		if params.Amount != 0 {
			body.Add("amount", strconv.FormatInt(params.Amount, 10))
		}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if params.Discountable {
			body.Add("discountable", strconv.FormatBool(true))
		}

		params.AppendTo(body)
	}

	invoiceItem := &stripe.InvoiceItem{}
	err := c.B.Call("POST", "/invoiceitems/"+id, c.Key, body, commonParams, invoiceItem)

	return invoiceItem, err
}
Example #10
0
// Update updates an order's properties.
// For more details see https://stripe.com/docs/api#update_order.
func (c Client) Update(id string, params *stripe.OrderUpdateParams) (*stripe.Order, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}
		commonParams = &params.Params

		if params.Coupon != "" {
			body.Add("coupon", params.Coupon)
		}

		if params.SelectedShippingMethod != "" {
			body.Add("selected_shipping_method", params.SelectedShippingMethod)
		}

		if params.Status != "" {
			body.Add("status", string(params.Status))
		}

		params.AppendTo(body)
	}

	o := &stripe.Order{}
	err := c.B.Call("POST", "/orders/"+id, c.Key, body, commonParams, o)

	return o, err
}
Example #11
0
func (c Client) Capture(id string, params *stripe.CaptureParams) (*stripe.Charge, error) {
	var body *stripe.RequestValues
	token := c.Key
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &stripe.RequestValues{}

		if params.Amount > 0 {
			body.Add("amount", strconv.FormatUint(params.Amount, 10))
		}

		if len(params.Email) > 0 {
			body.Add("receipt_email", params.Email)
		}

		if params.Fee > 0 {
			body.Add("application_fee", strconv.FormatUint(params.Fee, 10))
		}

		params.AppendTo(body)
	}

	charge := &stripe.Charge{}

	err := c.B.Call("POST", fmt.Sprintf("/charges/%v/capture", id), token, body, commonParams, charge)

	return charge, err
}
Example #12
0
func (c Client) Update(id string, params *stripe.BankAccountParams) (*stripe.BankAccount, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &stripe.RequestValues{}

		if params.Default {
			body.Add("default_for_currency", strconv.FormatBool(params.Default))
		}

		params.AppendTo(body)
	}

	ba := &stripe.BankAccount{}
	err := c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba)

	return ba, err
}
Example #13
0
func (c Client) Cancel(id string, params *stripe.SubParams) (*stripe.Sub, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		if params.EndCancel {
			body.Add("at_period_end", strconv.FormatBool(true))
		}

		params.AppendTo(body)
		commonParams = &params.Params
	}

	sub := &stripe.Sub{}
	err := c.B.Call("DELETE", fmt.Sprintf("/subscriptions/%v", id), c.Key, body, commonParams, sub)

	return sub, err
}
Example #14
0
func (c Client) Update(id string, params *stripe.TransferParams) (*stripe.Transfer, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params

		body = &stripe.RequestValues{}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		params.AppendTo(body)
	}

	transfer := &stripe.Transfer{}
	err := c.B.Call("POST", "/transfers/"+id, c.Key, body, commonParams, transfer)

	return transfer, err
}
Example #15
0
func (c Client) Update(id string, params *stripe.PlanParams) (*stripe.Plan, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &stripe.RequestValues{}

		if len(params.Name) > 0 {
			body.Add("name", params.Name)
		}

		if len(params.Statement) > 0 {
			body.Add("statement_descriptor", params.Statement)
		}

		params.AppendTo(body)
	}

	plan := &stripe.Plan{}
	err := c.B.Call("POST", "/plans/"+id, c.Key, body, commonParams, plan)

	return plan, err
}
Example #16
0
func (c Client) List(params *stripe.TransferListParams) *Iter {
	var body *stripe.RequestValues
	var lp *stripe.ListParams
	var p *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		if params.Created > 0 {
			body.Add("created", strconv.FormatInt(params.Created, 10))
		}

		if params.Date > 0 {
			body.Add("date", strconv.FormatInt(params.Date, 10))
		}

		if len(params.Recipient) > 0 {
			body.Add("recipient", params.Recipient)
		}

		if len(params.Status) > 0 {
			body.Add("status", string(params.Status))
		}

		params.AppendTo(body)
		lp = &params.ListParams
		p = params.ToParams()
	}

	return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
		list := &stripe.TransferList{}
		err := c.B.Call("GET", "/transfers", c.Key, b, p, list)

		ret := make([]interface{}, len(list.Values))
		for i, v := range list.Values {
			ret[i] = v
		}

		return ret, list.ListMeta, err
	})}
}
Example #17
0
func (c Client) Update(id string, params *stripe.ChargeParams) (*stripe.Charge, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &stripe.RequestValues{}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if len(params.Fraud) > 0 {
			body.Add("fraud_details[user_report]", string(params.Fraud))
		}

		params.AppendTo(body)
	}

	charge := &stripe.Charge{}
	err := c.B.Call("POST", "/charges/"+id, c.Key, body, commonParams, charge)

	return charge, err
}
Example #18
0
// Pay pays an order
// For more details see https://stripe.com/docs/api#pay_order.
func (c Client) Pay(id string, params *stripe.OrderPayParams) (*stripe.Order, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}
		commonParams = &params.Params
		if params.Source == nil && len(params.Customer) == 0 {
			err := errors.New("Invalid order pay params: either customer or a source must be set")
			return nil, err
		}
		// We can't use `AppendDetails` since that nests under `card`.
		if params.Source != nil {
			if len(params.Source.Token) > 0 {
				body.Add("source", params.Source.Token)
			} else if params.Source.Card != nil {
				c := params.Source.Card

				body.Add("source[object]", "card")
				body.Add("source[number]", c.Number)
				body.Add("source[exp_month]", c.Month)
				body.Add("source[exp_year]", c.Year)

				if len(c.CVC) > 0 {
					body.Add("source[cvc]", c.CVC)
				}

				body.Add("source[name]", c.Name)

				if len(c.Address1) > 0 {
					body.Add("source[address_line1]", c.Address1)
				}

				if len(c.Address2) > 0 {
					body.Add("source[address_line2]", c.Address2)
				}
				if len(c.City) > 0 {
					body.Add("source[address_city]", c.City)
				}

				if len(c.State) > 0 {
					body.Add("source[address_state]", c.State)
				}
				if len(c.Zip) > 0 {
					body.Add("source[address_zip]", c.Zip)
				}
				if len(c.Country) > 0 {
					body.Add("source[address_country]", c.Country)
				}
			}
		}

		if len(params.Customer) > 0 {
			body.Add("customer", params.Customer)
		}

		if params.ApplicationFee > 0 {
			body.Add("application_fee", strconv.FormatInt(params.ApplicationFee, 10))
		}

		if params.Email != "" {
			body.Add("email", params.Email)
		}

		params.AppendTo(body)
	}

	o := &stripe.Order{}
	err := c.B.Call("POST", "/orders/"+id+"/pay", c.Key, body, commonParams, o)

	return o, err
}
Example #19
0
// Update updates a SKU's properties.
// For more details see https://stripe.com/docs/api#update_sku.
func (c Client) Update(id string, params *stripe.SKUParams) (*stripe.SKU, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		// Required fields
		if params.Price > 0 {
			body.Add("price", strconv.FormatInt(params.Price, 10))
		}

		if len(params.Currency) > 0 {
			body.Add("currency", params.Currency)
		}

		// Optional fields
		if params.Active != nil {
			body.Add("active", strconv.FormatBool(*(params.Active)))
		}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if len(params.Image) > 0 {
			body.Add("image", params.Image)
		}

		for k, v := range params.Attrs {
			body.Add(fmt.Sprintf("attributes[%v]", k), v)
		}

		inventory := params.Inventory

		if len(inventory.Type) > 0 {
			body.Add("inventory[type]", inventory.Type)
			switch inventory.Type {
			case "finite":
				body.Add("inventory[quantity]", strconv.FormatInt(inventory.Quantity, 10))
			case "bucket":
				body.Add("inventory[value]", inventory.Value)
			}
		}

		if params.PackageDimensions != nil {
			body.Add("package_dimensions[height]",
				fmt.Sprintf("%.2f", params.PackageDimensions.Height))
			body.Add("package_dimensions[length]",
				fmt.Sprintf("%.2f", params.PackageDimensions.Length))
			body.Add("package_dimensions[width]",
				fmt.Sprintf("%.2f", params.PackageDimensions.Width))
			body.Add("package_dimensions[weight]",
				fmt.Sprintf("%.2f", params.PackageDimensions.Weight))
		}

		if params.Product != "" {
			body.Add("product", params.Product)
		}

		params.AppendTo(body)
	}

	p := &stripe.SKU{}
	err := c.B.Call("POST", "/skus/"+id, c.Key, body, commonParams, p)

	return p, err
}
Example #20
0
// Update updates a product's properties.
// For more details see https://stripe.com/docs/api#update_product.
func (c Client) Update(id string, params *stripe.ProductParams) (*stripe.Product, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		if len(params.Name) > 0 {
			body.Add("name", params.Name)
		}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if params.Active != nil {
			body.Add("active", strconv.FormatBool(*(params.Active)))
		}

		if len(params.Images) > 0 {
			for _, v := range params.Images {
				body.Add("images[]", v)
			}
		}

		if len(params.URL) > 0 {
			body.Add("url", params.URL)
		}

		// Passing empty attributes should unset the attributes.
		if params.Attrs != nil {
			if len(params.Attrs) > 0 {
				for _, v := range params.Attrs {
					body.Add("attributes[]", v)
				}
			} else {
				body.Add("attributes", "")
			}
		}

		for _, app := range params.DeactivateOn {
			body.Add("deactivate_on[]", app)
		}

		params.AppendTo(body)
	}

	p := &stripe.Product{}
	err := c.B.Call("POST", "/products/"+id, c.Key, body, commonParams, p)

	return p, err
}
Example #21
0
func (c Client) Update(id string, params *stripe.CustomerParams) (*stripe.Customer, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &stripe.RequestValues{}

		if params.Balance != 0 {
			body.Add("account_balance", strconv.FormatInt(params.Balance, 10))
		} else if params.BalanceZero {
			body.Add("account_balance", "0")
		}

		if params.Source != nil {
			params.Source.AppendDetails(body, true)
		}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if len(params.Coupon) > 0 {
			body.Add("coupon", params.Coupon)
		}

		if len(params.Email) > 0 {
			body.Add("email", params.Email)
		}

		if len(params.DefaultSource) > 0 {
			body.Add("default_source", params.DefaultSource)
		}
		params.AppendTo(body)

		if params.Shipping != nil {
			params.Shipping.AppendDetails(body)
		}

		if len(params.BusinessVatID) > 0 {
			body.Add("business_vat_id", params.BusinessVatID)
		}
	}

	cust := &stripe.Customer{}
	err := c.B.Call("POST", "/customers/"+id, c.Key, body, commonParams, cust)

	return cust, err
}
Example #22
0
func (c Client) New(params *stripe.SubParams) (*stripe.Sub, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params
	token := c.Key

	if params != nil {
		body = &stripe.RequestValues{}
		body.Add("plan", params.Plan)
		body.Add("customer", params.Customer)

		if len(params.Token) > 0 {
			body.Add("card", params.Token)
		} else if params.Card != nil {
			params.Card.AppendDetails(body, true)
		}

		if len(params.Coupon) > 0 {
			body.Add("coupon", params.Coupon)
		}

		if params.TrialEndNow {
			body.Add("trial_end", "now")
		} else if params.TrialEnd > 0 {
			body.Add("trial_end", strconv.FormatInt(params.TrialEnd, 10))
		}

		if params.TaxPercent > 0 {
			body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64))
		} else if params.TaxPercentZero {
			body.Add("tax_percent", "0")
		}

		if params.Quantity > 0 {
			body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
		} else if params.QuantityZero {
			body.Add("quantity", "0")
		}

		if params.FeePercent > 0 {
			body.Add("application_fee_percent", strconv.FormatFloat(params.FeePercent, 'f', 2, 64))
		}

		if params.BillingCycleAnchorNow {
			body.Add("billing_cycle_anchor", "now")
		} else if params.BillingCycleAnchor > 0 {
			body.Add("billing_cycle_anchor", strconv.FormatInt(params.BillingCycleAnchor, 10))
		}

		commonParams = &params.Params

		params.AppendTo(body)
	}

	sub := &stripe.Sub{}
	err := c.B.Call("POST", "/subscriptions", token, body, commonParams, sub)

	return sub, err
}
Example #23
0
func (c Client) Update(id string, params *stripe.SubParams) (*stripe.Sub, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params
	token := c.Key

	if params != nil {
		body = &stripe.RequestValues{}

		if len(params.Plan) > 0 {
			body.Add("plan", params.Plan)
		}

		if params.NoProrate {
			body.Add("prorate", strconv.FormatBool(false))
		}

		if len(params.Token) > 0 {
			body.Add("card", params.Token)
		} else if params.Card != nil {
			if len(params.Card.Token) > 0 {
				body.Add("card", params.Card.Token)
			} else {
				params.Card.AppendDetails(body, true)
			}
		}

		if len(params.Coupon) > 0 {
			body.Add("coupon", params.Coupon)
		}

		if params.TrialEndNow {
			body.Add("trial_end", "now")
		} else if params.TrialEnd > 0 {
			body.Add("trial_end", strconv.FormatInt(params.TrialEnd, 10))
		}

		if params.Quantity > 0 {
			body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
		}

		if params.FeePercent > 0 {
			body.Add("application_fee_percent", strconv.FormatFloat(params.FeePercent, 'f', 2, 64))
		}

		if params.TaxPercent > 0 {
			body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64))
		} else if params.TaxPercentZero {
			body.Add("tax_percent", "0")
		}

		if params.ProrationDate > 0 {
			body.Add("proration_date", strconv.FormatInt(params.ProrationDate, 10))
		}

		commonParams = &params.Params
		params.AppendTo(body)
	}

	sub := &stripe.Sub{}
	err := c.B.Call("POST", fmt.Sprintf("/subscriptions/%v", id), token, body, commonParams, sub)

	return sub, err
}
Example #24
0
// New POSTs a new order.
// For more details see https://stripe.com/docs/api#create_order.
func (c Client) New(params *stripe.OrderParams) (*stripe.Order, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}
		commonParams = &params.Params
		// Required fields
		body.Add("currency", string(params.Currency))

		if params.Customer != "" {
			body.Add("customer", params.Customer)
		}

		if params.Email != "" {
			body.Add("email", params.Email)
		}

		if len(params.Items) > 0 {
			for _, item := range params.Items {
				body.Add("items[][description]", item.Description)
				body.Add("items[][type]", string(item.Type))
				body.Add("items[][amount]", strconv.FormatInt(item.Amount, 10))
				if item.Currency != "" {
					body.Add("items[][currency]", string(item.Currency))
				}
				if item.Parent != "" {
					body.Add("items[][parent]", item.Parent)
				}
				if item.Quantity != nil {
					body.Add("items[][quantity]", strconv.FormatInt(*item.Quantity, 10))
				}
			}
		}

		if params.Shipping != nil {
			if params.Shipping.Address != nil {
				body.Add("shipping[address][line1]", params.Shipping.Address.Line1)
				if params.Shipping.Address.Line2 != "" {
					body.Add("shipping[address][line2]", params.Shipping.Address.Line2)
				}
				if params.Shipping.Address.City != "" {
					body.Add("shipping[address][city]", params.Shipping.Address.City)
				}
				if params.Shipping.Address.Country != "" {
					body.Add("shipping[address][country]", params.Shipping.Address.Country)
				}
				if params.Shipping.Address.PostalCode != "" {
					body.Add("shipping[address][postal_code]", params.Shipping.Address.PostalCode)
				}
				if params.Shipping.Address.State != "" {
					body.Add("shipping[address][state]", params.Shipping.Address.State)
				}
			}

			if params.Shipping.Name != "" {
				body.Add("shipping[name]", params.Shipping.Name)
			}
			if params.Shipping.Phone != "" {
				body.Add("shipping[phone]", params.Shipping.Phone)
			}
		}

		params.AppendTo(body)
	}

	p := &stripe.Order{}
	err := c.B.Call("POST", "/orders", c.Key, body, commonParams, p)

	return p, err
}
Example #25
0
// Return returns all or part of an order.
// For more details see https://stripe.com/docs/api#return_order.
func (c Client) Return(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		if len(params.Items) > 0 {
			for _, item := range params.Items {
				if item.Description != "" {
					body.Add("items[][description]", item.Description)
				}
				body.Add("items[][type]", string(item.Type))
				if item.Amount > 0 {
					body.Add("items[][amount]", strconv.FormatInt(item.Amount, 10))
				}
				if item.Currency != "" {
					body.Add("items[][currency]", string(item.Currency))
				}
				if item.Parent != "" {
					body.Add("items[][parent]", item.Parent)
				}
				if item.Quantity != nil {
					body.Add("items[][quantity]", strconv.FormatInt(*item.Quantity, 10))
				}
			}
		}

		params.AppendTo(body)
	}

	ret := &stripe.OrderReturn{}
	err := c.B.Call("POST", fmt.Sprintf("/orders/%s/returns", id), c.Key, body, commonParams, ret)

	return ret, err
}
Example #26
0
func (c Client) New(params *stripe.CustomerParams) (*stripe.Customer, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}
		if params.Balance != 0 {
			body.Add("account_balance", strconv.FormatInt(params.Balance, 10))
		}

		if params.Source != nil {
			params.Source.AppendDetails(body, true)
		}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if len(params.Coupon) > 0 {
			body.Add("coupon", params.Coupon)
		}

		if len(params.Email) > 0 {
			body.Add("email", params.Email)
		}

		if len(params.Plan) > 0 {
			body.Add("plan", params.Plan)

			if params.Quantity > 0 {
				body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
			}

			if params.TrialEnd > 0 {
				body.Add("trial_end", strconv.FormatInt(params.TrialEnd, 10))
			}
		}

		if params.Shipping != nil {
			params.Shipping.AppendDetails(body)
		}

		if len(params.BusinessVatID) > 0 {
			body.Add("business_vat_id", params.BusinessVatID)
		}

		if params.TaxPercent > 0 {
			body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64))
		} else if params.TaxPercentZero {
			body.Add("tax_percent", "0")
		}

		commonParams = &params.Params

		params.AppendTo(body)
	}

	cust := &stripe.Customer{}
	err := c.B.Call("POST", "/customers", c.Key, body, commonParams, cust)

	return cust, err
}
Example #27
0
// New POSTs a new product.
// For more details see https://stripe.com/docs/api#create_product.
func (c Client) New(params *stripe.ProductParams) (*stripe.Product, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}

		// Required fields
		body.Add("name", params.Name)

		// Optional fields
		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if params.ID != "" {
			body.Add("id", params.ID)
		}

		if params.Active != nil {
			body.Add("active", strconv.FormatBool(*(params.Active)))
		}

		if params.Caption != "" {
			body.Add("caption", params.Caption)
		}

		if len(params.Attrs) > 0 {
			for _, v := range params.Attrs {
				body.Add("attributes[]", v)
			}
		}

		if len(params.Images) > 0 {
			for _, v := range params.Images {
				body.Add("images[]", v)
			}
		}

		if len(params.URL) > 0 {
			body.Add("url", params.URL)
		}

		if params.Shippable != nil {
			body.Add("shippable", strconv.FormatBool(*(params.Shippable)))
		}

		if params.PackageDimensions != nil {
			body.Add("package_dimensions[height]",
				fmt.Sprintf("%.2f", params.PackageDimensions.Height))
			body.Add("package_dimensions[length]",
				fmt.Sprintf("%.2f", params.PackageDimensions.Length))
			body.Add("package_dimensions[width]",
				fmt.Sprintf("%.2f", params.PackageDimensions.Width))
			body.Add("package_dimensions[weight]",
				fmt.Sprintf("%.2f", params.PackageDimensions.Weight))
		}

		for _, app := range params.DeactivateOn {
			body.Add("deactivate_on[]", app)
		}

		params.AppendTo(body)
	}

	p := &stripe.Product{}
	err := c.B.Call("POST", "/products", c.Key, body, commonParams, p)

	return p, err
}
Example #28
0
// New POSTs a new source.
// For more details see https://stripe.com/docs/api#create_source.
func (c Client) New(params *stripe.SourceObjectParams) (*stripe.Source, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}
		commonParams = &params.Params

		// Required fields
		body.Add("type", params.Type)

		// Optional fields
		if params.Currency != "" {
			body.Add("currency", string(params.Currency))
		}
		if params.Amount > 0 {
			body.Add("amount", strconv.FormatUint(params.Amount, 10))
		}
		if params.Flow != "" {
			body.Add("flow", string(params.Flow))
		}
		if params.Owner != nil {
			if params.Owner.Address != nil {
				if params.Owner.Address.Line1 != "" {
					body.Add("owner[address][line1]", params.Owner.Address.Line1)
				}
				if params.Owner.Address.Line2 != "" {
					body.Add("owner[address][line2]", params.Owner.Address.Line2)
				}
				if params.Owner.Address.City != "" {
					body.Add("owner[address][city]", params.Owner.Address.City)
				}
				if params.Owner.Address.State != "" {
					body.Add("owner[address][state]", params.Owner.Address.State)
				}
				if params.Owner.Address.PostalCode != "" {
					body.Add("owner[address][postal_code]", params.Owner.Address.PostalCode)
				}
				if params.Owner.Address.Country != "" {
					body.Add("owner[address][country]", params.Owner.Address.Country)
				}
			}
			if params.Owner.Email != "" {
				body.Add("owner[email]", params.Owner.Email)
			}
			if params.Owner.Name != "" {
				body.Add("owner[name]", params.Owner.Name)
			}
			if params.Owner.Phone != "" {
				body.Add("owner[phone]", params.Owner.Phone)
			}
		}

		if params.Redirect != nil {
			if params.Redirect.ReturnURL != "" {
				body.Add("redirect[return_url]", params.Redirect.ReturnURL)
			}
		}

		for k, v := range params.TypeData {
			body.Add(fmt.Sprintf("%s[%s]", params.Type, k), v)
		}

		params.AppendTo(body)
	}

	p := &stripe.Source{}
	err := c.B.Call("POST", "/sources", c.Key, body, commonParams, p)

	return p, err
}
Example #29
0
func (c Client) Update(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) {
	var body *stripe.RequestValues
	token := c.Key
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &stripe.RequestValues{}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if len(params.Statement) > 0 {
			body.Add("statement_descriptor", params.Statement)
		}

		if len(params.Sub) > 0 {
			body.Add("subscription", params.Sub)
		}

		if params.Closed {
			body.Add("closed", strconv.FormatBool(true))
		} else if params.NoClosed {
			body.Add("closed", strconv.FormatBool(false))
		}

		if params.Forgive {
			body.Add("forgiven", strconv.FormatBool(true))
		}

		if params.Fee > 0 {
			body.Add("application_fee", strconv.FormatUint(params.Fee, 10))
		}

		if params.TaxPercent > 0 {
			body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64))
		} else if params.TaxPercentZero {
			body.Add("tax_percent", "0")
		}

		params.AppendTo(body)
	}

	invoice := &stripe.Invoice{}
	err := c.B.Call("POST", "/invoices/"+id, token, body, commonParams, invoice)

	return invoice, err
}
Example #30
0
func writeAccountParams(
	params *stripe.AccountParams, body *stripe.RequestValues,
) {
	if len(params.Country) > 0 {
		body.Add("country", params.Country)
	}

	if len(params.Email) > 0 {
		body.Add("email", params.Email)
	}

	if params.DebitNegativeBal {
		body.Add("debit_negative_balances", strconv.FormatBool(true))
	} else if params.NoDebitNegativeBal {
		body.Add("debit_negative_balances", strconv.FormatBool(false))
	}

	if len(params.DefaultCurrency) > 0 {
		body.Add("default_currency", params.DefaultCurrency)
	}

	if params.ExternalAccount != nil {
		if len(params.ExternalAccount.Token) > 0 {
			body.Add("external_account", params.ExternalAccount.Token)
		} else {
			body.Add("external_account[object]", "bank_account")
			body.Add("external_account[account_number]", params.ExternalAccount.Account)
			body.Add("external_account[country]", params.ExternalAccount.Country)
			body.Add("external_account[currency]", params.ExternalAccount.Currency)

			if len(params.ExternalAccount.Routing) > 0 {
				body.Add("external_account[routing_number]", params.ExternalAccount.Routing)
			}
		}
	}

	if len(params.Statement) > 0 {
		body.Add("statement_descriptor", params.Statement)
	}

	if len(params.BusinessName) > 0 {
		body.Add("business_name", params.BusinessName)
	}

	if len(params.BusinessPrimaryColor) > 0 {
		body.Add("business_primary_color", params.BusinessPrimaryColor)
	}

	if len(params.BusinessUrl) > 0 {
		body.Add("business_url", params.BusinessUrl)
	}

	if len(params.SupportPhone) > 0 {
		body.Add("support_phone", params.SupportPhone)
	}

	if len(params.SupportEmail) > 0 {
		body.Add("support_email", params.SupportEmail)
	}

	if len(params.SupportUrl) > 0 {
		body.Add("support_url", params.SupportUrl)
	}

	if params.LegalEntity != nil {
		params.LegalEntity.AppendDetails(body)
	}

	if params.TransferSchedule != nil {
		params.TransferSchedule.AppendDetails(body)
	}

	if params.TOSAcceptance != nil {
		params.TOSAcceptance.AppendDetails(body)
	}

	if len(params.FromRecipient) > 0 {
		body.Add("from_recipient", params.FromRecipient)
	}
}