I have 2 xml string, which come from below 2 functions :
1) $accessRequestXML = $accessRequesttXML->asXML();
It products this xml string :
<?xml version="1.0"?>
<AccessRequest>
<AccessLicenseNumber>7D54A69331203795</AccessLicenseNumber>
<UserId>peterfelts</UserId>
<Password>abc123</Password>
<AccessRequest>
2)
$rateRequestXml = $rateRequestXML->asXML();
It products this xml string :
<?xml version="1.0"?>
<RatingServiceSelectionRequest>
<Request>
<RequestAction>Rate</RequestAction>
<RequestOption>Rate</RequestOption>
</Request>
<Shipment>
<Shipper>
<Name>Name</Name>
<ShipperNumber></ShipperNumber>
<Address>
<AddressLine1>Address Line</AddressLine1>
<City>Corado</City>
<PostalCode>00646</PostalCode>
<CountryCode>PR</CountryCode>
</Address>
</Shipper>
<ShipTo>
<CompanyName>Company Name</CompanyName>
<Address>
<AddressLine1>Address Line</AddressLine1>
<City>Corado</City>
<PostalCode>00646</PostalCode>
<CountryCode>PR</CountryCode>
</Address>
</ShipTo>
<ShipFrom>
<CompanyName>Company Name</CompanyName>
<Address>
<AddressLine1>Address Line</AddressLine1>
<City>Boca Raton</City>
<StateProvinceCode>FL</StateProvinceCode>
<PostalCode>33434</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</ShipFrom>
<Service>
<Code>02</Code>
<Description>2nd Day Air</Description>
</Service>
<Package>
<PackagingType>
<Code>02</Code>
<Description>UPS Package</Description>
</PackagingType>
<PackageWeight>
<UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>15.2</Weight>
</PackageWeight>
</Package>
</Shipment>
</RatingServiceSelectionRequest>
I want to add RatingServiceSelectionRequest this node to AccessRequest
I want result like this :
<?xml version="1.0"?>
<AccessRequest>
<AccessLicenseNumber>7D54A69331203795</AccessLicenseNumber>
<UserId>peterfelts</UserId>
<Password>abc123</Password>
<RatingServiceSelectionRequest>
<Request>
<RequestAction>Rate</RequestAction>
<RequestOption>Rate</RequestOption>
</Request>
<Shipment>
<Shipper>
<Name>Name</Name>
<ShipperNumber></ShipperNumber>
<Address>
<AddressLine1>Address Line</AddressLine1>
<City>Corado</City>
<PostalCode>00646</PostalCode>
<CountryCode>PR</CountryCode>
</Address>
</Shipper>
<ShipTo>
<CompanyName>Company Name</CompanyName>
<Address>
<AddressLine1>Address Line</AddressLine1>
<City>Corado</City>
<PostalCode>00646</PostalCode>
<CountryCode>PR</CountryCode>
</Address>
</ShipTo>
<ShipFrom>
<CompanyName>Company Name</CompanyName>
<Address>
<AddressLine1>Address Line</AddressLine1>
<City>Boca Raton</City>
<StateProvinceCode>FL</StateProvinceCode>
<PostalCode>33434</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</ShipFrom>
<Service>
<Code>02</Code>
<Description>2nd Day Air</Description>
</Service>
<Package>
<PackagingType>
<Code>02</Code>
<Description>UPS Package</Description>
</PackagingType>
<PackageWeight>
<UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>15.2</Weight>
</PackageWeight>
</Package>
</Shipment>
</RatingServiceSelectionRequest>
</AccessRequest>
Can anyone please help me how can i do this ?
IMHO - the best way to do this is to import the XML into DOM which allows you more flexible ways of adding nodes and moving them around.
This code loads the access request as the start of the DOM document and then imports the second XML as a new node, it then appends it to the end of the existing XML...
$dom = new DOMDocument();
$dom->loadXML($accessRequestXML->asXML());
$importrr = dom_import_simplexml($rateRequestXml);
$domImportRR = $dom->importNode($importrr, true);
$dom->documentElement->appendChild($domImportRR);
echo $dom->saveXML();
Related
Anyone knows how to read ADF file from the URL in PHP and render it and save it in MySQL table?
When I use function like
$xml=simplexml_load_file($_REQUEST['adfpath']) or die("Error: Cannot create object");
it's showing
Error: Cannot create object
Below is the ADF File Sample:
<?ADF VERSION "1.0"?>
<?XML VERSION "1.0"?>
<adf>
<prospect>
<requestdate>2010-11-18</requestdate>
<vehicle>
<year></year>
<make></make>
<model></model>
</vehicle>
<customer>
<contact>
<name part="first">Test11</name>
<name part="last">mctester</name>
<address type ="home">
<street line ="1">1722 W test test RD</street>
<city></city>
<state>AZ</state>
<postalcode></postalcode>
</address>
<phone type="voice"></phone>
</contact>
</customer>
<vendor>
<vendorname>
Test vender
</vendorname>
</vendor>
<provider>
<name part='full'>test11 test22 </name>
<service>Leads - </service>
<url>test</url>
<email>test</email>
<phone>800-123-4567</phone>
<contact primarycontact='1'>
<name part='full'>Dennys Test11</name>
<email>test</email>
<phone type='voice' time='day'></phone>
<phone type='fax' time='day'></phone>
<address>
<street line='1'>Apple </street>
<street line='2'>K Mart </street>
<city></city>
<regioncode></regioncode>
<postalcode></postalcode>
<country>US</country>
</address>
</contact>
</provider>
</prospect>
</adf>
Any help is greatly appreciated..
i get an error, 520002 - Internal Error from PayPal, when I try to create and send an invoice.
I can do it with ci-merchant but no with angelleye (for codeigniter). When I try to create it I get this errors:
<?xml version="1.0" encoding="utf-8"?>
<CreateAndSendInvoiceRequest xmlns="http://svcs.paypal.com/types/ap">
<requestEnvelope xmlns="">
<detailLevel>ReturnAll</detailLevel>
<errorLanguage>en_US</errorLanguage>
</requestEnvelope>
<invoice xmlns="">
<merchantEmail xmlns="">lalanzaos#gmail.com</merchantEmail>
<payerEmail xmlns="">oscar73#gmail.com</payerEmail>
<itemList xmlns="">
<item xmlns="">
<name xmlns="">Clases de idiomas (Español)</name>
<description xmlns="">Dia/s: 2014-08-08</description>
<date xmlns="">2014-08-22</date>
<quantity xmlns="">1</quantity><unitPrice xmlns="">11.00</unitPrice>
</item>
</itemList>
<currencyCode xmlns="">USD</currencyCode>
<invoiceDate xmlns="">2014-08-22</invoiceDate>
<dueDate xmlns="">2014-08-22</dueDate>
<referrerCode xmlns="">AngellEYE_PHPClass</referrerCode>
</invoice>
</CreateAndSendInvoiceRequest>
<?xml version='1.0' encoding='UTF-8'?>
<ns3:FaultMessage xmlns:ns3="http://svcs.paypal.com/types/common" xmlns:ns2="http://svcs.paypal.com/types/pt">
<responseEnvelope>
<timestamp>2014-08-22T04:12:25.170-07:00</timestamp>
<ack>Failure</ack>
<correlationId>87f10d36a1e29</correlationId>
<build>11737381</build>
</responseEnvelope>
<error>
<errorId>520002</errorId>
<domain>PLATFORM</domain>
<subdomain>Application</subdomain>
<severity>Error</severity>
<category>Application</category>
<message>Internal Error</message>
</error>
</ns3:FaultMessage>
It seems that the date format is not being correctly passed . It should be like below :
<invoiceDate xmlns="">2014-08-23T22:33:35</invoiceDate>
<dueDate xmlns="">2014-08-24T22:33:35</dueDate>
It should be working fine with this formatting .
Does Authorize.net ARP API accept XML data if the data field is empty ? Do we need to have the data on all the XML elements ?
I used the following XML for updating the subscription.
<?xml version="1.0" encoding="utf-8"?>
<ARBUpdateSubscriptionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>435345345345</name>
<transactionKey>sdfsdfsdfsdf</transactionKey>
</merchantAuthentication>
<refId>155969e50PGj</refId>
<subscriptionId>234324</subscriptionId>
<subscription>
<amount>75</amount>
<customer>
<id>155969</id>
<email></email>
<phoneNumber></phoneNumber>
</customer>
<billTo>
<firstName></firstName>
<lastName></lastName>
<company></company>
<address></address>
<city></city>
<state></state>
<zip></zip>
<country></country>
</billTo>
<shipTo>
<firstName></firstName>
<lastName></lastName>
<company></company>
<address></address>
<city></city>
<state></state>
<zip></zip>
<country></country>
</shipTo>
</subscription>
</ARBUpdateSubscriptionRequest>
I got the following error :
<?xml version="1.0" encoding="utf-8"?>
<ARBUpdateSubscriptionResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<refId>155969e50PGj</refId>
<messages>
<resultCode>Error</resultCode>
<message>
<code>E00014</code>
<text>Bill-To First Name is required.</text>
</message>
<message>
<code>E00014</code>
<text>Bill-To Last Name is required.</text>
</message>
</messages>
</ARBUpdateSubscriptionResponse>
ARBUpdateSubscriptionRequest is required other XML in request
<?xml version="1.0" encoding="utf-8"?>
<ARBUpdateSubscriptionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>mytestacct</name>
<transactionKey>112223344</transactionKey>
</merchantAuthentication>
<refId>Sample</refId>
<subscriptionId>100748</subscriptionId>
<subscription>
<payment>
<creditCard>
<cardNumber>4111111111111111</cardNumber>
<expirationDate>2010-08</expirationDate>
</creditCard>
</payment>
</subscription>
</ARBUpdateSubscriptionRequest>
Hello I am creating a wordpress website for a client using WooCommerce. The site is complete but the client wants the ability to create shipments from the shop_order page. I have most of this figured out, the problem is my XML request to the UPS API. I have checked and recheck, and I cant seem to find the error:
<ShipmentConfirmResponse><Response><ResponseStatusCode>0</ResponseStatusCode><ResponseStatusDescription>Failure</ResponseStatusDescription><Error><ErrorSeverity>Hard</ErrorSeverity><ErrorCode>10002</ErrorCode><ErrorDescription>The XML document is well formed but the document is not valid</ErrorDescription></Error></Response></ShipmentConfirmResponse>
Below is my xml mark up with sensitive info hidden.
<?xml version="1.0" ?>
<AccessRequest xml:lang='en-US'>
<AccessLicenseNumber>******</AccessLicenseNumber>
<UserId>********</UserId>
<Password>********</Password>
</AccessRequest>
<?xml version="1.0" ?>
<ShipConfirmRequest xml:lang='en-US'>
<Request>
<TransactionReference>
<CustomerContext>Customer Context</CustomerContext>
<XpciVersion>1.0</XpciVersion>
</TransactionReference>
<RequestAction>ShipConfirm</RequestAction>
<RequestOption>validate</RequestOption>
</Request>
<Shipment>
<Shipper>
<ShipperNumber>*******</ShipperNumber>
<Name>Canyon Werks, LLC</Name>
<Address>
<AddressLine>2941 Brookspark Drive</AddressLine>
<AddressLine></AddressLine>
<City>North Las Vegas</City>
<StateProvinceCode>NV</StateProvinceCode>
<PostalCode>89030</PostalCode>
<CountryCode>US</CountryCode>
</Address>
<Phone>
<Number>7022552222</Number>
</Phone>
</Shipper>
<ShipTo>
<Name>Justin Walker</Name>
<Address>
<AddressLine>2675 Windmill Pkwy</AddressLine>
<AddressLine>3024</AddressLine>
<City>Henderson</City>
<StateProvinceCode>NV</StateProvinceCode>
<PostalCode>89074</PostalCode>
<CountryCode>US</CountryCode>
</Address>
<Phone>
<Number>7024609485</Number>
</Phone>
</ShipTo>
<ShipFrom>
<Name>Canyon Werks, LLC</Name>
<Address>
<AddressLine>2941 Brookspark Drive</AddressLine>
<AddressLine></AddressLine>
<City>North Las Vegas</City>
<StateProvinceCode>NV</StateProvinceCode>
<PostalCode>89030</PostalCode>
<CountryCode>US</CountryCode>
</Address>
<Phone>
<Number>7022552222</Number>
</Phone>
</ShipFrom>
<PaymentInformation>
<ShipmentCharge>
<Type>01</Type>
<BillShipper>
<AccountNumber>*******</AccountNumber>
</BillShipper>
</ShipmentCharge>
</PaymentInformation>
<Service>
<Code>03</Code>
</Service>
<Package>
<Packaging>
<Code>02</Code>
<Description>Customer Supplied</Description>
</Packaging>
<Dimensions>
<UnitOfMeasurement>
<Code>IN</Code>
</UnitOfMeasurement>
<Length>16</Length>
<Width>12</Width>
<Height>6</Height>
</Dimensions>
<PackageWeight>
<UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>6.07</Weight>
</PackageWeight>
</Package>
</Shipment>
<LabelSpecification>
<LabelImageFormat>
<Code>GIF</Code>
</LabelImageFormat>
</LabelSpecification>
</ShipConfirmRequest>
I am almost there on this, but I am stuck at this road block. If anyone can shed some light into this it would be much appreciated.
It was the service code container it must be included in the package container. I had it before it. Took me quite a while to figure out this dumb mistake on my part.
Before:
...
<Service>
<Code>03</Code>
</Service>
<Package>
...
After:
...
<Package>
<Service>
<Code>03</Code>
</Service>
...
Thanks for the help, and yes UPS requires a strange XML format.
The XML processing instruction appears twice:
<?xml version="1.0" ?>
This indicates the presence of two distinct XML documnents:
<?xml version="1.0" ?>
<AccessRequest xml:lang='en-US'>
<AccessLicenseNumber>******</AccessLicenseNumber>
<UserId>********</UserId>
<Password>********</Password>
</AccessRequest>
and
<?xml version="1.0" ?>
<ShipConfirmRequest xml:lang='en-US'>
<Request>
<TransactionReference>
<CustomerContext>Customer Context</CustomerContext>
<XpciVersion>1.0</XpciVersion>
</TransactionReference>
<RequestAction>ShipConfirm</RequestAction>
<RequestOption>validate</RequestOption>
</Request>
<!-- ... -->
</ShipConfirmRequest>
I've got my script worked out to grab information from the CIM:
$content =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
"<getCustomerProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
merchantAuthenticationBlock().
"<customerProfileId>$cid</customerProfileId>" .
"</getCustomerProfileRequest>";
$response = send_xml_request($content);
$parsedresponse = parse_api_response($response);
So how, now, do I write the returned value to a variable?
I've tried:
$customerPaymentProfileId = $parsedresponse->customerPaymentProfileId;
$customerShippingAddressId = $parsedresponse->customerShippingAddressId;
But this returns the variables empty. I feel like I'm missing something simple.
To see the structure of $parsedresponse do either print_r($parsedresponse) or var_dump($parsedresponse). From there you can see how the array is structured and get your values from there.
FYI, the payment profiles are in an array so you will need to loop through them to get their values. Assuming parsedresponse is the root XML node you can get them like this:
foreach ($parsedresponse->profile->paymentProfiles as $profile)
{
echo $profile->customerPaymentProfileId;
}
FYI, this is a sample array structure for this response (From the AuthnetXML Sample Code. I am the author of this library):
<?xml version="1.0" encoding="utf-8"?>
<getCustomerProfileResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<messages>
<resultCode>Ok</resultCode>
<message>
<code>I00001</code>
<text>Successful.</text>
</message>
</messages>
<profile>
<merchantCustomerId>12345</merchantCustomerId>
<email>user#example.com</email>
<customerProfileId>5427896</customerProfileId>
<paymentProfiles>
<billTo>
<firstName>John</firstName>
<lastName>Smith</lastName>
<address>123 Main Street</address>
<city>Townsville</city>
<state>NJ</state>
<zip>12345</zip>
<phoneNumber>800-555-1234</phoneNumber>
</billTo>
<customerPaymentProfileId>4796541</customerPaymentProfileId>
<payment>
<creditCard>
<cardNumber>XXXX1111</cardNumber>
<expirationDate>XXXX</expirationDate>
</creditCard>
</payment>
</paymentProfiles>
<paymentProfiles>
<billTo>
<firstName>John</firstName>
<lastName>Doe</lastName>
<company/>
<address>123 Main St.</address>
<city>Bellevue</city>
<state>WA</state>
<zip>98004</zip>
<country>USA</country>
<phoneNumber>800-555-1234</phoneNumber>
<faxNumber>800-555-1234</faxNumber>
</billTo>
<customerPaymentProfileId>4796585</customerPaymentProfileId>
<payment>
<creditCard>
<cardNumber>XXXX1111</cardNumber>
<expirationDate>XXXX</expirationDate>
</creditCard>
</payment>
</paymentProfiles>
<shipToList>
<firstName>John</firstName>
<lastName>Smith</lastName>
<address>123 Main Street</address>
<city>Townsville</city>
<state>NJ</state>
<zip>12345</zip>
<phoneNumber>800-555-1234</phoneNumber>
<customerAddressId>4907537</customerAddressId>
</shipToList>
<shipToList>
<firstName>John</firstName>
<lastName>Doe</lastName>
<company/>
<address>123 Main St.</address>
<city>Bellevue</city>
<state>WA</state>
<zip>98004</zip>
<country>USA</country>
<phoneNumber>800-555-1234</phoneNumber>
<faxNumber>800-555-1234</faxNumber>
<customerAddressId>4907591</customerAddressId>
</shipToList>
</profile>
</getCustomerProfileResponse>