mirror of
https://github.com/cubixle/ebay.git
synced 2026-04-24 21:24:47 +01:00
Add PlaceProxyBid
This commit is contained in:
52
offer.go
52
offer.go
@@ -76,15 +76,15 @@ const (
|
||||
// GetBidding retrieves the buyer's bidding details on a specific auction item.
|
||||
//
|
||||
// eBay API docs: https://developer.ebay.com/api-docs/buy/offer/resources/bidding/methods/getBidding
|
||||
func (s *OfferService) GetBidding(ctx context.Context, itemID, marketplaceID string, opts ...Opt) (Item, error) {
|
||||
func (s *OfferService) GetBidding(ctx context.Context, itemID, marketplaceID string, opts ...Opt) (Bidding, error) {
|
||||
u := fmt.Sprintf("buy/offer/v1_beta/bidding/%s", itemID)
|
||||
opts = append(opts, OptBuyMarketplace(marketplaceID))
|
||||
req, err := s.client.NewRequest(http.MethodGet, u, nil, opts...)
|
||||
if err != nil {
|
||||
return Item{}, err
|
||||
return Bidding{}, err
|
||||
}
|
||||
var it Item
|
||||
return it, s.client.Do(ctx, req, &it)
|
||||
var bid Bidding
|
||||
return bid, s.client.Do(ctx, req, &bid)
|
||||
}
|
||||
|
||||
// ProxyBid represents an eBay proxy bid.
|
||||
@@ -94,7 +94,7 @@ type ProxyBid struct {
|
||||
|
||||
// Some valid eBay error codes for the PlaceProxyBid method.
|
||||
//
|
||||
// eBay API docs: https://developer.ebay.com/api-docs/buy/offer/resources/bidding/methods/getBidding#h2-error-codes
|
||||
// eBay API docs: https://developer.ebay.com/api-docs/buy/offer/resources/bidding/methods/placeProxyBid#h2-error-codes
|
||||
const (
|
||||
ErrPlaceProxyBidAuctionEndedBecauseOfBuyItNow = 120002
|
||||
ErrPlaceProxyBidBidCannotBeGreaterThanBuyItNowPrice = 120005
|
||||
@@ -111,34 +111,38 @@ const (
|
||||
|
||||
// PlaceProxyBid places a proxy bid for the buyer on a specific auction item.
|
||||
//
|
||||
// Curency is the three-letter ISO 4217 code representing the currency.
|
||||
// For one hundred US dollars, MaxAmout is "100.00" and currency is "USD".
|
||||
//
|
||||
// You must ensure the user agrees to the "Terms of use for Adult Only category"
|
||||
// (https://signin.ebay.com/ws/eBayISAPI.dll?AdultSignIn2) if he wishes to bid on on a adult-only item.
|
||||
// An item is adult-only if the AdultOnly field returned by the Browse API is set to true.
|
||||
//
|
||||
// eBay API docs: https://developer.ebay.com/api-docs/buy/offer/resources/bidding/methods/getBidding
|
||||
// eBay API docs: https://developer.ebay.com/api-docs/buy/offer/resources/bidding/methods/placeProxyBid
|
||||
func (s *OfferService) PlaceProxyBid(ctx context.Context, itemID, marketplaceID, maxAmount, currency string, userConsentAdultOnlyItem bool, opts ...Opt) (ProxyBid, error) {
|
||||
u := fmt.Sprintf("buy/offer/v1_beta/bidding/%s/place_proxy_bid", itemID)
|
||||
opts = append(opts, OptBuyMarketplace(marketplaceID))
|
||||
pl := struct {
|
||||
MaxAmount struct {
|
||||
Currency string `json:"currency"`
|
||||
Value string `json:"value"`
|
||||
} `json:"maxAmount"`
|
||||
UserConsent struct {
|
||||
AdultOnlyItem bool `json:"adultOnlyItem"`
|
||||
} `json:"userConsent"`
|
||||
}{
|
||||
MaxAmount: struct {
|
||||
Currency string `json:"currency"`
|
||||
Value string `json:"value"`
|
||||
}{currency, maxAmount},
|
||||
UserConsent: struct {
|
||||
AdultOnlyItem bool `json:"adultOnlyItem"`
|
||||
}{userConsentAdultOnlyItem},
|
||||
type userConsent struct {
|
||||
AdultOnlyItem bool `json:"adultOnlyItem,omitempty"`
|
||||
}
|
||||
type amount struct {
|
||||
Currency string `json:"currency"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
type payload struct {
|
||||
MaxAmount amount `json:"maxAmount"`
|
||||
UserConsent *userConsent `json:"userConsent,omitempty"`
|
||||
}
|
||||
pl := payload{
|
||||
MaxAmount: amount{Currency: currency, Value: maxAmount},
|
||||
}
|
||||
if userConsentAdultOnlyItem {
|
||||
pl.UserConsent = &userConsent{userConsentAdultOnlyItem}
|
||||
}
|
||||
req, err := s.client.NewRequest(http.MethodPost, u, &pl, opts...)
|
||||
if err != nil {
|
||||
return ProxyBid{}, err
|
||||
}
|
||||
var p ProxyBid
|
||||
return p, s.client.Do(ctx, req, &p)
|
||||
var bid ProxyBid
|
||||
return bid, s.client.Do(ctx, req, &bid)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user