蛋蛋星球-制度模式
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

  1. package paypal
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "net/http"
  7. "github.com/go-pay/gopay"
  8. )
  9. // AddTrackingNumber 添加物流单号
  10. // Code = 0 is success
  11. // 文档:https://developer.paypal.com/docs/api/orders/v2/#orders_track_create
  12. func (c *Client) AddTrackingNumber(ctx context.Context, orderId string, bm gopay.BodyMap) (ppRsp *AddTrackingNumberRsp, err error) {
  13. if err = bm.CheckEmptyError("tracking_number", "carrier", "capture_id"); err != nil {
  14. return nil, err
  15. }
  16. url := fmt.Sprintf(addTrackingNumber, orderId)
  17. res, bs, err := c.doPayPalPost(ctx, bm, url)
  18. if err != nil {
  19. return nil, err
  20. }
  21. ppRsp = &AddTrackingNumberRsp{Code: Success}
  22. ppRsp.Response = new(OrderDetail)
  23. if err = json.Unmarshal(bs, ppRsp.Response); err != nil {
  24. return nil, fmt.Errorf("[%w]: %v, bytes: %s", gopay.UnmarshalErr, err, string(bs))
  25. }
  26. if res.StatusCode != http.StatusCreated {
  27. ppRsp.Code = res.StatusCode
  28. ppRsp.Error = string(bs)
  29. ppRsp.ErrorResponse = new(ErrorResponse)
  30. _ = json.Unmarshal(bs, ppRsp.ErrorResponse)
  31. }
  32. return ppRsp, nil
  33. }