Skip to content

Commit

Permalink
Changes for Galette 1.1 support (contributions amount ar enow stored …
Browse files Browse the repository at this point in the history
…core side)
  • Loading branch information
trasher committed May 19, 2024
1 parent b3e0513 commit be8a3e7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
9 changes: 1 addition & 8 deletions lib/GalettePaypal/Controllers/PaypalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,7 @@ public function form(Request $request, Response $response): Response
);
}

if (!$paypal->areAmountsLoaded()) {
$this->flash->addMessageNow(
'warning',
_T("Predefined amounts cannot be loaded, that is not a critical error.", "paypal")
);
}

// display page
// display page
$this->view->render(
$response,
$this->getTemplate('paypal_form'),
Expand Down
8 changes: 4 additions & 4 deletions lib/GalettePaypal/Paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*
* @author Johan Cwiklinski <johan@x-tnd.be>
*/

class Paypal
{
public const TABLE = 'types_cotisation_prices';
Expand Down Expand Up @@ -98,7 +97,7 @@ public function load(): void
}
}
$this->loaded = true;
$this->loadAmounts();
$this->loadContributionsTypes();
} catch (\Exception $e) {
Analog::log(
'[' . get_class($this) . '] Cannot load paypal preferences |' .
Expand All @@ -116,7 +115,7 @@ public function load(): void
*
* @return void
*/
private function loadAmounts(): void
private function loadContributionsTypes(): void
{
$ct = new ContributionsTypes($this->zdb);
$this->prices = $ct->getCompleteList();
Expand All @@ -142,7 +141,6 @@ private function loadAmounts(): void
foreach ($results as $paypal) {
if ($paypal['id_type_cotis'] == $k) {
$_found = true;
$this->prices[$k]['amount'] = (double)$paypal['amount'];
break;
}
}
Expand All @@ -162,6 +160,8 @@ private function loadAmounts(): void
}
if (count($queries) > 0) {
$this->newEntries($queries);
$this->loadContributionsTypes();
return;
}
//amounts should be loaded here
$this->amounts_loaded = true;
Expand Down
18 changes: 7 additions & 11 deletions templates/default/paypal_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,20 @@
<div class="ui bottom attached accordion-styled segment">
<div class="active content field">
<div class="field inline">
{% if paypal.areAmountsLoaded() %}
{% if amounts|length > 0 %}
{% if amounts|length > 0 %}
<input type="hidden" name="item_name" id="item_name" value="{% if login.isLogged() %}{{ _T("annual fee") }}{% else %}{{ _T("donation in money") }}{% endif %}"/>
{% for k, amount in amounts %}
{% for k, amount in amounts %}
{% if loop.index0 != 0 %}<br/>{% endif %}
<input type="radio" name="item_number" id="in{{ k }}" value="{{ k }}"{% if loop.index0 == 0 %} checked="checked"{% endif %}/>
<label for="in{{ k }}"><span id="in{{ k }}_name">{{ amount['name'] }}</span>
{% if amount['amount'] > 0 %}
{% if amount['amount'] > 0 %}
(<span id="in{{ k }}_amount">{{ amount['amount']|number_format(2, ',', ' ') }}</span> €){# TODO: parametize currency #}
{% endif %}
{% endif %}
</label>
{% endfor %}
{% else %}
{% endfor %}
{% else %}
<label for="item_name">{{ _T("Payment reason:", "paypal") }}</label>
<input type="text" name="item_name" id="item_name" value="{% if login.isLogged() %}{{ _T("annual fee") }}{% else %}{{ _T("donation in money") }}{% endif %}"/>
{% endif %}
{% else %}
{{ _T("No predefined amounts have been configured yet.", "paypal") }}
{% endif %}
</div>

Expand Down Expand Up @@ -96,7 +92,7 @@
{% endblock %}

{% block javascripts %}
{% if paypal.isLoaded() and paypal.getId() is not null and paypal.areAmountsLoaded() %}
{% if paypal.isLoaded() and paypal.getId() is not null %}
<script type="text/javascript">
$(function() {
$('input[name="item_number"]').change(function(){
Expand Down
5 changes: 2 additions & 3 deletions templates/default/paypal_preferences.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@
} %}
{% endif %}

{% if paypal.areAmountsLoaded() and amounts|length > 0 %}
{% if paypal.isLoaded() and amounts|length > 0 %}
<table class="listing ui celled striped table">
<thead>
<tr>
<th class="listing">{{ _T("Contribution type") }}</th>
<th class="listing">{{ _T("Amount") }}</th>
<th class="listing">{{ _T("Inactive") }}</th>
</tr>
</thead>
Expand All @@ -60,7 +59,7 @@
<label for="amount_{{ k }}">{{ amount['name'] }}</label>
</td>
<td>
<input type="text" name="amounts[]" id="amount_{{ k }}" value="{{ amount['amount']|number_format(2, ',', '') }}"/>
<input type="text" name="amounts[]" id="amount_{{ k }}" value="{{ amount['amount']|number_format(2, ',', '') }}" disabled="disabled"/>
</td>
<td>
<input type="checkbox" name="inactives[]" id="inactives_{{ k }}"{% if paypal.isInactive(k) %} checked="checked"{% endif %} value="{{ k }}"/>
Expand Down

0 comments on commit be8a3e7

Please sign in to comment.