my-maxi-skirt /wp-content/plugins/wp-lister-for-ebay/classes/EbayController.php

Language PHP Lines 824
MD5 Hash 31a19a2bdc64b669aed56f3ea04c89bf Estimated Cost $13,432 (why?)
Repository https://bitbucket.org/sanders_nick/my-maxi-skirt.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
<?php

class EbayController {
    
    var $logger;

    var $apiurl;
    var $signin;
    var $devId;
    var $appId;
    var $certId;
    var $RuName;
    var $siteId;
    var $sandbox;
    var $compLevel;

    #public $data = array();    
    public $session;            // ebay session
    public $sp;                 // ebay service proxy    
    public $message = false;    
    public $error = false;
    public $lastResults = array();

    public function __construct() {
        global $wpl_logger;
        $this->logger = &$wpl_logger;
        // $this->config();
    }

    public function config() {
        // add EbatNs folder to include path - required for SDK
        // $incPath = WPLISTER_PATH . '/includes/EbatNs';
        // set_include_path( get_include_path() . ':' . $incPath );        
    }

    static function loadEbayClasses() {
        // we want to be patient when talking to ebay
        set_time_limit(600);

        // add EbatNs folder to include path - required for SDK
        $incPath = WPLISTER_PATH . '/includes/EbatNs';
        set_include_path( get_include_path() . ':' . $incPath );

        // use autoloader to load EbatNs classes
        spl_autoload_register('WPL_Autoloader::autoloadEbayClasses');

    }


    function GetEbaySignInUrl($RuName = null, $Params = null)
    {
        $s = $this->session;
        if ($s->getAppMode() == 0) 
            $url = 'https://signin.' . $this->_getDomainnameBySiteId( $s->getSiteId() ) . '/ws/eBayISAPI.dll?SignIn';
        else 
            $url = 'https://signin.sandbox.' . $this->_getDomainnameBySiteId( $s->getSiteId() ) . '/ws/eBayISAPI.dll?SignIn';
        if ($RuName != null)
            $url .= '&runame=' . $RuName;
        if ($Params != null)
            $url .= '&ruparams=' . $Params;
        return $url;
    }
    
    
    // get SessionID and build AuthURL
    public function getAuthUrl(){ 

        // fetch SessionID - valid for about 5 minutes
        $SessionID = $this->GetSessionID( $this->RuName );

        // save SessionID to DB
        update_option('wplister_ebay_sessionid', $SessionID);

        // build auth url
        $query = array( 'RuName' => $this->RuName, 'SessID' => $SessionID );
        $url = $this->GetEbaySignInUrl() . '&'. http_build_query( $query );
        $this->logger->info( 'AuthUrl: ' . $url );

        return $url;
    }
 
    // do FetchToken and save to DB
    public function doFetchToken(){ 
        
        $SessionID = get_option('wplister_ebay_sessionid');        
        $token = $this->FetchToken( $SessionID );

        if ($token) {
            update_option('wplister_ebay_token', $token);
            update_option('wplister_setup_next_step', '2');
        }
        
    }
 
    // do getTokenExpirationTime and save to DB
    public function getTokenExpirationTime( $site_id, $sandbox_enabled ){ 

        $token = get_option('wplister_ebay_token');
        $expdate = $this->fetchTokenExpirationTime( $token );

        update_option('wplister_ebay_token_expirationtime', $expdate);
        return $expdate;
    }
 
