Commit 91f10df7 authored by Michael Iseard's avatar Michael Iseard
Browse files

Reformat code

parent 214276b7
......@@ -305,7 +305,7 @@ class Admin {
$table_handle,
'kudos',
[
'confirmationDelete' => __( 'Are you sure you want to delete this donor?', 'kudos-donations' ) ,
'confirmationDelete' => __( 'Are you sure you want to delete this donor?', 'kudos-donations' ),
]
);
}
......@@ -422,10 +422,10 @@ class Admin {
break;
case 'kudos_cancel_subscription':
$payment_service = PaymentService::factory();
$subscription_id = isset( $_REQUEST['subscriptionId'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['subscriptionId'] ) ) : '';
$customer_id = isset( $_REQUEST['customerId'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['customerId'] ) ) : '';
$subscription = $payment_service->cancel_subscription( $subscription_id, $customer_id );
$payment_service = PaymentService::factory();
$subscription_id = isset( $_REQUEST['subscriptionId'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['subscriptionId'] ) ) : '';
$customer_id = isset( $_REQUEST['customerId'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['customerId'] ) ) : '';
$subscription = $payment_service->cancel_subscription( $subscription_id, $customer_id );
if ( $subscription ) {
new AdminNotice( __( 'Subscription cancelled', 'kudos-donations' ) );
}
......
......@@ -100,7 +100,7 @@ class CampaignsTable extends WP_List_Table {
$campaigns[ $key ]['date'] = date( "r", hexdec( substr( $id, 3, 8 ) ) );
$campaigns[ $key ]['transactions'] = 0;
$campaigns[ $key ]['total'] = $this->campaigns->get_campaign_total($id);
$campaigns[ $key ]['total'] = $this->campaigns->get_campaign_total( $id );
if ( $transactions ) {
$campaigns[ $key ]['last_donation'] = end( $transactions )->created;
$campaigns[ $key ]['transactions'] = count( $transactions );
......@@ -204,11 +204,12 @@ class CampaignsTable extends WP_List_Table {
*/
protected function column_name( array $item ): string {
$url = add_query_arg([
'page' => 'kudos-settings',
'tab_name' => 'campaigns',
'campaign_id' => $item['id']
], admin_url());
$url = add_query_arg( [
'page' => 'kudos-settings',
'tab_name' => 'campaigns',
'campaign_id' => $item['id'],
],
admin_url() );
$actions = [
'edit' => sprintf(
......
......@@ -30,11 +30,11 @@ class DonorsTable extends WP_List_Table {
$this->table = DonorEntity::get_table_name();
$this->search_columns = [
'name' => __( 'Name', 'kudos-donations' ),
'email' => __( 'Email', 'kudos-donations' ),
'address' => __( 'Address', 'kudos-donations' ),
'order_id' => __( 'Order ID', 'kudos-donations' ),
'customer_id' => __( 'Customer ID', 'kudos-donations' ),
'name' => __( 'Name', 'kudos-donations' ),
'email' => __( 'Email', 'kudos-donations' ),
'address' => __( 'Address', 'kudos-donations' ),
'order_id' => __( 'Order ID', 'kudos-donations' ),
'customer_id' => __( 'Customer ID', 'kudos-donations' ),
];
$this->export_columns = [
......@@ -98,13 +98,13 @@ class DonorsTable extends WP_List_Table {
*/
public function column_names(): array {
return [
'email' => __( 'E-mail', 'kudos-donations' ),
'name' => __( 'Name', 'kudos-donations' ),
'address' => __( 'Address', 'kudos-donations' ),
'donations' => __( 'Donations', 'kudos-donations' ),
'mode' => __( 'Mode', 'kudos-donations' ),
'customer_id' => __( 'Customer ID', 'kudos-donations' ),
'created' => __( 'Date', 'kudos-donations' ),
'email' => __( 'E-mail', 'kudos-donations' ),
'name' => __( 'Name', 'kudos-donations' ),
'address' => __( 'Address', 'kudos-donations' ),
'donations' => __( 'Donations', 'kudos-donations' ),
'mode' => __( 'Mode', 'kudos-donations' ),
'customer_id' => __( 'Customer ID', 'kudos-donations' ),
'created' => __( 'Date', 'kudos-donations' ),
];
}
......@@ -235,12 +235,12 @@ class DonorsTable extends WP_List_Table {
*/
protected function column_email( array $item ): string {
$url = add_query_arg([
'page' => esc_attr($_REQUEST['page']),
'action' => 'delete',
'id' => sanitize_text_field( $item['id'] ),
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['singular'] )
]);
$url = add_query_arg( [
'page' => esc_attr( $_REQUEST['page'] ),
'action' => 'delete',
'id' => sanitize_text_field( $item['id'] ),
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['singular'] ),
] );
$title = sprintf(
'<a href="mailto: %1$s" />%1$s</a>',
......
......@@ -299,9 +299,9 @@ class SubscriptionsTable extends WP_List_Table {
'</strong>';
$url = add_query_arg( [
'page' => esc_attr( $_REQUEST['page'] ),
'id' => sanitize_text_field( $item['id'] ),
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['singular'] ),
'page' => esc_attr( $_REQUEST['page'] ),
'id' => sanitize_text_field( $item['id'] ),
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['singular'] ),
] );
$actions = [];
......
......@@ -34,11 +34,11 @@ class TransactionsTable extends WP_List_Table {
$this->campaigns = new Campaigns();
$this->search_columns = [
'name' => __( 'Name', 'kudos-donations' ),
'email' => __( 'Email', 'kudos-donations' ),
'campaign_id' => __( 'Campaign', 'kudos-donations' ),
'order_id' => __( 'Order ID', 'kudos-donations' ),
'customer_id' => __( 'Customer ID', 'kudos-donations' ),
'name' => __( 'Name', 'kudos-donations' ),
'email' => __( 'Email', 'kudos-donations' ),
'campaign_id' => __( 'Campaign', 'kudos-donations' ),
'order_id' => __( 'Order ID', 'kudos-donations' ),
'customer_id' => __( 'Customer ID', 'kudos-donations' ),
];
$this->export_columns = [
......@@ -116,7 +116,7 @@ class TransactionsTable extends WP_List_Table {
}
$having = ! empty( $having ) ? 'HAVING ' . implode( " AND ", $having ) : '';
$query = $query . $having;
$query = $query . $having;
return $this->mapper->get_results( $query );
......@@ -154,7 +154,7 @@ class TransactionsTable extends WP_List_Table {
public function get_hidden_columns(): array {
return [
'transaction_id',
'customer_id'
'customer_id',
];
}
......@@ -269,16 +269,16 @@ class TransactionsTable extends WP_List_Table {
protected function column_created( array $item ): string {
$title = '<strong>' .
wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
strtotime( $item['created'] ) ) .
'</strong>';
$url = add_query_arg([
'page' => esc_attr( $_REQUEST['page'] ),
'action' => 'delete',
'id' => $item['id'],
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['singular'] )
]);
$url = add_query_arg( [
'page' => esc_attr( $_REQUEST['page'] ),
'action' => 'delete',
'id' => $item['id'],
'_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['singular'] ),
] );
$actions = apply_filters(
TransactionEntity::get_table_name( false ) . '_actions',
......@@ -424,8 +424,8 @@ class TransactionsTable extends WP_List_Table {
$status = __( 'Unknown', 'kudos-donations' );
}
if($item['refunds']) {
$status .= ' (' . __('Refunded', 'kudos-donations') . ')';
if ( $item['refunds'] ) {
$status .= ' (' . __( 'Refunded', 'kudos-donations' ) . ')';
}
return apply_filters( 'kudos_transactions_column_status', $status, $item['order_id'] );
......
......@@ -46,7 +46,7 @@ switch ( $table_action ) {
?>
<form id="subscriptions-table" method="POST">
<?php
$table->display();
$table->display();
?>
</form>
</div>
......@@ -12,48 +12,48 @@ use Kudos\Service\AdminNotice;
$table = new SubscriptionsTable();
$table->prepare_items();
$table_action = $table->current_action();
$records = isset($_REQUEST['bulk-action']) ? count($_REQUEST['bulk-action']) : 0;
$records = isset( $_REQUEST['bulk-action'] ) ? count( $_REQUEST['bulk-action'] ) : 0;
switch ($table_action) {
case 'cancel':
$message = __('Subscription cancelled', 'kudos-donations');
break;
case 'delete':
$message = __('Subscription deleted', 'kudos-donations');
break;
case 'bulk-cancel':
$message = sprintf(
/* translators: %s: Number of records */
_n('Cancelled %s subscription', 'Cancelled %s subscriptions', $records, 'kudos-donations'),
$records
);
break;
case 'bulk-delete':
$message = sprintf(
/* translators: %s: Number of records */
_n('Deleted %s subscription', 'Deleted %s subscriptions', $records, 'kudos-donations'),
$records
);
break;
switch ( $table_action ) {
case 'cancel':
$message = __( 'Subscription cancelled', 'kudos-donations' );
break;
case 'delete':
$message = __( 'Subscription deleted', 'kudos-donations' );
break;
case 'bulk-cancel':
$message = sprintf(
/* translators: %s: Number of records */
_n( 'Cancelled %s subscription', 'Cancelled %s subscriptions', $records, 'kudos-donations' ),
$records
);
break;
case 'bulk-delete':
$message = sprintf(
/* translators: %s: Number of records */
_n( 'Deleted %s subscription', 'Deleted %s subscriptions', $records, 'kudos-donations' ),
$records
);
break;
}
?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php esc_attr_e('Subscriptions', 'kudos-donations'); ?></h1>
<?php if (isset($_REQUEST['s'])) { ?>
<h1 class="wp-heading-inline"><?php esc_attr_e( 'Subscriptions', 'kudos-donations' ); ?></h1>
<?php if ( isset( $_REQUEST['s'] ) ) { ?>
<span class="subtitle">
<?php
/* translators: %s: Search term */
printf(__('Search results for “%s”'), $_REQUEST['s'])
?>
/* translators: %s: Search term */
printf( __( 'Search results for “%s”' ), $_REQUEST['s'] )
?>
</span>
<?php } ?>
<?php
if (isset($message)) {
$notice = new AdminNotice(esc_html($message));
$notice->render();
}
?>
if ( isset( $message ) ) {
$notice = new AdminNotice( esc_html( $message ) );
$notice->render();
}
?>
<form id="subscriptions-table" method="POST">
<?php $table->display(); ?>
</form>
......
......@@ -33,7 +33,7 @@ echo get_search_query();
<div class="wrap">
<h1 class="wp-heading-inline"><?php esc_attr_e( 'Transactions', 'kudos-donations' ); ?></h1>
<?php if ( isset( $_REQUEST['s'] ) ) { ?>
<span class="subtitle">
<span class="subtitle">
<?php
/* translators: %s: Search term */
printf( __( 'Search results for “%s”' ), $_REQUEST['s'] )
......
......@@ -64,10 +64,11 @@ abstract class AbstractEntity implements EntityInterface {
$this->$property = $value;
} else {
$logger = LoggerService::factory();
$logger->warning( 'Error setting property.', [
"property" => $property,
"entity" => static::class
] );
$logger->warning( 'Error setting property.',
[
"property" => $property,
"entity" => static::class,
] );
}
}
}
......
......@@ -151,7 +151,7 @@ class Front {
$handle = $this->plugin_name . '-button-block';
wp_enqueue_style( $handle, Utils::get_asset_url( 'kudos-button-block.css' ), [], $this->version);
wp_enqueue_style( $handle, Utils::get_asset_url( 'kudos-button-block.css' ), [], $this->version );
wp_enqueue_script(
$handle,
Utils::get_asset_url( 'kudos-button-block.js' ),
......@@ -189,10 +189,10 @@ class Front {
*/
public static function api_ready(): bool {
$vendor = Settings::get_setting( 'payment_vendor' );
$api_connected = Settings::get_setting( $vendor . '_connected' );
$api_mode = Settings::get_setting( $vendor . '_api_mode' );
$api_key = Settings::get_setting( $vendor . '_' . $api_mode . '_api_key' );
$vendor = Settings::get_setting( 'payment_vendor' );
$api_connected = Settings::get_setting( $vendor . '_connected' );
$api_mode = Settings::get_setting( $vendor . '_api_mode' );
$api_key = Settings::get_setting( $vendor . '_' . $api_mode . '_api_key' );
if ( ! $api_connected && ! $api_key ) {
return false;
......@@ -234,9 +234,9 @@ class Front {
$atts = shortcode_atts(
[
'button_label' => __( 'Donate now', 'kudos-donations' ),
'campaign_id' => 'default',
'alignment' => 'none',
'button_label' => __( 'Donate now', 'kudos-donations' ),
'campaign_id' => 'default',
'alignment' => 'none',
],
$atts,
'kudos'
......@@ -288,7 +288,7 @@ class Front {
public function kudos_render_callback( array $atts ): ?string {
// Continue only if payment API ready
if(self::api_ready()) {
if ( self::api_ready() ) {
// Set campaign according to atts
$campaigns = new Campaigns();
......
......@@ -123,7 +123,7 @@ class Campaigns {
public function get_campaign( ?string $value ): ?array {
$campaigns = $this->campaigns;
$key = array_search( $value, array_column( (array)$campaigns, 'id' ) );
$key = array_search( $value, array_column( (array) $campaigns, 'id' ) );
// Check if key is an index and if so return index from forms
if ( is_int( $key ) ) {
......@@ -138,16 +138,17 @@ class Campaigns {
* Gets total value paid for campaign
*
* @param string $campaign_id
*
* @return float|int
*/
public function get_campaign_total( string $campaign_id ) {
$mapper = new MapperService(TransactionEntity::class);
$transactions = $mapper->get_all_by([
'campaign_id' => $campaign_id
]);
$mapper = new MapperService( TransactionEntity::class );
$transactions = $mapper->get_all_by( [
'campaign_id' => $campaign_id,
] );
return array_sum(array_map(function ($transaction) {
return array_sum( array_map( function ( $transaction ) {
if ( 'paid' === $transaction->status ) {
$refunds = $transaction->get_refund();
if ( $refunds ) {
......@@ -156,8 +157,10 @@ class Campaigns {
return $transaction->value;
}
}
return 0;
}, (array) $transactions));
},
(array) $transactions ) );
}
......
......@@ -71,7 +71,7 @@ class Settings {
'smtp_encryption' => [
'type' => 'string',
'show_in_rest' => true,
'default' => 'tls'
'default' => 'tls',
],
'smtp_autotls' => [
'type' => 'boolean',
......
......@@ -50,15 +50,15 @@ class ActivatorService {
Settings::update_setting( 'show_intro', 1 );
// Apply mode to Donors
$mapper = new MapperService(DonorEntity::class);
$mapper = new MapperService( DonorEntity::class );
$donors = $mapper->get_all_by();
/** @var DonorEntity $donor */
foreach ($donors as $donor) {
foreach ( $donors as $donor ) {
$transactions = $donor->get_transactions();
if($transactions) {
$donor->set_fields(['mode' => $transactions[0]->mode]);
if ( $transactions ) {
$donor->set_fields( [ 'mode' => $transactions[0]->mode ] );
}
$mapper->save($donor);
$mapper->save( $donor );
}
}
......
......@@ -38,18 +38,20 @@ class MailerService extends AbstractService {
*/
public function register_rest_routes() {
register_rest_route('kudos/v1', 'email/test', [
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'send_test' ],
'args' => [
'email' => [
'required' => true,
register_rest_route( 'kudos/v1',
'email/test',
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'send_test' ],
'args' => [
'email' => [
'required' => true,
],
],
],
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
]);
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
] );
}
/**
......
......@@ -194,6 +194,7 @@ class MapperService extends AbstractService {
if ( null === $this->repository ) {
$this->logger->warning( 'Failed to get repository.' );
return null;
}
......
......@@ -51,13 +51,13 @@ class PaymentService extends AbstractService {
parent::__construct();
switch (Settings::get_setting('payment_vendor')) {
switch ( Settings::get_setting( 'payment_vendor' ) ) {
case 'mollie':
$this->vendor = MollieVendor::factory();
break;
default:
$this->vendor = MollieVendor::factory();
$this->logger->critical('No payment vendor specified. Using Mollie.');
$this->logger->critical( 'No payment vendor specified. Using Mollie.' );
}
}
......@@ -98,7 +98,7 @@ class PaymentService extends AbstractService {
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
]
],
];
foreach ( $routes as $key => $route ) {
......@@ -152,8 +152,8 @@ class PaymentService extends AbstractService {
// Verify nonce
if ( ! wp_verify_nonce( $request->get_header( 'X-WP-Nonce' ), 'wp_rest' ) ) {
wp_send_json_error( [
'message' => __( 'Request invalid.', 'kudos-donations' ),
'nonce' => $request->get_header('X-WP-Nonce')
'message' => __( 'Request invalid.', 'kudos-donations' ),
'nonce' => $request->get_header( 'X-WP-Nonce' ),
] );
}
......@@ -176,24 +176,24 @@ class PaymentService extends AbstractService {
// Search for existing donor based on email and mode.
/** @var DonorEntity $donor */
$donor = $mapper->get_one_by([
$donor = $mapper->get_one_by( [
'email' => $email,
'mode' => $this->vendor->get_api_mode()
'mode' => $this->vendor->get_api_mode(),
] );
// 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,
'mode' => $this->vendor->get_api_mode(),
'street' => $street,
'postcode' => $postcode,
'city' => $city,
......@@ -243,14 +243,14 @@ class PaymentService extends AbstractService {
*/
public function cancel_subscription( string $subscription_id, $customer_id = null ): bool {
$mapper = new MapperService( SubscriptionEntity::class );
$mapper = new MapperService( SubscriptionEntity::class );
/** @var SubscriptionEntity $subscription */
$subscription = $mapper->get_one_by( [ 'subscription_id' => $subscription_id ] );
if ( $subscription ) {
$this->vendor->cancel_subscription($subscription_id, $customer_id);
$this->vendor->cancel_subscription( $subscription_id, $customer_id );
$this->logger->info(
'Subscription cancelled.',
......@@ -296,9 +296,9 @@ class PaymentService extends AbstractService {
string $customer_id = null
) {
$order_id = Utils::generate_id( 'kdo_' );
$currency = 'EUR';
$value = number_format( $value, 2, '.', '' );
$order_id = Utils::generate_id( 'kdo_' );
$currency = 'EUR';
$value = number_format( $value, 2, '.', '' );
// Set payment frequency.
$frequency_text = Utils::get_frequency_name( $interval );
......@@ -430,7 +430,7 @@ class PaymentService extends AbstractService {
*/
public function handle_webhook( WP_REST_Request $request ) {
return $this->vendor->rest_webhook($request);
return $this->vendor->rest_webhook( $request );
}
}
......@@ -11,9 +11,9 @@ use WP_REST_Response;
abstract class AbstractVendor extends AbstractService {
/**
* @param TransactionEntity $transaction,
* @param string $mandate_id,
* @param string $interval,
* @param TransactionEntity $transaction ,
* @param string $mandate_id ,
* @param string $interval ,
* @param string $years
*/
abstract public function create_subscription(
......@@ -27,6 +27,7 @@ abstract class AbstractVendor extends AbstractService {
* Returns all subscriptions for customer
*
* @param string $customer_id customer id.
*
* @since 2.0.0
*/
abstract public function get_subscriptions( string $customer_id );
......@@ -36,6 +37,7 @@ abstract class AbstractVendor extends AbstractService {
*
* @param string $subscription_id subscription id.
* @param null|string $customer_id customer id.
*
* @return bool
*/
abstract public function cancel_subscription( string $subscription_id, $customer_id = null ): bool;
......@@ -93,7 +95,7 @@ abstract class AbstractVendor extends AbstractService {
*
* @return string