gpt4 book ai didi

php - Paypal 退款交易问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:09:25 25 4
gpt4 key购买 nike

我正在使用 PayPal 退款支付网关。我的主要目标是向用户退还金额,同时我必须向另一个用户支付一定金额。在这里,我作为管理员,假设我有 150 美元通过 PayPal 记入我的账户。我有它的交易 ID。现在我需要返回假设 100 美元给用户 1,我需要发送 20 美元给用户 2。

                 <?php

/**
*
*
* This PayPal API provides the functionality of Refunding Amount.
* Credentials are omitted from here for privacy purpose. To use it credentials are compulsory to provide.
*/
class PayPalRefund
{
private $API_Username, $API_Password, $Signature, $API_Endpoint, $version;
function __construct($mode = "sandbox")
{
if($mode == "live")
{
$this->API_Username = "sample@gmail.com";
$this->API_Password = "137301275897";
$this->Signature = "AoNBG1CB1212IgLS5QaKlVpODjsaTncPABthzh5N-Nzz511tOodumbgF0TvVDq";
$this->API_Endpoint = "https://api-3t.paypal.com/nvp";
}
else
{
$this->API_Username = "sample@gmail.com";
$this->API_Password = "137301275897";
$this->Signature = "AoNBG1CB1212IgLS5QaKlVpODjsaTncPABthzh5N-Nzz5t11OodumbgF0TvVDq";
$this->API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
}
$this->version = "51.0";
}

/**
* This function actually Sends the CURL Request for Refund
* @param string - $requestString
* @return array - returns the response
*/
function sendRefundRequest($requestString)
{
$this->API_UserName = urlencode($this->API_Username);
$this->API_Password = urlencode($this->API_Password);
$this->API_Signature = urlencode($this->Signature);

$this->version = urlencode($this->version);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

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.
$reqStr = "METHOD=RefundTransaction&VERSION={$this->version}&PWD={$this->API_Password}&USER={$this->API_UserName}&SIGNATURE={$this->API_Signature}$requestString";

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

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

if(!$curlResponse)
return array("ERROR_MESSAGE"=>"RefundTransaction failed".curl_error($ch)."(".curl_errno($ch).")");

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

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

if((0 == sizeof($aryResponse)) || !array_key_exists('ACK', $aryResponse))
return array("ERROR_MESSAGE"=>"Invalid HTTP Response for POST request ($reqStr) to {$this->API_Endpoint}");

return $aryResponse;
}

/**
* @param array $aryData
* @return array
*/
function refundAmount($aryData)
{
if(trim(@$aryData['currencyCode'])=="")
return array("ERROR_MESSAGE"=>"Currency Code is Missing");
if(trim(@$aryData['refundType'])=="")
return array("ERROR_MESSAGE"=>"Refund Type is Missing");
if(trim(@$aryData['transactionID'])=="")
return array("ERROR_MESSAGE"=>"Transaction ID is Missing");

$requestString = "&TRANSACTIONID={$aryData['transactionID']}&REFUNDTYPE={$aryData['refundType']}&CURRENCYCODE={$aryData['currencyCode']}";

if(trim(@$aryData['invoiceID'])!="")
$requestString = "&INVOICEID={$aryData['invoiceID']}";

if(isset($aryData['memo']))
$requestString .= "&NOTE={$aryData['memo']}";

if(strcasecmp($aryData['refundType'], 'Partial') == 0)
{
if(!isset($aryData['amount']))
{
return array("ERROR_MESSAGE"=>"For Partial Refund - It is essential to mention Amount");
}
else
{
$requestString = $requestString."&AMT={$aryData['amount']}";
}

if(!isset($aryData['memo']))
{
return array("ERROR_MESSAGE"=>"For Partial Refund - It is essential to enter text for Memo");
}
}

$resCurl = $this->sendRefundRequest($requestString);
return $resCurl;
}
}
?>

/**
*
*
* This PayPal API provides the functionality of Refunding Amount.
* Credentials are omitted from here for privacy purpose. To use it credentials are compulsory to provide.
*/

/*
* Currency Types
* ('USD', 'GBP', 'EUR', 'JPY', 'CAD', 'AUD')
*
* Refund Type
* ('Partial', 'Full')
*
* Transaction ID
* We can get the Transaction ID from IPN Response
*/

/*
* Partial Refund
*/
$aryData['transactionID'] = "7H123X43620BH3959058";
$aryData['refundType'] = "Partial"; //Partial or Full
$aryData['currencyCode'] = "USD";
$aryData['amount'] = 2.00;
$aryData['memo'] = "There Memo Detail entered for Partial Refund";
// $aryData['invoiceID'] = "xxxxxxxxxx";

//echo "<pre>";
//print_r($aryData);die;
$ref = new PayPalRefund("sandbox");
$aryRes = $ref->refundAmount($aryData);

if($aryRes['ACK'] == "Success")
echo "Amount Refunded Successfully";
else
echo "Error Refunding Amount";

echo "<pre>";
print_r($aryRes);
echo "</pre>";




?>

我收到错误的退款金额:

              Error Refunding Amount
Array
(
[TIMESTAMP] => 2014-05-23T07:13:21Z
[CORRELATIONID] => f42e83df6f52b
[ACK] => Failure
[VERSION] => 51.0
[BUILD] => 11110362
[L_ERRORCODE0] => 10007
[L_SHORTMESSAGE0] => Permission denied
[L_LONGMESSAGE0] => You do not have permission to refund this transaction
[L_SEVERITYCODE0] => Error
)

最佳答案

您需要获得收到资金的用户的许可,然后代表他进行退款。

阅读this了解具体方法。

改变

"scope":"INVOICING"

"scope":"REFUND"

关于php - Paypal 退款交易问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23823553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com