/** * 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) { $strings = parent::substitutionStrings($html, $runContentPluginsIfAllowedByPlan); $plan = $this->getPlan(); // For donations, [PLAN_PRICE] is the amount just donated, as it's user-selectable: $strings['PLAN_PRICE'] = cbpaidMoney::getInstance()->renderPrice($this->amount, $this->currency, $html, false); $strings['PLAN_RATE'] = sprintf('%.2f', cbpaidApp::getCurrenciesConverter()->convertCurrency($this->currency, $plan->currency(), $this->amount)); $strings['PLAN_FIRST_RATE'] = $strings['PLAN_RATE']; return $strings; }
/** * USED by XML interface ONLY !!! Renders main currency conversion rates * * @param string $value * @param ParamsInterface $params * @return string HTML to display */ public function renderMainRate($value, $params) { $textCurrency = $params->get('currency_code', 'USD'); $textSecondaryCurrency = $params->get('secondary_currency_code'); $price = 1.0; // $priceText = $this->renderPrice( $price, $textCurrency, true ); if ($textSecondaryCurrency && $textSecondaryCurrency != $textCurrency) { $_CBPAY_CURRENCIES = cbpaidApp::getCurrenciesConverter(); $secondaryPrice = $_CBPAY_CURRENCIES->convertCurrency($textCurrency, $textSecondaryCurrency, $price); if ($secondaryPrice !== null) { // we do not want roundings here: // $secondaryPriceText = $this->renderPrice( $secondaryPrice, $textSecondaryCurrency, true ); // return $secondaryPriceText . ' / ' . $priceText; return sprintf('%s %0.2f / %s %0.2f', $textSecondaryCurrency, $secondaryPrice, $textCurrency, $price); } else { $error = $_CBPAY_CURRENCIES->getError(); return '<span style="color:red">' . $error . '</span>'; } } return null; }
/** * returns price (rate) in the given currency. * * @param float $amount Amount to convert * @param string $fromCurrencyCode ISO currency * @param string $toCurrencyCode ISO currency * @param boolean $withRounding If roundings corresponding to params should be done * @param boolean $withMarkup If markup corresponding to params should be done * @return float|null returns $price in $currency_code or null if it can not convert. */ public function convertPrice( $amount, $fromCurrencyCode, $toCurrencyCode, $withRounding, $withMarkup ) { if ( $toCurrencyCode && ( $toCurrencyCode != $fromCurrencyCode ) ) { $_CBPAY_CURRENCIES =& cbpaidApp::getCurrenciesConverter(); $amount = $_CBPAY_CURRENCIES->convertCurrency( $fromCurrencyCode, $toCurrencyCode, $amount ); // null if cannot convert if ( $amount !== null ) { if ( $withMarkup ) { $markup = $this->params->get( 'currency_conversion_markup_percent', 0 ); if ( $markup ) { $amount = $amount * ( 1.0 + ( $markup / 100.0 ) ); } } if ( $withRounding ) { $roundings = $this->params->get( 'rounding_converted_currency_price', 0 ); $priceRoundings = ( $roundings ? $this->params->get('price_roundings', 100 ) : 100 ); $amount = round( $amount * $priceRoundings ) / $priceRoundings; } } } return $amount; }
/** * Changes the currency of a payment basket * and stores the updated basket, items and totalizers. * * @param string $newCurrency Warning: Must be sanitized before * @param boolean $updateBasket Update basket and totalizer calling $this->updateBasketRecomputeTotalizers() * @return void */ public function changeCurrency( $newCurrency, $updateBasket = true ) { // Are we really changing ? if ( $this->mc_currency != $newCurrency ) { // Is basket still just a not-committed order ? if ( $this->payment_status == 'NotInitiated' ) { // Check if currency conversion rate is defined: $_CBPAY_CURRENCIES =& cbpaidApp::getCurrenciesConverter(); $rate = $_CBPAY_CURRENCIES->convertCurrency( $this->mc_currency, $newCurrency, $this->mc_gross ); // null if cannot convert if ( $rate !== null ) { // We could convert, so it's safe to re-compute the basket: foreach ( $this->loadPaymentItems() as $item ) { // Update each item in basket from its subscription so that any plan-depending settings are taken in account: // $item = NEW cbpaidPaymentItem(); $subscription = $item->loadSubscription(); if ( $subscription ) { // $subscription = NEW cbpaidSomething(); $subscription->updatePaymentItem( $item, $this, null, $newCurrency ); } } $this->checkPaymentMethodValidForCurrency( $newCurrency ); $this->mc_currency = $newCurrency; if ( $updateBasket ) { $this->updateBasketRecomputeTotalizers(); } } } } }
/** * Called upon * administrator/index3.php?option=com_comprofiler&view=pluginmenu&cid=566&menu=curconvcheck&no_html=1&format=raw * * @return string HTML */ protected function currencyconvertercheck() { $ret = null; $_CBPAY_CURRENCIES = cbpaidApp::getCurrenciesConverter(); $secondaryPrice = $_CBPAY_CURRENCIES->convertCurrency('EUR', 'USD', 1.0); if ($secondaryPrice === null) { $ret = '<div class="cbDisabled">' . $_CBPAY_CURRENCIES->getError() . '</div>'; } return $ret; }
/** * Computes the amount after percentage, only if it's combined * * @param float $amount * @param float $amountTaxExcl * @param float $periodProrater * @param boolean $isFirstPeriod * @param string $currency_code * @return float|null */ public function getAmountAfterPercents( $amount, $amountTaxExcl, $periodProrater, $isFirstPeriod, $currency_code ) { $return = null; if ( in_array( $this->tax_kind, array( 'fixed_percent' ) ) ) { $_CBPAY_CURRENCIES =& cbpaidApp::getCurrenciesConverter(); $cbpaidMoney =& cbpaidMoney::getInstance(); $return = $_CBPAY_CURRENCIES->convertCurrency( $cbpaidMoney->currency( $this->tax_currency ), $currency_code, $this->tax_amount ); // null if cannot convert } if ( $return !== null ) { $return *= $periodProrater; } return $return; }
/** * DO NOT USE ANYMORE * @obsolete since CBSubs 1.1 * * @ param void $name */ function & cbpaid_GetInstance( /* $name */ ) { cbpaidApp::getCurrenciesConverter(); }