Documentation
¶
Overview ¶
Package buyproxy is the official Go SDK for BuyProxy — residential, mobile, ISP and datacenter proxies over a typed API.
client := buyproxy.New() // reads BUYPROXY_API_KEY
plans, _ := client.Plans.List(ctx)
res, _ := client.Plans.Generate(ctx, plans[0].ID, &buyproxy.GenerateParams{Country: "US", Count: 5})
resp, _ := res.Proxies[0].HTTPClient().Get("https://api.ipify.org")
Index ¶
- Constants
- Variables
- type APIError
- type Account
- type AccountService
- type AllocateParams
- type Allocation
- type AuthService
- type Balance
- type BalancesService
- type BillingInterval
- type CardCheckout
- type CardCheckoutParams
- type Catalog
- type Client
- type ConnectionError
- type CryptoCheckout
- type Customer
- type CustomerDetail
- type CustomerGenerateParams
- type CustomerPlan
- type CustomerStatus
- type CustomerUpdate
- type CustomerUsage
- type CustomersService
- func (s *CustomersService) Allocate(ctx context.Context, username string, p AllocateParams) (*Allocation, error)
- func (s *CustomersService) Create(ctx context.Context, label string) (*Customer, error)
- func (s *CustomersService) Generate(ctx context.Context, username string, p CustomerGenerateParams) (*GeneratedProxies, error)
- func (s *CustomersService) Get(ctx context.Context, username string) (*CustomerDetail, error)
- func (s *CustomersService) List(ctx context.Context, status CustomerStatus) ([]Customer, error)
- func (s *CustomersService) Update(ctx context.Context, username string, u CustomerUpdate) (*Customer, error)
- func (s *CustomersService) Usage(ctx context.Context, username string) (*CustomerUsage, error)
- type DedicatedFamily
- type GenerateCapabilities
- type GenerateParams
- type GeneratedProxies
- type MobileSelection
- type Option
- type PaidPlan
- type PaymentMethod
- type PendingAllocation
- type Plan
- type PlansService
- type PoolEntry
- type PoolPurchaseParams
- type PoolService
- func (s *PoolService) Get(ctx context.Context) ([]PoolEntry, error)
- func (s *PoolService) Purchase(ctx context.Context, p PoolPurchaseParams) (*WalletPurchase, error)
- func (s *PoolService) TopupCard(ctx context.Context, p PoolTopupParams) (*CardCheckout, error)deprecated
- func (s *PoolService) TopupCrypto(ctx context.Context, p PoolTopupParams) (*CryptoCheckout, error)deprecated
- type PoolTopupParamsdeprecated
- type Product
- type ProductKey
- type ProductsService
- type Protocol
- type Proxy
- type ResellerService
- type ResellerSummary
- type SignupParams
- type SignupResult
- type TopupService
- type Transaction
- type TransactionsService
- type VerifyResult
- type Wallet
- type WalletEntry
- type WalletPurchase
- type WalletPurchaseParams
- type WalletService
- type WalletTopup
Constants ¶
const DefaultBaseURL = "https://www.buyproxy.org"
DefaultBaseURL is the production API.
const Version = "1.1.0"
Version is the SDK version, sent in the User-Agent.
Variables ¶
var ( ErrValidation = errors.New("buyproxy: invalid request") ErrAuthentication = errors.New("buyproxy: authentication failed") ErrInsufficientBandwidth = errors.New("buyproxy: insufficient bandwidth") ErrForbidden = errors.New("buyproxy: forbidden") ErrNotFound = errors.New("buyproxy: not found") ErrRateLimited = errors.New("buyproxy: rate limited") ErrServer = errors.New("buyproxy: server error") // ErrRetired matches calls the API no longer serves (HTTP 410), such as the old bandwidth top-ups. The // error's message names the wallet call to use instead. ErrRetired = errors.New("buyproxy: retired endpoint") )
Sentinel errors for use with errors.Is:
if errors.Is(err, buyproxy.ErrInsufficientBandwidth) { ... }
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
// HTTP status code.
Status int
// Message is the API's own error text.
Message string
// Body is the raw response body.
Body []byte
// RetryAfter is set on 429 when the API said how long to wait.
RetryAfter time.Duration
}
APIError is returned for every non-2xx response.
type Account ¶
type Account struct {
Email string `json:"email"`
Name string `json:"name"`
Plan string `json:"plan"`
PlanExpiresAt *string `json:"planExpiresAt"`
// BalanceGB is the lifetime GB credited. Spendable per-product balances come from Balances.List.
BalanceGB float64 `json:"balanceGb"`
CreatedAt string `json:"createdAt"`
}
Account is the account behind the API key.
type AccountService ¶
type AccountService struct {
// contains filtered or unexported fields
}
type AllocateParams ¶
type AllocateParams struct {
ProductKey ProductKey `json:"productKey"`
GB int `json:"gb"` // whole GB, at least the product's minimum
// IdempotencyKey makes retries safe: repeating a key returns AlreadyApplied and moves nothing.
IdempotencyKey string `json:"-"`
}
AllocateParams moves GB from your pool onto a customer.
type Allocation ¶
type Allocation struct {
ProductKey ProductKey `json:"productKey"`
ProductID string `json:"productId"`
GB int `json:"gb"`
AlreadyApplied bool `json:"alreadyApplied"`
PoolRemainingGB float64 `json:"poolRemainingGb"`
}
Allocation is the result of an allocation.
type AuthService ¶
type AuthService struct {
// contains filtered or unexported fields
}
AuthService creates an account without a browser: Signup, then VerifyOTP with the emailed code.
func (*AuthService) ResendOTP ¶
func (s *AuthService) ResendOTP(ctx context.Context, email string) error
func (*AuthService) Signup ¶
func (s *AuthService) Signup(ctx context.Context, p SignupParams) (*SignupResult, error)
func (*AuthService) VerifyOTP ¶
func (s *AuthService) VerifyOTP(ctx context.Context, email, code string) (*VerifyResult, error)
type Balance ¶
type Balance struct {
ProductKey *ProductKey `json:"productKey"`
ProductID string `json:"productId"`
// PlanID is what to pass to Plans.Generate; nil until the product has been funded once.
PlanID *string `json:"planId"`
ActiveGB float64 `json:"activeGb"`
PendingGB float64 `json:"pendingGb"` // paid for but still being added
TotalGB float64 `json:"totalGb"`
ExpiresAt *string `json:"expiresAt"`
}
Balance is the spendable bandwidth on one product.
type BalancesService ¶
type BalancesService struct {
// contains filtered or unexported fields
}
type BillingInterval ¶
type BillingInterval string
BillingInterval is "month" or "year".
const ( Monthly BillingInterval = "month" Yearly BillingInterval = "year" )
type CardCheckout ¶
type CardCheckout struct {
PayURL string `json:"payUrl"`
// TransactionID is nil when PayURL is the subscription portal rather than a new payment.
TransactionID *string `json:"transactionId"`
}
CardCheckout is a Stripe checkout to open in a browser.
type CardCheckoutParams ¶
type CardCheckoutParams struct {
Kind string `json:"kind"`
ProductKey ProductKey `json:"productKey,omitempty"`
GB int `json:"gb,omitempty"`
Plan PaidPlan `json:"plan,omitempty"`
Interval BillingInterval `json:"interval,omitempty"`
}
CardCheckoutParams starts a plan subscription by card (Kind "plan", Plan, Interval). Build it with PlanCardParams. Kind "topup" was retired on 9 November 2026: bandwidth is bought from the wallet (see WalletService).
func PlanCardParams ¶
func PlanCardParams(plan PaidPlan, interval BillingInterval) CardCheckoutParams
PlanCardParams builds the params for a plan subscription. An empty interval means monthly.
func TopupCardParams
deprecated
func TopupCardParams(product ProductKey, gb int) CardCheckoutParams
TopupCardParams builds the params for a pay-as-you-go card top-up.
Deprecated: retired on 9 November 2026, Topup.Card now fails with ErrRetired for these params. Add money with Wallet.Topup, then buy with Wallet.Purchase(ctx, BuyGB(product, gb)).
type Catalog ¶
type Catalog struct {
Products []Product `json:"products"`
// MinTopupCents is the smallest wallet deposit, in cents ($5.00 is 500).
MinTopupCents int `json:"minTopupCents"`
// VolumeBonus: bandwidth orders of ThresholdGB or more get floor(gb × Rate) extra GB free.
VolumeBonus struct {
ThresholdGB int `json:"thresholdGb"`
Rate float64 `json:"rate"`
} `json:"volumeBonus"`
Plans []struct {
Plan PaidPlan `json:"plan"`
MonthlyPriceCents int `json:"monthlyPriceCents"`
IncludedGB float64 `json:"includedGb"`
} `json:"plans"`
}
Catalog is the public product catalog with live prices.
type Client ¶
type Client struct {
Products *ProductsService
Auth *AuthService
Account *AccountService
Balances *BalancesService
Plans *PlansService
Wallet *WalletService
Topup *TopupService
Transactions *TransactionsService
Reseller *ResellerService
// contains filtered or unexported fields
}
Client talks to the BuyProxy API. It is safe for concurrent use.
type ConnectionError ¶
type ConnectionError struct{ Err error }
ConnectionError means the request never got a response (DNS, reset, timeout, offline).
func (*ConnectionError) Error ¶
func (e *ConnectionError) Error() string
func (*ConnectionError) Unwrap ¶
func (e *ConnectionError) Unwrap() error
type CryptoCheckout ¶
CryptoCheckout is a crypto invoice to open in a browser.
type Customer ¶
type Customer struct {
Username string `json:"username"`
Label string `json:"label"`
Status CustomerStatus `json:"status"`
CreatedAt string `json:"createdAt"`
}
Customer is a reseller sub-account.
type CustomerDetail ¶
type CustomerDetail struct {
Customer
Plans []CustomerPlan `json:"plans"`
Pending []PendingAllocation `json:"pending"`
}
CustomerDetail is a customer with their plans.
type CustomerGenerateParams ¶
type CustomerGenerateParams struct {
PlanID string `json:"planId"`
GenerateParams
}
CustomerGenerateParams is GenerateParams plus the customer's plan.
type CustomerPlan ¶
CustomerPlan is a Plan plus the customer's remaining GB.
type CustomerStatus ¶
type CustomerStatus string
CustomerStatus is "active" or "suspended".
const ( CustomerActive CustomerStatus = "active" CustomerSuspended CustomerStatus = "suspended" )
type CustomerUpdate ¶
type CustomerUpdate struct {
Label string `json:"label,omitempty"`
Status CustomerStatus `json:"status,omitempty"`
}
CustomerUpdate renames and/or suspends/reactivates; empty fields are left unchanged.
type CustomerUsage ¶
type CustomerUsage struct {
Plans []struct {
ID string `json:"id"`
ProductID string `json:"productId"`
ProductKey *ProductKey `json:"productKey"`
RemainingGB float64 `json:"remainingGb"`
TotalGB float64 `json:"totalGb"`
UsedGB float64 `json:"usedGb"`
ExpiresAt *string `json:"expiresAt"`
} `json:"plans"`
Pending []PendingAllocation `json:"pending"`
}
CustomerUsage is a snapshot of a customer's consumption.
type CustomersService ¶
type CustomersService struct {
// contains filtered or unexported fields
}
func (*CustomersService) Allocate ¶
func (s *CustomersService) Allocate(ctx context.Context, username string, p AllocateParams) (*Allocation, error)
Allocate moves GB from your pool onto a customer. Set IdempotencyKey to make retries safe.
func (*CustomersService) Create ¶
Create makes an isolated sub-account with no bandwidth — fund it with Allocate.
func (*CustomersService) Generate ¶
func (s *CustomersService) Generate(ctx context.Context, username string, p CustomerGenerateParams) (*GeneratedProxies, error)
func (*CustomersService) Get ¶
func (s *CustomersService) Get(ctx context.Context, username string) (*CustomerDetail, error)
func (*CustomersService) List ¶
func (s *CustomersService) List(ctx context.Context, status CustomerStatus) ([]Customer, error)
List returns your customers; pass a status ("active"/"suspended") to filter, or "" for all.
func (*CustomersService) Update ¶
func (s *CustomersService) Update(ctx context.Context, username string, u CustomerUpdate) (*Customer, error)
func (*CustomersService) Usage ¶
func (s *CustomersService) Usage(ctx context.Context, username string) (*CustomerUsage, error)
type DedicatedFamily ¶ added in v1.1.0
type DedicatedFamily string
DedicatedFamily is a dedicated (per-IP) product, or ISP Unlimited.
const ( DedicatedISP DedicatedFamily = "isp" DedicatedIPv4 DedicatedFamily = "ipv4" DedicatedIPv6 DedicatedFamily = "ipv6" DedicatedMobile DedicatedFamily = "mobile" ISPUnlimited DedicatedFamily = "ispunlimited" )
type GenerateCapabilities ¶
type GenerateCapabilities struct {
MaxCount int `json:"maxCount"`
MaxStickyMinutes int `json:"maxStickyMinutes"` // 0 means no sticky sessions on this product
Protocols []Protocol `json:"protocols"`
Targeting struct {
Country bool `json:"country"`
State bool `json:"state"`
City bool `json:"city"`
ISP bool `json:"isp"`
} `json:"targeting"`
}
GenerateCapabilities describes what a plan's generate call accepts.
type GenerateParams ¶
type GenerateParams struct {
Protocol Protocol `json:"protocol,omitempty"` // default "http"
Count int `json:"count,omitempty"` // 1–1000, default 1
Country string `json:"country,omitempty"` // ISO 3166-1 alpha-2, e.g. "US"
State string `json:"state,omitempty"`
City string `json:"city,omitempty"`
ISP string `json:"isp,omitempty"`
// StickyMinutes keeps the same IP for that long. Leave 0 for a fresh IP per request (rotating).
StickyMinutes int `json:"stickyMinutes,omitempty"`
}
GenerateParams controls proxy generation. Zero values are omitted, so the API's defaults apply.
type GeneratedProxies ¶
GeneratedProxies is the result of a Generate call: the raw lines plus parsed proxies.
type MobileSelection ¶ added in v1.1.0
type MobileSelection struct {
OperatorID string `json:"operatorId"`
RotationID string `json:"rotationId"`
ServiceType string `json:"serviceType"` // "dedicated" or "shared"
}
MobileSelection picks the carrier and rotation for a dedicated mobile rental.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithAPIKey ¶
WithAPIKey sets the key (bp_key_… personal, bp_live_… reseller). Default: $BUYPROXY_API_KEY.
func WithBaseURL ¶
WithBaseURL overrides the API origin (default https://www.buyproxy.org).
func WithHTTPClient ¶
WithHTTPClient supplies your own *http.Client (timeouts, tracing, proxies).
func WithMaxRetries ¶
WithMaxRetries sets retries for rate limits and transient failures (default 2).
type PaymentMethod ¶ added in v1.1.0
type PaymentMethod string
PaymentMethod is how money goes into the wallet: PayByCard or PayByCrypto.
const ( PayByCard PaymentMethod = "card" PayByCrypto PaymentMethod = "crypto" )
type PendingAllocation ¶
type PendingAllocation struct {
ProductID string `json:"productId"`
ProductKey *ProductKey `json:"productKey"`
GB float64 `json:"gb"`
}
PendingAllocation is GB allocated but still being added to a plan.
type Plan ¶
type Plan struct {
ID string `json:"id"`
ProductID string `json:"productId"`
ProductKey *ProductKey `json:"productKey"`
Name string `json:"name"`
Label *string `json:"label"`
DataGBRemaining float64 `json:"dataGbRemaining"`
DataGBTotal float64 `json:"dataGbTotal"`
ExpiresAt *string `json:"expiresAt"`
CreatedAt string `json:"createdAt"`
Generate *GenerateCapabilities `json:"generate"`
}
Plan is bandwidth you hold on one product.
type PlansService ¶
type PlansService struct {
// contains filtered or unexported fields
}
func (*PlansService) Generate ¶
func (s *PlansService) Generate(ctx context.Context, planID string, p *GenerateParams) (*GeneratedProxies, error)
Generate creates proxy lines against one of your plans. Lines are on-demand — don't store them.
type PoolEntry ¶
type PoolEntry struct {
ProductKey ProductKey `json:"productKey"`
ProductID string `json:"productId"`
Label string `json:"label"`
GB float64 `json:"gb"`
}
PoolEntry is unallocated reseller bandwidth on one product.
type PoolPurchaseParams ¶ added in v1.1.0
type PoolPurchaseParams struct {
ProductKey ProductKey `json:"productKey"`
GB int `json:"gb"` // whole GB, from the product's MinGB to 10,000
// IdempotencyKey (up to 128 characters) is sent as the Idempotency-Key header: repeat the purchase with the
// same key after a timeout and you are charged once.
IdempotencyKey string `json:"-"`
}
PoolPurchaseParams buys bandwidth into the reseller pool, paid from the wallet.
type PoolService ¶
type PoolService struct {
// contains filtered or unexported fields
}
func (*PoolService) Get ¶
func (s *PoolService) Get(ctx context.Context) ([]PoolEntry, error)
Get returns your unallocated bandwidth, per product.
func (*PoolService) Purchase ¶ added in v1.1.0
func (s *PoolService) Purchase(ctx context.Context, p PoolPurchaseParams) (*WalletPurchase, error)
Purchase buys GB into your pool, paid from your wallet. The GB is in the pool as soon as this returns. It is never retried on a server error: set IdempotencyKey and repeat the call yourself to retry safely.
func (*PoolService) TopupCard
deprecated
func (s *PoolService) TopupCard(ctx context.Context, p PoolTopupParams) (*CardCheckout, error)
TopupCard started a card checkout for pool bandwidth.
Deprecated: retired on 9 November 2026, it now fails with ErrRetired without a request. Use Wallet.Topup, then Pool.Purchase.
func (*PoolService) TopupCrypto
deprecated
func (s *PoolService) TopupCrypto(ctx context.Context, p PoolTopupParams) (*CryptoCheckout, error)
TopupCrypto started a crypto invoice for pool bandwidth.
Deprecated: retired on 9 November 2026, it now fails with ErrRetired without a request. Use Wallet.Topup, then Pool.Purchase.
type PoolTopupParams
deprecated
type PoolTopupParams struct {
ProductKey ProductKey `json:"productKey"`
GB int `json:"gb"`
}
PoolTopupParams buys bandwidth into the reseller pool.
Deprecated: used only by the retired Pool.TopupCard and Pool.TopupCrypto. Use Pool.Purchase with PoolPurchaseParams.
type Product ¶
type Product struct {
ProductKey ProductKey `json:"productKey"`
ProductID string `json:"productId"`
Name string `json:"name"`
Description string `json:"description"`
MinGB int `json:"minGb"` // smallest order in whole GB (1 GB; 2 GB for Premium Residential)
PricePerGBCents *int `json:"pricePerGbCents"` // nil if pricing is momentarily unavailable
Currency string `json:"currency"`
}
Product is one item in the catalog.
type ProductKey ¶
type ProductKey string
ProductKey is accepted by every bandwidth purchase and allocation call. See Products.List.
const ( ProductResidential ProductKey = "residential" ProductPremium ProductKey = "premium" ProductISP ProductKey = "isp" ProductMobile ProductKey = "mobile" ProductIPv4 ProductKey = "ipv4" ProductIPv6 ProductKey = "ipv6" )
type ProductsService ¶
type ProductsService struct {
// contains filtered or unexported fields
}
ProductsService is the public catalog.
type Proxy ¶
Proxy is one generated proxy. The API returns username:password@host:port lines.
func ParseProxy ¶
ParseProxy parses a username:password@host:port line. '@' and ':' are allowed inside the password.
func (Proxy) Curl ¶
Curl returns a ready-to-run curl command that prints your exit IP through this proxy.
func (Proxy) Env ¶
Env returns the environment variables understood by curl, wget, git and most CLIs.
func (Proxy) HTTPClient ¶
HTTPClient returns an *http.Client that sends every request through this proxy.
type ResellerService ¶
type ResellerService struct {
Customers *CustomersService
Pool *PoolService
// contains filtered or unexported fields
}
func (*ResellerService) Me ¶
func (s *ResellerService) Me(ctx context.Context) (*ResellerSummary, error)
type ResellerSummary ¶
type ResellerSummary struct {
Email string `json:"email"`
CustomerCount int `json:"customerCount"`
ActiveCustomerCount int `json:"activeCustomerCount"`
Pool []PoolEntry `json:"pool"`
}
ResellerSummary is the result of Reseller.Me.
type SignupParams ¶
type SignupParams struct {
Email string `json:"email"`
Password string `json:"password"`
Name string `json:"name,omitempty"`
}
SignupParams creates an account (no API key needed).
type SignupResult ¶
SignupResult is the result of Auth.Signup.
type TopupService ¶
type TopupService struct {
// contains filtered or unexported fields
}
func (*TopupService) Card ¶
func (s *TopupService) Card(ctx context.Context, p CardCheckoutParams) (*CardCheckout, error)
Card starts a plan subscription by card (Stripe Checkout). Open PayURL to pay. Build p with PlanCardParams. Bandwidth top-ups (TopupCardParams) were retired and fail with ErrRetired: use Wallet.Topup and Wallet.Purchase.
func (*TopupService) Crypto
deprecated
func (s *TopupService) Crypto(ctx context.Context, product ProductKey, gb int) (*CryptoCheckout, error)
Crypto started a crypto bandwidth top-up.
Deprecated: retired on 9 November 2026, it now fails with ErrRetired without a request. Use Wallet.Topup(ctx, PayByCrypto, amountCents), then Wallet.Purchase(ctx, BuyGB(product, gb)).
type Transaction ¶
type Transaction struct {
ID string `json:"id"`
// Kind is "wallet" for a wallet deposit, "plan" for a subscription payment, and "topup", "scraper" or
// "dedicated" for older direct payments.
Kind string `json:"kind"`
Status string `json:"status"` // pending | succeeded | failed
PaymentMethod string `json:"paymentMethod"`
Interval *BillingInterval `json:"interval"`
AmountCents int `json:"amountCents"`
Currency string `json:"currency"`
GB *float64 `json:"gb"` // including any volume bonus
ProductKey *ProductKey `json:"productKey"`
Plan *string `json:"plan"`
ResellerPool bool `json:"resellerPool"`
CreatedAt string `json:"createdAt"`
}
Transaction is one payment.
type TransactionsService ¶
type TransactionsService struct {
// contains filtered or unexported fields
}
func (*TransactionsService) Get ¶
func (s *TransactionsService) Get(ctx context.Context, id string) (*Transaction, error)
func (*TransactionsService) List ¶
func (s *TransactionsService) List(ctx context.Context, limit int) ([]Transaction, error)
List returns recent payments. limit <= 0 uses the API default.
func (*TransactionsService) Wait ¶
func (s *TransactionsService) Wait(ctx context.Context, id string, interval time.Duration) (*Transaction, error)
Wait polls until the payment settles (succeeded or failed) or ctx ends.
type VerifyResult ¶
type VerifyResult struct {
OK bool `json:"ok"`
IsNew bool `json:"isNew"`
User struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"user"`
}
VerifyResult is the result of Auth.VerifyOTP.
type Wallet ¶ added in v1.1.0
type Wallet struct {
BalanceCents int `json:"balanceCents"`
TotalToppedUpCents int `json:"totalToppedUpCents"`
TotalSpentCents int `json:"totalSpentCents"`
Recent []WalletEntry `json:"recent"` // newest first
}
Wallet is your account's USD balance, topped up by card or crypto and spent on any product.
type WalletEntry ¶ added in v1.1.0
type WalletEntry struct {
ID string `json:"_id"`
Type string `json:"type"` // topup | purchase | refund
AmountCents int `json:"amountCents"` // signed: positive adds to the wallet, negative spends it
BalanceAfterCents int `json:"balanceAfterCents"`
Description string `json:"description"`
CreatedAt string `json:"createdAt"`
}
WalletEntry is one line of wallet activity.
type WalletPurchase ¶ added in v1.1.0
type WalletPurchase struct {
OK bool `json:"ok"`
Summary string `json:"summary"` // what was bought, e.g. "10 GB Core Residential"
AmountCents int `json:"amountCents"` // what it cost
BalanceCents int `json:"balanceCents"` // wallet balance afterwards
OrderID string `json:"orderId,omitempty"`
}
WalletPurchase is the result of a wallet or pool purchase.
type WalletPurchaseParams ¶ added in v1.1.0
type WalletPurchaseParams struct {
Kind string `json:"kind"` // gb | scraper | dedicated
ProductKey ProductKey `json:"productKey,omitempty"`
GB int `json:"gb,omitempty"`
AmountCents int `json:"amountCents,omitempty"`
Family DedicatedFamily `json:"family,omitempty"`
Country string `json:"country,omitempty"` // ISO 3166-1 alpha-3, e.g. "USA"
PeriodDays int `json:"periodDays,omitempty"`
Quantity int `json:"quantity,omitempty"`
Mobile *MobileSelection `json:"mobile,omitempty"`
// IdempotencyKey (up to 128 characters) is sent as the Idempotency-Key header: repeat a purchase with the same
// key after a timeout and you are charged once. Derive it from your own data, such as an order id.
IdempotencyKey string `json:"-"`
}
WalletPurchaseParams says what to buy from the wallet. Build it with BuyGB, BuyScraperCredit, RentDedicated or RentISPUnlimited; zero fields are left out of the request.
func BuyGB ¶ added in v1.1.0
func BuyGB(product ProductKey, gb int) WalletPurchaseParams
BuyGB buys whole GB of one product (from its MinGB to 10,000). Orders of 100 GB or more include the volume bonus.
func BuyScraperCredit ¶ added in v1.1.0
func BuyScraperCredit(amountCents int) WalletPurchaseParams
BuyScraperCredit moves amountCents (at least 100) of wallet money onto the Scraper API balance.
func RentDedicated ¶ added in v1.1.0
func RentDedicated(family DedicatedFamily, country string, periodDays, quantity int) WalletPurchaseParams
RentDedicated rents quantity dedicated IPs in a country (ISO alpha-3) for periodDays (7, 14, 30, 60, 90, 180, 270 or 365). Set Mobile for DedicatedMobile.
func RentISPUnlimited ¶ added in v1.1.0
func RentISPUnlimited(mbps int) WalletPurchaseParams
RentISPUnlimited rents one month of ISP Unlimited at mbps (10, 25, 50 or 100).
func (WalletPurchaseParams) WithIdempotencyKey ¶ added in v1.1.0
func (p WalletPurchaseParams) WithIdempotencyKey(key string) WalletPurchaseParams
WithIdempotencyKey returns a copy of p that is safe to retry with the same key.
type WalletService ¶ added in v1.1.0
type WalletService struct {
// contains filtered or unexported fields
}
WalletService is your account's USD wallet: add money by card or crypto, then spend it on any product. It works with a personal or a reseller key.
func (*WalletService) Get ¶ added in v1.1.0
func (s *WalletService) Get(ctx context.Context) (*Wallet, error)
Get returns the balance in cents and the most recent wallet activity.
func (*WalletService) Purchase ¶ added in v1.1.0
func (s *WalletService) Purchase(ctx context.Context, p WalletPurchaseParams) (*WalletPurchase, error)
Purchase spends wallet money on bandwidth, Scraper API credit or a dedicated rental, charged and delivered at once. A short wallet returns an error matching ErrInsufficientBandwidth whose Body carries shortfallCents. It is never retried on a server error: set IdempotencyKey and repeat the call yourself to retry safely.
func (*WalletService) Topup ¶ added in v1.1.0
func (s *WalletService) Topup(ctx context.Context, method PaymentMethod, amountCents int) (*WalletTopup, error)
Topup starts a payment that adds amountCents (500 to 200000, so $5 to $2,000) to the wallet. Open CheckoutURL() to pay, then Transactions.Wait: the money is in the wallet once it says "succeeded".
type WalletTopup ¶ added in v1.1.0
type WalletTopup struct {
PayURL string `json:"payUrl,omitempty"`
URL string `json:"url,omitempty"`
TransactionID string `json:"transactionId"`
}
WalletTopup is a payment page that adds money to the wallet: PayURL for card, URL for crypto.
func (*WalletTopup) CheckoutURL ¶ added in v1.1.0
func (t *WalletTopup) CheckoutURL() string
CheckoutURL returns the page to pay on, for either method.