/** * Get list of plan_id of all items purchased simultaneously * * @param cbpaidPaymentBasket $paymentBasket * @return array of int planids array( plan_id => quantity ) */ public static function getPlansQuantityofBasket( $paymentBasket ) { $sameTimePurchasingPlansIds = array(); foreach ( $paymentBasket->loadPaymentItems() as $item ) { if ( ! isset( $sameTimePurchasingPlansIds[$item->plan_id] ) ) { $sameTimePurchasingPlansIds[$item->plan_id] = 0; } $sameTimePurchasingPlansIds[$item->plan_id] += $item->quantity; } return $sameTimePurchasingPlansIds; }
/** * Extends the XML invoice address in params * * @param SimpleXMLElement $param * @param PluginTable $pluginObject * @param cbpaidPaymentBasket $paymentBasket (the data being displayed) * @param boolean $isSaving * @return SimpleXMLElement */ public function onxmlBeforeCbSubsDisplayOrSaveInvoice( /** @noinspection PhpUnusedParameterInspection */ $param, $pluginObject, $paymentBasket, $isSaving ) { global $_CB_framework, $_PLUGINS; $paymentItems = $paymentBasket->loadPaymentItems(); $taxableTotalizers = $paymentBasket->loadPaymentTotalizers(); $_PLUGINS->loadPluginGroup( 'user/plug_cbpaidsubscriptions/plugin/cbsubstax/validations', null, ( $_CB_framework->getUi() == 2 ? 0 : 1 ) ); $taxRulesRates = cbpaidPaymentTotalizer_salestax::getApplicableRatesWithoutBusinessCheck( $paymentBasket, $paymentItems, $taxableTotalizers ); $fromXml = array(); foreach ( $taxRulesRates as $AllTaxRates ) { foreach ( $AllTaxRates as $taxRate ) { //$taxRate = NEW cbpaidsalestaxTotalizertype(); $business_check = $taxRate->business_check; if ( $business_check ) { $absoluteValidationsPath = $_CB_framework->getCfg('absolute_path') . '/'. $_PLUGINS->getPluginRelPath( $pluginObject ) . '/plugin/cbsubstax/validations/' . $business_check; $valphp = $absoluteValidationsPath . '/validation.php'; if ( is_readable( $valphp ) ) { /** @noinspection PhpIncludeInspection */ include_once $valphp; // $className = 'cbpaidValidate_' . $tax->business_check; } $fromFile = $absoluteValidationsPath . '/xml/edit.invoice.xml'; if ( is_readable( $fromFile ) ) { $fromRoot = new SimpleXMLElement( $fromFile, LIBXML_NONET | ( defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0 ), true ); $fromXml = array_merge( $fromXml, $fromRoot->xpath( '/*/editinvoicevalidationintegration/*' ) ); } } } } return $fromXml; }
/** * Handles changes of payment basket $paymentBasket payment statuses events * This function may be called more than one time for events different than the Completed or Processed state if there are multiple notifications * * $unifiedStatus status mappings with e.g. Paypal status: * CB Unified status Paypal status * Completed <-- Completed * Processed <-- Processed, Canceled_Reversal * Denied <-- Denied, Expired, Failed, Voided * Refunded <-- Reversed, Refunded, Partially-Refunded * Pending <-- Pending, In-Progress * RegistrationCancelled <-- A new cb registration got cancelled by user (e.g. paypal cancel payment button) * * @param UserTable $user User paying * @param cbpaidPaymentBasket $paymentBasket CBPaid Payment basket being paid (corresponding to PayPal variable names) * @param cbpaidUsersubscriptionRecord[] $subscriptions CBPay Subscriptions being paid * @param string $unifiedStatus new unified status: see above * @param string $previousUnifiedStatus previous unified status: see above * @param string $eventType type of event (paypal type): 'web_accept', 'subscr_payment', 'subscr_signup', 'subscr_modify', 'subscr_eot', 'subscr_cancel', 'subscr_failed' * @param cbpaidPaymentNotification $notification notification object of the payment * @return void */ public function onCPayAfterPaymentStatusUpdateEvent( $user, $paymentBasket, /** @noinspection PhpUnusedParameterInspection */ $subscriptions, $unifiedStatus, /** @noinspection PhpUnusedParameterInspection */ $previousUnifiedStatus, /** @noinspection PhpUnusedParameterInspection */ $eventType, /** @noinspection PhpUnusedParameterInspection */ $notification ) { global $_CB_framework, $_SERVER; if ( ! is_object( $user ) ) { return; } if ( ! in_array( $unifiedStatus, array( 'Completed', 'Processed' ) ) ) { return; } $params = cbpaidApp::settingsParams(); $trackingCode = trim( $params->get( 'googleanalytics_trackingcode', null ) ); if ( ! $trackingCode ) { return; } $isHttps = ( isset( $_SERVER['HTTPS'] ) && ( ! empty( $_SERVER['HTTPS'] ) ) && ( $_SERVER['HTTPS'] != 'off' ) ); $_CB_framework->document->addHeadScriptUrl( ( $isHttps ? 'https://ssl.' : 'http://www.' ) . 'google-analytics.com/ga.js' ); $domainName = trim( $params->get( 'googleanalytics_domainname', null ) ); $js = "var _gaq = _gaq || [];" . "_gaq.push(['_setAccount', '" . addslashes( $trackingCode ) . "']);"; if ( $domainName ) { $js .= "_gaq.push(['_setDomainName', '" . addslashes( $domainName ) . "']);" . ( $domainName != 'none' ? "_gaq.push(['_setAllowHash', false]);" : null ); } $js .= "_gaq.push(['_trackPageview']);" . "_gaq.push(['_addTrans'," . "'" . addslashes( $paymentBasket->item_number ) . "'," // Order ID . "'Community Builder'," // Affiliation . "'" . addslashes( $paymentBasket->mc_gross ) . "'," // Total . "'" . addslashes( $paymentBasket->tax ) . "'," // Tax . "'" . addslashes( $paymentBasket->mc_shipping ) . "'," // Shipping . "'" . addslashes( $paymentBasket->address_city ) . "'," // City . "'" . addslashes( $paymentBasket->address_state ) . "'," // State . "'" . addslashes( $paymentBasket->address_country ) . "'" // Country . "]);"; $paymentItems = $paymentBasket->loadPaymentItems(); if ( $paymentItems ) foreach ( $paymentItems as $item ) { $subscription = $item->loadSubscription(); $plan = $subscription->getPlan(); $js .= "_gaq.push(['_addItem'," . "'" . addslashes( $paymentBasket->item_number ) . "'," // Order ID . "'" . addslashes( $item->id ) . "'," // SKU . "'" . addslashes( $plan->name ) . "'," // Product Name . "'" . addslashes( $plan->item_type ) . "'," // Category . "'" . addslashes( $item->getPrice() ) . "'," // Price . "'" . addslashes( $item->quantity ) . "'" // Quantity . "]);"; } $js .= "_gaq.push(['_trackTrans']);"; $_CB_framework->outputCbJQuery( $js ); }