德尔福的eBay API CompleteSaleRequest无法保存ShipmentTrackingDetails

时间:2016-02-20 17:42:14

标签: api delphi ebay

我在调用CompleteSaleRequest eBay API函数时尝试保存ShipmentTrackingDetails(ShippingCarrierUsed和ShipmentTrackingNumber)。据我所知,我所做的所有事情都是根据eBay API规范进行的,该调用会返回成功,但是当我检索订单时,跟踪详细信息不会保存。我的功能如下:

function CompleteSale(OrderID: String; var ErrMsg: String): Boolean;
var
  req: CompleteSaleRequest;
  service: eBayAPIInterface;
  res: CompleteSaleResponse;
begin
  Result := False;
  service := GeteBayAPIInterface(nil, 'CompleteSale');

  req := CompleteSaleRequest.Create;
  req.OrderID := OrderID;
  req.Shipment := ShipmentType.Create;
  req.Shipment.SetShipmentTrackingDetailsLength(1);
  req.Shipment.ShipmentTrackingDetails[0] := ShipmentTrackingDetailsType.Create;
  ShipmentTrackingDetailsType(req.Shipment.ShipmentTrackingDetails[0]).ShippingCarrierUsed := [some custom text];
  ShipmentTrackingDetailsType(req.Shipment.ShipmentTrackingDetails[0]).ShipmentTrackingNumber := [some customer tracking number];
  req.Shipped := True;

  try
    try
      InitRequest(req);
      Screen.Cursor := crHourGlass;
      res := service.CompleteSale(req);
      Screen.Cursor := crDefault;
      Result := True;
    except
      on E: Exception do
        ErrMsg := E.Message;
    end;
  finally
    req.Free;
  end;
end;

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

在其他任何事情之前,尝试检查您的请求生成的xml并由Ebay api返回。为此,将tXMLDocument放在表单上,​​然后使用 THTTPRIO的OnBeforeExecute和OnAfterExecute事件:

procedure TForm1.HTTPRIO1BeforeExecute(const MethodName: string;
SOAPRequest: TStream);
begin
XML1.LoadFromStream(SOAPRequest);
XML1.SaveToFile('Somefile.xml');
...

这样您就可以控制输入xml并最终更改代码。 基本上如果您可以在您的xml中看到ShipmentTrackingNumber和ShipmentCarrieUsed,那么调用应该是成功的,但是自从Ebay实际上“刷新”其服务器上的数据(根据我的经验)后,有时需要几个小时

如果您有兴趣,有完整的工作生产解决方案,不幸的是它是C ++ Builder:

  String    CallName="CompleteSale";
  int SiteId=Ebay->SiteId; //77
  String Version=Ebay->Version;
  String AppId=Ebay->AppId;
  String DevId=Ebay->DevId;
  String CertId=Ebay->CertId;
  String SiteUrl=Ebay->SiteUrl;
  String AuthToken=Ebay->AuthToken;
  String CarrierUsed=Ebay->CarrierUsed;
  String Link=UnicodeString(SiteUrl)+CallName+'&'+"&siteid="+SiteId+'&'+"&appid="+
  AppId+'&'+"&version="+Version+'&'+"&routing=default";

  while(!FDQWorker->Eof) {
  String OrderLineItemId=FDQWorker->FieldByName("OrderLineItemID")->AsString;

CompleteSaleRequest * CS = new CompleteSaleRequest;
CompleteSaleResponse * CSResp = new CompleteSaleResponse;
RequesterCredentials * HDR = new RequesterCredentials;
CallName="CompleteSale";
String PUrl =  Link;
 EbayCall = GeteBayAPIInterface(false,PUrl,HTP1);
 HDR->eBayAuthToken=AuthToken;
 UserIdPasswordType *Cred = new UserIdPasswordType();
 HDR->Credentials  =  Cred;
 HDR->Credentials->AppId=AppId;
 HDR->Credentials->DevId=DevId;
 HDR->Credentials->AuthCert=CertId;
 _di_ISOAPHeaders headers = EbayCall;
 HTP1->SOAPHeaders->Send(HDR);
 HTP1->SOAPHeaders->SetOwnsSentHeaders(True);
 CS->Version=Version;
 CS->OrderLineItemID=OrderLineItemId;
 CS->Shipped=true;
 CS->WarningLevel=WarningLevelCodeType::High;
 ShipmentType * Shipment = new ShipmentType;
 CS->Shipment = Shipment;

 Array_Of_ShipmentTrackingDetailsType ShipmentD;

 ShipmentD.Length=PNumbers->Count; //Multiple Parcels Stringlist

 for (int i = 0; i < ShipmentD.Length; i++) {
  ShipmentTrackingDetailsType * ShipmentT = new ShipmentTrackingDetailsType;
  ShipmentT->ShipmentTrackingNumber=PNumbers->Strings[i];
  ShipmentT->ShippingCarrierUsed=CarrierUsed;
 ShipmentD[i]=ShipmentT;
 }


 CS->Shipment->ShipmentTrackingDetails=ShipmentD;

  CSResp = EbayCall->CompleteSale(CS);
...
}

最好的问候