    // establish connection to eBay API
    public function initEbay( $site_id, $sandbox_enabled, $token = false){ 

        // init autoloader fro EbatNs classes
        $this->loadEbayClasses();

        $this->logger->info('initEbay()');
        require_once 'EbatNs_ServiceProxy.php';
        require_once 'EbatNs_Logger.php';

        // hide inevitable cURL warnings from SDK 
        // *** DISABLE FOR DEBUGGING ***
        $this->error_reporting_level = error_reporting();
        error_reporting( E_ERROR );

        $this->siteId = $site_id;
        $this->sandbox = $sandbox_enabled;
        #$this->compLevel = 765;

        if ( $sandbox_enabled ) {
            
            // sandbox keys
            $this->devId  = 'db0c17b6-c357-4a38-aa60-7e80158f57dc';
            $this->appId  = 'LWSWerbu-c159-4552-8411-1406ca5a2bba';
            $this->certId = '33272b6e-ef02-4d22-a487-a1a3f02b9c66';
            $this->RuName = 'LWS_Werbung_Gmb-LWSWerbu-c159-4-tchfyrowj';

            $this->apiurl = 'https://api.sandbox.ebay.com/ws/api.dll';
            $this->signin = 'https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?SignIn&';

        } else {

            // production keys
            $this->devId  = 'db0c17b6-c357-4a38-aa60-7e80158f57dc';
            $this->appId  = 'LWSWerbu-6147-43ed-9835-853f7b5dc6cb';
            $this->certId = '61212d27-f74b-416b-8d48-3160f245443f';
            $this->RuName = 'LWS_Werbung_Gmb-LWSWerbu-6147-4-ywstl';

            $this->apiurl = 'https://api.ebay.com/ws/api.dll';
            $this->signin = 'https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&';
        }

        // init session
        $session = new EbatNs_Session();

        // depends on the site working on (needs ID-Value !)
        $session->setSiteId($site_id);

        // environment (0=production, 1=sandbox)
        if ( $sandbox_enabled == '1' ) {
            $this->logger->info('initEbay(): SANDBOX ENABLED');
            $session->setAppMode(1);    // this must be set *before* setting the keys (appId, devId, ...)
        } else {
            $session->setAppMode(0);    
        }

        $session->setAppId($this->appId);
        $session->setDevId($this->devId);
        $session->setCertId($this->certId);

        if ( $token ) { 
            
            // use a token as credential
            $session->setTokenMode(true);

            // do NOT use a token file !
            $session->setTokenUsePickupFile(false);

            // token of the user
            $session->setRequestToken($token);

        } else {
            $session->setTokenMode(false);
        }

        // creating a proxy for UTF8
        $sp = new EbatNs_ServiceProxy($session, 'EbatNs_DataConverterUtf8');

        // // logger doc: http://www.intradesys.com/de/forum/1528
        // if ( get_option('wplister_log_level') > 5 ) {
        //     #$sp->attachLogger( new EbatNs_Logger(false, 'stdout', true, false) );
        //     $sp->attachLogger( new EbatNs_Logger(false, $this->logger->file ) );
        // }

        // attach custom DB Logger for Tools page
        // if ( get_option('wplister_log_to_db') == '1' ) {
        if ( 'wplister-tools' == $_REQUEST['page'] ) {
            $sp->attachLogger( new WPL_EbatNs_Logger( false, 'db' ) );
        }
        
        // save service proxy - and session
        $this->sp = $sp;
        $this->session = $session;

    }

    // close connection to eBay API
    public function closeEbay(){ 
        // restore error reporting level 
        error_reporting( $this->error_reporting_level );
    }
 

    // get SessionID for Auth&Auth
    public function GetSessionID( $RuName ){ 
        require_once 'GetSessionIDRequestType.php';

        // prepare request
        $req = new GetSessionIDRequestType();
        $req->setRuName($RuName);
        #$req->setErrorLanguage('en_US');
        
        // send request
        $res = $this->sp->GetSessionID($req);

        // handle errors like blocked ips
        if ( $res->Ack != 'Success' ) {
            echo "<h1>Problem connecting to eBay</h1>";
            echo "<p>WP-Lister can't seem to establish a connection to eBay's servers. This could be caused by a firewall blocking cURL from accessing unkown ip addresses.</p>";
            echo "<p>Only your hosting company can sort out the problems causing cURL not to connect properly. Your hosting company's server administrator should be able to resolve the permission problems preventing cURL from working. They've probably got overly limiting restrictions configured on the server, preventing it from being able to do the communication required for listing items on eBay.</p>";
            echo "<p>debug output:</p>";
            echo "<pre>"; print_r($res); echo "</pre>";
            die();
        }

        // TODO: handle error        
        return ( $res->SessionID );
        
    }
    public function FetchToken( $SessionID ){ 
        require_once 'FetchTokenRequestType.php';

        // prepare request
        $req = new FetchTokenRequestType();
        $req->setSessionID($SessionID);
        #$req->setErrorLanguage(0);
        
        // send request
        $res = $this->sp->FetchToken($req);

        // TODO: handle error        
        return ( $res->eBayAuthToken );
        
    }

