Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
angelablake committed Jun 14, 2023
2 parents 5215934 + 5229306 commit 589d392
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 116 deletions.
4 changes: 2 additions & 2 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: The most robust, flexible, and intuitive way to accept donations on WordPress.
* Author: GiveWP
* Author URI: https://givewp.com/
* Version: 2.28.0
* Version: 2.29.0
* Requires at least: 5.0
* Requires PHP: 7.0
* Text Domain: give
Expand Down Expand Up @@ -316,7 +316,7 @@ private function setup_constants()
{
// Plugin version.
if (!defined('GIVE_VERSION')) {
define('GIVE_VERSION', '2.28.0');
define('GIVE_VERSION', '2.29.0');
}

// Plugin Root File.
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: donation, donate, recurring donations, fundraising, crowdfunding
Requires at least: 5.0
Tested up to: 6.2
Requires PHP: 7.0
Stable tag: 2.28.0
Stable tag: 2.29.0
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -258,6 +258,11 @@ The 2% fee on Stripe donations only applies to donations taken via our free Stri
8. GiveWP has a dedicated support team to help answer any questions you may have and help you through stumbling blocks.

== Changelog ==
= 2.29.0: June 14th, 2023 =
* Feature: A refund checkbox can be enabled on the admin screen.
* Enhancement: PayPal Donations onboarding validates only the PayPal seller capabilities that block payment processing.
* Fix: Donor Created Date column is now included in the Donor csv export.

= 2.28.0: June 8th, 2023 =
* Enhancement: Improvements to checkboxes in the Field API in preparation for GiveWP 3.0
* Fix: Resolves an issue with Form Field Manager caused in 2.27.3. Please update both GiveWP and Form Field Manager.
Expand Down
87 changes: 46 additions & 41 deletions src/Exports/DonorsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,8 @@ public function set_properties($request)
}

/**
* @since 2.21.2
*/
public function csv_cols(): array
{
return $this->flattenAddressColumn(
array_intersect_key([
'full_name' => __('Name', 'give'),
'email' => __('Email', 'give'),
'address' => [
'address_line1' => __('Address', 'give'),
'address_line2' => __('Address 2', 'give'),
'address_city' => __('City', 'give'),
'address_state' => __('State', 'give'),
'address_zip' => __('Zip', 'give'),
'address_country' => __('Country', 'give'),
],
'userid' => __('User ID', 'give'),
'donations' => __('Number of donations', 'give'),
'donation_sum' => __('Total Donated', 'give'),
], $this->postedData['give_export_columns'])
);
}

/**
* @since 2.21.2
* @since 2.29.0 Include donor created date
* @since 2.21.2
*/
public function get_data(): array
{
Expand All @@ -81,6 +58,7 @@ public function get_data(): array
['donors.name', 'full_name'],
['donors.email', 'email'],
['donors.user_id', 'userid'],
['donors.date_created', 'donor_created_date'],
['donors.purchase_count', 'donations'],
['donors.purchase_value', 'donation_sum']
);
Expand Down Expand Up @@ -116,14 +94,15 @@ public function get_data(): array
$donorQuery->joinRaw("JOIN ({$donationQuery->getSQL()}) AS sub ON donors.id = sub.donorId");

if ($this->shouldIncludeAddress()) {
$donorQuery->attachMeta('give_donormeta',
$donorQuery->attachMeta(
'give_donormeta',
'donors.ID',
'donor_id',
['_give_donor_address_billing_line1_0', 'address_line1'],
['_give_donor_address_billing_line2_0', 'address_line2'],
['_give_donor_address_billing_city_0', 'address_city'],
['_give_donor_address_billing_city_0', 'address_city'],
['_give_donor_address_billing_state_0', 'address_state'],
['_give_donor_address_billing_zip_0', 'address_zip'],
['_give_donor_address_billing_zip_0', 'address_zip'],
['_give_donor_address_billing_country_0', 'address_country']
);
}
Expand All @@ -143,6 +122,45 @@ protected function shouldIncludeAddress(): bool
return isset($this->postedData['give_export_columns']['address']);
}

