php - How to check paypal RefundTransaction API is completed or not? -



php - How to check paypal RefundTransaction API is completed or not? -

how check paypal refundtransaction api completed or not?

i utilize code refund paypal

.....................................................................................................................................................................

<?php // set dynamically. $amounttobeexpected = "0.99"; // php 4.1 // read post paypal scheme , add together 'cmd' $req = 'cmd=_notify-validate'; foreach ($_post $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post paypal scheme validate $header .= "post /cgi-bin/webscr http/1.0\r\n"; $header .= "content-type: application/x-www-form-urlencoded\r\n"; $header .= "content-length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); // assign posted variables local variables $item_name = $_post['item_name']; $item_number = $_post['item_number']; $payment_status = $_post['payment_status']; $payment_amount = $_post['mc_gross']; $payment_currency = $_post['mc_currency']; $txn_id = $_post['txn_id']; $receiver_email = $_post['receiver_email']; $payer_email = $_post['payer_email']; if (!$fp) { // http error } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "verified") == 0) { // check payment_status completed // check txn_id has not been processed // check receiver_email primary paypal email // check payment_amount/payment_currency right // process payment if($payment_amount != $amounttobeexpected) { /** refundtransaction nvp example; lastly modified 08may23. * * issue refund prior transaction. */ $environment = 'sandbox'; // or 'beta-sandbox' or 'live' /** * send http post request * * @param string api method name * @param string post message fields in &name=value pair format * @return array parsed http response body */ function pphttppost($methodname_, $nvpstr_) { global $environment; // set api credentials, paypal end point, , api version. $api_username = urlencode('my_api_username'); $api_password = urlencode('my_api_password'); $api_signature = urlencode('my_api_signature'); $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 curl parameters. $ch = curl_init(); curl_setopt($ch, curlopt_url, $api_endpoint); curl_setopt($ch, curlopt_verbose, 1); // turn off server , 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 api operation, version, , api signature in request. $nvpreq = "method=$methodname_&version=$version&pwd=$api_password&user=$api_username&signature=$api_signature$nvpstr_"; // set request post field curl. curl_setopt($ch, curlopt_postfields, $nvpreq); // response server. $httpresponse = curl_exec($ch); if(!$httpresponse) { exit("$methodname_ failed: ".curl_error($ch).'('.curl_errno($ch).')'); } // extract response details. $httpresponsear = explode("&", $httpresponse); $httpparsedresponsear = array(); foreach ($httpresponsear $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 post request($nvpreq) $api_endpoint."); } homecoming $httpparsedresponsear; } // set request-specific fields. $transactionid = urlencode($txn_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 together request-specific fields 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 not specified.'); } else { $nvpstr = $nvpstr."&amt=$amount"; } if(!isset($memo)) { exit('partial refund memo not specified.'); } } // execute api operation; see 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)); } } } else if (strcmp ($res, "invalid") == 0) { } } fclose ($fp); } ?>

if ack parameter in response comes success or successwithwarning know worked.

php paypal

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -