public function testGetSubscriptionList() { $refId = "ref" . time(); $paging = new AuthorizeNetSubscriptionListPaging(); $paging->limit = 10; $paging->offset = 1; $sorting = new AuthorizeNetSubscriptionListSorting(); $sorting->orderBy = "firstName"; $sorting->orderDescending = "false"; $getSubscriptionList = new AuthorizeNetGetSubscriptionList(); $getSubscriptionList->searchType = "subscriptionActive"; $getSubscriptionList->paging = $paging; $getSubscriptionList->sorting = $sorting; // Create the request and send it. $request = new AuthorizeNetARB(); $request->setRefId($refId); $response = $request->getSubscriptionList($getSubscriptionList); // 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"); }
/** * 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; } }
/** * web service used to update the credit card information of the logged in user * @author Priti Kabra */ public function api_updateCreditCard() { $errMsg = $this->checkApiHeaderInfo(); $error = !empty($errMsg) ? 1 : 0; if ($error == 0) { $conditions = array('Subscription.user_id' => $this->loggedInUserId, 'Subscription.is_active' => 1); $this->Subscription->bindModel(array('hasOne' => array('BusinessOwner' => array('className' => 'BusinessOwner', 'foreignKey' => false, 'conditions' => array('BusinessOwner.user_id = Subscription.user_id'))))); $subscripData = $this->Subscription->find('first', array('conditions' => $conditions)); if ($this->Subscription->hasAny($conditions)) { $subscription = new AuthorizeNet_Subscription(); $subscription->creditCardCardNumber = $this->jsonDecodedRequestedData->CC_Number; $subscription->creditCardExpirationDate = $this->jsonDecodedRequestedData->CC_year . '-' . $this->jsonDecodedRequestedData->CC_month; $subscription->creditCardCardCode = $this->jsonDecodedRequestedData->CC_cvv; $subscription->billToFirstName = $this->jsonDecodedRequestedData->CC_Name; $subscription->billToLastName = $this->jsonDecodedRequestedData->CC_Name; $request = new AuthorizeNetARB(); $response = $request->updateSubscription($subscripData['Subscription']['subscription_id'], $subscription); if ($response->xml->messages->resultCode == 'Ok') { $info['credit_card_number'] = substr($this->jsonDecodedRequestedData->CC_Number, -4, 4); $this->BusinessOwner->id = $this->Encryption->decode($subscripData['BusinessOwner']['id']); $this->BusinessOwner->saveField('credit_card_number', $this->Encryption->encode(substr($this->jsonDecodedRequestedData->CC_Number, -4, 4))); $this->set(array('code' => Configure::read('RESPONSE_SUCCESS'), 'result' => $info, 'message' => 'The credit card Information has been updated successfully', '_serialize' => array('code', 'result', 'message'))); } else { $this->errorMessageApi('Credit card cannot be updated for cancelled membership'); } } else { $this->set(array('code' => Configure::read('RESPONSE_SUCCESS'), 'message' => 'Credit card cannot be updated for cancelled membership', '_serialize' => array('code', 'message'))); } } else { $this->errorMessageApi($errMsg); } }
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 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; } }
private static function get_arb($local_api_settings = array()) { self::include_api(); $api_settings = self::get_api_settings($local_api_settings); $is_sandbox = $api_settings['mode'] == "test"; $arb = new AuthorizeNetARB($api_settings["login_id"], $api_settings["transaction_key"]); $arb->setSandbox($is_sandbox); return $arb; }
function process_subscription($item, $data, $config) { //Check for subscriptions $sub = array(); if (!defined('AUTHORIZENET_API_LOGIN_ID')) { define("AUTHORIZENET_API_LOGIN_ID", $config["x_login"]); define("AUTHORIZENET_TRANSACTION_KEY", $config["x_tran_key"]); } $unit = $item["subscription"]["period"] == 1 ? 'days' : 'months'; $member_id = $this->EE->session->userdata["member_id"]; $email = $this->EE->session->userdata["email"]; // Set the start date $start_dt = date('Y-m-d', strtotime('+' . $item["subscription"]["length"] . ' ' . $unit)); // Check if there is a trial subscription $price = $item["subscription"]["price"]; $renewal_price = $item["subscription"]["price"]; unset($item["subscription"]["price"]); $trial_occur = ""; $trial_price = ""; if ($item["subscription"]["trial_occur"] > 1) { // reduce the trial occurrences by one since we // already gave them the discount on the first // payment $occur = $item["subscription"]["trial_occur"] - 1; if ($occur >= 1) { #$renewal_price = $item["subscription"]["trial_price"]; $trial_occur = $occur; $trial_price = $item["subscription"]["trial_price"]; } } $subscription = new AuthorizeNet_Subscription(); $subscription->name = $item["title"]; $subscription->intervalLength = $item["subscription"]["length"]; $subscription->intervalUnit = $unit; $subscription->startDate = $start_dt; $subscription->totalOccurrences = 9999; $subscription->trialOccurrences = $trial_occur; $subscription->amount = $price; $subscription->trialAmount = $trial_price; $subscription->creditCardCardNumber = $data["autho_cc_num"]; $subscription->creditCardExpirationDate = $data["autho_cc_year"] . '-' . $data["autho_cc_month"]; $subscription->creditCardCardCode = $data["autho_cc_code"]; $subscription->orderInvoiceNumber = $data["order_id"]; $subscription->orderDescription = ""; $subscription->customerId = $member_id; $subscription->customerEmail = $email; $subscription->customerPhoneNumber = $data["br_billing_phone"]; $subscription->billToFirstName = $data["br_billing_fname"]; $subscription->billToLastName = $data["br_billing_lname"]; $subscription->billToCompany = $data["br_billing_company"]; $subscription->billToAddress = $data["br_billing_address1"] . ' ' . $data["br_billing_address2"]; $subscription->billToCity = $data["br_billing_city"]; $subscription->billToState = $data["br_billing_state"]; $subscription->billToZip = $data["br_billing_zip"]; $subscription->billToCountry = $data["br_billing_country"]; $subscription->shipToFirstName = $data["br_shipping_fname"]; $subscription->shipToLastName = $data["br_shipping_lname"]; $subscription->shipToCompany = $data["br_shipping_company"]; $subscription->shipToAddress = $data["br_shipping_address1"] . ' ' . $data["br_shipping_address2"]; $subscription->shipToCity = $data["br_shipping_city"]; $subscription->shipToState = $data["br_shipping_state"]; $subscription->shipToZip = $data["br_shipping_zip"]; $subscription->shipToCountry = $data["br_shipping_country"]; $refId = "ref" . time(); // Create the request and send it. $request = new AuthorizeNetARB(); // do we need to process in sandbox mode if (array_key_exists("x_test_request", $config) && $config["x_test_request"] == 'FALSE') { $request->setSandbox(FALSE); } $request->setRefId($refId); $response = $request->createSubscription($subscription); $item["subscription"]["code"] = (string) $response->xml->refId; $item["subscription"]["status_id"] = 1; $item["subscription"]["result"] = (string) $response->xml->messages->resultCode; $item["subscription"]["message"] = (string) $response->xml->messages->message->text; $item["subscription"]["subscription_id"] = (int) $response->xml->subscriptionId; $item["subscription"]["renewal_price"] = $renewal_price; $item["subscription"]["trial_occur"] = $trial_occur; $item["subscription"]["trial_price"] = $trial_price; $item["subscription"]["next_renewal"] = $start_dt; $item["subscription"]["cc_last_four"] = substr($data["autho_cc_num"], -4, 4); $item["subscription"]["cc_month"] = $data["autho_cc_month"]; $item["subscription"]["cc_year"] = $data["autho_cc_year"]; return $item["subscription"]; }
/** *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); } }
private function get_arb($local_api_settings = array()) { if (!empty($local_api_settings)) { $this->log_debug(__METHOD__ . '(): Local API settings enabled.'); $api_settings = array('login_id' => rgar($local_api_settings, 'login_id'), 'transaction_key' => rgar($local_api_settings, 'transaction_key'), 'mode' => rgar($local_api_settings, 'mode')); } else { $api_settings = $this->get_api_settings($local_api_settings); } $this->include_api(); $is_sandbox = $api_settings['mode'] == 'test'; $arb = new AuthorizeNetARB($api_settings['login_id'], $api_settings['transaction_key']); $arb->setSandbox($is_sandbox); return $arb; }
public function handle_expiration($payment) { if (!class_exists('AuthorizeNetAIM')) { require_once WPBDP_PATH . 'vendors/anet_php_sdk/AuthorizeNet.php'; } $recurring = $payment->get_recurring_item(); $listing = WPBDP_Listing::get($payment->get_listing_id()); if (!$listing || !$recurring) { return; } $recurring_id = $payment->get_data('recurring_id'); $arb = new AuthorizeNetARB(wpbdp_get_option('authorize-net-login-id'), wpbdp_get_option('authorize-net-transaction-key')); if (wpbdp_get_option('payments-test-mode')) { $arb->setSandbox(true); } else { $arb->setSandbox(false); } $response = $arb->getSubscriptionStatus($recurring_id); $status = $response->isOk() ? $response->getSubscriptionStatus() : ''; if ('active' == $status) { // If subscription is active, renew automatically for another period. $term_payment = $payment->generate_recurring_payment(); $term_payment->set_status(WPBDP_Payment::STATUS_COMPLETED, WPBDP_Payment::HANDLER_GATEWAY); $term_payment->save(); } else { // If subscription is not active, make item non recurring so it expires normally next time. $recurring_item = $payment->get_recurring_item(); $listing->make_category_non_recurring($recurring_item->rel_id_1); } }
/** * Initializes and returns AuthorizeNetARB object. * * @since 3.5 * * @access protected * @return AuthorizeNetARB The instance of AuthorizeNetARB class. */ protected function _get_arb() { require_once MEMBERSHIP_ABSPATH . '/classes/Authorize.net/AuthorizeNet.php'; // merchant information $login_id = $this->_get_option('api_user'); $transaction_key = $this->_get_option('api_key'); $mode = $this->_get_option('mode', self::MODE_SANDBOX); $arb = new AuthorizeNetARB($login_id, $transaction_key); $arb->setSandbox($mode != self::MODE_LIVE); if (defined('MEMBERSHIP_AUTHORIZE_LOGFILE')) { $arb->setLogFile(MEMBERSHIP_AUTHORIZE_LOGFILE); } return $arb; }