Array
(
)

Popular um webservice via soap

PHP
Luan
   - 06 mar 2013

Pessoal tenho que fazer um script em php que popula um webservice da braspag, eles me mandarão um txt com o seguinte xml:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/20...Schema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlso.../soap/envelope/">
<soap:Body>
<AuthorizeTransaction xmlns="https://www.pagador....service/pagador">
<request>
<OrderData>
<MerchantId>9654B689-7B20-7E1A-19C6-B0DBD54520A4</MerchantId>
<OrderId>04032013001</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>TESTE</CardHolder>
<CardNumber>0000000000000001</CardNumber>
<SaveCreditCard>true</SaveCreditCard>
<CardSecurityCode>111</CardSecurityCode>
<CardExpirationDate>11/2013</CardExpirationDate>
</PaymentDataRequest>
</PaymentDataCollection>
<RequestId>80a51fb5-f9d7-44b8-bdc2-da2d533f3b8d</RequestId>
<Version>1.0</Version>
</request>
</AuthorizeTransaction>
</soap:Body>
</soap:Envelope>

Montei o seguinte script assim:

<?
$parameters = new stdClass();
$parameters->request = new StdClass();
$parameters->request->OrderData->MerchantId='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$parameters->request->OrderData->OrderId='Test0004';
$parameters->request->OrderData->BraspagOrderId='xsi:nil=true';
$parameters->request->CustomerData->CustomerIdentity='99999999999';
$parameters->request->CustomerData->CustomerName='Teste';
$parameters->request->CustomerData->CustomerEmail='compradot@teste.com';
$parameters->request->CustomerData->CustomerAddressData='xsi:nil=true';
$parameters->request->CustomerData->DeliveryAddressData='xsi:nil=true';
$parameters->request->PaymentDataCollection->PaymentDataRequest='xsi:type=CreditCardDataRequest';
$parameters->request->PaymentDataCollection->PaymentMethod='997';
$parameters->request->PaymentDataCollection->Amount='500';
$parameters->request->PaymentDataCollection->Currency='BRL';
$parameters->request->PaymentDataCollection->Country='BRA';
$parameters->request->PaymentDataCollection->NumberOfPayments='1';
$parameters->request->PaymentDataCollection->PaymentPlan='0';
$parameters->request->PaymentDataCollection->TransactionType='1';
$parameters->request->PaymentDataCollection->CardHolder='Comprador Teste';
$parameters->request->PaymentDataCollection->CardNumber='0000000000000001';
$parameters->request->PaymentDataCollection->CardSecurityCode='123';
$parameters->request->PaymentDataCollection->CardExpirationDate='05/2018';
$parameters->request->PaymentDataCollection->AdditionalDataCollection.'xsi:nil=true';
$parameters->request->RequestId='9654B689-7B20-7E1A-19C6-B0DBD54520A4';
$parameters->request->Version='1.0';
// Verifica se tem o SOAP instalado.
if (!class_exists('SoapClient')){
echo ("O módulo PHP-Soap nâo esta instalado.");
} else {
try {

$braspag = new SoapClient('https://homologacao....ction.asmx?WSDL',

array(
'trace' => 'true',
'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 '<br>------Começa aqui !--------<br>';
echo "<pre>";

var_dump($braspag->__getLastRequestHeaders()); //the headers of your last request
var_dump($braspag->__getLastRequest()); //your last request

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

O problema é que quando rodo o script ele apresenta o seguinte erro :
There is an error in XML document (2, 462). ---> Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

o problema esta nesta linha:
$parameters->request->OrderData->BraspagOrderId='xsi:nil=true';
Essa linha teria que ficar igual o xml, assim :
<BraspagOrderId xsi:nil="true" />
Mas como eu faria para fazer um array com o nome assim:
BraspagOrderId xsi:nil
Lembrando que tem um espaço entre o "BraspagOrderId" e o "xsi" e um ":" aqui
alguem tem alguma alternativa ?
Grato

Marcio Araujo
   - 25 mar 2013

complicado!!!