コード例 #1
0
	/**
	 * Returns substitution strings
	 *
	 * @see cbpaidSomething::substitutionStrings()
	 *
	 * @param  boolean  $html                              HTML or TEXT return
	 * @param  boolean  $runContentPluginsIfAllowedByPlan  DEFAULT: TRUE
	 * @return array
	 */
	public function substitutionStrings( $html, $runContentPluginsIfAllowedByPlan = true ) {
		$reason										=	$this->status == 'C' ? 'N' : 'R';
		$autorecurring								=	false;
		$strings									=	array_merge( parent::substitutionStrings( $html, $runContentPluginsIfAllowedByPlan ), $this->substitutionStringsForItemDetailed( $html, $reason, $autorecurring ) );
		// Fix according to meaning outside an order:
		unset( $strings['VALIDITY_IF_NOT_AUTORECURRING'] );
		unset( $strings['EXPIRY'] );
		unset( $strings['VALIDITY'] );
		return $strings;
	}
コード例 #2
0
	/**
	 * Called at each change of user subscription state due to a plan activation or deactivation
	 *
	 * @param  UserTable        $user               The user owning the $subscription with that $planId
	 * @param  string           $status             New status: 'A'=Active, 'X'=Expired, 'C'=Cancelled
	 * @param  int              $planId             Plan Id which is changing status
	 * @param  int              $replacedPlanId     Replaced Plan Id in case of an upgrade
	 * @param  ParamsInterface  $integrationParams  Integration parameters for that plan $planId
	 * @param  string           $cause              'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied'
	 * @param  string           $reason             'N' new subscription, 'R' renewal, 'U'=update )
	 * @param  int              $now                Unix time
	 * @param  cbpaidSomething  $subscription       Subscription/Donation/Merchandise record
	 * @param  int              $autorenewed        0: not auto-renewing (manually renewed), 1: automatically renewed (if $reason == 'R')
	 * @return void
	 */
	public function onCPayUserStateChange( $user, $status, /** @noinspection PhpUnusedParameterInspection */ $planId, /** @noinspection PhpUnusedParameterInspection */ $replacedPlanId, $integrationParams, $cause, $reason, /** @noinspection PhpUnusedParameterInspection */ $now, $subscription, $autorenewed ) {
		if ( ! is_object( $user ) ) {
			return;
		}

		$event			=	null;

		if ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason != 'R' ) ) {
			$event		=	'activation';
		} elseif ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason == 'R' ) && ( $autorenewed == 0 ) ) {
			$event		=	'renewal';
		} elseif ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason == 'R' ) && ( $autorenewed == 1 ) ) {
			$event		=	'autorenewal';
		} elseif ( ( $status == 'X' ) && ( $cause != 'Pending' ) ) {
			$event		=	'expired';
		} elseif ( ( $status == 'C' ) && ( $cause != 'Pending' ) ) {
			$event		=	'deactivation';
		} elseif ( ( $cause == 'Pending' ) && ( $reason != 'R' ) && ( $autorenewed == 0 ) ) {
			$event		=	'pendingfirst';
		} elseif ( ( $cause == 'Pending' ) && ( $reason == 'R' ) && ( $autorenewed == 0 ) ) {
			$event		=	'pendingrenewal';
		}

		if ( $event ) {
			$fromName		=	$integrationParams->get( 'cbemail_name_' . $event, null );
			$fromEmail		=	$integrationParams->get( 'cbemail_address_' . $event, null );
			$aTo			=	$integrationParams->get( 'cbemail_to_' . $event, null );
			$aCC			=	$integrationParams->get( 'cbemail_cc_' . $event, null );
			$aBCC			=	$integrationParams->get( 'cbemail_bcc_' . $event, null );
			$aSub			=	$integrationParams->get( 'cbemail_sub_' . $event, null );
			$aMsg			=	$integrationParams->get( 'cbemail_msg_' . $event, null );
			$aAtch			=	$integrationParams->get( 'cbemail_atch_' . $event, null );
			$aType			=	(int) $integrationParams->get( 'cbemail_type_' . $event, 0 );
			$extraStrings	=	$subscription->substitutionStrings( $aType == 1 );
			$this->sendMail( $user, $fromEmail, $fromName, $aTo, $aSub, $aMsg, $aType, $aCC, $aBCC, $aAtch, $extraStrings );
		}
	}
