/** * cancelSubscription($purchaseLog, $subscription) find the subscription and cancel it * TODO rewrite to be used as API * @param int $purchlogID */ function cancelSubscription($purchaseLog = false, $subscription = false) { if ($purchaseLog != false && $subscription != false) { $ref_id = $subscription['ref_id']; $subscription_id = $subscription['subscription_id']; $cancellation = new AuthorizeNetARB(); $cancellation->setRefId($ref_id); $cancel_response = $cancellation->cancelSubscription($subscription_id); if ($cancel_response->isOk()) { return true; } else { return false; } } else { return false; } }
function cancelsubscription($data) { $subid = $data['0']; $id = $data['1']; $gateway = $data['2']; $ad_id = $data['3']; $db = JFactory::getDBO(); if ($subid) { require_once dirname(__FILE__) . '/authorizenet/lib/AuthorizeNet.php'; $auth_net_login_id = $this->params->get('login_id', '1'); $auth_net_tran_key = $this->params->get('tran_key', '1'); $plgPaymentAuthorizenetHelper = new plgPaymentAuthorizenetHelper(); $auth_net_url = $plgPaymentAuthorizenetHelper->buildAuthorizenetUrl(); define("AUTHORIZENET_API_LOGIN_ID", $auth_net_login_id); define("AUTHORIZENET_TRANSACTION_KEY", $auth_net_tran_key); $refId = $id; // Cancel the subscription. $cancellation = new AuthorizeNetARB(); $cancellation->setRefId($refId); $response = $cancellation->cancelSubscription($subid); if ($response->xml->messages->resultCode != 'Ok') { $payment_status = "P"; $error = JText::_('AUTH_SUB_CANCEL_FAIL') . $response->xml->messages->message->text; } else { $payment_status = "C"; $success = JText::_('AUTH_SUB_CANCEL_SUCCESS'); $paymentdata = new stdClass(); } $result = array('transaction_id' => $refId, 'subscription_id' => $subid, 'order_id' => $data['order_id'], 'status' => $payment_status, 'total_paid_amt' => $data['amount'], 'raw_data' => $response, 'payment_type' => 'recurring', 'error' => $error, 'success' => $success, 'return' => $data['return']); return $result; } }
public function testCreateSubscriptionECheck() { $subscription = new AuthorizeNet_Subscription(); $subscription->name = "my test echeck subscription"; $subscription->intervalLength = "1"; $subscription->intervalUnit = "months"; $subscription->startDate = "2015-04-12"; $subscription->totalOccurrences = "2"; $subscription->trialOccurrences = ""; $subscription->amount = "11.99"; $subscription->trialAmount = ""; $subscription->bankAccountAccountType = "checking"; $subscription->bankAccountRoutingNumber = "121000248"; $subscription->bankAccountAccountNumber = "12345678"; $subscription->bankAccountNameOnAccount = "John Doe"; $subscription->bankAccountEcheckType = "WEB"; $subscription->bankAccountBankName = "Bank of Earth"; $subscription->orderInvoiceNumber = ""; $subscription->orderDescription = ""; $subscription->customerId = "12"; $subscription->customerEmail = "*****@*****.**"; $subscription->customerPhoneNumber = ""; $subscription->customerFaxNumber = ""; $subscription->billToFirstName = "john"; $subscription->billToLastName = "doe"; $subscription->billToCompany = ""; $subscription->billToAddress = ""; $subscription->billToCity = ""; $subscription->billToState = ""; $subscription->billToZip = ""; $subscription->billToCountry = ""; $subscription->shipToFirstName = ""; $subscription->shipToLastName = ""; $subscription->shipToCompany = ""; $subscription->shipToAddress = ""; $subscription->shipToCity = ""; $subscription->shipToState = ""; $subscription->shipToZip = ""; $subscription->shipToCountry = ""; $refId = "ref" . time(); // Create the request and send it. $request = new AuthorizeNetARB(); $request->setRefId($refId); $response = $request->createSubscription($subscription); // Handle the response. $this->assertTrue($response->isOk()); $this->assertEquals($response->getMessageCode(), "I00001"); $this->assertEquals($response->getMessageText(), "Successful."); $this->assertEquals($response->getRefId(), $refId); $this->assertEquals($response->getResultCode(), "Ok"); // Cancel the subscription to avoid duplicate errors in future $cancellation = new AuthorizeNetARB(); $cancellation->setRefId($refId); $cancel_response = $cancellation->cancelSubscription($response->getSubscriptionId()); $this->assertTrue($cancel_response->isOk()); }
/** *function to cancel the subscription of the recurring *@author Priti Kabra */ public function api_cancelMembership() { $errMsg = $this->checkApiHeaderInfo(); $error = !empty($errMsg) ? 1 : 0; if ($error == 0) { $userData = $this->User->find('first', array('conditions' => array('User.id' => $this->loggedInUserId, 'Subscription.is_active' => 1))); if (!empty($userData)) { $userGroups = $this->BusinessOwner->find('all', array('fields' => array('BusinessOwner.id', 'BusinessOwner.user_id, BusinessOwner.group_id, BusinessOwner.email, BusinessOwner.fname, BusinessOwner.lname, BusinessOwner.group_role', 'Group.id', 'Group.total_member', 'Group.group_leader_id'), 'conditions' => array('BusinessOwner.group_id' => $userData['BusinessOwners']['group_id']))); $request = new AuthorizeNetARB(); $response = $request->cancelSubscription($userData['Subscription']['subscription_id']); if ($response->xml->messages->message->text == 'Successful.') { $this->Subscription->updateAll(array('Subscription.is_active' => 0), array('Subscription.subscription_id' => $userData['Subscription']['subscription_id'])); $format = "both"; if ($userData['BusinessOwners']['group_role'] == 'participant') { $check = $this->participantCancelPlan($userData, $format); } else { if ($userData['BusinessOwners']['group_role'] == 'co-leader') { $check = $this->coLeaderCancelPlan($userGroups, $format); } else { $check = $this->leaderCancelPlan($userGroups, $format); } } $this->set(array('code' => Configure::read('RESPONSE_SUCCESS'), 'message' => 'Your request have been registered with FoxHopr', '_serialize' => array('code', 'message'))); } else { $this->set(array('code' => Configure::read('RESPONSE_SUCCESS'), 'message' => 'Your membership plan has already been cancelled', '_serialize' => array('code', 'message'))); } } else { $this->set(array('code' => Configure::read('RESPONSE_SUCCESS'), 'message' => 'Your membership plan has already been cancelled', '_serialize' => array('code', 'message'))); } } else { $this->errorMessageApi($errMsg); } }