问题描述
因此,我已经开始了这个小课程,以处理PayPal无效,退款和取消订阅的问题.我的问题是,推荐的做法是什么?我的意思是,我应该尝试使交易无效,然后忽略错误,然后退款,然后取消订阅吗?
So I've started this little class for doing PayPal voids, refunds, and subscription cancels. My question is, what's the recommended practice? I mean, should I attempt to void the transaction, then ignore error, then refund it, and then cancel the subscription?
请注意,在我的情况下,交易是通过单击PayPal订阅按钮开始的,然后在六个月的期限结束后重新进行一次交易,然后客户要求退款并停止进一步的订阅.
Note in my case, the transaction was started from a click on a PayPal Subscription button, and then it got renewed once after the 6 month period ended, and then the customer wanted a refund and to stop further subscriptions.
<?php
class Paypp {
public static function voidCard($r) {
$asData = array(
'METHOD' => 'DoVoid',
'AUTHORIZATIONID' => @ $r['paypal_txn_id'] // tnx_id from subscr_payment IPN
);
return self::_sendData($asData);
}
public static function cancelSubscription($r) {
$asData = array(
'METHOD' => 'ManageRecurringPaymentsProfileStatus',
'PROFILEID' => @ $r['paypal_subscr_profile_id'], // subscr_id from subscr_payment IPN
'ACTION' => 'cancel'
);
return self::_sendData($asData);
}
public static function refundCard($r) {
$asData = array(
'METHOD' => 'RefundTransaction',
'TRANSACTIONID' => @ $r['paypal_txn_id'],
'REFUNDTYPE' => 'full',
'CURRENCYCODE' => @ $r['currency'],
'AMT' => @ $r['gross']
);
return self::_sendData($asData);
}
private static function _sendData($asData) {
global $config;
$sActive = $config->PAYMENT_GATEWAY_DATA->pp->ACTIVE;
$sURL = $config->PAYMENT_GATEWAY_DATA->pp->$sActive->NVP_URL;
$sVersion = $config->PAYMENT_GATEWAY_DATA->pp->$sActive->NVP_VERSION;
$sUser = $config->PAYMENT_GATEWAY_DATA->pp->$sActive->NVP_USER;
$sPass = $config->PAYMENT_GATEWAY_DATA->pp->$sActive->NVP_PASS;
$sSig = $config->PAYMENT_GATEWAY_DATA->pp->$sActive->NVP_SIG;
$asExtra = array(
'VERSION' => $sVersion,
'USER' => $sUser,
'PWD' => $sPass,
'SIGNATURE' => $sSig
);
$asData = array_merge($asData,$asExtra);
$asOpt = array(
CURLOPT_HEADER => FALSE,
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POSTFIELDS => http_build_query($asData),
CURLOPT_VERBOSE => TRUE,
);
$hCurl = curl_init($sURL);
curl_setopt_array($hCurl, $asOpt);
$bVerifySSL = @ $config->VERIFY_SSL;
curl_setopt($hCurl, CURLOPT_SSL_VERIFYPEER, $bVerifySSL);
$sResponse = curl_exec($hCurl);
curl_close($hCurl);
return $sResponse;
}
} // end class
推荐答案
通过沙盒中的反复试验,我发现工作流程应该是:
Through trial and error in the sandbox, I found what the workflow should be:
-
跳过空白.根据贝宝(PayPal)代表的说法:无效仅对授权和订单有效,您无法通过订阅创建任何内容."
Skip void. According to a PayPal rep: "Voids are only valid for authorizations and orders, and you can't create either through a subscription."
是的,退款.它再次运行txn_id,这对于您在订阅过程中收到的每个subscr_payment是唯一的.因此,您只会退还您在IPN上收到的最新subscr_payment.
Yes, refund. It runs agains the txn_id, which is unique for every subscr_payment that you receive in the subscription process. So, you'll only refund the most recent subscr_payment you received on your IPN.
是的,取消订阅-仅退款不会为您完成这一步骤.
Yes, cancel subscription -- the refund alone won't do that step for you.
这篇关于带停止和退款订阅的PayPal NVP API的推荐做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!