コード例 #3
0
	/**
	 * Called at each change of user subscription state due to a plan activation or deactivation
	 *
	 * @param  UserTable        $user
	 * @param  string           $status
	 * @param  int              $planId
	 * @param  int              $replacedPlanId
	 * @param  ParamsInterface  $integrationParams
	 * @param  string           $cause            'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied'
	 * @param  string           $reason           'N' new subscription, 'R' renewal, 'U'=update )
	 * @param  int              $now              Unix time
	 * @param  cbpaidSomething  $subscription     Subscription/Donation/Merchandise record
	 * @param  int              $autorenewed      0: not auto-renewing (manually renewed), 1: automatically renewed (if $reason == 'R')
	 */
	public function onCPayUserStateChange( &$user, $status, /** @noinspection PhpUnusedParameterInspection */ $planId, /** @noinspection PhpUnusedParameterInspection */ $replacedPlanId, &$integrationParams, /** @noinspection PhpUnusedParameterInspection */ $cause, /** @noinspection PhpUnusedParameterInspection */ $reason, /** @noinspection PhpUnusedParameterInspection */ $now, &$subscription, /** @noinspection PhpUnusedParameterInspection */ $autorenewed ) {
		if ( ! is_object( $user ) ) {
			return;
		}

		$cbUser							=&	CBuser::getInstance( $user->id );

		if ( ! $cbUser ) {
			$cbUser						=&	CBuser::getInstance( null );
		}

		$extraStrings					=	$subscription->substitutionStrings( false );
		
		for ( $i = 1; $i <= 10; $i++ ) {
			$fieldId					=	$integrationParams->get( 'cbfields_fieldid' . $i, 0 );
			$increment					=	$integrationParams->get( 'cbfields_increment' . $i, 0 );
			$fieldContent				=	$cbUser->replaceUserVars( $integrationParams->get( 'cbfields_contentoffield' . $i, null ), false, false, $extraStrings, false );
			$fieldRemoveOnDeact			=	$integrationParams->get( 'cbfields_removeondeact' . $i, 1 );
			$fieldRemoveContent			=	$integrationParams->get( 'cbfields_removecontent' . $i, 1 );
			$field						=	$this->_getFieldInfo( $fieldId );
			if ( $field !== null ) {
				if ( ( ( $field->type != 'integer' ) && in_array( $increment, array( 1, 2, 3, 4 ) ) ) || ( in_array( $field->type, array( 'multiselect', 'multicheckbox' ) ) && in_array( $increment, array( 5, 6 ) ) ) ) {
					$increment			=	0;
				}

				if ( $status == 'A' ) {
					$this->_addField( $user, $field, $fieldContent, $increment );
				} else {
					if ( $fieldRemoveOnDeact ) {
						$this->_removeField( $user, $field, $fieldContent, $increment, $fieldRemoveContent );
					}
				}
			}
		}
	}
コード例 #4
0
ファイル: cbsubs.url.php プロジェクト: kosmosby/medicine-prof
	/**
	 * Called at each change of user subscription state due to a plan activation or deactivation
	 *
	 * @param  UserTable        $user
	 * @param  string           $status
	 * @param  int              $planId
	 * @param  int              $replacedPlanId
	 * @param  ParamsInterface  $integrationParams
	 * @param  string           $cause              'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied'
	 * @param  string           $reason             'N' new subscription, 'R' renewal, 'U'=update
	 * @param  int              $now                Unix time
	 * @param cbpaidSomething   $subscription
	 */
	public function onCPayUserStateChange( &$user, $status, $planId, $replacedPlanId, &$integrationParams, $cause, $reason, /** @noinspection PhpUnusedParameterInspection */ $now, &$subscription ) {
		global $_CB_framework;
		
		if ( ! $user ) {
			return;
		}
		
		$event		=	null;
		
		if ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason != 'R' ) ) {
			$event	=	'activation';
		} elseif ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason == 'R' ) ) {
			$event	=	'renewal';
		} elseif ( ( $status == 'X' ) && ( $cause != 'Pending' ) ) {
			$event	=	'expiration';
		} elseif ( ( $status == 'C' ) && ( $cause != 'Pending' ) ) {
			$event	=	'deactivation';
		}
		
		if ( $event ) {
			$path									=	$integrationParams->get( 'url_path_' . $event, null );
			$method									=	$integrationParams->get( 'url_method_' . $event, 'GET' );
			$results								=	$integrationParams->get( 'url_results_' . $event, 0 );
			
			if ( $path ) {

				// add substitutions for: [plan_id], [replaced_plan_id], [subscription_id], [parent_plan_id], [parent_subscription_id]
				$extraStringsLocal					=	array(
													'plan_id'					=>	(int) $planId,
													'replaced_plan_id'			=>	(int) $replacedPlanId,
													'subscription_id'			=>	(int) $subscription->id,
													'parent_plan_id'			=>	(int) $subscription->parent_plan,
													'parent_subscription_id'	=>	(int) $subscription->parent_subscription
													);
				$extraStrings						=	array_merge( $subscription->substitutionStrings( false ), $extraStringsLocal );

				cbimport( 'cb.snoopy' );
				
				$cbUser								=&	CBuser::getInstance( $user->id );
				
				if ( ! $cbUser ) {
					return;
				}
				
				$path								=	trim( $cbUser->replaceUserVars( $path, array( $this, '_urlencode' ), false, $extraStrings, false ) );
				$snoopy								=	new CBSnoopy();
				$snoopy->read_timeout				=	30;
				
				switch ($method ) {
					case 'POST':
						$post						=	$integrationParams->get( 'url_post_' . $event, null );
						$formvar					=	array();

						if ( $post ) {
							$formvars				=	explode( "\n", $post );
							foreach ( $formvars as $vars ) {
								$var				=	explode( '=', trim( $vars ), 2 );
								if ( count( $var ) == 2 ) {
									$key			=	trim( $var[0] );
									$value			=	trim( $cbUser->replaceUserVars( $var[1], false, false, $extraStrings, false ) );
									$formvar[$key]	=	$value;
								}
							}
						}
						
						$snoopy->submit( $path, $formvar );
						break;

					case 'XML':
						$xmlText					=	$integrationParams->get( 'url_xml_' . $event, null );
						$xmlText					=	trim( $cbUser->replaceUserVars( $xmlText, array( $this, '_htmlspecialchars' ), false, $extraStrings, false ) );
						$formvar					=	array( 'xml' => $xmlText );
						$snoopy->set_submit_xml();
						$snoopy->submit( $path, $formvar );
						break;

					case 'GET':
					default:
						$snoopy->fetch( $path );
						break;
				}

				if ( $results && ( ! $snoopy->error ) && ( $snoopy->status == 200 ) && $snoopy->results && ( $_CB_framework->getUi() == 1 ) ) {
					// display only in frontend:
					echo '<div class="CBSubsURL_Results_' . (int) $planId . '">' . $snoopy->results . '</div>';
				}
			}
		}
	}