Ejemplo n.º 1
0
 function ePayCreateProfile1($orderInfo, $credit_info, $params = array())
 {
     ini_set('max_execution_time', '180');
     // Now proceed the Recurring payment plan creation;
     // Load Basic Information;
     $result = array();
     $db = oseDB::instance();
     $user_id = $orderInfo->user_id;
     $msc_id = $orderInfo->entry_id;
     $order_id = $orderInfo->order_id;
     $order_number = $orderInfo->order_number;
     $orderInfoParams = oseJson::decode($orderInfo->params);
     $desc = parent::generateDesc($order_id);
     $billingInfo = parent::getBillingInfo($orderInfo->user_id);
     $taxRate = isset($orderInfoParams->tax_rate) ? $orderInfoParams->tax_rate : 0;
     $currency = $orderInfo->payment_currency;
     $user =& JFactory::getUser($orderInfo->user_id);
     $app =& JFactory::getApplication();
     $currentSession = JSession::getInstance('none', array());
     $stores = $currentSession->getStores();
     $Itemid = parent::getItemid();
     $config = oseMscConfig::getConfig('', 'obj');
     $cc_methods = explode(',', $config->cc_methods);
     if (!in_array('ePay', $cc_methods) || $config->enable_cc == false) {
         return self::getErrorMessage('cc', '0003', null);
     }
     $pConfig = $config;
     //oseRegistry::call('msc')->getConfig('payment', 'obj');
     if (!isset($pConfig->ePay_testmode) || $pConfig->ePay_testmode == true) {
         $test_mode = true;
         $ePayCustomerID = '87654321';
         $ePayUsername = '******';
         $ePayPassword = '******';
     } else {
         $test_mode = false;
         $ePayCustomerID = $pConfig->ePayCustomerID;
         $ePayUsername = $pConfig->ePayUsername;
         $ePayPassword = $pConfig->ePayPassword;
         if (empty($ePayCustomerID) || empty($ePayUsername)) {
             return self::getErrorMessage('cc', '0001', null);
         }
     }
     // Assign Values;
     $refID = substr($order_number, 0, 19) . "A";
     $invoice = substr($order_number, 0, 19) . "A";
     $name = "MEM{$msc_id}UID{$user_id}_" . date("Ymdhis");
     // Credit Card Informaiton;
     $creditcard = $credit_info["creditcard_number"];
     $cardCode = $credit_info["creditcard_cvv"];
     $expiration = $credit_info["creditcard_expirationdate"];
     $expiration = strval($expiration);
     // Recurring payment setting;
     $msc = oseRegistry::call('msc');
     //oseExit($mscTrialRecurrence);
     $initStartDate = date("d/m/Y", strtotime("+ 1 day"));
     $initAmount = $orderInfo->payment_price;
     $recurAmount = $orderInfoParams->next_total;
     $totalOccurrences = 9999;
     /// Finished getting all necessary Information;///
     /// Start Creating Subscription Plans ;
     // Check if Price is set correctly;
     if (empty($recurAmount)) {
         return self::getErrorMessage('cc', '0002');
     }
     // First time charge for those does not support initial payments;
     // SUITABLE HERE - ePay;
     $result = self::ePayOneOffPay($orderInfo, $credit_info, $params, $TransactionType = 'AUTH_CAPTURE', true);
     if ($result['ePayTrxnStatus'] == false) {
         return self::getErrorMessage('cc', '0000', $result['ePayTrxnError']);
     }
     if (!empty($orderInfoParams->has_trial)) {
         $trialOccurrences = "1";
         $mscTrialRecurrence = self::TranslateInterval($orderInfoParams->t1, $orderInfoParams->p1);
         $recurStartDate = date("d/m/Y", strtotime("+ {$mscTrialRecurrence['length']} {$mscTrialRecurrence['unit']}"));
         $mscRegRecurrence = self::TranslateInterval($orderInfoParams->t3, $orderInfoParams->p3);
     } else {
         $trialOccurrences = "0";
         $mscRegRecurrence = self::TranslateInterval($orderInfoParams->t3, $orderInfoParams->p3);
         $recurStartDate = date("d/m/Y", strtotime("+ {$mscRegRecurrence['length']} {$mscRegRecurrence['unit']}"));
     }
     // Start creating profiles;
     $postVar = array();
     $postVar['CustomerRef'] = $user->id;
     //$postVar['ePayTotalAmount']= $taxRate / 100 * $recurAmount+ $recurAmount;
     //oseExit($billingInfo);
     if (!empty($billingInfo->firstname)) {
         $postVar['CustomerFirstName'] = substr($billingInfo->firstname, 0, 50);
         $postVar['CustomerLastName'] = substr($billingInfo->lastname, 0, 50);
     } else {
         $customerName = explode(' ', $credit_info["creditcard_name"]);
         $postVar['CustomerFirstName'] = substr($customerName[0], 0, 50);
         $postVar['CustomerLastName'] = substr($customerName[count($customerName) - 1], 0, 50);
     }
     $postVar['CustomerEmail'] = $billingInfo->email;
     $postVar['CustomerAddress'] = substr($billingInfo->addr1, 0, 50);
     $postVar['CustomerPostcode'] = substr(str_replace(" ", "", $billingInfo->postcode), 0, 6);
     $postVar['CustomerState'] = substr($billingInfo->state, 0, 50);
     $postVar['CustomerCountry'] = substr($billingInfo->country, 0, 20);
     $creditCardExpiryDate = $credit_info["creditcard_expirationdate"];
     $creditCardExpiryDate = explode("-", strval($creditCardExpiryDate));
     $postVar['RebillCCName'] = substr($credit_info["creditcard_name"], 0, 50);
     $postVar['RebillCCNumber'] = substr($credit_info["creditcard_number"], 0, 19);
     $postVar['RebillCCExpMonth'] = substr($creditCardExpiryDate[1], 0, 2);
     $postVar['RebillCCExpYear'] = substr($creditCardExpiryDate[0], 0, 4);
     $postVar['RebillInvRef'] = $refID;
     $postVar['RebillInvDesc'] = '';
     $postVar['RebillInitAmt'] = 0;
     $postVar['RebillInitDate'] = $initStartDate;
     $postVar['RebillRecurAmt'] = intval(($taxRate / 100 * $recurAmount + $recurAmount) * 100);
     $postVar['RebillStartDate'] = $recurStartDate;
     $postVar['RebillInterval'] = $mscRegRecurrence['length'];
     $postVar['RebillIntervalType'] = $mscRegRecurrence['IntervalType'];
     $postVar['RebillEndDate'] = date("d/m/Y", strtotime("+ 3 years"));
     $resArray = self::ePayRebillAPIConnect($ePayCustomerID, $ePayUsername, $ePayPassword, $test_mode, $postVar, true);
     if ($resArray['Result'] == 'Success') {
         $params['payment_serial_number'] = $refID;
         $params['payment_method'] = 'ePay';
         $return = self::confirmOrder($order_id, $params);
         return $return;
     } else {
         $params['payment_serial_number'] = $refID;
         $params['payment_mode'] = 'm';
         $params['payment_method'] = 'ePay';
         //$return = self:: confirmOrder($order_id, $params );
         return self::getErrorMessage('cc', '0004', $resArray['ErrorDetails']);
     }
 }