Esempio n. 1
0
 /**
  * @param  $invoice SJB_Invoice
  * @return array
  */
 function getFormFields($invoice)
 {
     $form_fields = array();
     $properties = $this->details->getProperties();
     $id = $properties['id']->getValue();
     if ($invoice->isRecurring()) {
         // hard-coded fields
         $form_fields['cmd'] = '_xclick-subscriptions';
         $form_fields['notify_url'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/notifications/{$id}/";
         $form_fields['return'] = SJB_System::getSystemSettings('SITE_URL') . '/my-products/?subscriptionComplete=true';
         $form_fields['src'] = '1';
         $recurringProduct = array();
         $products = array();
         $items = $invoice->getPropertyValue('items');
         if (!empty($items['products'])) {
             foreach ($items['products'] as $key => $product) {
                 if ($product != -1) {
                     $productInfo = $invoice->getItemValue($key);
                     if (!empty($productInfo['recurring']) && !$recurringProduct) {
                         $recurringProduct = $productInfo;
                     }
                     $products[] = $productInfo;
                 }
             }
         }
         $taxInfo = $invoice->getPropertyValue('tax_info');
         if ($taxInfo && !$taxInfo['price_includes_tax']) {
             $recurringProduct['price'] += SJB_TaxesManager::getTaxAmount($recurringProduct['price'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
         }
         $product = new SJB_Product($recurringProduct, $recurringProduct['product_type']);
         if (count($products) > 1) {
             $form_fields['a1'] = $invoice->getPropertyValue('total');
             $form_fields['p1'] = $product->getExpirationPeriod();
             $form_fields['t1'] = 'D';
         }
         $form_fields['a3'] = $recurringProduct['price'];
         $form_fields['p3'] = $product->getExpirationPeriod();
         $form_fields['t3'] = 'D';
         $form_fields['custom'] = $recurringProduct['sid'];
         $form_fields['no_note'] = '1';
         $form_fields['no_shipping'] = '1';
     } else {
         // hard-coded fields
         $form_fields['cmd'] = '_xclick';
         $form_fields['amount'] = $invoice->getPropertyValue('total');
         $form_fields['return'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/callback/{$id}/{$invoice->getSID()}/";
         $form_fields['notify_url'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/callback/{$id}/{$invoice->getSID()}/";
     }
     $form_fields['cancel_return'] = SJB_System::getSystemSettings('SITE_URL') . "/my-account/";
     $form_fields['rm'] = 2;
     // POST method for call back
     // configuration fields
     $form_fields['business'] = $properties['paypal_account_email']->getValue();
     $form_fields['currency_code'] = $properties['currency_code']->getValue();
     // payment-related fields
     $form_fields['item_name'] = $invoice->getProductNames();
     $form_fields['item_number'] = $invoice->getSID();
     return $form_fields;
 }
Esempio n. 2
0
 function createSubscription($payment_data)
 {
     $validation_result = $this->validatePayment($payment_data);
     if ($validation_result !== true) {
         return $validation_result;
     }
     $properties = $this->details->getProperties();
     $api_login_id = $properties['authnet_api_login_id']->getValue();
     $transaction_key = $properties['authnet_api_transaction_key']->getValue();
     $use_test_account = $properties['authnet_use_test_account']->getValue();
     $invoice = SJB_InvoiceManager::getObjectBySID($payment_data['item_number']);
     if (empty($invoice)) {
         return;
     }
     $items = $invoice->getPropertyValue('items');
     $taxInfo = $invoice->getPropertyValue('tax_info');
     if (!empty($items['products'])) {
         foreach ($items['products'] as $key => $product) {
             if ($product != -1) {
                 $product_info = $invoice->getItemValue($key);
                 $payment_data['item_number'] = $invoice->getSID();
                 $payment_data['item_name'] = 'Payment for product ' . $product_info['name'];
                 $payment_data['x_description'] = 'Payment for product ' . $product_info['name'];
                 $payment_data['x_amount'] = $product_info['amount'];
                 if ($taxInfo && !$taxInfo['price_includes_tax']) {
                     $payment_data['x_amount'] += SJB_TaxesManager::getTaxAmount($payment_data['x_amount'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
                 }
                 $aimProcessor = new AuthnetAIMProcessor($api_login_id, $transaction_key, $use_test_account);
                 $aimProcessor->setTransactionType('AUTH_CAPTURE');
                 $aimProcessor->setParameter('x_login', $api_login_id);
                 $aimProcessor->setParameter('x_tran_key', $transaction_key);
                 $aimProcessor->setParameter('x_card_num', $payment_data['x_card_num']);
                 $aimProcessor->setParameter('x_amount', $payment_data['x_amount']);
                 $aimProcessor->setParameter('x_exp_date', $payment_data['x_exp_date']);
                 $aimProcessor->process();
                 if (!$aimProcessor->isApproved()) {
                     return array($aimProcessor->getResponseMessage());
                 }
                 $recurringID = null;
                 if (!empty($product_info['recurring'])) {
                     $product = new SJB_Product($product_info, $product_info['product_type']);
                     $expiration_period = $product->getExpirationPeriod();
                     $arbProcessor = new AuthnetARBProcessor($api_login_id, $transaction_key, $use_test_account);
                     $arbProcessor->setParameter('refID', $payment_data['item_number']);
                     $arbProcessor->setParameter('subscrName', $payment_data['x_description']);
                     $arbProcessor->setParameter('interval_length', $expiration_period);
                     $arbProcessor->setParameter('interval_unit', 'days');
                     $arbProcessor->setParameter('startDate', date("Y-m-d", strtotime("+ {$expiration_period} days")));
                     $arbProcessor->setParameter('totalOccurrences', 9999);
                     $arbProcessor->setParameter('trialOccurrences', 0);
                     $arbProcessor->setParameter('amount', $payment_data['x_amount']);
                     $arbProcessor->setParameter('trialAmount', 0.0);
                     $arbProcessor->setParameter('cardNumber', $payment_data['x_card_num']);
                     $arbProcessor->setParameter('expirationDate', $payment_data['x_exp_date']);
                     $arbProcessor->setParameter('orderInvoiceNumber', $payment_data['item_number']);
                     $arbProcessor->setParameter('orderDescription', $payment_data['x_description']);
                     $arbProcessor->setParameter('firstName', $payment_data['x_first_name']);
                     $arbProcessor->setParameter('lastName', $payment_data['x_last_name']);
                     $arbProcessor->setParameter('company', $payment_data['x_company']);
                     $arbProcessor->setParameter('address', $payment_data['x_address']);
                     $arbProcessor->setParameter('city', $payment_data['x_city']);
                     $arbProcessor->setParameter('state', $payment_data['x_state']);
                     $arbProcessor->setParameter('zip', $payment_data['x_zip']);
                     $arbProcessor->createAccount();
                     if (!$arbProcessor->isSuccessful()) {
                         return array($arbProcessor->getResponse());
                     }
                     $recurringID = $arbProcessor->getSubscriberID();
                 }
                 $user_sid = $invoice->getUserSID();
                 $listingNumber = $product_info['qty'];
                 $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $recurringID, 'gateway_id' => 'authnet_sim', 'numberOfListings' => $listingNumber));
                 $contract->setUserSID($user_sid);
                 $contract->setPrice($product_info['amount']);
                 if ($contract->saveInDB()) {
                     SJB_ShoppingCart::deleteItemFromCartBySID($product_info['shoppingCartRecord'], $user_sid);
                     $bannerInfo = $product_info['banner_info'];
                     if ($product_info['product_type'] == 'banners' && !empty($bannerInfo)) {
                         $bannersObj = new SJB_Banners();
                         $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $user_sid, $contract->getID());
                         $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                         SJB_AdminNotifications::sendAdminBannerAddedLetter($user_sid, $bannerGroup);
                     }
                     if ($contract->isFeaturedProfile()) {
                         SJB_UserManager::makeFeaturedBySID($user_sid);
                     }
                     if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                         SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $product_info);
                     }
                 }
             }
         }
         $invoice->setCallbackData($payment_data);
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
         SJB_InvoiceManager::saveInvoice($invoice);
         SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
     }
     return true;
 }
Esempio n. 3
0
 private function getCustomerInfoQueryForRecurring($data, $recurring = false)
 {
     $query = array();
     $expDateMonth = $data['exp_date_mm'];
     $padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT));
     if ($recurring == false) {
         if (!empty($data['products'])) {
             $dataArray = $data['products'];
         } else {
             return '';
         }
     } elseif (!empty($data['recurring'])) {
         $dataArray = $data['recurring'];
     } else {
         return '';
     }
     foreach ($dataArray as $key => $products) {
         $product = new SJB_Product($products, $products['product_type']);
         $expPeriod = $product->getExpirationPeriod();
         $customer = array('TOKEN' => '', 'CREDITCARDTYPE' => '', 'ACCT' => urlencode($data['card_number']), 'EXPDATE' => $padDateMonth . ($expDateYear = urlencode($data['exp_date_yy'])), 'FIRSTNAME' => urlencode($data['first_name']), 'LASTNAME' => urlencode($data['last_name']), 'PROFILESTARTDATE' => date('Y-n-d') . 'T' . date('G:i:s'), 'DESC' => urlencode($products['name']), 'BILLINGPERIOD' => urlencode('Day'), 'BILLINGFREQUENCY' => urlencode($expPeriod), 'CURRENCYCODE' => urlencode($data['currency_code']), 'AMT' => urlencode($products['price']), 'NOTIFYURL' => urlencode($data['notify_url']), 'ITEMNUMBER' => urlencode($data['item_number']), 'CUSTOM' => urlencode($products['sid']));
         if ($recurring === false) {
             $customer['TOTALBILLINGCYCLES'] = urlencode(1);
             if (empty($expPeriod)) {
                 $customer['BILLINGFREQUENCY'] = urlencode(30);
             }
         }
         $query[$key] = '&' . http_build_query($customer);
     }
     return $query;
 }
