从PayPal SOAP API获取交易详情(希望也是自定义字段)

De'*_* W. 6 paypal paypal-soap paypal-rest-sdk

我正在尝试从PayPal的SOAP API 获取交易详细信息,但我遇到了来自PayPal的错误.它返回错误:

The transaction id is not valid
Run Code Online (Sandbox Code Playgroud)

我知道这是一个有效的交易ID,因为我能够使用PayPal NVP API获取交易详情,但可能我的SOAP请求格式不正确.我遵循了可以在Web上找到的PayPal SOAP API示例来构建SOAP XML但它们很小.我正在使用mac的PAW程序向PayPal的API发送SOAP请求,但这个问题应该可以使用HTTP客户端重现.

我尝试使用PayPal的REST API,但没有办法获取交易详情(例如姓名,电子邮件,支付金额,自定义字段).我还试图使用NVP(名称 - 值 - 对)API,我确实收到了交易细节,但它没有给我所有存储的交易自定义字段.当我登录PayPal并查看单个事务时,我可以看到该事务的所有自定义字段,因此我知道它们已被存储.

SOAP API是我最后的希望.

这是我正在使用的SOAP信封请求:

 <?xml version="1.0" encoding="UTF-8"?>
 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:ebay:api:PayPalAPI" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:ed="urn:ebay:apis:EnhancedDataTypes">
      <soapenv:Header>
           <ns:RequesterCredentials>
                <ebl:Credentials>
                     <ebl:Username>soap_api_username_here</ebl:Username>
                     <ebl:Password>soap_api_password_here</ebl:Password>
                     <ebl:Signature>soap_api_signature_here</ebl:Signature>
                </ebl:Credentials>
           </ns:RequesterCredentials>
      </soapenv:Header>
      <soapenv:Body>
           <ns:GetTransactionDetailsReq>
                <ns:GetTransactionDetailsRequest>
                     <ebl:Version>93.0</ebl:Version>
                     <ebl:TransactionID>8FX18476NR449891W</ebl:TransactionID>
                </ns:GetTransactionDetailsRequest>
           </ns:GetTransactionDetailsReq>
      </soapenv:Body>
 </soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

这是我从PayPal SOAP API收到的响应:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ed="urn:ebay:apis:EnhancedDataTypes" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">
      <SOAP-ENV:Header>
        <Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType"/>
        <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">
          <Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">
            <Username xsi:type="xs:string"/>
            <Password xsi:type="xs:string"/>
            <Signature xsi:type="xs:string"/>
            <Subject xsi:type="xs:string"/>
          </Credentials>
        </RequesterCredentials>
      </SOAP-ENV:Header>
      <SOAP-ENV:Body id="_0">
        <GetTransactionDetailsResponse xmlns="urn:ebay:api:PayPalAPI">
          <Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2016-08-02T16:43:02Z</Timestamp>
          <Ack xmlns="urn:ebay:apis:eBLBaseComponents">Failure</Ack>
          <CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">a464c181339f4</CorrelationID>
          <Errors xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:ErrorType">
            <ShortMessage xsi:type="xs:string">Transaction refused because of an invalid argument. See additional error messages for details.</ShortMessage>
            <LongMessage xsi:type="xs:string">The transaction id is not valid</LongMessage>
            <ErrorCode xsi:type="xs:token">10004</ErrorCode>
            <SeverityCode xmlns="urn:ebay:apis:eBLBaseComponents">Error</SeverityCode>
          </Errors>
          <Version xmlns="urn:ebay:apis:eBLBaseComponents">93.0</Version>
          <Build xmlns="urn:ebay:apis:eBLBaseComponents">000000</Build>
          <PaymentTransactionDetails xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:PaymentTransactionType">
            <ReceiverInfo xsi:type="ebl:ReceiverInfoType"/>
            <PayerInfo xsi:type="ebl:PayerInfoType">
              <PayerStatus xsi:type="ebl:PayPalUserStatusCodeType">verified</PayerStatus>
              <PayerName xsi:type="ebl:PersonNameType"/>
              <Address xsi:type="ebl:AddressType">
                <AddressOwner xsi:type="ebl:AddressOwnerCodeType">PayPal</AddressOwner>
                <AddressStatus xsi:type="ebl:AddressStatusCodeType">None</AddressStatus>
              </Address>
            </PayerInfo>
            <PaymentInfo xsi:type="ebl:PaymentInfoType">
              <TransactionType xsi:type="ebl:PaymentTransactionCodeType">none</TransactionType>
              <PaymentType xsi:type="ebl:PaymentCodeType">none</PaymentType>
              <PaymentStatus xsi:type="ebl:PaymentStatusCodeType">None</PaymentStatus>
              <PendingReason xsi:type="ebl:PendingStatusCodeType">none</PendingReason>
              <ReasonCode xsi:type="ebl:ReversalReasonCodeType">none</ReasonCode>
            </PaymentInfo>
            <PaymentItemInfo xsi:type="ebl:PaymentItemInfoType">
              <Subscription xsi:type="ebl:SubscriptionInfoType"/>
              <Auction xsi:type="ebl:AuctionInfoType"/>
            </PaymentItemInfo>
          </PaymentTransactionDetails>
        </GetTransactionDetailsResponse>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

我不确定我做错了什么但也许有经验的人可以比我更容易发现错误.我回答了另一个用户关于PayPal REST API的问题,并从中获取了交易详情,但据我所知,没有办法在交易后获取客户详细信息.如果您已经找到了使用REST API实现此目的的方法,请告诉我因为我宁愿使用REST而不是SOAP.

谢谢.

小智 1

该错误消息是一个转移注意力的信息。PayPal 找不到任何 TransactionId,将空 TransactionId 报告为无效。

TransactionId 元素属于urn:ebay:api:PayPalAPI命名空间。您的 XML 将其附加到urn:ebay:apis:eBLBaseComponents命名空间。您所需要做的就是将 更改ebl:TransactionIdns:TransactionId

 <?xml version="1.0" encoding="UTF-8"?>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:ebay:api:PayPalAPI" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:ed="urn:ebay:apis:EnhancedDataTypes">
  <soapenv:Header>
       <ns:RequesterCredentials>
            <ebl:Credentials>
                 <ebl:Username>soap_api_username_here</ebl:Username>
                 <ebl:Password>soap_api_password_here</ebl:Password>
                 <ebl:Signature>soap_api_signature_here</ebl:Signature>
            </ebl:Credentials>
       </ns:RequesterCredentials>
  </soapenv:Header>
  <soapenv:Body>
      <ns:GetTransactionDetailsReq>
           <ns:GetTransactionDetailsRequest>
                <ebl:Version>204.0</ebl:Version>
                <ns:TransactionID>8FX18476NR449891W</ns:TransactionID>
           </ns:GetTransactionDetailsRequest>
      </ns:GetTransactionDetailsReq>
 </soapenv:Body>
Run Code Online (Sandbox Code Playgroud)

在 PayPal 知识库查看此示例。