    public function fetchTokenExpirationTime( $SessionID ){ 
        require_once 'GetTokenStatusRequestType.php';

        // prepare request
        $req = new GetTokenStatusRequestType();
        $req->setSessionID($SessionID);
        #$req->setErrorLanguage(0);
        
        // send request
        $res = $this->sp->GetTokenStatus($req);

        // TODO: handle error        
        return ( $res->ExpirationTime );
        
    }

    // ajax: initialize categories update
    // returns: tasklist
    public function initCategoriesUpdate(){ 
        $site_id = get_option('wplister_ebay_site_id');
        $cm = new EbayCategoriesModel();
        return $cm->initCategoriesUpdate( $this->session, $site_id );
    }
    // ajax: load single branch of ebay categories
    // returns: result
    public function loadEbayCategoriesBranch( $cat_id ){ 
        $site_id = get_option('wplister_ebay_site_id');
        $cm = new EbayCategoriesModel();
        return $cm->loadEbayCategoriesBranch( $cat_id, $this->session, $site_id );
    }

    // load full categories list and insert to db (old)
    public function loadCategories(){ 
        $site_id = get_option('wplister_ebay_site_id');
        $cm = new EbayCategoriesModel();
        $cm->downloadCategories( $this->session, $site_id );
    }

    // load Store categories list and insert to db
    public function loadStoreCategories(){ 
        $cm = new EbayCategoriesModel();
        $cm->downloadStoreCategories( $this->session );
    }

    // load shipping services and insert to db
    public function loadShippingServices(){ 
        $sm = new EbayShippingModel();
        $sm->downloadCountryDetails( $this->session );
        $sm->downloadShippingLocations( $this->session );
        $sm->downloadShippingDetails( $this->session );
        $sm->downloadDispatchTimes( $this->session );      
    }

    // load shipping services and insert to db
    public function loadPaymentOptions(){ 
        $sm = new EbayPaymentModel();
        $sm->downloadPaymentDetails( $this->session );      
    }

    // load available dispatch times
    public function loadDispatchTimes(){ 
        $sm = new EbayShippingModel();
        return $sm->downloadDispatchTimes( $this->session );      
    }


    // update transactions
    public function loadTransactions( $days = null ){ 
        $sm = new TransactionsModel();
        $sm->updateTransactions( $this->session, $days );
    }

    // update listings
    public function updateListings(){ 
        $sm = new ListingsModel();
        $sm->updateEndedListings( $this->session );
    }

    // get category conditions
    public function getCategoryConditions( $category_id ){ 
        $sm = new EbayCategoriesModel();
        return $sm->getCategoryConditions( $this->session, $category_id );
    }

    // get category specifics
    public function getCategorySpecifics( $category_id ){ 
        $sm = new EbayCategoriesModel();
        return $sm->getCategorySpecifics( $this->session, $category_id );
    }



    // process $this->lastResults and look for errors and/or warnings
    public function processLastResults(){ 
        $this->logger->debug('processLastResults()'.print_r( $this->lastResults, 1 ));

        $this->isSuccess = true;
        $this->hasErrors = false;
        $this->hasWarnings = false;

        foreach ($this->lastResults as $result) {
            if ( ! $result->success ) $this->isSuccess = false;
        }

    }



