Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michael Iseard
Kudos-Donations
Commits
53d5ba59
Commit
53d5ba59
authored
Oct 20, 2021
by
Michael Iseard
Browse files
Add "Add missing transactions" command to debug
parent
e7449cb8
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/Controller/Admin.php
View file @
53d5ba59
...
...
@@ -541,7 +541,7 @@ class Admin {
new
AdminNotice
(
__
(
'Database re-created'
,
'kudos-donations'
)
);
break
;
case
'kudos_sync_
payment
s'
:
case
'kudos_sync_
transaction
s'
:
$mollie
=
$this
->
mollie
;
$updated
=
$mollie
->
sync_transactions
();
if
(
$updated
)
{
...
...
@@ -558,6 +558,25 @@ class Admin {
break
;
}
new
AdminNotice
(
__
(
'No transactions need updating'
,
'kudos-donations'
)
);
break
;
case
'kudos_add_missing_transactions'
:
$mollie
=
$this
->
mollie
;
$updated
=
$mollie
->
add_missing_transactions
();
if
(
$updated
)
{
new
AdminNotice
(
sprintf
(
/* translators: %s: Number of records. */
_n
(
'Added %s transaction'
,
'Added %s transactions'
,
$updated
,
'kudos-donations'
),
$updated
)
);
break
;
}
new
AdminNotice
(
__
(
'No transactions need adding'
,
'kudos-donations'
)
);
}
do_action
(
'kudos_admin_actions_extra'
,
$action
);
...
...
app/Service/Vendor/MollieVendor.php
View file @
53d5ba59
...
...
@@ -732,7 +732,72 @@ class MollieVendor implements VendorInterface {
$order_id
=
$payment
->
metadata
->
order_id
??
null
;
$mapper
->
get_repository
(
TransactionEntity
::
class
);
if
(
$order_id
)
{
if
(
$order_id
)
{
/**
* Find existing transaction.
* @var TransactionEntity $transaction
*/
$transaction
=
$mapper
->
get_one_by
(
[
'order_id'
=>
$order_id
,
'status'
=>
'open'
,
]
);
if
(
$transaction
)
{
$transaction
->
set_fields
(
[
'status'
=>
$payment
->
status
,
'customer_id'
=>
$payment
->
customerId
,
'value'
=>
$amount
->
value
,
'currency'
=>
$amount
->
currency
,
'sequence_type'
=>
$payment
->
sequenceType
,
'method'
=>
$payment
->
method
,
'mode'
=>
$payment
->
mode
,
'subscription_id'
=>
$payment
->
subscriptionId
,
'campaign_id'
=>
$payment
->
metadata
?
$payment
->
metadata
->
campaign_id
:
null
,
]
);
$mapper
->
save
(
$transaction
);
$updated
++
;
}
}
}
}
catch
(
ApiException
$e
)
{
$this
->
logger
->
error
(
$e
->
getMessage
()
);
}
}
}
return
$updated
;
}
/**
* Adds missing transactions from Mollie.
* Returns the number of transactions added.
*
* @return int
*/
public
function
add_missing_transactions
():
int
{
$added
=
0
;
$mapper
=
$this
->
mapper
;
$mapper
->
get_repository
(
DonorEntity
::
class
);
$donors
=
$mapper
->
get_all_by
();
/** @var DonorEntity $donor */
foreach
(
$donors
as
$donor
)
{
$customer_id
=
$donor
->
customer_id
;
if
(
$donor
->
mode
!==
$this
->
api_mode
)
{
$this
->
set_api_mode
(
$donor
->
mode
);
}
$customer
=
$this
->
get_customer
(
$customer_id
);
if
(
$customer
)
{
try
{
$payments
=
$customer
->
payments
();
foreach
(
$payments
as
$payment
)
{
$order_id
=
$payment
->
metadata
->
order_id
??
null
;
if
(
$order_id
)
{
$mapper
->
get_repository
(
TransactionEntity
::
class
);
/**
* Find existing transaction.
...
...
@@ -744,30 +809,26 @@ class MollieVendor implements VendorInterface {
// Add new transaction if none found.
if
(
!
$transaction
)
{
$transaction
=
new
TransactionEntity
(
[
'order_id'
=>
$order_id
,
]
);
}
else
{
$transaction
->
set_fields
([
'created'
=>
$payment
->
createdAt
]);
}
$transaction
->
set_fields
(
[
$transaction
=
new
TransactionEntity
(
[
'order_id'
=>
$order_id
,
'created'
=>
$payment
->
createdAt
,
'status'
=>
$payment
->
status
,
'customer_id'
=>
$payment
->
customerId
,
'value'
=>
$amount
->
value
,
'currency'
=>
$amount
->
currency
,
'value'
=>
$
payment
->
amount
->
value
,
'currency'
=>
$
payment
->
amount
->
currency
,
'sequence_type'
=>
$payment
->
sequenceType
,
'method'
=>
$payment
->
method
,
'mode'
=>
$payment
->
mode
,
'subscription_id'
=>
$payment
->
subscriptionId
,
'transaction_id'
=>
$payment
->
id
,
'campaign_id'
=>
$payment
->
metadata
?
$payment
->
metadata
->
campaign_id
:
null
,
]
);
$mapper
->
save
(
$transaction
);
$updated
++
;
]
);
$mapper
->
save
(
$transaction
);
$added
++
;
}
}
}
}
catch
(
ApiException
$e
)
{
...
...
@@ -776,6 +837,6 @@ class MollieVendor implements VendorInterface {
}
}
return
$
updat
ed
;
return
$
add
ed
;
}
}
app/View/kudos-admin-debug.php
View file @
53d5ba59
...
...
@@ -200,10 +200,17 @@ $tab = $_GET['tab'] ?? $default_tab;
<hr/>
<p>
Mollie actions.
</p>
<form
action=
"
<?php
echo
esc_url
(
$url
);
?>
"
method=
'post'
>
<?php
wp_nonce_field
(
'kudos_sync_payments'
);
?>
<form
action=
"
<?php
echo
esc_url
(
$url
);
?>
"
method=
'post'
style=
"display: inline"
>
<?php
wp_nonce_field
(
'kudos_sync_transactions'
);
?>
<button
class=
"button-secondary confirm"
type=
'submit'
name=
'kudos_action'
value=
'kudos_sync_transactions'
>
Sync transactions
</button>
</form>
<form
action=
"
<?php
echo
esc_url
(
$url
);
?>
"
method=
'post'
style=
"display: inline"
>
<?php
wp_nonce_field
(
'kudos_add_missing_transactions'
);
?>
<button
class=
"button-secondary confirm"
type=
'submit'
name=
'kudos_action'
value=
'kudos_
sync_payments'
>
Sync payment
s
value=
'kudos_
add_missing_transactions'
>
Add missing transaction
s
</button>
</form>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment