コード例 #1
0
	/**
	 * Create a payment item for a payment basket to be created
	 *
	 * @param  int                          $quantity          Quantity
	 * @param  string                       $currency_code     The currency of the payment basket (so the payment item must be converted into that currency
	 * @param  string                       $artNumber         Text for the article number
	 * @param  string                       $prefixText        Text to prefix before the item descriptions								//TBD this should be on a per-item basis
	 * @param  string                       $reason            payment reason: 'N'=new subscription (default), 'R'=renewal, 'U'=update
	 * @param  int                          $now               unix time of now (single now time for consistency in db)
	 * @param  boolean                      $tryAutorecurring  try to build the payment basket as autorecurring
	 * @return cbpaidPaymentItem                               return FALSE if can't be purchased/subscribed
	 */
	public function & createPaymentItem( $quantity, $currency_code, $artNumber, $prefixText, $reason, $now, $tryAutorecurring ) {
		$item						=	new cbpaidPaymentItem( $this->_db );

		$item->callIntegrations( 'beforeCreatePaymentItem', $this, null );

		$bonustime					=	$this->getPlanAttribute( 'bonustime' );
		$planId						=	$this->plan_id;
		// $expiryTime				=	$this->computeExpiryTimeIfActivatedNow( $now, $reason );			//$this->expiry_date : this value is NULL at this stage here, so of no real use...
		// $expiry_date				=	( $expiryTime === null ? null : date( 'Y-m-d H:i:s', $expiryTime ) );
		$startTime					=	$this->computeStartTimeIfActivatedNow( $now, $reason );
		$start_date					=	date( 'Y-m-d H:i:s', $startTime );

		list( $first_rate, $first_validity, $rate, $validity, $prorate_discount, $autorecurring, $recurring_max_times )	=	$this->computeItemRatesAndValidity( $quantity, $currency_code, $reason, $now, $tryAutorecurring );

		if ( $first_rate === false ) {
			$false					=	false;
			return $false;
		}

		$stopTime					=	$this->computeExpiryTimeIfActivatedNow( $now, $reason, 1 );
		$stop_date					=	$stopTime ? date( 'Y-m-d H:i:s', $stopTime ) : '0000-00-00 00:00:00';
		$secondStopTime				=	$this->computeExpiryTimeIfActivatedNow( $now, $reason, 2 );
		$second_stop_date			=	$secondStopTime ? date( 'Y-m-d H:i:s', $secondStopTime ) : '0000-00-00 00:00:00';

		// build item description line, default:	[ITEM_ALIAS]	and		[PREFIX_TEXT] [PLANS_TITLE]: [ITEM_NAME][VALIDITY_IF_NOT_AUTORECURRING] for [USERNAME]
		cbimport( 'cb.tabs' );					// cbFormatDate needs this and cbreplaceVars too
		$extraStrings				=	$this->substitutionStringsForItemDetailed( false, $reason, $autorecurring );

		$cbUser						=	CBuser::getInstance( $this->user_id );
		$itemDescription			=	$cbUser->replaceUserVars( CBPTXT::T( $this->getPlanAttribute( 'item_text' ) ), false, false, $extraStrings, false );
		$itemAlias					=	$cbUser->replaceUserVars( CBPTXT::T( $this->getPlanAttribute( 'item_alias' ) ), false, false, $extraStrings, false );

		$item->createItem(	'usersubscription',
			$quantity,
			$artNumber,
			$itemDescription,
			$itemAlias,
			$currency_code,
			$rate,
			$this->getPlanAttribute( 'owner' ),
			$reason
		);
		$item->setSubscriptionVars(	$this->id, $planId,
			$validity, $start_date, $stop_date, $second_stop_date,
			$autorecurring, $recurring_max_times,
			$first_rate, $first_validity, $bonustime,
			$prorate_discount
		);

		$item->callIntegrations( 'afterCreatePaymentItem', $this, null );

		return $item;
	}
コード例 #2
0
	/**
	 * Create a payment item for a payment basket to be created
	 *
	 * @param  int                          $quantity          Quantity
	 * @param  string                       $currency_code     The currency of the payment basket (so the payment item must be converted into that currency
	 * @param  string                       $artNumber         Text for the article number
	 * @param  string                       $prefixText        Text to prefix before the item descriptions								//TBD this should be on a per-item basis
	 * @param  string                       $reason            payment reason: 'N'=new subscription (default), 'R'=renewal, 'U'=update
	 * @param  int                          $now               unix time of now (single now time for consistency in db)
	 * @param  boolean                      $tryAutorecurring  try to build the payment basket as autorecurring
	 * @return cbpaidPaymentItem                               return FALSE if can't be purchased/subscribed
	 */
	public function & createPaymentItem( $quantity, $currency_code, $artNumber, $prefixText, $reason, $now, $tryAutorecurring ) {
		$item						=	new cbpaidPaymentItem( $this->_db );

		$item->callIntegrations( 'beforeCreatePaymentItem', $this, null );

		$planId						=	$this->plan_id;
		$start_date					=	date( 'Y-m-d H:i:s', $now );
		$rate						=	$this->getPriceOfNextPayment( $currency_code, $now, $quantity, $reason );	// N=New, R=Renew + U = Upgrade
		if ( $rate === false ) {
			$false					=	false;
			return $false;
		}

		// build item description line, default:	[ITEM_ALIAS]	and		[PREFIX_TEXT] [PLANS_TITLE]: [ITEM_NAME][VALIDITY_IF_NOT_AUTORECURRING] for [USERNAME]
		cbimport( 'cb.tabs' );					// cbFormatDate needs this and cbreplaceVars too
		$extraStrings				=	$this->substitutionStringsForItemDetailed( false, $reason, false );

		$cbUser						=	CBuser::getInstance( $this->user_id );
		$itemDescription			=	$cbUser->replaceUserVars( CBPTXT::T( $this->getPlanAttribute( 'item_text' ) ), false, false, $extraStrings, false );
		$itemAlias					=	$cbUser->replaceUserVars( CBPTXT::T( $this->getPlanAttribute( 'item_alias' ) ), false, false, $extraStrings, false );

		$item->createItem(	strtolower( $this->recordName() ),
			$quantity,
			$artNumber,
			$itemDescription,
			$itemAlias,
			$currency_code,
			$rate,
			$this->getPlanAttribute( 'owner' ),
			$reason
		);

		$validity					=	'0000-00-00 00:00:00';
		$stop_date					=	'0000-00-00 00:00:00';
		$second_stop_date			=	'0000-00-00 00:00:00';
		$autorecurring				=	0;
		$recurring_max_times		=	0;
		$first_rate					=	null;
		$first_validity				=	null;
		$bonustime					=	'0000-00-00 00:00:00';
		$prorate_discount			=	0.0;
		$item->setSubscriptionVars(	$this->id, $planId,
			$validity, $start_date, $stop_date, $second_stop_date,
			$autorecurring, $recurring_max_times,
			$first_rate, $first_validity, $bonustime,
			$prorate_discount
		);

		$item->callIntegrations( 'afterCreatePaymentItem', $this, null );

		return $item;
	}