public function actionEdit(array $variables = array()) { craft()->userSession->requireAdmin(); $charge = new ChargePlugin(); if (!isset($variables['coupon'])) { if (isset($variables['couponId'])) { $couponId = $variables['couponId']; $variables['coupon'] = craft()->charge_coupon->getCouponById($couponId); } else { // New coupon, load a blank object $variables['coupon'] = new Charge_CouponModel(); } } $variables['paymentTypes'] = array('one-off' => 'One-Off', 'recurring' => 'Recurring'); $variables['couponTypes'] = array('percentage' => 'Percentage Off', 'amount' => 'Fixed Amount'); $variables['durations'] = array('once' => 'Once', 'forever' => 'Forever', 'repeating' => 'Repeating'); foreach (ChargePlugin::getCurrencies() as $key => $row) { $variables['currencies'][$key] = strtoupper($key) . ' - ' . $row['name']; } // Revert the coupon amount just in case if ($variables['coupon']->amountOff > 0) { $variables['coupon']->amountOff = number_format($variables['coupon']->amountOff / 100, 2); } $this->renderTemplate('charge/coupon/_settings', $variables); }
public function getSettingsHtml() { $currencies = array(); foreach (ChargePlugin::getCurrencies('all') as $key => $currency) { $currencies[strtoupper($key)] = strtoupper($key) . ' - ' . $currency['name']; } return craft()->templates->render('charge/_settings', array('settings' => $this->getSettings(), 'currencies' => $currencies, 'accountModes' => array('test' => 'Test Mode', 'live' => 'Live Mode'))); }
public function constructPlanName(ChargeModel &$model, $format = 'safe') { // Allow this to be overridden from the model, so if a dev want's to set // a specific name using the onBeforeCharge event, they can if (isset($model->planName) and $model->planName != '') { return $model->planName; } // 75 Every [x] Month(s) if ($format == 'symbol') { $currency = ChargePlugin::getCurrencies($model->planCurrency); $planName[] = $currency['symbol'] . number_format($model->planAmount / 100, 2); } else { $planName[] = number_format($model->planAmount / 100, 2); $planName[] = strtoupper($model->planCurrency); } // $plan_name[] = $plan['amount']; if ($model->planInterval == '') { $model->planInterval = 'month'; } if ($model->planIntervalCount > 1) { // every [x] [period]s $planName[] = 'Every ' . $model->planIntervalCount . ' ' . ucwords($model->planInterval . 's'); } else { $planName[] = ucwords($model->planInterval . 'ly'); } return implode(' ', $planName); }
private function _formatAmount($amount, $currency, $format = 'symbol') { $charset = craft()->templates->getTwig()->getCharset(); $currency = ChargePlugin::getCurrencies($currency); return new \Twig_Markup(html_entity_decode($currency[$format] . number_format($amount / 100, 2), ENT_QUOTES), $charset); }