Bonjour, je possède un site d'échange de monnaie qui utilise le script de Paypal PaymentExpressCheckout ou l'on peux acheter de ma monnaie en échange d'argent réel, de ce coté la, tout fonctionne parfaitement, mais ce que j'aimerais faire, c'est faire en sorte que si l'on veut retirer l'argent et le remettre sur son compte Paypal, on puisse le faire en cliquant sur un seul bouton, et je ne vois pas comment faire.

Je m'explique :

Par exemple : client@client.fr achète 5 € de ma monnaie, les 5€ arrive sur payment@comptepaypaldemonsite.com après qu'il se soit connecté

Ce que je veux faire, c'est que lorsqu'il clique sur Retirer, cela prend 5€ ( exemple ) sur payment@comptepaypaldemonsite.com et ça les remets sur client@client.fr

( Comme sur 5euros.com, par exemple )

Si quelqu'un saurait me donner un coup de main :S

Merci ! :)

5 réponses


Uneo7
Réponse acceptée

La doc est au contraire très claire ;)
il te suffit d'un appel post api avec les infos suivantes

USER=merchant_user_name
PWD=merchant_password
SIGNATURE=merchant_signature
METHOD=RefundTransaction
VERSION=94
TRANSACTIONID=transaction_ID    #ID of the transaction for which the refund is made 
REFUNDTYPE=Full    #Specifies a full refund; a partial refund requires more input fields
ToinouPHP
Auteur
Réponse acceptée

J'ai regardé, mon script est donc le suivant :

<?php
/**
 * Send HTTP POST Request
 *
 * @param     string     The API method name
 * @param     string     The POST Message fields in &name=value pair format
 * @return     array     Parsed HTTP Response body
 */
function PPHttpPost($methodName_, $nvpStr_) {
 global $environment;

 // Set up your API credentials, PayPal end point, and API version.
 $API_UserName = urlencode('monid');
 $API_Password = urlencode('monpswd');
 $API_Signature = urlencode('masign');
 $API_Endpoint = "https://api-3t.paypal.com/nvp";
 if("sandbox" === $environment || "beta-sandbox" === $environment) {
 $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
 }
 $version = urlencode('51.0');

 // Set the curl parameters.
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
 curl_setopt($ch, CURLOPT_VERBOSE, 1);

 // Turn off the server and peer verification (TrustManager Concept).
 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 operation, version, and API signature in the request.
 $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&
            SIGNATURE=$API_Signature$nvpStr_";

 // Set the request as a POST FIELD for curl.
 curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

 // Get response from the server.
 $httpResponse = curl_exec($ch);

 if(!$httpResponse) {
 exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
 }

 // Extract the response details.
 $httpResponseAr = explode("&", $httpResponse);

 $httpParsedResponseAr = array();
 foreach ($httpResponseAr as $i => $value) {
 $tmpAr = explode("=", $value);
 if(sizeof($tmpAr) > 1) {
 $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
 }
 }

 if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
 exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
 }

 return $httpParsedResponseAr;
}

// Set request-specific fields.
$transactionID = urlencode('example_transaction_id');
$refundType = urlencode('Full');  // or 'Partial'
$amount;                          // required if Partial.
$memo;                            // required if Partial.
$currencyID = urlencode('USD');   // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

// Add request-specific fields to the request string.
$nvpStr = "&TRANSACTIONID=$transactionID&REFUNDTYPE=$refundType&CURRENCYCODE=$currencyID";

if(isset($memo)) {
 $nvpStr .= "&NOTE=$memo";
}

if(strcasecmp($refundType, 'Partial') == 0) {
 if(!isset($amount)) {
 exit('Partial Refund Amount is not specified.');
 } else {
 $nvpStr = $nvpStr."&AMT=$amount";
 }

 if(!isset($memo)) {
 exit('Partial Refund Memo is not specified.');
 }
}

// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('RefundTransaction', $nvpStr);

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) ||
   "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
 exit('Refund Completed Successfully: '.print_r($httpParsedResponseAr, true));
} else  {
 exit('RefundTransaction failed: ' . print_r($httpParsedResponseAr, true));
}
?>

Et ça me dit que l'authentification est refusée, alors que tout est bon x)

RefundTransaction failed: Array ( [TIMESTAMP] => 2015%2d04%2d14T19%3a17%3a30Z [CORRELATIONID] => 41c235f4452c2 [ACK] => Failure [VERSION] => 51%2e0 [BUILD] => 16204765 [L_ERRORCODE0] => 10002 [L_SHORTMESSAGE0] => Authentication%2fAuthorization%20Failed [L_LONGMESSAGE0] => You%20do%20not%20have%20permissions%20to%20make%20this%20API%20call [L_SEVERITYCODE0] => Error )

Merci, le problème, c'est qu'ils ne donnent pas d'exemple concret... La doc de Paypal est assez pauvre :S

T'est tu bien autentifié ? Vérifie aussi que le n° de transaction à rembourser soit valide ;)