使用Web服务错误 - SOAP PHP

时间:2013-01-21 12:51:55

标签: php web-services soap

我正在尝试发送数据以使用Web服务。 但它返回错误:

  

错误:服务器无法读取请求。 --->有一个错误   XML文档(2,734)。 --->指定的类型是抽象的:   名称= PaymentDataRequest',   namespace ='https://www.pagador.com.br/webservice/pagador',at。

有人能帮帮我吗? 这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
    <AuthorizeTransaction xmlns="https://www.pagador.com.br/webservice/pagador">
      <request>
        <OrderData>
          <MerchantId>xxxxxxxxxxxxxxx</MerchantId>
          <OrderId>Test0003</OrderId>
          <BraspagOrderId xsi:nil="true" />
        </OrderData>
        <CustomerData>
          <CustomerIdentity>99999999999</CustomerIdentity>
          <CustomerName>Teste</CustomerName>
          <CustomerEmail>compradot@teste.com</CustomerEmail>
          <CustomerAddressData xsi:nil="true" />
          <DeliveryAddressData xsi:nil="true" />
        </CustomerData>
        <PaymentDataCollection>
          <PaymentDataRequest xsi:type="CreditCardDataRequest">
            <PaymentMethod>997</PaymentMethod>
            <Amount>100</Amount>
            <Currency>BRL</Currency>
            <Country>BRA</Country>
            <NumberOfPayments>1</NumberOfPayments>
            <PaymentPlan>0</PaymentPlan>
            <TransactionType>2</TransactionType>
            <CardHolder>Comprador Teste</CardHolder>
            <CardNumber>0000000000000001</CardNumber>
            <CardSecurityCode>111</CardSecurityCode>
            <CardExpirationDate>07/2017</CardExpirationDate>
            <AdditionalDataCollection xsi:nil="true" />
          </PaymentDataRequest>
        </PaymentDataCollection>
        <RequestId>80a51fb5-f9d7-44b8-bdc2-da2d533f3b8d</RequestId>
        <Version>1.0</Version>
      </request>
    </AuthorizeTransaction>
  </soap:Body>
</soap:Envelope>

代码:

$parameters             = new stdClass();
$parameters->request    = new StdClass();

$parameters->request->OrderData->MerchantId='xxxxxxxxxx';
$parameters->request->OrderData->OrderId='Test0004';
$parameters->request->CustomerData->CustomerIdentity='99999999999';
$parameters->request->CustomerData->CustomerName='Teste';
$parameters->request->CustomerData->CustomerEmail='compradot@teste.com';
$parameters->request->CustomerData->CustomerEmail='compradot@teste.com';
$parameters->request->PaymentDataCollection->PaymentDataRequest='997';
$parameters->request->PaymentDataCollection->PaymentDataRequest->Amount='100';
$parameters->request->PaymentDataCollection->PaymentDataRequest->Currency='BRL';
$parameters->request->PaymentDataCollection->PaymentDataRequest->Country='BRA';
$parameters->request->PaymentDataCollection->PaymentDataRequest->NumberOfPayments='1';
$parameters->request->PaymentDataCollection->PaymentDataRequest->PaymentPlan='0';
$parameters->request->PaymentDataCollection->PaymentDataRequest->TransactionType='2';
$parameters->request->PaymentDataCollection->PaymentDataRequest->CardHolder='Comprador Teste';
$parameters->request->PaymentDataCollection->PaymentDataRequest->CardNumber='0000000000000001';
$parameters->request->PaymentDataCollection->PaymentDataRequest->CardSecurityCode='111';
$parameters->request->PaymentDataCollection->PaymentDataRequest->CardExpirationDate='07/2017';
$parameters->request->RequestId='80a51fb5-f9d7-44b8-bdc2-da2d533f3b8d';                             
$parameters->request->Version='1.0';

