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
22224726
Commit
22224726
authored
Jan 31, 2021
by
Michael Iseard
Browse files
Add test mode to Donor entity.
parent
055f752b
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/Admin/Table/DonorsTable.php
View file @
22224726
...
...
@@ -101,6 +101,7 @@ class DonorsTable extends WP_List_Table {
'name'
=>
__
(
'Name'
,
'kudos-donations'
),
'address'
=>
__
(
'Address'
,
'kudos-donations'
),
'donations'
=>
__
(
'Donations'
,
'kudos-donations'
),
'mode'
=>
__
(
'Mode'
,
'kudos-donations'
),
'created'
=>
__
(
'Date'
,
'kudos-donations'
),
];
}
...
...
app/Entity/DonorEntity.php
View file @
22224726
...
...
@@ -18,6 +18,13 @@ class DonorEntity extends AbstractEntity {
* @var string
*/
public
$email
;
/**
* API Mode used to create donor.
*
* @var string
*/
public
$mode
;
/**
* Donor's name
*
...
...
app/Service/ActivatorService.php
View file @
22224726
...
...
@@ -43,9 +43,23 @@ class ActivatorService {
if
(
version_compare
(
$old_version
,
'2.3.0'
,
'<'
)
)
{
global
$wpdb
;
$table
=
TransactionEntity
::
get_table_name
();
$wpdb
->
query
(
"ALTER TABLE
$table
RENAME COLUMN `campaign_label` TO `campaign_id`"
);
// Rename setting
$transaction_table
=
TransactionEntity
::
get_table_name
();
$wpdb
->
query
(
"ALTER TABLE
$transaction_table
RENAME COLUMN `campaign_label` TO `campaign_id`"
);
Settings
::
update_setting
(
'show_intro'
,
1
);
// Apply mode to Donors
$mapper
=
new
MapperService
(
DonorEntity
::
class
);
$donors
=
$mapper
->
get_all_by
();
/** @var DonorEntity $donor */
foreach
(
$donors
as
$donor
)
{
$transactions
=
$donor
->
get_transactions
();
if
(
$transactions
)
{
$donor
->
set_fields
([
'mode'
=>
$transactions
[
0
]
->
mode
]);
}
$mapper
->
save
(
$donor
);
}
}
if
(
version_compare
(
$old_version
,
'2.2.0'
,
'<'
)
)
{
...
...
@@ -98,6 +112,7 @@ class ActivatorService {
country VARCHAR(255),
customer_id VARCHAR(255),
secret VARCHAR(255),
mode VARCHAR(45) NOT NULL,
PRIMARY KEY (id)
)
$charset_collate
"
;
...
...
app/Service/MapperService.php
View file @
22224726
...
...
@@ -192,12 +192,9 @@ class MapperService extends AbstractService {
*/
public
function
get_repository
()
{
try
{
if
(
null
===
$this
->
repository
)
{
throw
new
MapperException
(
'No repository specified'
);
}
}
catch
(
MapperException
$e
)
{
$this
->
logger
->
warning
(
'Failed to get repository.'
,
[
'message'
=>
$e
->
getMessage
()
]
);
if
(
null
===
$this
->
repository
)
{
$this
->
logger
->
warning
(
'Failed to get repository.'
);
return
null
;
}
return
$this
->
repository
;
...
...
app/Service/PaymentService.php
View file @
22224726
...
...
@@ -174,21 +174,25 @@ class PaymentService extends AbstractService {
if
(
$email
)
{
// Search for existing donor.
// Search for existing donor
based on email and mode
.
/** @var DonorEntity $donor */
$donor
=
$mapper
->
get_one_by
(
[
'email'
=>
$email
]
);
$donor
=
$mapper
->
get_one_by
([
'email'
=>
$email
,
'mode'
=>
$this
->
vendor
->
get_api_mode
()
]
);
// Create new donor.
// Create new donor
if none found
.
if
(
empty
(
$donor
->
customer_id
)
)
{
$donor
=
new
DonorEntity
();
$customer
=
$this
->
vendor
->
create_customer
(
$email
,
$name
);
$donor
->
set_fields
(
[
'customer_id'
=>
$customer
->
id
]
);
$donor
->
set_fields
(
[
'customer_id'
=>
$customer
->
id
]
);
}
// Update new/existing donor.
$donor
->
set_fields
(
[
'email'
=>
$email
,
'mode'
=>
$this
->
vendor
->
get_api_mode
(),
'name'
=>
$name
,
'street'
=>
$street
,
'postcode'
=>
$postcode
,
...
...
app/Service/Vendor/AbstractVendor.php
View file @
22224726
...
...
@@ -58,7 +58,7 @@ abstract class AbstractVendor extends AbstractService {
abstract
public
function
get_payment
(
string
$mollie_payment_id
);
/**
* Create a
Mollie
customer.
* Create a customer.
*
* @param string $email Donor email address.
* @param string $name Donor name.
...
...
@@ -66,7 +66,7 @@ abstract class AbstractVendor extends AbstractService {
abstract
public
function
create_customer
(
string
$email
,
string
$name
);
/**
* Get the customer
from Mollie
* Get the customer
*
* @param $customer_id
*/
...
...
@@ -80,7 +80,7 @@ abstract class AbstractVendor extends AbstractService {
abstract
public
function
create_payment
(
array
$payment_array
);
/**
*
Mollie
webhook action
*
Vendor
webhook action
*
* @param WP_REST_Request $request Request array.
*
...
...
@@ -88,6 +88,13 @@ abstract class AbstractVendor extends AbstractService {
*/
abstract
public
function
rest_webhook
(
WP_REST_Request
$request
);
/**
* Vendor API mode
*
* @return string
*/
abstract
public
function
get_api_mode
():
string
;
/**
* Returns the vendor name as a string
*
...
...
app/Service/Vendor/MollieVendor.php
View file @
22224726
...
...
@@ -186,7 +186,7 @@ class MollieVendor extends AbstractVendor {
public
function
create_customer
(
string
$email
,
string
$name
)
{
$customer_array
=
[
'email'
=>
$email
,
'email'
=>
$email
];
if
(
$name
)
{
...
...
@@ -226,7 +226,7 @@ class MollieVendor extends AbstractVendor {
*
* @param array $payment_array Parameters to pass to mollie to create a payment.
*
* @return
false
|Payment
* @return
bool
|Payment
* @since 1.0.0
*/
public
function
create_payment
(
array
$payment_array
):
?Payment
{
...
...
@@ -516,4 +516,15 @@ class MollieVendor extends AbstractVendor {
return
$response
;
}
/**
* Returns the api mode
*
* @return string
*/
public
function
get_api_mode
():
string
{
return
$this
->
api_mode
;
}
}
Write
Preview
Supports
Markdown
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