    // call verifyAddItem on selected items
    public function verifyItems( $id ){ 
        $this->logger->info('EC::verifyItems('.$id.')');
        
        $sm = new ListingsModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $this->lastResults[] = $sm->verifyAddItem( $single_id, $this->session );   
            }
            $this->processLastResults();
        } else {
            $this->lastResults[] = $sm->verifyAddItem( $id, $this->session );          
            $this->processLastResults();
            return $this->lastResults;
        }
        
    }

    // call ReviseItem on selected items
    public function reviseItems( $id ){ 
        
        $sm = new ListingsModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $this->lastResults[] = $sm->reviseItem( $single_id, $this->session );  
            }
            $this->processLastResults();
        } else {
            $this->lastResults[] = $sm->reviseItem( $id, $this->session );         
            $this->processLastResults();
            return $this->lastResults;
        }
        
    }

    // call AddItem on selected items
    public function sendItemsToEbay( $id ){ 
        
        $sm = new ListingsModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $this->lastResults[] = $sm->addItem( $single_id, $this->session ); 
            }
            $this->processLastResults();
        } else {
            $this->lastResults[] = $sm->addItem( $id, $this->session );            
            $this->processLastResults();
            return $this->lastResults;
        }
        
    }

    // call EddItem on selected items
    public function endItemsOnEbay( $id ){ 
        
        $sm = new ListingsModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $this->lastResults[] = $sm->endItem( $single_id, $this->session ); 
            }
            $this->processLastResults();
        } else {
            $this->lastResults[] = $sm->endItem( $id, $this->session );            
            $this->processLastResults();
            return $this->lastResults;
        }
        
    }

    // call relistItem on selected items
    public function relistItems( $id ){ 
        $this->logger->info('EC::relistItems('.$id.')');
        
        $sm = new ListingsModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $this->lastResults[] = $sm->relistItem( $single_id, $this->session );   
            }
            $this->processLastResults();
        } else {
            $this->lastResults[] = $sm->relistItem( $id, $this->session );          
            $this->processLastResults();
            return $this->lastResults;
        }
        
    }


    // call GetItemDetails on selected items
    public function updateItemsFromEbay( $id ){ 
        
        $sm = new ListingsModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $this->lastResults[] = $sm->updateItemDetails( $single_id, $this->session );   
            }
            $this->processLastResults();
        } else {
            $this->lastResults[] = $sm->updateItemDetails( $id, $this->session );          
            $this->processLastResults();
            return $this->lastResults;
        }
        
    }


    // delete selected items
    public function deleteListings( $id ){ 
        
        $sm = new ListingsModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $sm->deleteItem( $single_id );  
            }
        } else {
            $sm->deleteItem( $id );         
        }
        
    }

    // delete selected items
    public function deleteProfiles( $id ){ 
        
        $sm = new ProfilesModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $sm->deleteItem( $single_id );  
            }
        } else {
            $sm->deleteItem( $id );         
        }
        
    }

    // delete selected items
    public function deleteTransactions( $id ){ 
        
        $sm = new TransactionsModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $sm->deleteItem( $single_id );  
            }
        } else {
            $sm->deleteItem( $id );         
        }
        
    }


    // call verifyAddItem on all prepared items
    public function verifyAllPreparedItems(){   

        $sm = new ListingsModel();
        $items = $sm->getAllPrepared();
        
        foreach( $items as $item ) {
            $sm->verifyAddItem( $item['id'], $this->session );  
        }
        
    }

    // call AddItem on all verified items
    public function publishAllVerifiedItems(){  

        $sm = new ListingsModel();
        $items = $sm->getAllVerified();
        
        foreach( $items as $item ) {
            $sm->addItem( $item['id'], $this->session );    
        }
        
    }

    // call reviseItem on all changed items
    public function reviseAllChangedItems(){   

        $sm = new ListingsModel();
        $items = $sm->getAllChanged();
        
        foreach( $items as $item ) {
            $sm->reviseItem( $item['id'], $this->session );  
        }
        
    }

    // call updateItemDetails on all published and changed items
    public function updateAllPublishedItems(){   

        $sm = new ListingsModel();
        $items = $sm->getAllPublished();
        
        foreach( $items as $item ) {
            $sm->updateItemDetails( $item['id'], $this->session );  
        }
        
    }


    // call updateSingleTransaction on selected transactions
    public function updateTransactionsFromEbay( $id ){ 
        
        $sm = new TransactionsModel();

        if ( is_array( $id )) {
            foreach( $id as $single_id ) {
                $sm->updateSingleTransaction( $this->session, $single_id );   
            }
        } else {
            $sm->updateSingleTransaction( $this->session, $id );          
        }
        
    }


    // GetNotificationPreferences
    public function GetNotificationPreferences(){ 
        require_once 'GetNotificationPreferencesRequestType.php';

        // prepare request
        $req = new GetNotificationPreferencesRequestType();
        $req->setPreferenceLevel('Application');
        #$req->setPreferenceLevel('User');
        
        // send request
        $res = $this->sp->GetNotificationPreferences($req);

        // second request for user data
        $req->setPreferenceLevel('User');
        $res2 = $this->sp->GetNotificationPreferences($req);

        // handle result
        return ( print_r( $res, 1 ) . print_r( $res2, 1 ) );
        
    }

    // SetNotificationPreferences
    public function SetNotificationPreferences(){ 
        require_once 'SetNotificationPreferencesRequestType.php';

        $app_url = admin_url().'admin-ajax.php?action=handle_ebay_notify';

        // prepare request
        #$req = new SetNotificationPreferencesRequestType();
        #$req->setDeliveryURLName('http://www.example.com/wp-admin/admin-ajax.php?action=handle_ebay_notify');



        # example from http://jolierouge.net/2011/05/spree-commerce-ebay-trading-api-and-the-ebay-accelerator-toolkit-from-intradesys-ebatns/
        $req = new SetNotificationPreferencesRequestType();

        // ApplicationDeliveryPreferences
        $req->ApplicationDeliveryPreferences = new ApplicationDeliveryPreferencesType();
        $req->ApplicationDeliveryPreferences->setApplicationEnable('Enable');
        $req->ApplicationDeliveryPreferences->setApplicationURL($app_url);
        //$req->ApplicationDeliveryPreferences->setAlertEmail("youremail");
        $req->ApplicationDeliveryPreferences->setAlertEnable("Enable");

        // ApplicationDeliveryPreferences.DeliveryURLDetails
        $details = new DeliveryURLDetailType();
        $details->setDeliveryURLName('wplister_notify_handler');
        $details->setDeliveryURL($app_url.'&details=true');
        $details->setStatus('Enable');
        $req->ApplicationDeliveryPreferences->setDeliveryURLDetails($details,null);

        // UserDeliveryPreferenceArray
        $user = new NotificationEnableArrayType();
        $notifs = array();
         // put all of the notices you want here.
        foreach (array('BidReceived',
                       'EndOfListing',
                       'FixedPriceEndOfTransaction',
                       'FixedPriceTransaction',
                       'ItemListed',
                       'ItemSold',
                       'FeedbackReceived') as $event) {
          $n = new NotificationEnableType();
          $n->setEventType($event);
          $n->setEventEnable('Enable');
          $notifs[] = $n;
        }
        $user->setNotificationEnable($notifs,null);
        $req->setUserDeliveryPreferenceArray($user);

        
        // send request
        $res = $this->sp->SetNotificationPreferences($req);

        // handle result
        return ( print_r( $res, 1 ) );
        
    }



    // GetUser
    public function GetUser(){ 

        // prepare request
        $req = new GetUserRequestType();
        
        // send request
        $res = $this->sp->GetUser($req);

        $UserID = $res->User->UserID;
        update_option('wplister_ebay_token_userid', $UserID);

        $user = new stdClass();
        $user->UserID              = $res->User->UserID;
        $user->Email               = $res->User->Email;
        $user->FeedbackScore       = $res->User->FeedbackScore;
        $user->FeedbackRatingStar  = $res->User->FeedbackRatingStar;
        $user->NewUser             = $res->User->NewUser;
        $user->IDVerified          = $res->User->IDVerified;
        $user->eBayGoodStanding    = $res->User->eBayGoodStanding;
        $user->Status              = $res->User->Status;
        $user->Site                = $res->User->Site;
        $user->VATStatus           = $res->User->VATStatus;
        $user->PayPalAccountLevel  = $res->User->PayPalAccountLevel;
        $user->PayPalAccountType   = $res->User->PayPalAccountType;
        $user->PayPalAccountStatus = $res->User->PayPalAccountStatus;

        $user->StoreOwner          = $res->User->SellerInfo->StoreOwner;
        $user->StoreURL            = $res->User->SellerInfo->StoreURL;
        $user->SellerBusinessType  = $res->User->SellerInfo->SellerBusinessType;
        $user->ExpressEligible     = $res->User->SellerInfo->ExpressEligible;
        $user->StoreSite           = $res->User->SellerInfo->StoreSite;

        update_option('wplister_ebay_user', $user);

        return ( $UserID );        
    }

    // GetTokenStatus
    public function GetTokenStatus(){ 
        // require_once 'GetTokenStatusRequestType.php';

        // prepare request
        $req = new GetTokenStatusRequestType();
        
        // send request
        $res = $this->sp->GetTokenStatus($req);

        $expdate = $res->TokenStatus->ExpirationTime;
        $expdate = str_replace('T', ' ', $expdate);
        $expdate = str_replace('.000Z', '', $expdate);

        update_option('wplister_ebay_token_expirationtime', $expdate);

        // handle result
        return ( $expdate );
        
    }

    // test connection to ebay api by single GetItem request
    public function testConnection(){ 
        #require_once 'GetItemRequestType.php';
        require_once 'GeteBayOfficialTimeRequestType.php';

        // prepare request
        $req = new GeteBayOfficialTimeRequestType();
        #$req->setItemID($item_id);
        
        // send request
        $res = $this->sp->GeteBayOfficialTime($req);

        // handle result
        return ( $res );
        
    }

    // TODO: fetch ebaySites from eBay
    public function getEbaySites() {

        $sites = array (        
            '0'   => 'US', 
            '2'   => 'Canada', 
            '3'   => 'UK', 
            '77'  => 'Germany', 
            '15'  => 'Australia', 
            '71'  => 'France', 
            '100' => 'eBayMotors', 
            '101' => 'Italy', 
            '146' => 'Netherlands', 
            '186' => 'Spain', 
            '203' => 'India', 
            '201' => 'HongKong', 
            '216' => 'Singapore', 
            '207' => 'Malaysia', 
            '211' => 'Philippines', 
            '210' => 'CanadaFrench', 
            '212' => 'Poland', 
            '123' => 'Belgium_Dutch', 
            '23'  => 'Belgium_French', 
            '16'  => 'Austria', 
            '193' => 'Switzerland', 
            '205' => 'Ireland'
        );
        return $sites;
    }

    // 
    function _getDomainnameBySiteId($siteid = 0)
    {
        switch ($siteid) {
            case 0:
                return 'ebay.com';
            case 2:
                return 'ebay.ca';
            case 3:
                return 'ebay.co.uk';
            case 15:
                return 'ebay.com.au';
            case 16:
                return 'ebay.at';
            case 23:
                return 'ebay.be';
            case 71:
                return 'ebay.fr';
            case 77:
                return 'ebay.de';
            case 100:
                return 'ebaymotors.com';
            case 101:
                return 'ebay.it';
            case 123:
                return 'ebay.be';
            case 146:
                return 'ebay.nl';
            case 186:
                return 'ebay.es';
            case 193:
                return 'ebay.ch';
            case 196:
                return 'ebay.tw';
            case 201:
                return 'ebay.hk';
            case 203:
                return 'ebay.in';
            case 207:
                return 'ebay.my';
            case 211:
                return 'ebay.ph';
            case 212:
                return 'ebay.pl';
            case 216:
                return 'ebay.sg';
            case 218:
                return 'ebay.se';
            case 223:
                return 'ebay.cn';
        }
        return 'ebay.com';

    } // _getDomainnameBySiteId()


}
Back to Top