Deleted cancelURL (is this required?). Rewrote cancelSubscription.
authorLisa Marie Maginnis <lisam@fsf.org>
Wed, 23 Apr 2014 17:27:11 +0000 (13:27 -0400)
committerLisa Marie Maginnis <lisam@fsf.org>
Wed, 23 Apr 2014 17:27:11 +0000 (13:27 -0400)
trustcommerce.php

index 8731fc78409b3a952c2018c08fb31f37a11dde36..9fa3590ff100f9f7861ce66b94bbd172beabb0e2 100644 (file)
@@ -318,59 +318,19 @@ class org_fsf_payment_trustcommerce extends CRM_Core_Payment {
     }
   }
 
-  function cancelSubscriptionURL($entityID = NULL, $entity = NULL) {
-    if ($entityID && $entity == 'membership') {
-      require_once 'CRM/Contact/BAO/Contact/Utils.php';
-      $contactID = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $entityID, "contact_id");
-      $checksumValue = CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf');
-
-      return CRM_Utils_System::url('civicrm/contribute/unsubscribe',
-        "reset=1&mid={$entityID}&cs={$checksumValue}", TRUE, NULL, FALSE, FALSE
-      );
-    }
-
-    return ($this->_mode == 'test') ? 'https://test.authorize.net' : 'https://authorize.net';
-  }
-
   function cancelSubscription() {
-    $template = CRM_Core_Smarty::singleton();
+    $tc_params['custid'] = $this->_getParam('user_name');
+    $tc_params['password'] = $this->_getParam('password');
+    $tc_params['action'] = 'unstore';
+    $tc_params['billingid'] = CRM_Utils_Array::value('subscriptionId', $params);
 
-    $template->assign('subscriptionType', 'cancel');
+    $result = tclink_send($tc_params);
 
-    $template->assign('apiLogin', $this->_getParam('apiLogin'));
-    $template->assign('paymentKey', $this->_getParam('paymentKey'));
-    $template->assign('subscriptionId', $this->_getParam('subscriptionId'));
-
-    $arbXML = $template->fetch('CRM/Contribute/Form/Contribution/AuthorizeNetARB.tpl');
-
-    // submit to authorize.net
-    $submit = curl_init($this->_paymentProcessor['url_recur']);
-    if (!$submit) {
+    /* Test if call failed */
+    if(!$result) {
       return self::error(9002, 'Could not initiate connection to payment gateway');
     }
-
-    curl_setopt($submit, CURLOPT_RETURNTRANSFER, 1);
-    curl_setopt($submit, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
-    curl_setopt($submit, CURLOPT_HEADER, 1);
-    curl_setopt($submit, CURLOPT_POSTFIELDS, $arbXML);
-    curl_setopt($submit, CURLOPT_POST, 1);
-    curl_setopt($submit, CURLOPT_SSL_VERIFYPEER, 0);
-
-    $response = curl_exec($submit);
-
-    if (!$response) {
-      return self::error(curl_errno($submit), curl_error($submit));
-    }
-
-    curl_close($submit);
-
-    $responseFields = $this->_ParseArbReturn($response);
-
-    if ($responseFields['resultCode'] == 'Error') {
-      return self::error($responseFields['code'], $responseFields['text']);
-    }
-
-    // carry on cancelation procedure
+    /* We are done, pass success */
     return TRUE;
   }