Я пытаюсь работать с LINQ to XML для разбора уведомлений, которые я получаю от Google Checkout.
Ответ таков:
<?xml version="1.0" encoding="UTF-8"?>
<authorization-amount-notification xmlns="http://checkout.google.com/schema/2" serial-number="153286076708098-00005-6">
<authorization-amount currency="USD">60.0</authorization-amount>
<authorization-expiration-date>2011-07-03T21:27:48.000Z</authorization-expiration-date>
<avs-response>Y</avs-response>
<cvn-response>M</cvn-response>
<timestamp>2011-06-26T21:28:48.741Z</timestamp>
<google-order-number>153286076708098</google-order-number>
<order-summary>
<total-chargeback-amount currency="USD">0.0</total-chargeback-amount>
<google-order-number>153286076708098</google-order-number>
<total-charge-amount currency="USD">0.0</total-charge-amount>
<total-refund-amount currency="USD">0.0</total-refund-amount>
<risk-information>
<ip-address>77.42.229.34</ip-address>
<billing-address>
<address1>somewhere in Beirut</address1>
<address2></address2>
<phone>70892555</phone>
<email>Technical@fisharwe.com</email>
<contact-name>Fisharwe User</contact-name>
<company-name></company-name>
<fax></fax>
<country-code>LB</country-code>
<city>Beirut</city>
<region></region>
<postal-code>1000</postal-code>
</billing-address>
<avs-response>Y</avs-response>
<cvn-response>M</cvn-response>
<eligible-for-protection>true</eligible-for-protection>
<partial-cc-number>1111</partial-cc-number>
<buyer-account-age>18</buyer-account-age>
</risk-information>
<authorization>
<authorization-amount currency="USD">60.0</authorization-amount>
<authorization-expiration-date>2011-07-03T21:27:48.000Z</authorization-expiration-date>
</authorization>
<purchase-date>2011-06-26T21:27:48.000Z</purchase-date>
<archived>false</archived>
<shopping-cart>
<items>
<item>
<item-name>Credits</item-name>
<item-description>Description</item-description>
<unit-price currency="USD">60.0</unit-price>
<quantity>1</quantity>
</item>
</items>
</shopping-cart>
<order-adjustment>
<merchant-codes />
<total-tax currency="USD">0.0</total-tax>
<adjustment-total currency="USD">0.0</adjustment-total>
</order-adjustment>
<promotions />
<buyer-id>975104325298289</buyer-id>
<buyer-marketing-preferences>
<email-allowed>false</email-allowed>
</buyer-marketing-preferences>
<buyer-shipping-address>
<address1>somewhere in Beirut</address1>
<address2></address2>
<phone>70892555</phone>
<email>Technical@fisharwe.com</email>
<contact-name>Fisharwe User</contact-name>
<company-name></company-name>
<fax></fax>
<structured-name>
<first-name>Fisharwe</first-name>
<last-name>User</last-name>
</structured-name>
<country-code>LB</country-code>
<city>Beirut</city>
<region></region>
<postal-code>1000</postal-code>
</buyer-shipping-address>
<order-total currency="USD">60.0</order-total>
<fulfillment-order-state>NEW</fulfillment-order-state>
<financial-order-state>CHARGEABLE</financial-order-state>
</order-summary>
</authorization-amount-notification>
Вот код, который яЯ использую:
var serverResponse = _checkoutService.Post(data, GoogleCheckoutConstants.ReportsUri);
var xmlData = XDocument.Parse(serverResponse);
bool charged = false;
if(xmlData.Root.Name.Equals("authorization-amount-notification"))
{
var amount = (from c in xmlData.Elements()
where c.Name.Equals("authorization-amount")
select c).First().Value;
var googleNumber = (from c in xmlData.Elements()
where c.Name.Equals("google-order-number")
select c).First().Value;
_checkoutService.ChargeAndShip(googleNumber, amount);
charged = true;
}
Впервые я использую LINQ to XML, поэтому я не совсем уверен, что не так с моим кодом.Но это даже не происходит внутри if statement
.Поэтому, когда я заменяю условие на:
if (serverResponse.IndexOf("authorization-amount-notification") > -1)
В результате я получаю ошибки, сообщающие, что amount
и googleNumber
не были найдены.
Любойпредложения?