try {

$braspag = new SoapClient( 'https://homologacao.pagador.com.br/webservice/pagadorTransaction.asmx?WSDL',

        array(
                'trace'                 => 1,
                'exceptions'            => 1,
                'style'                 => SOAP_DOCUMENT,
                'use'                   => SOAP_LITERAL,
                'soap_version'          => SOAP_1_1,
                'encoding'              => 'UTF-8'
        )

);


$AuthorizeTransactionResponse  = $braspag->AuthorizeTransaction($parameters);

print_r($AuthorizeTransactionResponse);

echo $AuthorizeTransactionResponse->AuthorizeTransactionResponse;

} 

catch(SoapFault $fault) {

echo 'Ocorreu um erro: ' , $fault->getMessage();

}

echo "<hr>";
print_r($parameters);
echo "<hr>";

echo "<pre>";
echo htmlspecialchars($braspag->__getLastRequestHeaders())."\n";
echo htmlspecialchars($braspag->__getLastRequest())."\n";
echo "Response:\n".htmlspecialchars($braspag->__getLastResponseHeaders())."\n";
echo htmlspecialchars($braspag->__getLastResponse())."\n";
echo "</pre>"; 

响应:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <AuthorizeTransactionResponse xmlns="https://www.pagador.com.br/webservice/pagador">
         <AuthorizeTransactionResult>
            <CorrelationId>xxxxxxxx</CorrelationId>
            <Success>true</Success>
            <ErrorReportDataCollection/>
            <OrderData>
               <OrderId>Test0003</OrderId>
               <BraspagOrderId>74025d35-2bae-48cb-b84e-07e5a1df4a50</BraspagOrderId>
            </OrderData>
            <PaymentDataCollection>
               <PaymentDataResponse xsi:type="CreditCardDataResponse">
                  <BraspagTransactionId>40dd42b0-7d86-4c90-ac0c-266e454bc2fc</BraspagTransactionId>
                  <PaymentMethod>997</PaymentMethod>
                  <Amount>100</Amount>
                  <AcquirerTransactionId>0118041611250</AcquirerTransactionId>
                  <AuthorizationCode>20130118041611250</AuthorizationCode>
                  <ReturnCode>6</ReturnCode>
                  <ReturnMessage>Operation Successful</ReturnMessage>
                  <Status>0</Status>
                  <CreditCardToken xsi:nil="true"/>
               </PaymentDataResponse>
            </PaymentDataCollection>
         </AuthorizeTransactionResult>
      </AuthorizeTransactionResponse>
   </soap:Body>
</soap:Envelope>

2 个答案:

答案 0 :(得分:2)

如果您使用像我这样的SOAP UI在开始实际实现之前先对Braspag进行测试,请修改PaymentDataRequest,如下所示

<pag:PaymentDataRequest xsi:type="CreditCardDataRequest">

如上所述SparKot

并添加缺少的参数

<pag:ServiceTaxAmount>0</pag:ServiceTaxAmount>
<pag:NumberOfPayments>1</pag:NumberOfPayments>
<pag:PaymentPlan>0</pag:PaymentPlan>
<pag:TransactionType>1</pag:TransactionType>
<pag:CardHolder>Comprador de Teste</pag:CardHolder>
<pag:CardNumber>0000000000000001</pag:CardNumber>
<pag:CardSecurityCode>999</pag:CardSecurityCode>
<pag:CardExpirationDate>05/2013</pag:CardExpirationDate>
<pag:CreditCardToken />
<pag:SaveCreditCard />

答案 1 :(得分:0)

来自WSDL链接

Pagador WebService - WSDL

我只能收集到:

  <s:complexType name="PaymentDataRequest" abstract="**true**">
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="PaymentMethod" type="s:short"/>
      <s:element minOccurs="1" maxOccurs="1" name="Amount" type="s:long"/>
      <s:element minOccurs="0" maxOccurs="1" name="Currency" type="s:string"/>
      <s:element minOccurs="0" maxOccurs="1" name="Country" type="s:string"/>
      <s:element minOccurs="0" maxOccurs="1" name="AdditionalDataCollection" type="tns:ArrayOfAdditionalDataRequest"/>
    </s:sequence>

PaymentDataRequest 是抽象的;您需要 CreditCardDataRequest 扩展 PaymentDataRequest