示例#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;
 }
示例#2
0
 function getFormFields($invoice)
 {
     $form_fields = array();
     $properties = $this->details->getProperties();
     $id = $properties['id']->getValue();
     $form_fields['sid'] = $properties['2co_account_id']->getValue();
     $form_fields['mode'] = '2CO';
     $form_fields['merchant_order_id'] = $invoice->getSID();
     $i = 1;
     $items = $invoice->getPropertyValue('items');
     $taxInfo = $invoice->getPropertyValue('tax_info');
     foreach ($items['products'] as $key => $product) {
         if ($product == -1) {
             $form_fields['li_' . $i . '_name'] = $items['custom_item'][$key];
         } else {
             $productInfo = $invoice->getItemValue($key);
             $form_fields['li_' . $i . '_name'] = $productInfo['name'];
             $form_fields['li_' . $i . '_product_id'] = $product;
             if ($invoice->isRecurring() && !empty($productInfo['recurring'])) {
                 $form_fields['li_' . $i . '_duration'] = 'Forever';
                 if (!empty($productInfo['period_name']) && $productInfo['period_name'] != 'unlimited') {
                     $period = $productInfo['period'] . " " . ucwords($productInfo['period_name']);
                     $form_fields['li_' . $i . '_recurrence'] = $period;
                 } else {
                     $form_fields['li_' . $i . '_recurrence'] = " Week";
                 }
             }
         }
         $form_fields['li_' . $i . '_type'] = 'product';
         if ($items['qty'][$key] > 0) {
             $form_fields['li_' . $i . '_quantity'] = 1;
             $form_fields['li_' . $i . '_price'] = sprintf('%.02f', $items['amount'][$key]);
             if ($taxInfo && !$taxInfo['price_includes_tax']) {
                 $form_fields['li_' . $i . '_price'] += SJB_TaxesManager::getTaxAmount($form_fields['li_' . $i . '_price'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
             }
         } else {
             $form_fields['li_' . $i . '_quantity'] = $items['qty'][$key];
             $form_fields['li_' . $i . '_price'] = sprintf('%.02f', $items['price'][$key]);
             if ($taxInfo && !$taxInfo['price_includes_tax']) {
                 $form_fields['li_' . $i . '_price'] += SJB_TaxesManager::getTaxAmount($form_fields['li_' . $i . '_price'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
             }
         }
         $form_fields['li_' . $i . '_tangible'] = 'N';
         $i++;
     }
     $user = SJB_UserManager::createTemplateStructureForCurrentUser();
     $form_fields['first_name'] = isset($user['FirstName']) ? $user['FirstName'] : '';
     $form_fields['last_name'] = isset($user['LastName']) ? $user['LastName'] : '';
     $form_fields['street_address'] = isset($user['Location']['Address']) ? $user['Location']['Address'] : '';
     $form_fields['city'] = isset($user['Location']['City']) ? $user['Location']['City'] : '';
     $form_fields['state'] = isset($user['Location']['State']) ? $user['Location']['State'] : '';
     $form_fields['zip'] = isset($user['Location']['ZipCode']) ? $user['Location']['ZipCode'] : '';
     $form_fields['country'] = isset($user['Location']['Country']) ? $user['Location']['Country'] : '';
     $form_fields['email'] = isset($user['email']) ? $user['email'] : '';
     $form_fields['phone'] = isset($user['PhoneNumber']) ? $user['PhoneNumber'] : '';
     $form_fields['x_receipt_link_url'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/callback/{$id}/{$invoice->getSID()}/";
     return $form_fields;
 }
 public function getFormFields()
 {
     if (is_null($this->formFields)) {
         $this->formFields = array();
         $items = $this->invoice->getPropertyValue('items');
         $taxInfo = $this->invoice->getPropertyValue('tax_info');
         if ($this->invoice->isRecurring()) {
             $i = 0;
             $this->formFields['notify_url'] = SJB_System::getSystemSettings('SITE_URL') . '/system/payment/notifications/' . self::GATEWAY_ID . '/';
             if (!empty($items['products'])) {
                 foreach ($items['products'] as $key => $product) {
                     $productInfo = $this->invoice->getItemValue($key);
                     if ($taxInfo) {
                         $productInfo['price'] += SJB_TaxesManager::getTaxAmount($productInfo['price'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
                     }
                     if (!empty($productInfo['recurring'])) {
                         $this->formFields['recurring'][$i] = $productInfo;
                     } else {
                         $this->formFields['products'][$i] = $productInfo;
                     }
                     $i += 1;
                 }
             }
         }
         $this->formFields['address'] = SJB_Request::getVar('address', false);
         $this->formFields['zip'] = SJB_Request::getVar('zip', false);
         $this->formFields['country'] = SJB_Request::getVar('country', false);
         $this->formFields['city'] = SJB_Request::getVar('city', false);
         $this->formFields['state'] = SJB_Request::getVar('state', false);
         $this->formFields['email'] = SJB_Request::getVar('email', false);
         $this->formFields['phone'] = SJB_Request::getVar('phone', false);
         $this->formFields['amount'] = SJB_Request::getVar('amount', false);
         $this->formFields['item_name'] = SJB_Request::getVar('item_name', false);
         $this->formFields['item_number'] = SJB_Request::getVar('item_number', false);
         $this->formFields['card_number'] = SJB_Request::getVar('card_number', false);
         $this->formFields['exp_date_mm'] = SJB_Request::getVar('exp_date_mm', false);
         $this->formFields['exp_date_yy'] = SJB_Request::getVar('exp_date_yy', false);
         $this->formFields['csc_value'] = SJB_Request::getVar('csc_value', false);
         $this->formFields['first_name'] = SJB_Request::getVar('first_name', false);
         $this->formFields['last_name'] = SJB_Request::getVar('last_name', false);
         $this->formFields['currency_code'] = SJB_Payment_PaypalProFillPaymentCard::getCurrencyCode();
     }
     return $this->formFields;
 }
示例#4
0
 public static function getTaxInfoByUserSidAndPrice($user_sid, $price)
 {
     $user = SJB_UserManager::getObjectBySID($user_sid);
     $location = $user->getPropertyValue('Location');
     $tax_info = SJB_TaxesManager::getTaxInfoByCountryAndState(SJB_Array::get($location, 'Country'), SJB_Array::get($location, 'State'));
     $empty_tax_info = array('sid' => '', 'tax_name' => '', 'price_includes_tax' => 0, 'tax_rate' => 0);
     $tax_info = array_merge($empty_tax_info, $tax_info);
     $tax_info['tax_amount'] = SJB_TaxesManager::getTaxAmount($price, $tax_info['tax_rate'], $tax_info['price_includes_tax']);
     return $tax_info;
 }
示例#5
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;
 }