Esempio n. 4
0
 public static function updateExpirationPeriod($contractSID)
 {
     $contractInfo = self::getInfo($contractSID);
     if ($contractInfo) {
         $productInfo = SJB_ProductsManager::getProductInfoBySID($contractInfo['product_sid']);
         $product = new SJB_Product($productInfo, $productInfo['product_type']);
         $is_recurring = !empty($productInfo['is_recurring']) ? $productInfo['is_recurring'] : false;
         $expirationPeriod = $product->getExpirationPeriod();
         if ($expirationPeriod) {
             if ($is_recurring) {
                 // Для рекьюринг планов, делаем запас для проплаты в 1 день
                 $expirationPeriod++;
             }
             $expired_date = date("Y-m-d", strtotime("+" . $expirationPeriod . " day"));
             SJB_DB::query("UPDATE `contracts` SET `expired_date` = ?s WHERE `id` = ?n", $expired_date, $contractSID);
         }
     }
 }
Esempio n. 5
0
 function _constructorByProduct($productInfo)
 {
     $productSID = $productInfo['product_sid'];
     $numberOfListings = isset($productInfo['numberOfListings']) ? $productInfo['numberOfListings'] : false;
     $this->product_sid = $productSID;
     $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
     $is_recurring = !empty($productInfo['recurring']) ? $productInfo['recurring'] : false;
     if ($productInfo['product_type'] == 'featured_user') {
         $this->featured_profile = true;
     }
     $this->product_type = $productInfo['product_type'];
     $product = new SJB_Product($productInfo, $productInfo['product_type']);
     if ($numberOfListings) {
         $product->setNumberOfListings($numberOfListings);
     } else {
         $numberOfListings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 0;
     }
     $this->setNumberOfListings($numberOfListings);
     $expirationPeriod = $product->getExpirationPeriod();
     if ($expirationPeriod) {
         if ($is_recurring) {
             // Для рекьюринг планов, делаем запас для проплаты в 1 день
             $expirationPeriod++;
         }
         $this->expired_date = date("Y-m-d", strtotime("+" . $expirationPeriod . " day"));
     }
     $this->price = $product->getPrice();
 }