gpt4 book ai didi

paypal - 通过 PayPal RefundTransaction NVP API 发放部分退款后,IPN 监听器仅显示付款状态为 "Refunded,"而不是 "Partially_Refunded"

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:12 26 4
gpt4 key购买 nike

当我使用 RefundTransaction API 操作在我的网站上发放部分退款时,退款处理成功。但是,我的 IPN 监听器不断收到此交易的付款状态 Refunded。我不确定为什么不是 Partially_Refunded

我已经使用 PayPal 的 IPN 模拟器测试了部分退款,我的 IPN 监听器在这些测试期间每次都返回 Partially_Refunded

这是我的 IPN 监听器文件的开头:

$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}


// STEP 2: POST IPN data back to PayPal to validate

$ch = curl_init($paypal_url);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

// In wamp-like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set
// the directory path of the certificate as shown below:
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
//mscampMail($my_email, 'MSCamp curl error', "Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);


// STEP 3: Inspect IPN validation result and act accordingly

if (strcmp ($res, "VERIFIED") == 0) {
// The IPN is verified, process it:
// check whether the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process the notification

require_once ('includes/mysql_connect.php');

// Get payment status & parent_txn_id if refund
$payment_status = escape_data($_POST['payment_status']);

// Cart Items
$num_cart_items = isset($_POST['num_cart_items']) ? $_POST['num_cart_items'] : '';

$txn_id = escape_data($_POST['txn_id']);
$user_id = escape_data($_POST['custom']);
$order_total = escape_data($_POST['mc_gross']);
$shipping_fee = escape_data($_POST['mc_handling']);
$first_name = escape_data($_POST['first_name']);
$last_name = escape_data($_POST['last_name']);

// For guest orders, need name & address info for shipping
$guest = $user_id == 0 ? 'guest' : '';
$address_street = escape_data($_POST['address_street']);
$address_city = escape_data($_POST['address_city']);
$address_state = escape_data($_POST['address_state']);
$address_zip = escape_data($_POST['address_zip']);

以及将部分退款数据发布到 PayPal 的函数:

function PPHttpPost($methodName_, $nvpStr_, $env) {
global $live;
// Set up your API credentials, PayPal end point, and API version.


if("sandbox" === $env)
$API_Endpoint = "https://api-3t.$env.paypal.com/nvp";
else
$API_Endpoint = "https://api-3t.paypal.com/nvp";

$version = urlencode('122');

// 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;
}

最后,当用户发起部分退款时调用上述函数的页面代码:

if ($live === false) $env = "sandbox";

// Set request-specific fields.
$item = urlencode($refund_detail['item']);
$amount = urlencode($refund_detail['cost']);
$inventory_num = urlencode($order_detail_id_for_refund);
$transactionID = urlencode($refund_detail['paypal_txn_id']);
$refundType = urlencode('Partial'); // or 'Partial'
$memo = urlencode("Refund of ".$refund_detail['item']); // required if Partial.
$currencyID = urlencode('USD'); // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

// Add request-specific fields to the request string.
$nvpStr = "&L_INVOICEITEMNAME0=$item&L_SKU0=$inventory_num&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.');
}
}

我的客户需要能够在网站上处理部分退款,因此我们将不胜感激向正确方向提出的任何建议或建议。我搜索了 Stackoverflow 和 Google 以获取更多信息,但无济于事。谢谢。

最佳答案

迈克,

payment_status = Refunded txn 将有一个 parent_txn_id 字段,其中包含“部分”退款的交易值。

假设您已将原始付款存储在数据库中,IPN 监听器可以查找原始交易并将该记录中的 mc_gross 与当前 IPN txn 中的相同字段进行比较。如果不同,则为“部分”退款。

关于paypal - 通过 PayPal RefundTransaction NVP API 发放部分退款后,IPN 监听器仅显示付款状态为 "Refunded,"而不是 "Partially_Refunded",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32448440/

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