Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions lib/GaletteStripe/StripeHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ public function add(array|string $action, string $argument = '', string $query =
$stripe = new Stripe($this->zdb, $this->preferences);
$request = $action;
$payment_method = $this->getStripePaymentMethod($request['data']['object']['payment_method']);

// Retrieve receipt URL and add it to the request
$charge = $this->getStripeCharge($request['data']['object']['latest_charge']);
$request['receipt_url'] = $charge['receipt_url'];

try {
$values = [
'history_date' => date('Y-m-d H:i:s'),
'intent_id' => $request['data']['object']['id'],
'amount' => $stripe->isZeroDecimal($stripe->getCurrency()) ? $request['data']['object']['amount'] : $request['data']['object']['amount'] / 100,
'payer_name' => $payment_method['billing_details']['name'],
'member_id' => $request['data']['object']['metadata']['member_id'] ?? 0,
'comments' => $request['data']['object']['metadata']['item_name'],
'request' => Galette::jsonEncode($request),
'state' => self::STATE_NONE
'amount' => $stripe->isZeroDecimal($stripe->getCurrency()) ? $request['data']['object']['amount'] : $request['data']['object']['amount'] / 100,
'method' => $payment_method['type'],
'state' => self::STATE_NONE,
'receipt_url' => $charge['receipt_url'],
'request' => Galette::jsonEncode($request)
];

$insert = $this->zdb->insert($this->getTableName());
Expand Down Expand Up @@ -145,9 +145,7 @@ public function getStripeHistory(): array
$oa = Galette::jsonDecode($o['request']);
}

$member_id = $oa['data']['object']['metadata']['member_id'] ?? '0';

$o['member_fullname'] = $this->getMemberFullName($member_id);
$o['member_fullname'] = $this->getMemberFullName($o['member_id']);
$o['raw_request'] = print_r($oa, true);
$o['request'] = $oa;

Expand All @@ -167,9 +165,9 @@ public function getStripeHistory(): array
/**
* Gets Member full name
*
* @param string $id ID of the member to retrieve
* @param int $id ID of the member to retrieve
*/
protected function getMemberFullName(string $id): string
protected function getMemberFullName(int $id): string
{
$fullname = _T('None', 'stripe');

Expand All @@ -180,7 +178,7 @@ protected function getMemberFullName(string $id): string
$row = $result->current();

if ($row) {
$fullname = mb_strtoupper($row['nom_adh']) . ' ' . $row['prenom_adh'];
$fullname = mb_strtoupper($row['nom_adh'], 'UTF-8') . ' ' . $row['prenom_adh'];
}

return $fullname;
Expand Down
15 changes: 9 additions & 6 deletions scripts/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ DROP TABLE IF EXISTS galette_stripe_history;
CREATE TABLE galette_stripe_history (
id_stripe int(11) NOT NULL auto_increment,
history_date datetime NOT NULL,
intent_id varchar(255) COLLATE utf8_unicode_ci,
intent_id varchar(255),
amount double NOT NULL,
payer_name varchar(255) COLLATE utf8_unicode_ci,
comments varchar(255) COLLATE utf8_unicode_ci,
request text COLLATE utf8_unicode_ci,
comments varchar(255),
request text,
state tinyint(4) NOT NULL DEFAULT 0,
payer_name varchar(255),
member_id int(10) NOT NULL,
method varchar(20) NOT NULL,
receipt_url varchar(255),
PRIMARY KEY (`id_stripe`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;

--
-- Table structure for table `galette_stripe_preferences`
Expand All @@ -27,7 +30,7 @@ CREATE TABLE galette_stripe_preferences (
val_pref varchar(200) NOT NULL default '',
PRIMARY KEY (id_pref),
UNIQUE KEY (nom_pref)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;

INSERT INTO galette_stripe_preferences (nom_pref, val_pref) VALUES ('stripe_pubkey', '');
INSERT INTO galette_stripe_preferences (nom_pref, val_pref) VALUES ('stripe_privkey', '');
Expand Down
27 changes: 15 additions & 12 deletions scripts/pgsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@

DROP SEQUENCE IF EXISTS galette_stripe_history_id_seq;
CREATE SEQUENCE galette_stripe_history_id_seq
START 1
INCREMENT 1
MAXVALUE 2147483647
MINVALUE 1
CACHE 1;
START 1
INCREMENT 1
MAXVALUE 2147483647
MINVALUE 1
CACHE 1;

DROP TABLE IF EXISTS galette_stripe_history;
CREATE TABLE galette_stripe_history (
id_stripe integer DEFAULT nextval('galette_stripe_history_id_seq'::text) NOT NULL,
history_date date NOT NULL,
intent_id character varying(255),
amount real NOT NULL,
payer_name character varying(255),
comments character varying(255),
request text,
state smallint DEFAULT 0 NOT NULL,
payer_name character varying(255),
member_id integer NOT NULL,
method character varying(20) NOT NULL,
receipt_url character varying(255),
PRIMARY KEY (id_stripe)
);

Expand All @@ -30,18 +33,18 @@ CREATE TABLE galette_stripe_history (
--
DROP SEQUENCE IF EXISTS galette_stripe_preferences_id_seq;
CREATE SEQUENCE galette_stripe_preferences_id_seq
START 1
INCREMENT 1
MAXVALUE 2147483647
MINVALUE 1
CACHE 1;
START 1
INCREMENT 1
MAXVALUE 2147483647
MINVALUE 1
CACHE 1;

DROP TABLE IF EXISTS galette_stripe_preferences;
CREATE TABLE galette_stripe_preferences (
id_pref integer DEFAULT nextval('galette_stripe_preferences_id_seq'::text) NOT NULL,
nom_pref character varying(100) NOT NULL default '',
val_pref character varying(200) NOT NULL default '',
PRIMARY KEY (id_pref)
PRIMARY KEY (id_pref)
);

CREATE UNIQUE INDEX galette_stripe_preferences_unique_idx ON galette_stripe_preferences (nom_pref);
Expand Down
11 changes: 0 additions & 11 deletions scripts/upgrade-to-1.0-mysql.sql

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/upgrade-to-1.0-pgsql.sql

This file was deleted.

44 changes: 44 additions & 0 deletions scripts/upgrade-to-1.0.0-mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--
-- This file is part of Galette Stripe plugin (https://galette-community.github.io/plugin-stripe).
-- SPDX-FileCopyrightText: Copyright © 2021-2026 The Galette Team
-- SPDX-License-Identifier: GPL-3.0-or-later
--

DROP TABLE galette_stripe_types_cotisation_prices;

ALTER TABLE galette_stripe_history
CHANGE COLUMN comment comments varchar(255),
CHANGE COLUMN metadata request text;

ALTER TABLE galette_stripe_history
MODIFY intent_id VARCHAR(255) COLLATE utf8mb4_unicode_520_ci,
MODIFY comments VARCHAR(255) COLLATE utf8mb4_unicode_520_ci,
MODIFY request TEXT COLLATE utf8mb4_unicode_520_ci,
CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;

ALTER TABLE galette_stripe_history
ADD COLUMN payer_name VARCHAR(255),
ADD COLUMN member_id INT(10) NOT NULL,
ADD COLUMN method VARCHAR(20) NOT NULL,
ADD COLUMN receipt_url VARCHAR(255);

UPDATE galette_stripe_history
SET
state = CASE
WHEN state = 0 THEN 3
ELSE state
END,
member_id = COALESCE(
CAST(
JSON_UNQUOTE(JSON_EXTRACT(request, '$.data.object.metadata.member_id'))
AS UNSIGNED
),
0
),
method = JSON_UNQUOTE(JSON_EXTRACT(request, '$.data.object.payment_method_types[0]')),
receipt_url = JSON_UNQUOTE(JSON_EXTRACT(request, '$.receipt_url'));

ALTER TABLE galette_stripe_preferences
MODIFY nom_pref VARCHAR(100) NOT NULL DEFAULT '',
MODIFY val_pref VARCHAR(200) NOT NULL DEFAULT '',
CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;
31 changes: 31 additions & 0 deletions scripts/upgrade-to-1.0.0-pgsql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--
-- This file is part of Galette Stripe plugin (https://galette-community.github.io/plugin-stripe).
-- SPDX-FileCopyrightText: Copyright © 2021-2026 The Galette Team
-- SPDX-License-Identifier: GPL-3.0-or-later
--

DROP TABLE galette_stripe_types_cotisation_prices;

ALTER TABLE galette_stripe_history
RENAME COLUMN metadata TO request,
ADD COLUMN payer_name character varying(255),
ADD COLUMN member_id integer,
ADD COLUMN method character varying(20),
ADD COLUMN receipt_url character varying(255);

UPDATE galette_stripe_history
SET
state = CASE
WHEN state = 0 THEN 3
ELSE state
END,
member_id = COALESCE(
(request #>> '{data,object,metadata,member_id}')::int,
0
),
method = request #>> '{data,object,payment_method_types,0}',
receipt_url = request #>> '{receipt_url}';

ALTER TABLE galette_stripe_history
ALTER COLUMN member_id SET NOT NULL,
ALTER COLUMN method SET NOT NULL;
60 changes: 21 additions & 39 deletions templates/default/stripe_history.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -87,45 +87,29 @@
{{ log.intent_id }}
</td>
<td class="left collapsing" data-col-label="{{ _T("Payer name", "stripe") }}">
{% if log.payer_name is not empty %}
{{ log.payer_name }}
{% else %}
{{ _T("None given", "stripe") }}
{% endif %}
{% if log.payer_name is not empty %}
{{ log.payer_name }}
{% else %}
{{ _T("None given", "stripe") }}
{% endif %}
</td>
<td class="left collapsing" data-col-label="{{ _T("Member") }}">
{% if log.request is iterable %}
{% if log.request.data.object.metadata.member_id is defined %}
<a href="{{ url_for("member", {"id": log.request.data.object.metadata.member_id}) }}">
{% endif %}
{{ log.member_fullname }}
{% if log.request.data.object.metadata.member_id is defined %}
</a>
{% endif %}
{% else %}
{{ _T("No request or unable to read request.", "stripe") }}
{% endif %}
{% if log.member_id != 0 %}
<a href="{{ url_for("member", {"id": log.member_id}) }}">
{% endif %}
{{ log.member_fullname }}
{% if log.member_id != 0 %}
</a>
{% endif %}
</td>
<td class="left collapsing" data-col-label="{{ _T("Contribution type") }}">
{% if log.request is iterable %}
{% if log.request.data.object.metadata.item_name is defined %}
{{ log.request.data.object.metadata.item_name }}
{% else %}
{{ _T("None", "stripe") }}
{% endif %}
{% endif %}
{{ log.comments }}
</td>
<td class="right collapsing" data-col-label="{{ _T("Amount") }}">
{{ log.amount }}
</td>
<td class="left collapsing" data-col-label="{{ _T("Method", "stripe") }}">
{% if log.request is iterable %}
{% if log.request.data.object.payment_method_types.0 is defined %}
{{ log.request.data.object.payment_method_types.0 }}
{% endif %}
{% else %}
{{ _T("No request or unable to read request.", "stripe") }}
{% endif %}
{{ log.method }}
</td>
<td class="left collapsing" data-col-label="{{ _T("Status", "stripe") }}">
{% if log.state == constant('GaletteStripe\\StripeHistory::STATE_PUBLIC') or log.state == constant('GaletteStripe\\StripeHistory::STATE_PROCESSED') %}
Expand All @@ -152,15 +136,13 @@
{% endif %}
</td>
<td class="left" data-col-label="{{ _T("Actions") }}">
{% if log.request is iterable %}
{% if log.request.receipt_url is defined %}
<a href="{{ log.request.receipt_url }}" class="icon-only" target="_blank">
<i class="receipt green icon" aria-hidden="true"></i>
<span class="visually-hidden">
{{ _T("View Stripe receipt of payment nb. %1$s sent by email to the payer", "stripe")|replace({"%1$s": log.intent_id}) }}
</span>
</a>
{% endif %}
{% if log.receipt_url is not empty %}
<a href="{{ log.receipt_url }}" class="icon-only" target="_blank">
<i class="receipt green icon" aria-hidden="true"></i>
<span class="visually-hidden">
{{ _T("View Stripe receipt of payment nb. %1$s sent by email to the payer", "stripe")|replace({"%1$s": log.intent_id}) }}
</span>
</a>
{% endif %}
<a href="#" class="icon-only view-request" data-modal="modal-{{ loop.index }}">
<i class="info circle blue icon" aria-hidden="true"></i>
Expand Down