Skip to content

Instantly share code, notes, and snippets.

@davidtsadler
Last active June 14, 2022 00:13
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save davidtsadler/4581805 to your computer and use it in GitHub Desktop.
Save davidtsadler/4581805 to your computer and use it in GitHub Desktop.
Example showing how to list an item to the eBay Sandbox using the eBay Accelerator Toolkit New Schema (EbatNS) for PHP.
<?php
/*
* Author: David T. Sadler (http://davidtsadler.com)
* Date: 2013-03-29
* License: I release this example into the public domain. Use at your own risk.
*
* Example showing how to list an item to the eBay Sandbox using the eBay Accelerator Toolkit New Schema (EbatNS) for PHP.
*
* This example uses version 815 released on the 2013-03-22.
* http://www.intradesys.de/en/system/files/its_downloads/EbatNs_1_0_815_P5_0.zip
*
* Note that you may have to register before you can download the EbatNS.
* http://www.intradesys.de/en/user/register
*
* This example listed the item found at http://cgi.sandbox.ebay.com/110114972201. Note that this item may no longer exist.
* Version 815 of the eBay API was used and the item was listed to site 0 (US) of the sandbox.
*/
require_once 'EbatNs/EbatNs_Session.php';
require_once 'EbatNs/EbatNs_ServiceProxy.php';
require_once 'EbatNs/EbatNs_Logger.php';
require_once 'EbatNs/AddItemRequestType.php';
require_once 'EbatNs/ItemType.php';
$item = new ItemType();
/*
* The item is to be listed on the US site.
*/
$item->setSite('US');
/*
* The item will be a single quantity auction lasting for 10 days.
* It will have a start price of $8.99 with a reserve of $9.99.
* Buyers can use the 'Buy It Now' button to purchase the item for $10.99.
*/
$item->setListingType('Chinese');
$item->setListingDuration('Days_10');
$item->setQuantity(1);
$item->setStartPrice(new_amount_type(8.99,'USD'));
$item->setReservePrice(new_amount_type(9.99,'USD'));
$item->setBuyItNowPrice(new_amount_type(10.99,'USD'));
/*
* Provide a title and description and other information such as the
* item's location.
*/
$item->setTitle('EbatNS Example Item 2013-03-29');
$item->setDescription('<h1>EbatNS Example Item</h1><p>Listed using the EbatNS</p>');
$item->setSKU('ABCD-0001');
$item->setCurrency('USD');
$item->setCountry('US');
$item->setLocation('Beverly Hills');
$item->setPostalCode('90210');
/*
* Display a picture with the item.
*/
$picture = new PictureDetailsType();
$picture->setGalleryType('Gallery');
$picture->setPictureURL('http://dl.dropbox.com/u/25261546/t%20shirts/white.jpg');
$item->setPictureDetails($picture);
/*
* Item will be listed in the Books > Audiobooks category.
*/
$primaryCategory = new CategoryType();
$primaryCategory->setCategoryID(29792);
$item->setPrimaryCategory($primaryCategory);
/*
* The item's condition is 'Brand New'.
*/
$item->setConditionID(1000);
/*
* Setup the item specifics.
* Because we are listing in the Books > Audiobooks category we will use the following specifics.
* Subject: Fiction & Literature
* Topic: Fantasy
* Format: MP3 CD
* Length: Unabridged
* Language: English
* Country of Manufacture: United States
*/
$itemSpecifics = new NameValueListArrayType();
$specific = new NameValueListType();
$specific->setName('Subject');
$specific->setValue('Fiction & Literature');
$itemSpecifics->setNameValueList($specific, 0);
$specific = new NameValueListType();
$specific->setName('Topic');
$specific->setValue('Fantasy');
$itemSpecifics->setNameValueList($specific, 1);
$specific = new NameValueListType();
$specific->setName('Format');
$specific->setValue('MP3 CD');
$itemSpecifics->setNameValueList($specific, 2);
$specific = new NameValueListType();
$specific->setName('Length');
$specific->setValue('Unabridged');
$itemSpecifics->setNameValueList($specific, 3);
$specific = new NameValueListType();
$specific->setName('Language');
$specific->setValue('English');
$itemSpecifics->setNameValueList($specific, 4);
$specific = new NameValueListType();
$specific->setName('Country of Manufacture');
$specific->setValue('United States');
$itemSpecifics->setNameValueList($specific, 5);
$item->setItemSpecifics($itemSpecifics);
/*
* Buyers can use one of two payment methods when purchasing the item.
* Visa or Master Card
* PayPal
* The item will be dispatched within 3 business days once payment has cleared.
*/
$item->setPaymentMethods('VisaMC', 0);
$item->setPaymentMethods('PayPal', 1);
$item->setPayPalEmailAddress('example@example.com');
$item->setDispatchTimeMax(3);
/*
* Setting up the shipping details.
* We will use Flat shipping for both domestic and international.
*/
$shippingDetails = new ShippingDetailsType();
$shippingDetails->setShippingType('Flat');
$shippingDetails->setPaymentInstructions('Praesent sagittis ornare.');
/*
* Create our first domestic shipping option.
* Offer the Economy Shipping (1-10 business days) service with free shipping.
*/
$shippingService = new ShippingServiceOptionsType();
$shippingService->setShippingServicePriority(1);
$shippingService->setShippingService('Other');
$shippingService->setShippingServiceCost(new_amount_type(0.00,'USD'));
$shippingService->setShippingServiceAdditionalCost(new_amount_type(0.00,'USD'));
$shippingService->setFreeShipping(true);
$shippingDetails->setShippingServiceOptions($shippingService, 0);
/*
* Create our second domestic shipping option.
* Offer the USPS Parcel Post (2-8 business days) service for $2.00.
*/
$shippingService = new ShippingServiceOptionsType();
$shippingService->setShippingServicePriority(2);
$shippingService->setShippingService('USPSParcel');
$shippingService->setShippingServiceCost(new_amount_type(2.00,'USD'));
$shippingDetails->setShippingServiceOptions($shippingService, 1);
/*
* Create our first international shipping option.
* Offer the USPS First Class Mail International service for $3.00.
* The item can be shipped Worldwide with this service.
*/
$shippingService = new InternationalShippingServiceOptionsType();
$shippingService->setShippingServicePriority(1);
$shippingService->setShippingService('USPSFirstClassMailInternational');
$shippingService->setShippingServiceCost(new_amount_type(3.00,'USD'));
$shippingService->setShipToLocation('Worldwide');
$shippingDetails->setInternationalShippingServiceOption($shippingService, 0);
/*
* Create our second international shipping option.
* Offer the USPS Priority Mail International (6-10 business days) service for $4.00.
* The item will only be shipped to the following locations with this service.
* N. and S. America
* Canada
* Australia
* Europe
* Japan
*/
$shippingService = new InternationalShippingServiceOptionsType();
$shippingService->setShippingServicePriority(2);
$shippingService->setShippingService('USPSPriorityMailInternational');
$shippingService->setShippingServiceCost(new_amount_type(4.00,'USD'));
$shippingService->setShipToLocation('Americas');
$shippingService->setShipToLocation('CA');
$shippingService->setShipToLocation('AU');
$shippingService->setShipToLocation('Europe');
$shippingService->setShipToLocation('JP');
$shippingDetails->setInternationalShippingServiceOption($shippingService, 1);
/*
* Regardless of which shipping service the buyer chooses the item will not
* be shipped to the following locations.
* Alaska/Hawaii
* US Protectorates
* APO/FPO
* Algeria
* Azerbaijan Republic
*/
$shippingDetails->setExcludeShipToLocation('Alaska/Hawaii');
$shippingDetails->setExcludeShipToLocation('US Protectorates');
$shippingDetails->setExcludeShipToLocation('APO/FPO');
$shippingDetails->setExcludeShipToLocation('DZ');
$shippingDetails->setExcludeShipToLocation('AZ');
/*
* Sales Tax details.
* %5 Alabama state.
* Will also be applied to any shipping and handling costs.
*/
$salesTax = new SalesTaxType();
$salesTax->setSalesTaxState('AL');
$salesTax->setSalesTaxPercent('5.000');
$salesTax->setShippingIncludedInTax(true);
$shippingDetails->setSalesTax($salesTax);
$item->setShippingDetails($shippingDetails);
/*
* ShipToRegistrationCountry must be true to have the ExcludeShipToLocation settings applied to the item.
*/
$buyerRequirments = new BuyerRequirementDetailsType();
$buyerRequirments->setShipToRegistrationCountry(true);
$item->setBuyerRequirementDetails($buyerRequirements);
/*
* The return policy is,
* A refund will be given as money back.
* The buyer will have 14 days in which to contact the seller after receiving the item.
* The buyer will pay the return shipping cost.
*/
$returnPolicy = new ReturnPolicyType();
$returnPolicy->setReturnsAcceptedOption('ReturnsAccepted');
$returnPolicy->setRefundOption('MoneyBack');
$returnPolicy->setReturnsWithinOption('Days_14');
$returnPolicy->setShippingCostPaidByOption('Buyer');
$returnPolicy->setDescription('Nulla odio diam, varius luctus augue.');
$item->setReturnPolicy($returnPolicy);
/*
* Now list the item on eBay.
*/
$session = new EbatNs_Session('config/ebay.config.php');
$proxy = new EbatNs_ServiceProxy($session);
$proxy->attachLogger(new EbatNs_Logger());
$req = new AddItemRequestType();
$req->Item = $item;
$res = $proxy->AddItem($req);
print_r($res);
/*
* Helper function to build and return a new AmountType object.
*/
function new_amount_type($value, $currency)
{
$amountType = new AmountType();
$amountType->setTypeValue($value);
$amountType->setTypeAttribute('currencyID', $currency);
return $amountType;
}
?>
Copy link

ghost commented May 23, 2016

Have you tried to sell an item on the French site with html in description and using French accents so far I have found this is not possible.

@bluequantum
Copy link

Hi do you have the full version of this so i could try out ?

@bluequantum
Copy link

is it still working in 2018?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment