AddItem
<?php
ini_set('max_execution_time',0);
AddItem();
function AddItem()
{
//print_r($_REQUEST);
$j=1;
$url= utf8_encode("https://api.sandbox.ebay.com/ws/api.dll");//if using sandbox environment & if using production environment then remove sandbox from url
$xmlrequest = '<?xml version="1.0" encoding="utf-8"?>
<AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>YOUR_AUTH_N_AUTH_TOKEN</eBayAuthToken>
</RequesterCredentials>
<ErrorLanguage>en_US</ErrorLanguage>
<WarningLevel>High</WarningLevel>
<Item>
<Title>'.$_REQUEST['title'].'</Title>
<Description>'.$_REQUEST['description'].'</Description>';
if(isset($_REQUEST['store_category_id']) && !empty($_REQUEST['store_category_id']))
{
$xmlrequest .= '<Storefront><StoreCategoryID>'.$_REQUEST['store_category_id'].'</StoreCategoryID></Storefront>';
}
$xmlrequest .= '<PrimaryCategory>';
if(!isset($_REQUEST['category_id']) || empty($_REQUEST['category_id']))
{
echo json_encode(array('status'=>'error','msg'=>'Category id must be given'));
$j=0;
}
else $xmlrequest .= '<CategoryID>'.$_REQUEST['category_id'].'</CategoryID>
</PrimaryCategory>';
if(!isset($_REQUEST['start_price']) || empty($_REQUEST['start_price']))
{
echo json_encode(array('status'=>'error','msg'=>'Starting price/Fixed price must be given'));
$j=0;
}
else $xmlrequest .= '<StartPrice>'.$_REQUEST['start_price'].'</StartPrice>';
$xmlrequest .= '<CategoryMappingAllowed>true</CategoryMappingAllowed>';
if(!isset($_REQUEST['condition_id']) || empty($_REQUEST['condition_id']))
{
echo json_encode(array('status'=>'error','msg'=>'Condition must be given'));
$j=0;
}
else $xmlrequest .= '<ConditionID>'.$_REQUEST['condition_id'].'</ConditionID>
<Country>US</Country>
<Currency>USD</Currency>';
if(!isset($_REQUEST['handling_time']) || empty($_REQUEST['handling_time']))
{
$_REQUEST['handling_time'] = '0';
}
$xmlrequest .= '<DispatchTimeMax>'.$_REQUEST['handling_time'].'</DispatchTimeMax>';
if(!isset($_REQUEST['duration']) || empty($_REQUEST['duration']))
{
echo json_encode(array('status'=>'error','msg'=>'Listing duration must be given'));
$j=0;
}
else $xmlrequest .= '<ListingDuration>Days_'.$_REQUEST['duration'].'</ListingDuration>';
if(!isset($_REQUEST['listing_type']) || empty($_REQUEST['listing_type']))
{
echo json_encode(array('status'=>'error','msg'=>'Listing type must be given'));
$j=0;
}
else $xmlrequest .= '<ListingType>'.$_REQUEST['listing_type'].'</ListingType>';
if($_REQUEST['listing_type'] == 'Chinese')
{
if(isset($_REQUEST['buy_price']) && !empty($_REQUEST['buy_price']))
{
$xmlrequest .= '<BuyItNowPrice>'.$_REQUEST['buy_price'].'</BuyItNowPrice>';
}
}
$xmlrequest .= '<PaymentMethods>'.$_REQUEST['payment_method'].'</PaymentMethods>';
if(isset($_REQUEST['best_offer']) && !empty($_REQUEST['best_offer']))
{
$xmlrequest .= '<BestOfferDetails>
<BestOfferEnabled>'.$_REQUEST['best_offer'].'</BestOfferEnabled>
</BestOfferDetails>';
}
else
{
$xmlrequest .= '<BestOfferDetails>
<BestOfferEnabled>false</BestOfferEnabled>
</BestOfferDetails>';
}
if($_REQUEST['payment_method'] == 'PayPal')
{
if(!isset($_REQUEST['paypal_email']) || empty($_REQUEST['paypal_email']))
{
echo json_encode(array('status'=>'error','msg'=>'PayPal E-mail cannot be empty'));
}
else $xmlrequest .= '<PayPalEmailAddress>'.$_REQUEST['paypal_email'].'</PayPalEmailAddress>';
}
$xmlrequest .= '<PictureDetails>
<GalleryType>Gallery</GalleryType>';
if(isset($_REQUEST['file']) && !empty($_REQUEST['file']))
{
foreach(explode(',',$_REQUEST['file']) as $file)
{
$xmlrequest .= '<PictureURL>'.$file.'
</PictureURL>';
}
$xmlrequest .= '</PictureDetails>';
}
if(isset($_REQUEST['postal_code']) && !empty($_REQUEST['postal_code']))
{
$xmlrequest .= '<PostalCode>'.$_REQUEST['postal_code'].'</PostalCode>';
}
$xmlrequest .= '<ProductListingDetails>
<UPC>885909298594</UPC>
<IncludeStockPhotoURL>true</IncludeStockPhotoURL>
<IncludeeBayProductDetails>true</IncludeeBayProductDetails>
<UseFirstProduct>true</UseFirstProduct>
<UseStockPhotoURLAsGallery>true</UseStockPhotoURLAsGallery>
<ReturnSearchResultOnDuplicates>true</ReturnSearchResultOnDuplicates>
</ProductListingDetails>';
if(isset($_REQUEST['quantity']) && !empty($_REQUEST['quantity']))
{
$quantity = $_REQUEST['quantity'];
}
else
{
$quantity = '1';
}
$xmlrequest .= '<Quantity>'.$quantity.'</Quantity>
<ReturnPolicy>';
if(!isset($_REQUEST['returns_acceptance']) || empty($_REQUEST['returns_acceptance']))
{
echo json_encode(array('status'=>'error','msg'=>'Returns acceptance option must be given'));
$j=0;
}
else $xmlrequest .= '<ReturnsAcceptedOption>'.$_REQUEST['returns_acceptance'].'</ReturnsAcceptedOption>
';
if(isset($_REQUEST['refund_option']) && !empty($_REQUEST['refund_option']))
{
$xmlrequest .= '<RefundOption>'.$_REQUEST['refund_option'].'</RefundOption>';
}
if(isset($_REQUEST['returns_duration']) && !empty($_REQUEST['returns_duration']))
{
$xmlrequest .= '<ReturnsWithinOption>Days_'.$_REQUEST['returns_duration'].'</ReturnsWithinOption>';
}
if(isset($_REQUEST['return_description']) && !empty($_REQUEST['return_description']))
{
$xmlrequest .= '<Description>'.$_REQUEST['return_description'].'</Description>';
}
$xmlrequest .= '<ShippingCostPaidByOption>'.$_REQUEST['return_paid_by'].'</ShippingCostPaidByOption>
</ReturnPolicy>
<ShippingDetails>';
if($_REQUEST['domestic_shipping'] == 'Free' && ($_REQUEST['international_shipping'] == '' || $_REQUEST['international_shipping'] == 'Noshipping'))
{
$xmlrequest .= '<ShippingType>Flat</ShippingType>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>
<ShippingServiceCost>0.00</ShippingServiceCost>
<ShippingServiceAdditionalCost>0.00</ShippingServiceAdditionalCost>
</ShippingServiceOptions>';
}
else if($_REQUEST['domestic_shipping'] == 'Flat' && ($_REQUEST['international_shipping'] == '' || $_REQUEST['international_shipping'] == 'Noshipping'))
{
$xmlrequest .= '<ShippingType>Flat</ShippingType>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>';
if(!isset($_REQUEST['domestic_service_cost']) || empty($_REQUEST['domestic_service_cost']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic service cost must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingServiceCost>'.$_REQUEST['domestic_service_cost'].'</ShippingServiceCost>
<ShippingServiceAdditionalCost>0.00</ShippingServiceAdditionalCost>
</ShippingServiceOptions>';
}
else if($_REQUEST['domestic_shipping'] == 'Free' && $_REQUEST['international_shipping'] == 'Flat')
{
$xmlrequest .= '<ShippingType>Flat</ShippingType>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>
<ShippingServiceCost>0.00</ShippingServiceCost>
<ShippingServiceAdditionalCost>0.00</ShippingServiceAdditionalCost>
</ShippingServiceOptions>
<InternationalShippingServiceOption>';
if(!isset($_REQUEST['international_shipping_service_option']) || empty($_REQUEST['international_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'International shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['international_shipping_service_option'].'</ShippingService>
<ShippingServicePriority>1</ShippingServicePriority>';
if(($_REQUEST['ship_location']) == 'Custom')
{
foreach(explode(',',$_REQUEST['location']) as $location)
{
$xmlrequest .= '<ShipToLocation>'.$location.'</ShipToLocation>';
}
}
else
{
$xmlrequest .= '<ShipToLocation>'.$_REQUEST['ship_location'].'</ShipToLocation>';
}
if(isset($_REQUEST['international_service_cost']) && !empty($_REQUEST['international_service_cost']))
{
$xmlrequest .= '<ShippingServiceCost>'.$_REQUEST['international_service_cost'].'</ShippingServiceCost>';
}
$xmlrequest .= '</InternationalShippingServiceOption>';
}
else if($_REQUEST['domestic_shipping'] == 'Flat' && $_REQUEST['international_shipping'] == 'Flat')
{
$xmlrequest .= '<ShippingType>Flat</ShippingType>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>';
if(!isset($_REQUEST['domestic_service_cost']) || empty($_REQUEST['domestic_service_cost']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic service cost must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingServiceCost>'.$_REQUEST['domestic_service_cost'].'</ShippingServiceCost>
<ShippingServiceAdditionalCost>0.00</ShippingServiceAdditionalCost>
</ShippingServiceOptions>
<InternationalShippingServiceOption>';
if(!isset($_REQUEST['international_shipping_service_option']) || empty($_REQUEST['international_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'International shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['international_shipping_service_option'].'</ShippingService>
<ShippingServicePriority>1</ShippingServicePriority>';
if(($_REQUEST['ship_location']) == 'Custom')
{
foreach(explode(',',$_REQUEST['location']) as $location)
{
$xmlrequest .= '<ShipToLocation>'.$location.'</ShipToLocation>';
}
}
else
{
$xmlrequest .= '<ShipToLocation>'.$_REQUEST['ship_location'].'</ShipToLocation>';
}
if(isset($_REQUEST['international_service_cost']) && !empty($_REQUEST['international_service_cost']))
{
$xmlrequest .= '<ShippingServiceCost>'.$_REQUEST['international_service_cost'].'</ShippingServiceCost>';
}
else
{
$xmlrequest .= '<ShippingServiceCost>0.00</ShippingServiceCost>';
}
$xmlrequest .= '</InternationalShippingServiceOption>';
}
else if($_REQUEST['domestic_shipping'] == 'Calculated' && ($_REQUEST['international_shipping'] == '' || $_REQUEST['international_shipping'] == 'Noshipping'))
{
$xmlrequest .= '<ShippingType>Calculated</ShippingType>
<CalculatedShippingRate>
<OriginatingPostalCode>'.$_REQUEST['postal_code'].'</OriginatingPostalCode>';
if(isset($_REQUEST['domestic_handling_cost']) && !empty($_REQUEST['domestic_handling_cost']))
{
//$_REQUEST['international_handling_cost'] = '0.00';
$xmlrequest .= '<PackagingHandlingCosts currencyID="USD">'.$_REQUEST['domestic_handling_cost'].'</PackagingHandlingCosts>';
}
else
{
$xmlrequest .= '<PackagingHandlingCosts currencyID="USD">0.00</PackagingHandlingCosts>';
}
if(!isset($_REQUEST['shipping_package']) || empty($_REQUEST['shipping_package']))
{
echo json_encode(array('status'=>'error','msg'=>'Shipping package must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingPackage>'.$_REQUEST['shipping_package'].'</ShippingPackage>';
if(!isset($_REQUEST['major_weight']) || empty($_REQUEST['major_weight']) || $_REQUEST['major_weight'] == '0')
{
echo json_encode(array('status'=>'error','msg'=>'Maximum weight must be given'));
$j=0;
}
else $xmlrequest .= '<WeightMajor unit="lbs">'.$_REQUEST['major_weight'].'</WeightMajor>';
if(isset($_REQUEST['minor_weight']) && !empty($_REQUEST['minor_weight']))
{
$xmlrequest .= '<WeightMinor unit="oz">'.$_REQUEST['minor_weight'].'</WeightMinor>';
}
else
{
$xmlrequest .= '<WeightMinor unit="oz">0</WeightMinor>';
}
if(isset($_REQUEST['package_length']) && !empty($_REQUEST['package_length']))
{
$xmlrequest .= '<PackageLength>'.$_REQUEST['package_length'].'</PackageLength>';
}
if(isset($_REQUEST['package_width']) && !empty($_REQUEST['package_width']))
{
$xmlrequest .= '<PackageWidth>'.$_REQUEST['package_width'].'</PackageWidth>';
}
if(isset($_REQUEST['package_height']) && !empty($_REQUEST['package_height']))
{
$xmlrequest .= '<PackageDepth>'.$_REQUEST['package_height'].'</PackageDepth>';
}
if(isset($_REQUEST['check_irregular']) && !empty($_REQUEST['check_irregular']))
{
$xmlrequest .= '<ShippingIrregular>true</ShippingIrregular>';
}
$xmlrequest .= '</CalculatedShippingRate>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>';
$xmlrequest .= '</ShippingServiceOptions>';
}
else if($_REQUEST['domestic_shipping'] == 'Calculated' && $_REQUEST['international_shipping'] == 'Calculated')
{
$xmlrequest .= '<ShippingType>Calculated</ShippingType>
<CalculatedShippingRate>
<OriginatingPostalCode>'.$_REQUEST['postal_code'].'</OriginatingPostalCode>';
if(isset($_REQUEST['domestic_handling_cost']) && !empty($_REQUEST['domestic_handling_cost']))
{
//$_REQUEST['international_handling_cost'] = '0.00';
$xmlrequest .= '<PackagingHandlingCosts currencyID="USD">'.$_REQUEST['domestic_handling_cost'].'</PackagingHandlingCosts>';
}
else
{
$xmlrequest .= '<PackagingHandlingCosts currencyID="USD">0.00</PackagingHandlingCosts>';
}
if(isset($_REQUEST['international_handling_cost']) && !empty($_REQUEST['international_handling_cost']))
{
//$_REQUEST['international_handling_cost'] = '0.00';
$xmlrequest .= '<InternationalPackagingHandlingCosts currencyID="USD">'.$_REQUEST['international_handling_cost'].'</InternationalPackagingHandlingCosts>';
}
else
{
$xmlrequest .= '<InternationalPackagingHandlingCosts currencyID="USD">0.00</InternationalPackagingHandlingCosts>';
}
if(!isset($_REQUEST['shipping_package']) || empty($_REQUEST['shipping_package']))
{
echo json_encode(array('status'=>'error','msg'=>'Shipping package type must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingPackage>'.$_REQUEST['shipping_package'].'</ShippingPackage>';
if(!isset($_REQUEST['major_weight']) || empty($_REQUEST['major_weight']) || $_REQUEST['major_weight'] == '0')
{
echo json_encode(array('status'=>'error','msg'=>'Maximum weight must be given'));
$j=0;
}
else $xmlrequest .= '<WeightMajor unit="lbs">'.$_REQUEST['major_weight'].'</WeightMajor>';
if(isset($_REQUEST['minor_weight']) && !empty($_REQUEST['minor_weight']))
{
$xmlrequest .= '<WeightMinor unit="oz">'.$_REQUEST['minor_weight'].'</WeightMinor>';
}
else
{
$xmlrequest .= '<WeightMinor unit="oz">0</WeightMinor>';
}
if(isset($_REQUEST['package_length']) && !empty($_REQUEST['package_length']))
{
$xmlrequest .= '<PackageLength>'.$_REQUEST['package_length'].'</PackageLength>';
}
if(isset($_REQUEST['package_width']) && !empty($_REQUEST['package_width']))
{
$xmlrequest .= '<PackageWidth>'.$_REQUEST['package_width'].'</PackageWidth>';
}
if(isset($_REQUEST['package_height']) && !empty($_REQUEST['package_height']))
{
$xmlrequest .= '<PackageDepth>'.$_REQUEST['package_height'].'</PackageDepth>';
}
if(isset($_REQUEST['check_irregular']) && !empty($_REQUEST['check_irregular']))
{
$xmlrequest .= '<ShippingIrregular>true</ShippingIrregular>';
}
$xmlrequest .= '</CalculatedShippingRate>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>
</ShippingServiceOptions>
<InternationalShippingServiceOption>';
if(!isset($_REQUEST['international_shipping_service_option']) || empty($_REQUEST['international_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'International shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['international_shipping_service_option'].'</ShippingService>
<ShippingServicePriority>1</ShippingServicePriority>';
if($_REQUEST['ship_location'] == 'Custom')
{
foreach(explode(',',$_REQUEST['location']) as $location)
{
$xmlrequest .= '<ShipToLocation>'.$location.'</ShipToLocation>';
}
}
else
{
$xmlrequest .= '<ShipToLocation>'.$_REQUEST['ship_location'].'</ShipToLocation>';
}
$xmlrequest .= '</InternationalShippingServiceOption>';
}
else if($_REQUEST['domestic_shipping'] == 'Flat' && $_REQUEST['international_shipping'] == 'Calculated')
{
$xmlrequest .= '<ShippingType>FlatDomesticCalculatedInternational</ShippingType>
<CalculatedShippingRate>
<OriginatingPostalCode>'.$_REQUEST['postal_code'].'</OriginatingPostalCode>';
if(isset($_REQUEST['international_handling_cost']) && !empty($_REQUEST['international_handling_cost']))
{
//$_REQUEST['international_handling_cost'] = '0.00';
$xmlrequest .= '<InternationalPackagingHandlingCosts currencyID="USD">'.$_REQUEST['international_handling_cost'].'</InternationalPackagingHandlingCosts>';
}
else
{
$xmlrequest .= '<InternationalPackagingHandlingCosts currencyID="USD">0.00</InternationalPackagingHandlingCosts>';
}
if(!isset($_REQUEST['shipping_package']) || empty($_REQUEST['shipping_package']))
{
echo json_encode(array('status'=>'error','msg'=>'Shipping package type must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingPackage>'.$_REQUEST['shipping_package'].'</ShippingPackage>';
if(!isset($_REQUEST['major_weight']) || empty($_REQUEST['major_weight']) || $_REQUEST['major_weight'] == '0')
{
echo json_encode(array('status'=>'error','msg'=>'Maximum weight must be given'));
$j=0;
}
else $xmlrequest .= '<WeightMajor unit="lbs">'.$_REQUEST['major_weight'].'</WeightMajor>';
if(isset($_REQUEST['minor_weight']) && !empty($_REQUEST['minor_weight']))
{
$xmlrequest .= '<WeightMinor unit="oz">'.$_REQUEST['minor_weight'].'</WeightMinor>';
}
else
{
$xmlrequest .= '<WeightMinor unit="oz">0</WeightMinor>';
}
if(isset($_REQUEST['package_length']) && !empty($_REQUEST['package_length']))
{
$xmlrequest .= '<PackageLength>'.$_REQUEST['package_length'].'</PackageLength>';
}
if(isset($_REQUEST['package_width']) && !empty($_REQUEST['package_width']))
{
$xmlrequest .= '<PackageWidth>'.$_REQUEST['package_width'].'</PackageWidth>';
}
if(isset($_REQUEST['package_height']) && !empty($_REQUEST['package_height']))
{
$xmlrequest .= '<PackageDepth>'.$_REQUEST['package_height'].'</PackageDepth>';
}
if(isset($_REQUEST['check_irregular']) && !empty($_REQUEST['check_irregular']))
{
$xmlrequest .= '<ShippingIrregular>true</ShippingIrregular>';
}
$xmlrequest .= '</CalculatedShippingRate>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>';
if(!isset($_REQUEST['domestic_service_cost']) || empty($_REQUEST['domestic_service_cost']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic service cost must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingServiceCost>'.$_REQUEST['domestic_service_cost'].'</ShippingServiceCost>
<ShippingServiceAdditionalCost>0.00</ShippingServiceAdditionalCost>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>
</ShippingServiceOptions>
<InternationalShippingServiceOption>';
if(!isset($_REQUEST['international_shipping_service_option']) || empty($_REQUEST['international_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'International shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['international_shipping_service_option'].'</ShippingService>
<ShippingServicePriority>1</ShippingServicePriority>';
if(($_REQUEST['ship_location']) == 'Custom')
{
foreach(explode(',',$_REQUEST['location']) as $location)
{
$xmlrequest .= '<ShipToLocation>'.$location.'</ShipToLocation>';
}
}
else
{
$xmlrequest .= '<ShipToLocation>'.$_REQUEST['ship_location'].'</ShipToLocation>';
}
$xmlrequest .= '</InternationalShippingServiceOption>';
}
else if($_REQUEST['domestic_shipping'] == 'Free' && $_REQUEST['international_shipping'] == 'Calculated')
{
$xmlrequest .= '<ShippingType>FlatDomesticCalculatedInternational</ShippingType>
<CalculatedShippingRate>
<OriginatingPostalCode>'.$_REQUEST['postal_code'].'</OriginatingPostalCode>';
if(isset($_REQUEST['international_handling_cost']) && !empty($_REQUEST['international_handling_cost']))
{
//$_REQUEST['international_handling_cost'] = '0.00';
$xmlrequest .= '<InternationalPackagingHandlingCosts currencyID="USD">'.$_REQUEST['international_handling_cost'].'</InternationalPackagingHandlingCosts>';
}
else
{
$xmlrequest .= '<InternationalPackagingHandlingCosts currencyID="USD">0.00</InternationalPackagingHandlingCosts>';
}
if(!isset($_REQUEST['shipping_package']) || empty($_REQUEST['shipping_package']))
{
echo json_encode(array('status'=>'error','msg'=>'Shipping package type must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingPackage>'.$_REQUEST['shipping_package'].'</ShippingPackage>';
if(!isset($_REQUEST['major_weight']) || empty($_REQUEST['major_weight']) || $_REQUEST['major_weight'] == '0')
{
echo json_encode(array('status'=>'error','msg'=>'Maximum weight must be given'));
$j=0;
}
$xmlrequest .= '<WeightMajor unit="lbs">'.$_REQUEST['major_weight'].'</WeightMajor>';
if(isset($_REQUEST['minor_weight']) && !empty($_REQUEST['minor_weight']))
{
$xmlrequest .= '<WeightMinor unit="oz">'.$_REQUEST['minor_weight'].'</WeightMinor>';
}
else
{
$xmlrequest .= '<WeightMinor unit="oz">0</WeightMinor>';
}
if(isset($_REQUEST['package_length']) && !empty($_REQUEST['package_length']))
{
$xmlrequest .= '<PackageLength>'.$_REQUEST['package_length'].'</PackageLength>';
}
if(isset($_REQUEST['package_width']) && !empty($_REQUEST['package_width']))
{
$xmlrequest .= '<PackageWidth>'.$_REQUEST['package_width'].'</PackageWidth>';
}
if(isset($_REQUEST['package_height']) && !empty($_REQUEST['package_height']))
{
$xmlrequest .= '<PackageDepth>'.$_REQUEST['package_height'].'</PackageDepth>';
}
if(isset($_REQUEST['check_irregular']) && !empty($_REQUEST['check_irregular']))
{
$xmlrequest .= '<ShippingIrregular>true</ShippingIrregular>';
}
$xmlrequest .= '</CalculatedShippingRate>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>
<ShippingServiceCost>0.00</ShippingServiceCost>
<ShippingServiceAdditionalCost>0.00</ShippingServiceAdditionalCost>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>
</ShippingServiceOptions>
<InternationalShippingServiceOption>';
if(!isset($_REQUEST['international_shipping_service_option']) || empty($_REQUEST['international_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'International shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['international_shipping_service_option'].'</ShippingService>
<ShippingServicePriority>1</ShippingServicePriority>';
if(($_REQUEST['ship_location']) == 'Custom')
{
foreach(explode(',',$_REQUEST['location']) as $location)
{
$xmlrequest .= '<ShipToLocation>'.$location.'</ShipToLocation>';
}
}
else
{
$xmlrequest .= '<ShipToLocation>'.$_REQUEST['ship_location'].'</ShipToLocation>';
}
$xmlrequest .= '</InternationalShippingServiceOption>';
}
else if($_REQUEST['domestic_shipping'] == 'Calculated' && $_REQUEST['international_shipping'] == 'Flat')
{
$xmlrequest .= '<ShippingType>CalculatedDomesticFlatInternational</ShippingType>
<CalculatedShippingRate>
<OriginatingPostalCode>'.$_REQUEST['postal_code'].'</OriginatingPostalCode>';
if(isset($_REQUEST['domestic_handling_cost']) && !empty($_REQUEST['domestic_handling_cost']))
{
//$_REQUEST['international_handling_cost'] = '0.00';
$xmlrequest .= '<PackagingHandlingCosts currencyID="USD">'.$_REQUEST['domestic_handling_cost'].'</PackagingHandlingCosts>';
}
else
{
$xmlrequest .= '<PackagingHandlingCosts currencyID="USD">0.00</PackagingHandlingCosts>';
}
if(!isset($_REQUEST['shipping_package']) || empty($_REQUEST['shipping_package']))
{
echo json_encode(array('status'=>'error','msg'=>'Shipping package type must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingPackage>'.$_REQUEST['shipping_package'].'</ShippingPackage>';
if(!isset($_REQUEST['major_weight']) || empty($_REQUEST['major_weight']) || $_REQUEST['major_weight'] == '0')
{
echo json_encode(array('status'=>'error','msg'=>'Maximum weight must be given'));
$j=0;
}
else $xmlrequest .= '<WeightMajor unit="lbs">'.$_REQUEST['major_weight'].'</WeightMajor>';
if(isset($_REQUEST['minor_weight']) && !empty($_REQUEST['minor_weight']))
{
$xmlrequest .= '<WeightMinor unit="oz">'.$_REQUEST['minor_weight'].'</WeightMinor>';
}
else
{
$xmlrequest .= '<WeightMinor unit="oz">0</WeightMinor>';
}
if(isset($_REQUEST['package_length']) && !empty($_REQUEST['package_length']))
{
$xmlrequest .= '<PackageLength>'.$_REQUEST['package_length'].'</PackageLength>';
}
if(isset($_REQUEST['package_width']) && !empty($_REQUEST['package_width']))
{
$xmlrequest .= '<PackageWidth>'.$_REQUEST['package_width'].'</PackageWidth>';
}
if(isset($_REQUEST['package_height']) && !empty($_REQUEST['package_height']))
{
$xmlrequest .= '<PackageDepth>'.$_REQUEST['package_height'].'</PackageDepth>';
}
if(isset($_REQUEST['check_irregular']) && !empty($_REQUEST['check_irregular']))
{
$xmlrequest .= '<ShippingIrregular>true</ShippingIrregular>';
}
$xmlrequest .= '</CalculatedShippingRate>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>
</ShippingServiceOptions>
<InternationalShippingServiceOption>';
if(!isset($_REQUEST['international_shipping_service_option']) || empty($_REQUEST['international_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'International shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['international_shipping_service_option'].'</ShippingService>
<ShippingServicePriority>1</ShippingServicePriority>';
if($_REQUEST['ship_location'] == 'Custom')
{
foreach(explode(',',$_REQUEST['location']) as $location)
{
$xmlrequest .= '<ShipToLocation>'.$location.'</ShipToLocation>';
}
}
else
{
$xmlrequest .= '<ShipToLocation>'.$_REQUEST['ship_location'].'</ShipToLocation>';
}
if(isset($_REQUEST['international_service_cost']) && !empty($_REQUEST['international_service_cost']))
{
$xmlrequest .= '<ShippingServiceCost>'.$_REQUEST['international_service_cost'].'</ShippingServiceCost>';
}
else
{
$xmlrequest .= '<ShippingServiceCost>0.00</ShippingServiceCost>';
}
$xmlrequest .= '</InternationalShippingServiceOption>';
}
else if($_REQUEST['domestic_shipping'] == 'Freight')
{
$xmlrequest .= '<ShippingType>Freight</ShippingType>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>';
if(!isset($_REQUEST['domestic_shipping_service_option']) || empty($_REQUEST['domestic_shipping_service_option']))
{
echo json_encode(array('status'=>'error','msg'=>'Domestic shipping service option must be given'));
$j=0;
}
else $xmlrequest .= '<ShippingService>'.$_REQUEST['domestic_shipping_service_option'].'</ShippingService>
</ShippingServiceOptions>';
}
$xmlrequest .= '</ShippingDetails>
<Site>US</Site>
</Item>
</AddItemRequest>
';
$headers = array(
'X-EBAY-API-DETAIL-LEVEL: 0',
'X-EBAY-API-COMPATIBILITY-LEVEL: 971',
'X-EBAY-API-APP-NAME' => 'YOUR_APP_ID',
'X-EBAY-API-DEV-NAME' => YOUR_DEV_ID',
'X-EBAY-API-CERT-NAME' => 'YOUR_CERT_ID',
'X-EBAY-API-SITEID : 0',
'X-EBAY-API-CALL-NAME: AddItem'
);
if($j!=0)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // set headers using $headers array
curl_setopt($ch, CURLOPT_POST, true); // POST request type
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlrequest); // set the body of the POST
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// return values as a string, not to std out
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$content=curl_exec($ch);
curl_close($ch);
echo json_encode(simplexml_load_string($content));
}
}
?>
Comments
Post a Comment