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

EDI, CMS, Outils, Scripts et API PHP Discussion :

récupérer les variable retournées par Paypal


Sujet :

EDI, CMS, Outils, Scripts et API PHP

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut récupérer les variable retournées par Paypal
    Bonjour,
    j'ai le script suivant pour les remboursement Paypal et j'aimerai quand le script me retourne la réponse mettre dans des variable les paramètres retournés, en GET ou en POST ça ne me retourne rien? et plus bas ce que Paypal me retourne, j'aimerai mettre dans une variable le REFUNDTRANSACTIONID:

    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
    $api_request = 'USER=sb-ph43mb1573904_api1.business.example.com'
                    .  '&PWD=2H8CW3P9C5FTKZYU'
                    .  '&SIGNATURE=Ahiik-MviymUik2ju1GqUXqTniYDAMmKwo1TUWZUOP99G4ZagtecMWEY'
                    .  '&VERSION=204.0'
                    .  '&METHOD=RefundTransaction'
                    .  '&rm=2'
                    .  '&REFUNDTYPE=Partial'//Full'Partial
                    .  '&AMT='.$prix
                    .  '&TransactionID='.$transaction_id;
     
                    //.  '&AMT='. $prix;
     
     
     
     
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp' ); // For live transactions, change to 'https://api-3t.paypal.com/nvp'
        curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
     
        // Uncomment these to turn off server and peer verification
        // curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
        // curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $ch, CURLOPT_POST, 1 );
     
        // Set the API parameters for this transaction
        curl_setopt( $ch, CURLOPT_POSTFIELDS, $api_request );
     
        // Request response from PayPal
        $response = curl_exec( $ch );
        // print_r($response);
     
        // If no response was received from PayPal there is no point parsing the response
        if( ! $response )
            die( 'Calling PayPal to change_subscription_status failed: ' . curl_error( $ch ) . '(' . curl_errno( $ch ) . ')' );
     
        curl_close( $ch );
     
        // An associative array is more usable than a parameter string
        parse_str( $response, $parsed_response );
     
        return $parsed_response;
    }
    $response = get_transaction_details($idtransaction,$id,$prix);
    echo "<pre>"; print_r($response); echo "</pre>";
    $trans=$_POST['REFUNDTRANSACTIONID'];
    $trans2=$_GET['REFUNDTRANSACTIONID'];
    echo $trans;
    echo $trans2;
    echo 'ok';
    retour Paypal
    [REFUNDTRANSACTIONID] => 5NP60292E8322745P
    [FEEREFUNDAMT] => 0.53
    [GROSSREFUNDAMT] => 7.80
    [NETREFUNDAMT] => 7.27
    [CURRENCYCODE] => CHF
    [TOTALREFUNDEDAMOUNT] => 7.80
    [TIMESTAMP] => 2020-05-19T11:40:21Z
    [CORRELATIONID] => 1f2550cf915e5
    [ACK] => Success
    [VERSION] => 204.0
    [BUILD] => 54563116
    [REFUNDSTATUS] => Instant
    [PENDINGREASON] => None

  2. #2
    Membre chevronné Avatar de ma5t3r
    Homme Profil pro
    Développeur freelance
    Inscrit en
    Mai 2015
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2015
    Messages : 320
    Par défaut
    Salut,
    Le mieux est d'utiliser les classes fournies par Paypal
    Ca évite les conneries.
    Tu as les exemples ci-dessous
    https://github.com/paypal/Checkout-P...evelop/samples

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    merci pour la réponse,
    c'est le captureOrder.php?
    mais pour integrer c'est pas simple?

  4. #4
    Membre chevronné Avatar de ma5t3r
    Homme Profil pro
    Développeur freelance
    Inscrit en
    Mai 2015
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2015
    Messages : 320
    Par défaut
    Non, c'est refundOrder dans ton cas.
    Si tu veux rembourser un achat.

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    j'envoi sur ce fichier et j'ai les infos en GET ou POST?

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    mais dans la réponse que me retourne Paypal j'ai déjà les infos!! il suffit de savoir les récupérer et c'est bon je pense? tu as vu la réponse Paypal je l'ai sur un de mes fichier quand je fais un remboursement il faudrait savoir comment récupérer ces infos depuis mon fichier?

  7. #7
    Membre chevronné Avatar de ma5t3r
    Homme Profil pro
    Développeur freelance
    Inscrit en
    Mai 2015
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2015
    Messages : 320
    Par défaut
    Ah ok :-)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $result = var_export($_POST, true);

  8. #8
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    ok merci, mais ou je met ce code? pour récupérer les infos ci-dessous:

    [REFUNDTRANSACTIONID] => 5NP60292E8322745P
    [FEEREFUNDAMT] => 0.53
    [GROSSREFUNDAMT] => 7.80
    [NETREFUNDAMT] => 7.27
    [CURRENCYCODE] => CHF
    [TOTALREFUNDEDAMOUNT] => 7.80
    [TIMESTAMP] => 2020-05-19T11:40:21Z
    [CORRELATIONID] => 1f2550cf915e5
    [ACK] => Success
    [VERSION] => 204.0
    [BUILD] => 54563116
    [REFUNDSTATUS] => Instant
    [PENDINGREASON] => None

    ce sont les infos que Paypal me retourne dans mon fichier php

  9. #9
    Membre chevronné Avatar de ma5t3r
    Homme Profil pro
    Développeur freelance
    Inscrit en
    Mai 2015
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2015
    Messages : 320
    Par défaut
    ce sont les infos que Paypal me retourne dans mon fichier php
    Tu stockes à priori le retour de ta requête cURL dans la variable $response.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $result = var_export($response, true);
    Ce qui te donnera un tableau associatif. Ensuite, tu es assez grand pour afficher ce que tu veux.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    $REFUNDTRANSACTIONID = $result['REFUNDTRANSACTIONID'];
    ...
    ...
    Tu me montres un tableau que Paypal te retourne. Je ne vois rien dans ton code, mis à part la variable $response qui pourrait contenir ce tableau.

  10. #10
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    oui, effectivement Paypal me retourne un tableau Array
    merci
    je vais essayer et je te redit

  11. #11
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    j'ai testé et voilà ce qu'il me retourne sur le fichier

    Warning: Illegal string offset 'REFUNDTRANSACTIONID' in /home/clients/b609dc3f5204f5728966dcae0fdec492/web/nouveausite/remboursement.php on line 84

  12. #12
    Membre chevronné Avatar de ma5t3r
    Homme Profil pro
    Développeur freelance
    Inscrit en
    Mai 2015
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2015
    Messages : 320
    Par défaut
    Poste le contenu de ton fichier remboursement.php

  13. #13
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    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
    <?php
    include "header.php";
    $id = $_GET['id'];
     
    ?>
    <h2><center>Voici les information que Paypal retourne concernant la commande n°<?php echo $id ?></center></h2>
    <?php
     
    $bdd=bdd();                   
    $transaction=$bdd->prepare("SELECT transaction_idP,prix_achats FROM achats WHERE id_achats=?");
    $transaction->bindParam(1, $id, PDO::PARAM_INT);
    $transaction -> execute();
    $donnees = $transaction -> fetch();
    $idtransaction=$donnees['transaction_idP'];
    $prix1=$donnees['prix_achats'];
     
    $prix=number_format( special_round($prix1*96/100,0.050) , $decimals =2);
    //echo $prix;
    //echo $id;
     
    function get_transaction_details( $transaction_id,$id,$prix) { 
    $date = date("d-m-Y");    
    $bdd=bdd();
    $req = $bdd->prepare("UPDATE achats SET status_achats = 'Remboursement' WHERE id_achats=? ");
    $req->bindParam(1, $id, PDO::PARAM_INT);
    $req -> execute();
    $req = $bdd->prepare("UPDATE achats SET date_remboursement = ? WHERE id_achats=? ");
    $req->bindParam(1, $date, PDO::PARAM_STR);
    $req->bindParam(2, $id, PDO::PARAM_INT);
    $req -> execute();
    $req = $bdd->prepare("UPDATE ventes SET status_ventes = 'Remboursement' WHERE id_ventes=? ");
    $req->bindParam(1, $id, PDO::PARAM_INT);
    $req -> execute();
    $req = $bdd->prepare("UPDATE achats SET remboursé = 1 WHERE id_achats=? ");
    $req->bindParam(1, $id, PDO::PARAM_INT);
    $req -> execute();
     
        $api_request = 'USER=sb-ph43mb1573904_api1.business.example.com'
                    .  '&PWD=2H8CW3P9C5FTKZYU'
                    .  '&SIGNATURE=Ahiik-MviymUik2ju1GqUXqTniYDAMmKwo1TUWZUOP99G4ZagtecMWEY'
                    .  '&VERSION=204.0'
                    .  '&METHOD=RefundTransaction'
                    .  '&rm=2'
                    .  '&REFUNDTYPE=Partial'//Full'Partial
                    .  '&AMT='.$prix
                    .  '&TransactionID='.$transaction_id;
     
                    //.  '&AMT='. $prix;
     
     
     
     
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp' ); // For live transactions, change to 'https://api-3t.paypal.com/nvp'
        curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
     
        // Uncomment these to turn off server and peer verification
        // curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
        // curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $ch, CURLOPT_POST, 1 );
     
        // Set the API parameters for this transaction
        curl_setopt( $ch, CURLOPT_POSTFIELDS, $api_request );
     
        // Request response from PayPal
        $response = curl_exec( $ch );
        // print_r($response);
     
        // If no response was received from PayPal there is no point parsing the response
        if( ! $response )
            die( 'Calling PayPal to change_subscription_status failed: ' . curl_error( $ch ) . '(' . curl_errno( $ch ) . ')' );
     
        curl_close( $ch );
     
        // An associative array is more usable than a parameter string
        parse_str( $response, $parsed_response );
     
        return $parsed_response;
    }
    $response = get_transaction_details($idtransaction,$id,$prix);
    echo "<pre>"; print_r($response); echo "</pre>";
    $result = var_export($response, true);
    $REFUNDTRANSACTIONID = $result['REFUNDTRANSACTIONID'];
     
    echo $REFUNDTRANSACTIONID;
     
    echo 'ok';
     
     
     
     
    include "footer.php";
    ?>

  14. #14
    Membre chevronné Avatar de ma5t3r
    Homme Profil pro
    Développeur freelance
    Inscrit en
    Mai 2015
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2015
    Messages : 320
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $REFUNDTRANSACTIONID = $response['REFUNDTRANSACTIONID'];
    Tu vires ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    $response = get_transaction_details($idtransaction,$id,$prix);
    echo "<pre>"; print_r($response); echo "</pre>";
    $result = var_export($response, true);
    $REFUNDTRANSACTIONID = $result['REFUNDTRANSACTIONID'];
     
    echo $REFUNDTRANSACTIONID;
     
    echo 'ok';
    et tu le remplaces par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    $response = get_transaction_details($idtransaction,$id,$prix);
    die(var_dump($response));
    Tu postes le résultat

  15. #15
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    voilà ce que sa retourne:

    array(9) { ["TIMESTAMP"]=> string(20) "2020-05-19T15:40:28Z" ["CORRELATIONID"]=> string(13) "82d855801825c" ["ACK"]=> string(7) "Failure" ["VERSION"]=> string(5) "204.0" ["BUILD"]=> string(8) "54563116" ["L_ERRORCODE0"]=> string(5) "10009" ["L_SHORTMESSAGE0"]=> string(19) "Transaction refused" ["L_LONGMESSAGE0"]=> string(76) "The partial refund amount must be less than or equal to the remaining amount" ["L_SEVERITYCODE0"]=> string(5) "Error" }

  16. #16
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    transaction failed c'est normal car j'ai déjà demandé le remboursement mais je teste avec ACK

  17. #17
    Membre chevronné Avatar de ma5t3r
    Homme Profil pro
    Développeur freelance
    Inscrit en
    Mai 2015
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2015
    Messages : 320
    Par défaut
    Bah voilà, tu as ton tableau associatif. Tu peux récupérer les valeurs qui y sont stockées.

    Si tu as une erreur sur la transaction, tu affiches l'erreur sinon tu traites les informations de ton tableau
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    $CODE = $response['CODE'];
    $REFUNDTRANSACTIONID = $response['REFUNDTRANSACTIONID'];
    ...
    ...

  18. #18
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    428
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Novembre 2008
    Messages : 428
    Par défaut
    merci brave homme , ça fonctionne maintenant, merci encore tu m'enlève une épine du pied
    salutations
    Pascal

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

Discussions similaires

  1. [AJAX] Récupérer une variable retournée par ajax
    Par renaud26 dans le forum jQuery
    Réponses: 7
    Dernier message: 03/07/2015, 00h00
  2. Récupérer les variables d'une autre fenêtre
    Par chuky dans le forum AWT/Swing
    Réponses: 8
    Dernier message: 20/05/2012, 20h24
  3. récupérer les données retournée par $.post
    Par mougeole dans le forum jQuery
    Réponses: 2
    Dernier message: 12/12/2010, 19h39
  4. Réponses: 9
    Dernier message: 09/09/2009, 16h51
  5. Récupérer les variables d'un .pm
    Par Feustine dans le forum Modules
    Réponses: 4
    Dernier message: 12/08/2005, 19h30

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