/**
* @since 2.21.2
*/
protected function filterExportData(array $exportData): array
{
/**
* @since 2.21.2
*
* @param array $exportData
*/
return apply_filters("give_export_get_data_{$this->export_type}", $exportData);
}

/**
* @since 2.29.0 Include donor created col
* @since 2.21.2
*/
public function csv_cols(): array
{
return $this->flattenAddressColumn(
array_intersect_key([
'full_name' => __('Name', 'give'),
'email' => __('Email', 'give'),
'address' => [
'address_line1' => __('Address', 'give'),
'address_line2' => __('Address 2', 'give'),
'address_city' => __('City', 'give'),
'address_state' => __('State', 'give'),
'address_zip' => __('Zip', 'give'),
'address_country' => __('Country', 'give'),
],
'userid' => __('User ID', 'give'),
'donor_created_date' => __('Donor Created', 'give'),
'donations' => __('Number of donations', 'give'),
'donation_sum' => __('Total Donated', 'give'),
], $this->postedData['give_export_columns'])
);
}

/**
* @since 2.21.2
*/
Expand All @@ -163,17 +181,4 @@ protected function flattenColumn(array $columnarData, string $columnName): array

return $columnarData;
}

/**
* @since 2.21.2
*/
protected function filterExportData(array $exportData): array
{
/**
* @since 2.21.2
*
* @param array $exportData
*/
return apply_filters("give_export_get_data_{$this->export_type}", $exportData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Give\Framework\LegacyPaymentGateways\Adapters;

use Give\Framework\PaymentGateways\Contracts\PaymentGatewayInterface;
use Give\Framework\PaymentGateways\PaymentGateway;
use Give\LegacyPaymentGateways\Adapters\LegacyPaymentGatewayAdapter;

use function method_exists;
Expand All @@ -20,7 +21,7 @@ public function connectGatewayToLegacyPaymentGatewayAdapter(string $gatewayClass
/** @var LegacyPaymentGatewayAdapter $legacyPaymentGatewayAdapter */
$legacyPaymentGatewayAdapter = give(LegacyPaymentGatewayAdapter::class);

/** @var PaymentGatewayInterface $registeredGateway */
/** @var PaymentGateway $registeredGateway */
$registeredGateway = give($gatewayClass);
$registeredGatewayId = $registeredGateway::id();

Expand All @@ -39,6 +40,28 @@ static function ($legacyPaymentData) use ($registeredGateway, $legacyPaymentGate
$legacyPaymentGatewayAdapter->handleBeforeGateway(give_clean($legacyPaymentData), $registeredGateway);
}
);

if ($registeredGateway->supportsRefund()) {
add_action(
"give_view_donation_details_totals_after",
static function (int $donationId) use ($registeredGateway, $legacyPaymentGatewayAdapter) {
$legacyPaymentGatewayAdapter->addOptRefundCheckbox($donationId, $registeredGateway);
},
PHP_INT_MAX // Ensure this will be the last callback registered to this hook.
);
add_action(
"give_update_payment_status",
static function (int $donationId, string $newStatus, string $oldStatus) use (
$registeredGateway,
$legacyPaymentGatewayAdapter
) {
$legacyPaymentGatewayAdapter->maybeRefundOnGateway($donationId, $newStatus, $oldStatus,
$registeredGateway);
},
11,
3
);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
use Give\Framework\Http\Response\Types\RedirectResponse;
use Give\Framework\PaymentGateways\CommandHandlers\PaymentCompleteHandler;
use Give\Framework\PaymentGateways\CommandHandlers\PaymentProcessingHandler;
use Give\Framework\PaymentGateways\CommandHandlers\PaymentRefundedHandler;
use Give\Framework\PaymentGateways\CommandHandlers\RedirectOffsiteHandler;
use Give\Framework\PaymentGateways\CommandHandlers\RespondToBrowserHandler;
use Give\Framework\PaymentGateways\Commands\GatewayCommand;
use Give\Framework\PaymentGateways\Commands\PaymentComplete;
use Give\Framework\PaymentGateways\Commands\PaymentProcessing;
use Give\Framework\PaymentGateways\Commands\PaymentRefunded;
use Give\Framework\PaymentGateways\Commands\RedirectOffsite;
use Give\Framework\PaymentGateways\Commands\RespondToBrowser;

Expand All @@ -26,8 +28,9 @@ class HandleGatewayPaymentCommand
/**
* Handle gateway command
*
* @since 2.27.0 return responses
* @since 2.18.0
* @since 2.29.0 Handle PaymentRefunded command
* @since 2.27.0 return responses
* @since 2.18.0
*
* @return JsonResponse|RedirectResponse
* @throws TypeNotSupported|Exception
Expand All @@ -50,6 +53,14 @@ public function __invoke(GatewayCommand $command, Donation $donation)
return new RedirectResponse(give_get_success_page_uri());
}

if ($command instanceof PaymentRefunded) {
$handler = new PaymentRefundedHandler($command);
$handler->handle($donation);
$url = isset($_REQUEST['_wp_http_referer']) ? home_url($_REQUEST['_wp_http_referer']) : home_url('/');

return new RedirectResponse($url);
}

if ($command instanceof RedirectOffsite) {
return (new RedirectOffsiteHandler())($command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public function getName(): string;
*/
public function getPaymentMethodLabel(): string;

/**
* Determines if refunds are supported
*
* @since 2.29.0
*
* @return bool
*/
public function supportsRefund(): bool;

/**
* Determines if subscriptions are supported
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ public function create(Donation $donation, array $gatewayData = [])
}
}

/**
* @since 2.29.0
*/
public function refund(Donation $donation)
{
try {
$command = $this->gateway->refundDonation($donation);

if ($command instanceof GatewayCommand) {
$this->handleGatewayCommand($command, $donation);
}
} catch (\Exception $exception) {
PaymentGatewayLog::error(
$exception->getMessage(),
[
'Payment Gateway' => $this->gateway::id(),
'Donation' => $donation->toArray(),
]
);

$message = __(
'An unexpected error occurred while refunding the donation. Please try again or contact a site administrator.',
'give'
);

$this->handleExceptionResponse($exception, $message);
}
}

/**
* Handle gateway command
*
Expand Down
12 changes: 10 additions & 2 deletions src/Framework/PaymentGateways/PaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
use Give\Framework\Exceptions\Primitives\Exception;
use Give\Framework\LegacyPaymentGateways\Contracts\LegacyPaymentGatewayInterface;
use Give\Framework\PaymentGateways\Actions\GenerateGatewayRouteUrl;
use Give\Framework\PaymentGateways\Commands\GatewayCommand;
use Give\Framework\PaymentGateways\Contracts\PaymentGatewayInterface;
use Give\Framework\PaymentGateways\Contracts\Subscription\SubscriptionAmountEditable;
use Give\Framework\PaymentGateways\Contracts\Subscription\SubscriptionDashboardLinkable;
use Give\Framework\PaymentGateways\Contracts\Subscription\SubscriptionPaymentMethodEditable;
use Give\Framework\PaymentGateways\Contracts\Subscription\SubscriptionTransactionsSynchronizable;
use Give\Framework\PaymentGateways\Controllers\PaymentGatewayController;
use Give\Framework\PaymentGateways\Routes\RouteSignature;
use Give\Framework\PaymentGateways\Traits\HandleHttpResponses;
use Give\Framework\PaymentGateways\Traits\HasRouteMethods;
Expand Down Expand Up @@ -59,6 +57,16 @@ public function __construct(SubscriptionModule $subscriptionModule = null)
$this->subscriptionModule = $subscriptionModule;
}

/**
* @inheritDoc
*
* @since 2.29.0
*/
public function supportsRefund(): bool
{
return $this->isFunctionImplementedInGatewayClass('refundDonation');
}

/**
* @inheritDoc
*/
Expand Down
Loading

0 comments on commit 589d392

Please sign in to comment.