* @link http://www.tassos.gr * @copyright Copyright © 2019 Tassos Marinos All Rights Reserved * @license GNU GPLv3 or later */ defined('_JEXEC') or die; use Joomla\CMS\Uri\Uri; // Setup variables if (!$field->value) { return; } $type = $fieldParams->get('type', 'checkout'); $paypal_account = $fieldParams->get('paypal_account', ''); $sandbox_mode = (bool) $fieldParams->get('sandbox_mode', ''); $sandbox_account = $fieldParams->get('sandbox_account', ''); $paypal_account = (!$sandbox_mode) ? $paypal_account : $sandbox_account; // get value data $data = isset($field->value) && is_string($field->value) ? json_decode($field->value) : (object) $field->value; // Setup variables $item_name = (isset($data->item_name) && !empty($data->item_name)) ? $data->item_name : ''; $price = (isset($data->price) && !empty($data->price)) ? $data->price : ''; // Do not render if name and price are empty except if we are rendering a checkout or donation button, // which do not require a fixed amount if ((empty($item_name) || empty($price)) && !in_array($type, ['checkout', 'donation'])) { return; } /** * Checkout button types can be rendered with no price set (users can then define a custom price on PayPal). * * However, some users do not want their checkout button to appear when no price is set. */ if ($type === 'checkout' && empty($price) && ! (bool) $fieldParams->get('allow_empty_value')) { return; } // Setup variables $currency = $fieldParams->get('currency', 'USD'); $billing_interval = $fieldParams->get('billing_interval', ''); $language = $fieldParams->get('language', 'auto'); $language_locale = $fieldParams->get('language_locale', ''); $return_url = $fieldParams->get('return_url', ''); $cancel_url = $fieldParams->get('cancel_url', ''); $button_style = $fieldParams->get('button_style', 'style'); $button_style_selector = $fieldParams->get('button_style_selector', ''); $button_style_image = $fieldParams->get('button_style_image', ''); $new_tab = (bool) $fieldParams->get('new_tab', ''); $new_tab = ($new_tab) ? ' target="_blank"' : ''; // base url $base_url = (!$sandbox_mode) ? 'https://www.paypal.com/cgi-bin/webscr' : 'https://www.sandbox.paypal.com/cgi-bin/webscr'; $image_name = ($button_style == 'style') ? $button_style_selector : $button_style_image; $image_url = ($button_style == 'style') ? Uri::root() . $image_name : $button_style_image; // command $command = '_xclick'; switch ($type) { case 'donation': $command = '_donations'; break; case 'subscription': $command = '_xclick-subscriptions'; break; } ?>
>