What is the Recommended Practice on PayPal NVP API with Stopping and Refunding Subscriptions?

最后都变了- 提交于 2019-12-12 06:37:16

问题


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?

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

回答1:


Skip the void step. Voids are only valid for authorizations and orders, and you can't create either through a subscription. But yes, you'll need to cancel the subscription and refund the individual payments.




回答2:


Through trial and error in the sandbox, I found what the workflow should be:

  1. Skip void. According to a PayPal rep: "Voids are only valid for authorizations and orders, and you can't create either through a subscription."

  2. 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.

  3. Yes, cancel subscription -- the refund alone won't do that step for you.



来源:https://stackoverflow.com/questions/43901069/what-is-the-recommended-practice-on-paypal-nvp-api-with-stopping-and-refunding-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!