IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Problème définition variable incompris


Sujet :

Langage PHP

  1. #1
    Membre confirmé
    Avatar de Skyxia
    Homme Profil pro
    Ingénieur réseau & sécurité
    Inscrit en
    Mai 2016
    Messages
    359
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur réseau & sécurité
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2016
    Messages : 359
    Points : 627
    Points
    627
    Billets dans le blog
    3
    Par défaut Problème définition variable incompris
    Bonjour à tous,

    Je viens vers vous car étant débutant je ne comprend pas mon erreur.
    Sur mon site, lorsque l'utilisateur décidé d'effectuer une action il se voit retourner une erreur 500 avec en réponse (après analyse avec Firebug) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    code: 500
    message: "Notice: Undefined variable: lemonwayKit"
    Voici les endroits dans le code où apparaît ce fameux "lemonwayKit" :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    class GlobalManager
    {
       pleins de choses
       private static $lemonwayKit;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    public function __construct($em, $container, $translator, $router)
        {
            pleins de choses
            $this->lemonWayAPI = new LemonWayProcess();
     
            if (!self::$lemonwayKit) {
                $lemonwayKit = new LemonWayKit();
                self::$lemonwayKit = $lemonwayKit;
            }
        }
    Ces deux parties se situent dans le haut de fichier et du code, et plus bas voici ce que j'ai :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    public function sendPayment($walletIdNearfix, $walletDetail, $amount, $message = '')
        {
     
            $params = array(
                'debitWallet' => $walletIdNearfix,
                'creditWallet' => $walletDetail,
                'amount' => $amount,
                'message' => $message,
            );
            error_log("Troisieme");
            //Send money from walletIdNearfix to $walletDetail
            $res = $lemonwayKit::$lemonwayKit->sendPayment($params);
            if (isset($res->lwError)) {
                $response = $lemonwayKit::$lemonwayKit->setErrorResponse($res->lwError->CODE, $res->lwError->MSG);
            } else {
                $response = $lemonwayKit::$lemonwayKit->setSuccessResponse($res->operations[0]);
            }
     
     
            return $response;
        }
    suivis de :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    public function cashMoneySponsorshipByUserId($userId)
        {
            //initialize LemonWay API
            $lemonway = $this->lemonWayAPI;
            //Get account from userId
            $compte = $this->compteRepo->find($userId);
            //if account is valid
            if ($compte->getIdEtatCompte()->getIdEtatCompte() == 3) {
                //get money sponsorship
                $moneySponsorship = $compte->getMoneySponsorship();
                if ($moneySponsorship > 0) {
     
                    $walletDetail = json_decode($lemonway->getWalletDetailsFromMail($compte->getEmail()), true);
     
                    $ibanSponsorId = 0;
     
                    if (isset($walletDetail['success'])) {
     
                        $ibanSponsorId = $walletDetail['success']['data'][0]['ibans'][0]['ID'][0];
     
                    }
                    if (empty($ibanSponsorId)) {
                        //code 1 : Iban is empty
                        return 1;
                    }
     
                    $walletIdNearfix = 11;
                    error_log("Premier");
                    //calcul amount from moneySponsorShip
                    $amount = array(
                        'amountTot' => number_format($moneySponsorship, 2, ".", ""),
                        'amountCom' => number_format(0, 2),
                    );
     
                    error_log("Deuxieme");
     
                    $this->sendPayment($walletIdNearfix, $walletDetail, $amount, $message = '');
                    error_log("Quatrieme");
    J'ai mis des error_log pour voir un peu ce qui se passait lors de l'exécution de l'action, en gros, mon error_log rentre dans le premier, également dans le deuxième, également dans le troisième (situé dans la fonction sendPayment) mais ne rentre pas dans le quatrième dû à l'erreur cité au début "Notice: Undefined variable: lemonwayKit".

    Quelqu'un serait-il en mesure de m'expliquer, pourquoi il me dit qu'elle n'est pas définie ?

    Cordialement, Skyxia.

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Pourquoi cette syntaxe "$lemonwayKit::$lemonwayKit" ?
    Tu l'as écris ou c'est un code fourni par le developpeur ?

  3. #3
    Membre confirmé
    Avatar de Skyxia
    Homme Profil pro
    Ingénieur réseau & sécurité
    Inscrit en
    Mai 2016
    Messages
    359
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur réseau & sécurité
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2016
    Messages : 359
    Points : 627
    Points
    627
    Billets dans le blog
    3
    Par défaut
    Dans l'exemple fournis dans le fichier LemonWayProcess.php :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    public function sendPayment($firtWalletId, $seconWalletId, $amount, $message = '')
        {
     
            $params = array(
                'debitWallet' => $firtWalletId,
                'creditWallet' => $seconWalletId,
                'amount' => $amount,
                'message' => $message
            );
            //Send money from wallet1 to wallet2
            $res = self::$lemonwayKit->sendPayment($params);
            if (isset($res->lwError)) {
                $response = self::setErrorResponse($res->lwError->CODE, $res->lwError->MSG);
            } else {
                $response = self::setSuccessResponse($res->operations[0]);
            }
     
            return $response;
     
        }
    Or si j'utilise "self" dans mon GlobalManager, cela ne fonctionnera pas les setErrorResponse & setSuccessResponse ne seront pas reconnu car ils ne sont définis que dans le fichier LemonWayProcess.php.. désolé ça peut te sembler logique ou pas mais je suis débutant et j'ai récupérer un projet en cours pour un stage où je mélange tout faute d'indications :/

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Sans en savoir plus sur l'organisation de tes classes c'est difficile de te répondre.

  5. #5
    Membre confirmé
    Avatar de Skyxia
    Homme Profil pro
    Ingénieur réseau & sécurité
    Inscrit en
    Mai 2016
    Messages
    359
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur réseau & sécurité
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2016
    Messages : 359
    Points : 627
    Points
    627
    Billets dans le blog
    3
    Par défaut
    Hum je peux vous mettre le code complet de mon GlobalManager (qui fait 560 lignes) mais je pense pas que cela ai un grand intérêt et vous fera perdre plus de temps qu'autre chose, surtout que sur les 560 lignes peut-être 60 sont de moi et le reste du code est pas si bien écrit à mon avis (projet sous-traité, puis récupérer par l'entreprise où j'effectue mon stage). mais sait-on jamais ^^

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?php
     
    namespace SM\Bundle\RESTBundle\Manager;
     
    use SM\Bundle\LemonwayBundle\API\LemonWayProcess;
    use SM\Bundle\LemonwayBundle\API\LemonWayKit;
    use SM\Bundle\LemonwayBundle\Constants\ErrorMessages;
    use SM\Bundle\LemonwayBundle\SMLemonwayBundle;
    use SM\Bundle\RESTBundle\Entity\Fichier;
    use SM\Bundle\RESTBundle\Entity\NearfixPaiement;
    use SM\Bundle\RESTBundle\Constants\Configs;
    use SM\Bundle\RESTBundle\Entity\Paiement;
    use SM\Bundle\RESTBundle\Repository\TypePaiementRepository;
    use Spatie\PdfToImage\Pdf;
    use SM\Bundle\RESTBundle\Utilities\Files;
    use SM\Bundle\RESTBundle\Manager\CompteManager;
     
    /**
     * Description of GlobalManager
     *
     */
     
    class GlobalManager
    {
     
        public $em;
        protected $container;
        protected $translator;
        protected $router;
        public $adresseRepo;
        public $carnetAddresseRepo;
        public $categorieInterventionRepo;
        public $categorieListeRepo;
        public $categorieMetierRepo;
        public $categorieNiveau2Repo;
        public $categorieNiveau3Repo;
        public $categorieNiveau4Repo;
        public $categorieNiveau5Repo;
        public $civiliteRepo;
        public $compteInterventionRepo;
        public $compteDemandeRepo;
        public $compteRepo;
        public $compteTokenRepo;
        public $devisDetailRepo;
        public $devisRepo;
        public $distanceInterventionRepo;
        public $documentsRepo;
        public $etatAdresseRepo;
        public $etatCarnetAdresseRepo;
        public $etatCategorieRepo;
        public $etatCompteRepo;
        public $etatDevisRepo;
        public $etatFactureRepo;
        public $etatFichierRepo;
        public $etatInterventionRepo;
        public $etatPaiementRepo;
        public $etatWalletRepo;
        public $factureDetailRepo;
        public $factureRepo;
        public $fichierRepo;
        public $fillieulRepo;
        public $interventionRepo;
        public $nafCat0Repo;
        public $nafCat1Repo;
        public $nafCat2Repo;
        public $nafCat3Repo;
        public $paiementRepo;
        public $nearfixPaiementRepo;
        public $parametresRepo;
        public $parametresTxtRepo;
        public $prelevementRepo;
        public $statusInterventionRepo;
        public $tvaRepo;
        public $typeAdresseRepo;
        public $typeCarnetAdresseRepo;
        public $typeCategorieRepo;
        public $typeCompteRepo;
        public $typeFichierRepo;
        public $typeInterventionRepo;
        public $typePaiementRepo;
        public $typePrelevementRepo;
        public $typeBuildingRepo;
        public $userDeviceRepo;
        public $walletRepo;
        public $noterRepo;
        public $statusDevisRepo;
        public $statusFactureRepo;
        public $typeUnitRepo;
        public $demandeTempRepo;
        public $commentsRepo;
        public $notificationRepo;
        public $lemonWayAPI;
        private static $lemonwayKit;
     
        /**
         * Construct
         *
         * @param type $em
         * @param type $container
         * @param type $translator
         * @param type $router
         */
        public function __construct($em, $container, $translator, $router)
        {
            $this->em = $em;
            $this->container = $container;
            $this->translator = $translator;
            $this->router = $router;
            $this->adresseRepo = $em->getRepository('SMRESTBundle:Adresse');
            $this->carnetAddresseRepo = $em->getRepository('SMRESTBundle:CarnetAddresse');
            $this->categorieInterventionRepo = $em->getRepository('SMRESTBundle:CategorieIntervention');
            $this->categorieListeRepo = $em->getRepository('SMRESTBundle:CategorieListe');
            $this->categorieMetierRepo = $em->getRepository('SMRESTBundle:CategorieMetier');
            $this->categorieNiveau2Repo = $em->getRepository('SMRESTBundle:CategorieNiveau2');
            $this->categorieNiveau3Repo = $em->getRepository('SMRESTBundle:CategorieNiveau3');
            $this->categorieNiveau4Repo = $em->getRepository('SMRESTBundle:CategorieNiveau4');
            $this->categorieNiveau5Repo = $em->getRepository('SMRESTBundle:CategorieNiveau5');
            $this->civiliteRepo = $em->getRepository('SMRESTBundle:Civilite');
            $this->compteInterventionRepo = $em->getRepository('SMRESTBundle:CompteIntervention');
            $this->compteDemandeRepo = $em->getRepository('SMRESTBundle:CompteDemande');
            $this->compteRepo = $em->getRepository('SMRESTBundle:Compte');
            $this->compteTokenRepo = $em->getRepository('SMRESTBundle:CompteToken');
            $this->devisDetailRepo = $em->getRepository('SMRESTBundle:DevisDetail');
            $this->devisRepo = $em->getRepository('SMRESTBundle:Devis');
            $this->distanceInterventionRepo = $em->getRepository('SMRESTBundle:DistanceIntervention');
            $this->documentsRepo = $em->getRepository('SMRESTBundle:Documents');
            $this->etatAdresseRepo = $em->getRepository('SMRESTBundle:EtatAdresse');
            $this->etatCarnetAdresseRepo = $em->getRepository('SMRESTBundle:EtatCarnetAdresse');
            $this->etatCategorieRepo = $em->getRepository('SMRESTBundle:EtatCategorie');
            $this->etatCompteRepo = $em->getRepository('SMRESTBundle:EtatCompte');
            $this->etatDevisRepo = $em->getRepository('SMRESTBundle:EtatDevis');
            $this->etatFactureRepo = $em->getRepository('SMRESTBundle:EtatFacture');
            $this->etatFichierRepo = $em->getRepository('SMRESTBundle:EtatFichier');
            $this->etatInterventionRepo = $em->getRepository('SMRESTBundle:EtatIntervention');
            $this->etatPaiementRepo = $em->getRepository('SMRESTBundle:EtatPaiement');
            $this->etatWalletRepo = $em->getRepository('SMRESTBundle:EtatWallet');
            $this->factureDetailRepo = $em->getRepository('SMRESTBundle:FactureDetail');
            $this->factureRepo = $em->getRepository('SMRESTBundle:Facture');
            $this->fichierRepo = $em->getRepository('SMRESTBundle:Fichier');
            $this->fillieulRepo = $em->getRepository('SMRESTBundle:Fillieul');
            $this->interventionRepo = $em->getRepository('SMRESTBundle:Intervention');
            $this->nafCat0Repo = $em->getRepository('SMRESTBundle:NafCat0');
            $this->nafCat1Repo = $em->getRepository('SMRESTBundle:NafCat1');
            $this->nafCat2Repo = $em->getRepository('SMRESTBundle:NafCat2');
            $this->nafCat3Repo = $em->getRepository('SMRESTBundle:NafCat3');
            $this->paiementRepo = $em->getRepository('SMRESTBundle:Paiement');
            $this->nearfixPaiementRepo = $em->getRepository('SMRESTBundle:NearfixPaiement');
            $this->parametresRepo = $em->getRepository('SMRESTBundle:Parametres');
            $this->parametresTxtRepo = $em->getRepository('SMRESTBundle:ParametresTxt');
            $this->prelevementRepo = $em->getRepository('SMRESTBundle:Prelevement');
            $this->statusInterventionRepo = $em->getRepository('SMRESTBundle:StatusIntervention');
            $this->tvaRepo = $em->getRepository('SMRESTBundle:Tva');
            $this->typeAdresseRepo = $em->getRepository('SMRESTBundle:TypeAdresse');
            $this->typeCarnetAdresseRepo = $em->getRepository('SMRESTBundle:TypeCarnetAdresse');
            $this->typeCategorieRepo = $em->getRepository('SMRESTBundle:TypeCategorie');
            $this->typeCompteRepo = $em->getRepository('SMRESTBundle:TypeCompte');
            $this->typeFichierRepo = $em->getRepository('SMRESTBundle:TypeFichier');
            $this->typeInterventionRepo = $em->getRepository('SMRESTBundle:TypeIntervention');
            $this->typePaiementRepo = $em->getRepository('SMRESTBundle:TypePaiement');
            $this->typePrelevementRepo = $em->getRepository('SMRESTBundle:TypePrelevement');
            $this->typeBuildingRepo = $em->getRepository('SMRESTBundle:TypeBuilding');
            $this->userDeviceRepo = $em->getRepository('SMRESTBundle:UserDevice');
            $this->walletRepo = $em->getRepository('SMRESTBundle:Wallet');
            $this->noterRepo = $em->getRepository('SMRESTBundle:Noter');
            $this->statusDevisRepo = $em->getRepository('SMRESTBundle:StatusDevis');
            $this->statusFactureRepo = $em->getRepository('SMRESTBundle:StatusFacture');
            $this->typeUnitRepo = $em->getRepository('SMRESTBundle:TypeUnit');
            $this->demandeTempRepo = $em->getRepository('SMRESTBundle:DemandeTemp');
            $this->commentsRepo = $em->getRepository('SMRESTBundle:Comments');
            $this->notificationRepo = $em->getRepository('SMRESTBundle:Notification');
            $this->lemonWayAPI = new LemonWayProcess();
     
            if (!self::$lemonwayKit) {
                $lemonwayKit = new LemonWayKit();
                self::$lemonwayKit = $lemonwayKit;
            }
        }
     
     
        /**
         * Get message by key from ParameterTb
         *
         * @param string $message
         * @param string $language
         * @return string
         */
        public function __($message, $language = 'fr')
        {
            $result = $this->parametresRepo->getParametreByNom($message, $language);
     
            return $result;
     
        }
     
        /**
         *
         * @param type $paramKey
         * @return type
         */
        public function getParamConfig($paramKey)
        {
            return $this->container->getParameter($paramKey);
     
        }
     
        /**
         * Generate HTML to PDF
         *
         * @param String $url
         * @param String $fileName
         * @param String $type
         * @return Fichier
         */
        public function generateHTMLtoPDF($url, $fileName, $type = Configs::FILE_TYPE_GENERAL_INVOICE, $urlImage = null)
        {
            $dataResponse = array();
            // rename file
            $fileName = Files::removeSpecialCharacter($fileName);
            $pdfFilesDir = $this->container->getParameter('pdf_files_dir');
            if (file_exists($pdfFilesDir . $fileName)) {
                unlink($pdfFilesDir . $fileName);
            }
            $imageFileName = pathinfo($fileName, PATHINFO_FILENAME) . '.jpg';
            // Generate PDF file
            $this->container->get('knp_snappy.pdf')->generate($url, $pdfFilesDir . $fileName);
     
            if (file_exists($pdfFilesDir . 'thumbnail/' . $imageFileName)) {
                unlink($pdfFilesDir . 'thumbnail/' . $imageFileName);
            }
     
            // Generate image file
            if ($urlImage == null) {
                $urlImage = $url;
            }
            $this->container->get('knp_snappy.image')->generate($urlImage, $pdfFilesDir . 'thumbnail/' . $imageFileName);
     
            // Set Fichier info
            $fichier = new Fichier();
            $typeFichier = $this->typeFichierRepo->findOneBy(array(
                'typeFichierKey' => $type));
     
            $fichier->setIdTypeFichier($typeFichier);
     
            $etatFichier = $this->etatFichierRepo->findOneBy(array(
                'idEtatFichier' => Configs::DEFAULT_STATUS_FILE_ATTACH));
            $fichier->setIdEtatFichier($etatFichier);
     
            $fichier->setCheminFichier($pdfFilesDir . $fileName);
            $fichier->setNomFichier($fileName);
            $fichier->setDateCreation(new \DateTime());
     
            // Save new fichier
            $this->em->persist($fichier);
            $this->em->flush();
     
            if ($fichier instanceof Fichier && !empty($fichier)) {
                $dataResponse = $fichier;
            }
     
            return $dataResponse;
     
        }
     
        /**
         * Get entity manager
         * @return type
         */
        public function getEntityManager()
        {
            return $this->em;
     
        }
     
        /**
         * Generate image thumbnail from PDF file
         *
         * @param String $pdfFileURL
         * @param String $fileName
         * @param Integer $quality Quality of image file
         */
        public function generateImageThumbnailFromPDF($pdfFileURL, $fileName, $quality = 100)
        {
            $pdfFilesDir = $this->container->getParameter('pdf_files_dir');
            $pdfThumbnailFilesDir = $this->container->getParameter('pdf_thumbnail_files_dir');
            // rename file
            $fileName = Files::removeSpecialCharacter($fileName);
            $imageFileName = pathinfo($fileName, PATHINFO_FILENAME) . '.jpg';
     
            // Remove old file if exist
            if (file_exists($pdfFilesDir . 'thumbnail/' . $imageFileName)) {
                unlink($pdfFilesDir . 'thumbnail/' . $imageFileName);
            }
     
            try {
                $qualityOption = ' -quality ' . $quality;
                $output = null;
                $returnVar = -1;
                $fileOutputPath = $pdfThumbnailFilesDir . $imageFileName;
                $command = 'convert ' . $pdfFileURL . $qualityOption . ' -append ' . $fileOutputPath;
                exec($command, $output, $returnVar);
     
                if ($returnVar === 0) {
                    return true;
                }
            } catch (Exception $exc) {
                // Not work
            }
     
            return false;
     
        }
     
        /**
         *  Build intervention code
         *
         * @param Intervention Object $intervention
         * @return Integer Intervention code
         */
        public function buildInterventionCode($intervention)
        {
            $interventionCodeOriginal = $this->getParamConfig('intervention_code_original');
            $interventionId = (int)$intervention->getIdIntervention();
     
            $interventionCode = $interventionCodeOriginal + $interventionId;
            if ($intervention->getInterventionCode() !== null) {
                $interventionCode = $intervention->getInterventionCode();
            }
     
            return $interventionCode;
     
        }
     
        public function addNearfixPaiement($lwData, $compte, $typePayment, $etatPayment, $status = 'CAPTURED', $options = 'Subscriber')
        {
            $mId = isset($lwData['ID'][0]) && $lwData['ID'][0] ? $lwData['ID'][0] : 0;
            $sen = isset($lwData['SEN'][0]) && $lwData['SEN'][0] ? $lwData['SEN'][0] : 0;
            $rec = isset($lwData['REC'][0]) && $lwData['REC'][0] ? $lwData['REC'][0] : 0;
            $deb = isset($lwData['DEB'][0]) && $lwData['DEB'][0] ? $lwData['DEB'][0] : 0;
            $cred = isset($lwData['CRED'][0]) && $lwData['CRED'][0] ? $lwData['CRED'][0] : 0;
            $com = isset($lwData['COM'][0]) && $lwData['COM'][0] ? $lwData['COM'][0] : 0;
            $msg = isset($lwData['MSG'][0]) && $lwData['MSG'][0] ? $lwData['MSG'][0] : '';
    //        $mLabel = isset($lwData['MLABEL'][0]) && $lwData['MLABEL'][0] ? $lwData['MLABEL'][0] : '';
            $status = isset($lwData['STATUS'][0]) && $lwData['STATUS'][0] ? $status : $status;
            $code = isset($lwData['CODE'][0]) && $lwData['CODE'][0] ? $lwData['CODE'][0] : 0;
    //        $extraIS3DS = isset($lwData['EXTRA']['IS3DS'][0]) && $lwData['EXTRA']['IS3DS'][0] ? $lwData['EXTRA']['IS3DS'][0] : 0;
    //        $extraCTRY = isset($lwData['EXTRA']['CTRY'][0]) && $lwData['EXTRA']['CTRY'][0] ? $lwData['EXTRA']['CTRY'][0] : 0;
    //        $extraAUTH = isset($lwData['EXTRA']['AUTH'][0]) && $lwData['EXTRA']['AUTH'][0] ? $lwData['EXTRA']['AUTH'][0] : 0;
     
            $paymentEntity = new NearfixPaiement();
            $paymentEntity->setLwIdPaiement($mId);
            $paymentEntity->setIdCompte($compte);
            $paymentEntity->setCom($com);
            $paymentEntity->setCred($cred);
            $paymentEntity->setDateCreation(new \DateTime);
            $paymentEntity->setDeb($deb);
            $paymentEntity->setRec($rec);
            $paymentEntity->setSen($sen);
            $paymentEntity->setDate(new \DateTime);
            $paymentEntity->setMsg($msg);
            $paymentEntity->setIdTypePaiement($typePayment);
            $paymentEntity->setIdEtatPaiement($etatPayment);
            $paymentEntity->setStatus($status);
            $paymentEntity->setCode($code);
            $paymentEntity->setOptions($options);
     
            $this->em->persist($paymentEntity);
            $this->em->flush();
     
            $paymentId = $paymentEntity->getIdPaiement();
            $now = new \DateTime('now');
     
            if (isset($paymentId) && $paymentId) {
                $fileName = 'Subscriber_' . $compte->getIdCompte() . '_' . $now->getTimestamp() . 'pdf';
                /**
                 * Generate DPF
                 */
                $pdfFilesDir = $this->container->getParameter('pdf_files_dir');
                if (file_exists($pdfFilesDir . $fileName)) {
                    unlink($pdfFilesDir . $fileName);
                }
                // rename file
                $fileName = Files::removeSpecialCharacter($fileName);
                $routerParams = array(
                    'id' => $paymentEntity->getIdPaiement());
                $host = $this->container->get('request')->getHost();
     
     
                $path = $this->container->get('router')->generate('sm_front_payment_pdf', $routerParams);
     
                $url = "http://{$host}{$path}";
                // Generate PDF file
                $this->container->get('knp_snappy.pdf')->generate($url, $pdfFilesDir . $fileName);
     
                /**
                 * SEND EMAIL
                 */
            }
            return;
     
        }
     
        public function convertToBase64($path, $param)
        {
            $base64 = '';
            $type = pathinfo($path . $param, PATHINFO_EXTENSION);
            if (file_exists($path . $param)) {
                $data = file_get_contents($path . $param);
                $base64 = base64_encode($data);
            }
     
            return $base64;
     
        }
     
        /**
         * send mail to admin nearfix
         * $parram['subject'] is Subject
         * $parram['fromEmail'] is from mail
         *  $parram['template'] is template mail
         * @param type $parram
         */
        public function sendMailToAdminNearfix($parram)
        {
            $compteManage = new CompteManager();
            $emailSubject = isset($parram['subject']) && $parram['subject'] != "" ? $parram['subject'] : "";
            $fromEmail = isset($parram['fromEmail']) && $parram['fromEmail'] != "" ? $parram['fromEmail'] : "";
            $emailTemplate = isset($parram['template']) && $parram['template'] != "" ? $parram['template'] : "";
            $emailAdminNearfix = $this->container->getParameter('email_default_admin');
            $emailContent = array(
                'subject' => $emailSubject,
    //                        'content' => array(
    //                            '%title_quote%' => $devis->getTitle(),
    //                            '%civilité%' => $clientGender,
    //                            '%nom_client%' => $clientName,
    //                            '%firtname_client%' => $clientFirstName
    //                        ),
                'fromEmail' => $fromEmail,
                'toEmail' => $emailAdminNearfix,
                'template' => $emailTemplate
            );
            $compteManage->sendMail($emailContent, $this->translator);
        }
     
        /**
         * @param Int $walledIdNearfix
         * @param Int $walletDetail
         * @param Double $amount
         * @param String $message
         *
         * @return String json
         */
     
        public function sendPayment($walletIdNearfix, $walletDetail, $amount, $message = '')
        {
     
            $params = array(
                'debitWallet' => $walletIdNearfix,
                'creditWallet' => $walletDetail,
                'amount' => $amount,
                'message' => $message,
            );
            error_log("Troisieme");
            //Send money from walletIdNearfix to $walletDetail
            $res = $lemonwayKit::$lemonwayKit->sendPayment($params);
            if (isset($res->lwError)) {
                $response = $lemonwayKit::$lemonwayKit->setErrorResponse($res->lwError->CODE, $res->lwError->MSG);
            } else {
                $response = $lemonwayKit::$lemonwayKit->setSuccessResponse($res->operations[0]);
            }
     
     
            return $response;
        }
     
     
        /**
         * @param $userId
         * @return int
         * 0 : success
         * 1 : Iban empty
         * 2 : money is 0
         * 3 : account is not valid
         * 4 : error lemonway
         */
        public function cashMoneySponsorshipByUserId($userId)
        {
            //initialize LemonWay API
            $lemonway = $this->lemonWayAPI;
            //Get account from userId
            $compte = $this->compteRepo->find($userId);
            //if account is valid
            if ($compte->getIdEtatCompte()->getIdEtatCompte() == 3) {
                //get money sponsorship
                $moneySponsorship = $compte->getMoneySponsorship();
                if ($moneySponsorship > 0) {
     
                    $walletDetail = json_decode($lemonway->getWalletDetailsFromMail($compte->getEmail()), true);
     
                    $ibanSponsorId = 0;
     
                    if (isset($walletDetail['success'])) {
     
                        $ibanSponsorId = $walletDetail['success']['data'][0]['ibans'][0]['ID'][0];
     
                    }
                    if (empty($ibanSponsorId)) {
                        //code 1 : Iban is empty
                        return 1;
                    }
     
                    $walletIdNearfix = 11;
                    error_log("Premier");
                    //calcul amount from moneySponsorShip
                    $amount = array(
                        'amountTot' => number_format($moneySponsorship, 2, ".", ""),
                        'amountCom' => number_format(0, 2),
                    );
     
                    error_log("Deuxieme");
     
                    $this->sendPayment($walletIdNearfix, $walletDetail, $amount, $message = '');
                    error_log("Quatrieme");
     
                    error_log("Cinquieme");
                    //call moneyOut from lemonWay
                    $moneyOut = json_decode($lemonway->moneyOut($walletIdNearfix, $ibanSponsorId, $amount, "Décagnotage"), true);
                    error_log(print_r($moneyOut, true));
     
                    /*
                     * THE
                     * Ajout #004 & #005
                     * Le 13/06/16 à 10h15
                     * @TODOO : Ajout Paiement de type 7
                     * @TODOO : Update MoneySponsorship à 0
                     */
     
                    //if moneyOut return no errors
                    if (!isset($moneyOut['error'])) {
                        $paiement = new Paiement();
                        $paiement->getIdTypePaiement();
                        $this->idTypePaiement = 7;
                        error_log("Sixieme");
                        //code 0 : success
                        return $moneyOut;
                    }
     
                    //Update MoneySponsorShip à 0
                    $compte->setMoneySponsorship=0;
                    error_log("Septieme");
                    //code 4 : error lemonway
                    return 4;
     
                }
                //code 2 : money sponsorship = 0
                return 2;
            }
            //code 3 : account is not valid
            return 3;
        }
    }
    Dans le cas où cela nous vous aide pas non plus (ce qui à mon avis sera le cas), vous pouvez clore le sujet je vais essayer de faire autrement :/

  6. #6
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    et setErrorResponse() ça fait partie de quelle classe ?

  7. #7
    Membre confirmé
    Avatar de Skyxia
    Homme Profil pro
    Ingénieur réseau & sécurité
    Inscrit en
    Mai 2016
    Messages
    359
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur réseau & sécurité
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2016
    Messages : 359
    Points : 627
    Points
    627
    Billets dans le blog
    3
    Par défaut
    Erreur de ma part, les setError se situe dans le fichier "LemonWayProcess.php"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?php
     
    namespace SM\Bundle\LemonwayBundle\API;
     
    use SM\Bundle\LemonwayBundle\API\LemonWayKit;
    use SM\Bundle\LemonwayBundle\Constants\ErrorMessages;
    use SM\Bundle\LemonwayBundle\SMLemonwayBundle;
     
    /**
     * Lemonway Process
     */
    class LemonWayProcess
    {
     
    //    private static $myUrls = array('returnUrl' => 'http://www.yourwebsite.com/index.php?url=return',
    //        'cancelUrl' => 'http://www.yourwebsite.com/index.php?url=cancel',
    //        'errorUrl' => 'http://www.yourwebsite.com/index.php?url=error',
    //        'cssUrl' => 'https://www.lemonway.fr/mercanet_lw.css');
    //    private static $testCard = array('number' => '5017670000001800',
    //        'crypto' => '123',
    //        'date' => '12/2017');
    //    private static $testFileToUpload = 'images/lemonway_logo.jpeg';
    //    private static $testIban = array('holder' => 'My Name',
    //        'iban' => 'retiré volontairement',
    //        'bic' => 'ABCDEFGHIJK',
    //        'address1' => 'Center branch',
    //        'address2' => 'Paris');
        private static $lemonwayKit;
        private static $returnUrl;
        private static $cancelUrl;
        private static $errorUrl;
     
      /**
         * Constructor
         */
        public function __construct()
        {
            // get Container
            $container = SMLemonwayBundle::getContainer();
            $htmlUrl = '';
            if ($container->hasParameter('html_url')) {
                $htmlUrl = $container->getParameter('html_url');
            }
            // init IO param
            if ($container->hasParameter('return_url') && $htmlUrl != '') {
                self::$returnUrl = $htmlUrl . $container->getParameter('return_url');
            }
            if ($container->hasParameter('cancel_url') && $htmlUrl != '') {
                self::$cancelUrl = $htmlUrl . $container->getParameter('cancel_url');
            }
            if ($container->hasParameter('error_url') && $htmlUrl != '') {
                self::$errorUrl = $htmlUrl . $container->getParameter('error_url');
            }
     
            if (!self::$lemonwayKit) {
                $lemonwayKit = new LemonWayKit();
                self::$lemonwayKit = $lemonwayKit;
            }
     
        }
     
     
     /**
         * Set Error Response
         * @param String  $code
         * @param String  $message
         *
         * @return String json
         */
        private static function setErrorResponse($code, $message)
        {
            $response = array(
                'status' => false,
                'error' => array(
                    'code' => $code,
                    'message' => $message
                )
            );
     
            return json_encode($response);
     
        }
     
        /**
         * Set Success Response
         *
         * @param array   $data
         *
         * @return String json
         */
        private static function setSuccessResponse($data)
        {
            if (!is_array($data)) {
                $data = array(
                    $data);
            }
            $response = array(
                'status' => true,
                'success' => array(
                    'data' => $data
                )
            );
     
            return json_encode($response);
     
        }
    Voilà c'est mieux ^^

  8. #8
    Membre confirmé
    Avatar de Skyxia
    Homme Profil pro
    Ingénieur réseau & sécurité
    Inscrit en
    Mai 2016
    Messages
    359
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur réseau & sécurité
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2016
    Messages : 359
    Points : 627
    Points
    627
    Billets dans le blog
    3
    Par défaut
    Ok j'ai changé un peu le code :

    Dans mon GlobalManager.php au dessus de ma fonction sendPayment j'ai ajouté les private static function setErrorResponse & private static function setSuccessResponse et donc dans ma fonction sendPayment j'ai changé comme ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    public function sendPayment($walletIdNearfix, $walletDetail, $amount, $message = '')
        {
     
            $params = array(
                'debitWallet' => $walletIdNearfix,
                'creditWallet' => $walletDetail,
                'amount' => $amount,
                'message' => $message,
            );
            error_log("Troisieme");
            //Send money from walletIdNearfix to $walletDetail
            $res = self::$lemonwayKit->sendPayment($params);
            if (isset($res->lwError)) {
                $response = self::setErrorResponse($res->lwError->CODE, $res->lwError->MSG);
            } else {
                $response = self::setSuccessResponse($res->operations[0]);
            }
     
     
            return $response;
        }
    Maintenant l'erreur affiché c'est plus une variable non définie mais juste :
    Notice: Array to string conversion
    une idée ? :/

  9. #9
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Quelle ligne provoque l'erreur ?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [VB.NET] Probléme de variable
    Par Silvia12 dans le forum Windows Forms
    Réponses: 3
    Dernier message: 02/03/2005, 11h51
  2. [Debutant(e)]problème de variable d'environnement
    Par tolsam dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 12/08/2004, 19h08
  3. Problème de variable
    Par vp dans le forum Windows
    Réponses: 2
    Dernier message: 14/05/2004, 16h27
  4. [Débutant] Problème de variables
    Par bonnefr dans le forum SWT/JFace
    Réponses: 9
    Dernier message: 12/05/2004, 17h41
  5. [servlet]problème de variable jamais nulle
    Par omega dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 18/03/2004, 09h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo