PHP code example of eiriksm / finn-transfer-sdk

1. Go to this page and download the library: Download eiriksm/finn-transfer-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eiriksm / finn-transfer-sdk example snippets




use eiriksm\FinnTransfer\AdTypes\TractorXml;
use eiriksm\FinnTransfer\FinnTransfer;
use GuzzleHttp\Client;

$partner_id = 'mypartnerid';
$provider = 'myprovider';
// Start by constructing an ad type. For example a tractor ad.
$ad = new TractorXml($partner_id, $provider);
// Then set some properties. We probably want to set an ad title, and a price,
// for example.
$ad->setHeading('Used tractor for sale');
$ad->setMotorPrice(10000);
// For this example, we will also set postcode, since that is NT = 'KOMPLETT_FRONTLASTER';
// Now, there is probably a whole lot more you want to set on the ad, but those
// were some examples. In the end, use this method to get the xml. This will
// also validate the XML according to the spec.
$xml = $ad->getXml();

// Next step would be to send this XML to finn.no.
$transfer = new FinnTransfer();
$transfer->setAd($ad);
// By default we are working against the dev environment of finn.no, but use
// this method to do it live(tm).
$transfer->getClient()->setLiveMode();
// Then get a HTTP client somehow.
$http_client = new Client();
// Now transfer the ad.
$result_xml = $transfer->transfer($http_client);