/** * Updates the payment item corresponding to this Something * * @param cbpaidPaymentItem $item * @param cbpaidPaymentBasket $paymentBasket * @param int $quantity Quantity * @param string $currency_code The currency of the payment basket (so the payment item must be converted into that currency * @return void */ public function updatePaymentItem( &$item, $paymentBasket , $quantity = null, $currency_code = null ) { $item->callIntegrations( 'beforeUpdatePaymentItem', $this, $paymentBasket ); if ( $quantity === null ) { $quantity = $item->quantity; } if ( $currency_code === null ) { $currency_code = $item->currency; } $reason = $item->reason; $tryAutorecurring = $item->autorecurring; $start_time = strtotime( $item->start_date ); list( $first_rate, /* $first_validity */, $rate, /* $validity */, $prorate_discount, /* $autorecurring */, /* $recurring_max_times */ ) = $this->computeItemRatesAndValidity( $quantity, $currency_code, $reason, $start_time, $tryAutorecurring ); if ( $first_rate !== false ) { $item->quantity = $quantity; $item->currency = $currency_code; $item->first_rate = $first_rate; $item->rate = $rate; $item->prorate_discount = $prorate_discount; } $item->callIntegrations( 'afterUpdatePaymentItem', $this, $paymentBasket ); }
/** * Updates the payment item corresponding to this Something * * @param cbpaidPaymentItem $item * @param cbpaidPaymentBasket $paymentBasket * @param int $quantity Quantity * @param string $currency_code The currency of the payment basket (so the payment item must be converted into that currency * @return void */ public function updatePaymentItem( &$item, $paymentBasket, $quantity = null, $currency_code = null ) { $item->callIntegrations( 'beforeUpdatePaymentItem', $this, $paymentBasket ); if ( $quantity === null ) { $quantity = $item->quantity; } if ( $currency_code === null ) { $currency_code = $item->currency; } $start_time = strtotime( $item->start_date ); $rate = $this->getPriceOfNextPayment( $currency_code, $start_time, $quantity, $item->reason ); if ( $rate === false ) { $rate = 0; } $item->currency = $currency_code; $item->rate = $rate; $item->quantity = $quantity; $item->callIntegrations( 'afterUpdatePaymentItem', $this, $paymentBasket ); }
/** * get the most recent payment basket for that user and plan, and with that subscription * * @param string $paymentStatus NULL: search any kind, 'NotInitiated': search only not initiated baskets which is not to old, string: search for particular status. * @return cbpaidPaymentItem or false */ public function & loadLatestPaymentItem( $paymentStatus = null ) { global $_CB_database; $paymentItem = new cbpaidPaymentItem( $_CB_database ); if ( $paymentItem->loadLatestPaymentItemOfUserPlanSubscription( $this->user_id, $this->plan_id, $this->id, $paymentStatus ) ) { return $paymentItem; } else { $false = false; return $false; } }
/** * loads and returns the cbpaidPaymentItem's of this cbPaymentBasket * they are cached into $this->_paymentItems as array of cbpaidPaymentItem * * @return cbpaidPaymentItem[] */ public function & loadPaymentItems() { global $_CB_database, $_PLUGINS; if ( $this->_paymentItems === null ) { $_PLUGINS->loadPluginGroup( 'user', 'cbsubs.' ); $_PLUGINS->loadPluginGroup('user/plug_cbpaidsubscriptions/plugin'); $sampleItem = new cbpaidPaymentItem( $_CB_database ); $this->_paymentItems = $sampleItem->loadThisMatchingList( array( 'payment_basket_id' => (int) $this->id ), array( 'ordering' => 'ASC' ) ); // foreach ( $this->_paymentItems as $item ) { // $sub->loadPlan(); // not yet needed, so don't do it yet. // } } return $this->_paymentItems; }
/** * Integration when a new payment item is added to a basket * * @param string $event * @param cbpaidSomething $something * @param cbpaidPaymentBasket|null $paymentBasket * @param cbpaidPaymentItem $paymentItem */ public function onCPayPaymentItemEvent( $event, /** @noinspection PhpUnusedParameterInspection */ $something, /** @noinspection PhpUnusedParameterInspection */ $paymentBasket, $paymentItem ) { if ( $event == 'addSomethingToBasket' ) { $tax_rule = (int) $paymentItem->getPlanParam( 'tax_rule_id', 0, null ); if ( $tax_rule == 0 ) { $tax_rule = (int) cbpaidTaxRule::getDefaultTaxRuleId(); } $paymentItem->tax_rule_id = $tax_rule; } }