Leaderboard
Popular Content
Showing content with the highest reputation on 04/16/2019 in all areas
-
Trutone Blesta Integration
activa reacted to Michael Kinder for a topic
1 point -
how to pass on paypal merchant fees?
activa reacted to Michael Kinder for a topic
A simple fix you could implement (I used to do this) is to setup a tax at a set percentage that will be sufficient to cover the PayPal fees and then once they pay, the fees will be taken from the total amount and you'll be left with the actual amount for the service.1 point -
Use Multi-Currency On Your Site Using GeoIP
Joseph H reacted to Michael Kinder for a topic
Hi everyone! I just wanted to share this with you because I think it would be useful to those who aren't necessarily familiar with PHP and want to display different currencies based upon the user's IP address. Big thanks to @Blesta.Store for sharing a big portion of this code already on the forum. This will pull prices from Blesta's API and allow you to use multiple currencies. After you've uploaded the API SDK, you're going to want to download this file: https://www.geoplugin.com/_media/webservices/geoplugin.class.phps Upload that file into your site's directory, then take the contents below and place it at the top of your site files (or the pages where you will be displaying the prices). <?php require_once('geoplugin.class.php'); $geoplugin = new geoPlugin(); $geoplugin->locate(); // create a variable for the country code $var_country_code = $geoplugin->countryCode; // redirect based on country code: if ($var_country_code == "AU") { $selected_currency = "AUD"; } else if ($var_country_code == "CA") { $selected_currency = "CAD"; } else if ($var_country_code == "AT") { $selected_currency = "EUR"; } else if ($var_country_code == "BE") { $selected_currency = "EUR"; } else if ($var_country_code == "BG") { $selected_currency = "EUR"; } else if ($var_country_code == "CY") { $selected_currency = "EUR"; } else if ($var_country_code == "CZ") { $selected_currency = "EUR"; } else if ($var_country_code == "DK") { $selected_currency = "EUR"; } else if ($var_country_code == "EE") { $selected_currency = "EUR"; } else if ($var_country_code == "FI") { $selected_currency = "EUR"; } else if ($var_country_code == "DE") { $selected_currency = "EUR"; } else if ($var_country_code == "GR") { $selected_currency = "EUR"; } else if ($var_country_code == "HU") { $selected_currency = "EUR"; } else if ($var_country_code == "IE") { $selected_currency = "EUR"; } else if ($var_country_code == "IT") { $selected_currency = "EUR"; } else if ($var_country_code == "LV") { $selected_currency = "EUR"; } else if ($var_country_code == "LU") { $selected_currency = "EUR"; } else if ($var_country_code == "MT") { $selected_currency = "EUR"; } else if ($var_country_code == "NL") { $selected_currency = "EUR"; } else if ($var_country_code == "PL") { $selected_currency = "EUR"; } else if ($var_country_code == "PT") { $selected_currency = "EUR"; } else if ($var_country_code == "RO") { $selected_currency = "EUR"; } else if ($var_country_code == "SK") { $selected_currency = "EUR"; } else if ($var_country_code == "SI") { $selected_currency = "EUR"; } else if ($var_country_code == "ES") { $selected_currency = "EUR"; } else if ($var_country_code == "SE") { $selected_currency = "EUR"; } else if ($var_country_code == "GB") { $selected_currency = "GBP"; } else if ($var_country_code == "IN") { $selected_currency = "INR"; } else if ($var_country_code == "MX") { $selected_currency = "MXN"; } else { $selected_currency = "USD"; } require_once "/home/username/public_html/blesta/api/blesta_api.php"; $user = "username"; $key = "key"; $url = "url"; $api = new BlestaApi($url, $user, $key); $company_id = 1; // Set acceptable currencies $valid_currencies = array("USD", "GBP", "EUR", "INR", "MXN", "AUD"); // Set default currency // Set another currency if given if (isset($_GET['currency']) && in_array(strtoupper($_GET['currency']), $valid_currencies)) $selected_currency = strtoupper($_GET['currency']); $price1 = getPackagePrice($api, 4, "month", 1); $price2 = getPackagePrice($api, 57, "year", 1); $price3 = getPackagePrice($api, 29, "month", 1); $price4 = getPackagePrice($api, 50, "month", 1); $price5 = getPackagePrice($api, 298, "year", 1); $price1_amount = formatCurrency($api, $price1->price, $price1->currency, $selected_currency, $company_id); $price2_amount = formatCurrency($api, $price2->price, $price2->currency, $selected_currency, $company_id); $price3_amount = formatCurrency($api, $price3->price, $price3->currency, $selected_currency, $company_id); $price4_amount = formatCurrency($api, $price4->price, $price4->currency, $selected_currency, $company_id); $price5_amount = formatCurrency($api, $price5->price, $price5->currency, $selected_currency, $company_id); function getPackagePrice($api, $package_id, $period, $term) { $package = $api->get("packages", "get", array('package_id' => $package_id))->response(); $package_price = null; foreach ($package->pricing as $price) { // Get monthly term if ($price->period == $period && $price->term == $term) { return $price; } } return false; } function formatCurrency($api, $amount, $from_currency, $to_currency, $company_id) { // Do the currency conversion $amount = $api->get("currencies", "convert", array('amount' => $amount, 'from_currency' => $from_currency, 'to_currency' => $to_currency, 'company_id' => $company_id))->response(); // Format the currency return $api->get("currencies", "toCurrency", array('value' => $amount, 'currency' => $to_currency, 'company_id' => $company_id))->response(); } ?> Next, you're going to want to create your API credentials in Blesta and fill them in appropriately. After you've done this, simply place the following code (changing the numbers appropriately) where you would like to display the prices. <?php echo $price1_amount; ?> Of course you can make modifications as you desire, but I wanted to share this with you in case anyone wanted to do the same.1 point -
Looks good! One thing you could do in the future to improve on this is to create a plugin for Blesta that accepts an IP address and uses the GeoIP2 database already supported by Blesta to determine the country (i.e. replaces the geoplugin.com file), then your plugin can do the mapping and return the appropriate currency for the country.1 point
-
A credit is a payment transaction that is not applied to any invoices. On that "Record Payment" page, simply enter the payment amount, but do not check any invoices to pay from the list. In that case, a transaction will be created and it will not be assigned to any invoices, therefore it will appear as available credit.1 point