Skip to content

Commit

Permalink
Merge branch 'release/3.12.2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloiankoski committed Jun 11, 2024
2 parents 09d06dd + 221edce commit 4ace382
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 9 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: 3.12.1
* Version: 3.12.2
* Requires at least: 6.3
* Requires PHP: 7.2
* Text Domain: give
Expand Down Expand Up @@ -404,7 +404,7 @@ private function setup_constants()
{
// Plugin version.
if (!defined('GIVE_VERSION')) {
define('GIVE_VERSION', '3.12.1');
define('GIVE_VERSION', '3.12.2');
}

// Plugin Root File.
Expand Down
6 changes: 5 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: 6.3
Tested up to: 6.5
Requires PHP: 7.2
Stable tag: 3.12.1
Stable tag: 3.12.2
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -262,6 +262,10 @@ The 2% fee on Stripe donations only applies to donations taken via our free Stri
10. Use almost any payment gateway integration with GiveWP through our add-ons or by creating your own add-on.

== Changelog ==
= 3.12.2: June 11th, 2024 =
* Fix: Resolved an issue where only the donation amount was sent to PayPal, ignoring event ticket values for one-time donations.
* Fix: Resolved an issue where donations were processed on PayPal but not recorded in GiveWP due to missing city, state, and zip fields.

= 3.12.1: June 5th, 2024 =
* Fix: Resolved an issue where the Donor Phone field was not included in the donor export
* Fix: Resolved an issue where the Billing Address field was not saved in Stripe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
namespace Give\EventTickets\Actions;

use Give\Donations\Models\Donation;
use Give\EventTickets\DataTransferObjects\TicketPurchaseData;
use Give\EventTickets\DataTransferObjects\EventTicketTypeData;
use Give\EventTickets\DataTransferObjects\TicketPurchaseData;
use Give\EventTickets\Fields\EventTickets;
use Give\EventTickets\Models\EventTicket;
use Give\EventTickets\Models\EventTicketType;
use Give\EventTickets\Repositories\EventRepository;
use Give\Framework\Blocks\BlockModel;
use Give\Framework\FieldsAPI\Exceptions\EmptyNameException;
Expand All @@ -16,13 +14,14 @@
class ConvertEventTicketsBlockToFieldsApi
{
/**
* @since 3.12.2 Remove event ID from field name
* @since 3.6.0
*
* @throws EmptyNameException
*/
public function __invoke(BlockModel $block, int $formId)
{
return EventTickets::make($block->getShortName() . '-' . $block->getAttribute('eventId'))
return EventTickets::make($block->getShortName())
->tap(function (EventTickets $eventTicketsField) use ($block, $formId) {
$eventId = $block->getAttribute('eventId');
$event = give(EventRepository::class)->getById($eventId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ import {PayPalSubscriber} from './types';

let currency;

let eventTickets;

/**
* @since 3.12.2
*/
const getEventTicketsTotalAmount = (
eventTickets: Array<{
ticketId: number;
quantity: number;
amount: number;
}>
) => {
const totalAmount = eventTickets.reduce((accumulator, eventTicket) => accumulator + eventTicket.amount, 0);
if (totalAmount > 0) {
return totalAmount / 100;
} else {
return 0;
}
};

const buttonsStyle = {
color: 'gold' as 'gold' | 'blue' | 'silver' | 'white' | 'black',
label: 'paypal' as 'paypal' | 'checkout' | 'buynow' | 'pay' | 'installment' | 'subscribe' | 'donate',
Expand Down Expand Up @@ -122,7 +142,15 @@ import {PayPalSubscriber} from './types';

formData.append('give_payment_mode', 'paypal-commerce');

formData.append('give-amount', getAmount());
const eventTicketsTotalAmount = eventTickets ? getEventTicketsTotalAmount(JSON.parse(eventTickets)) : 0;
const isSubscription = subscriptionPeriod ? subscriptionPeriod !== 'one-time' : false;
if (!isSubscription) {
formData.append('give-amount', getAmount() + eventTicketsTotalAmount);
} else {
formData.append('give-amount', getAmount()); // We don't want to charge the event tickets for each subscription renewal
}

formData.append('give-event-tickets-total-amount', String(eventTicketsTotalAmount));

formData.append('give-recurring-period', subscriptionPeriod);
formData.append('period', subscriptionPeriod);
Expand Down Expand Up @@ -276,15 +304,45 @@ import {PayPalSubscriber} from './types';

currency = useWatch({name: 'currency'});

eventTickets = useWatch({name: 'event-tickets'});

useEffect(() => {
if (orderCreated) {
updateOrderAmount = true;
}
}, [amount]);
}, [amount, eventTickets]);

return children;
};

/**
* @since 3.12.2
*/
const getRequiredValidationMessage = () => {
return __('This is a required field', 'give');
};

/**
* @since 3.12.2
*/
const isCityRequired = () => {
return Boolean(document.querySelector('.givewp-fields-text-city .givewp-field-required'));
};

/**
* @since 3.12.2
*/
const isStateRequired = () => {
return Boolean(document.querySelector('.givewp-fields-select-state .givewp-field-required'));
};

/**
* @since 3.12.2
*/
const isZipRequired = () => {
return Boolean(document.querySelector('.givewp-fields-text-zip .givewp-field-required'));
};

const SmartButtonsContainer = () => {
const {useWatch, useFormState} = window.givewp.form.hooks;
const donationType = useWatch({name: 'donationType'});
Expand Down Expand Up @@ -338,6 +396,29 @@ import {PayPalSubscriber} from './types';
return actions.reject();
}

/**
* Depending on the selected country, the city, state, and zip fields can be required or not and there are custom
* validation rules on the server side that check that. However, in this case, these validations are reached later
* when the donation is already created on the PayPal side. This way, we need the conditions below to check it earlier
* and prevent the donation creation on the PayPal side if the required billing address fields are missing.
*/
if (city.length === 0 && isCityRequired()) {
setError('city', {type: 'custom', message: getRequiredValidationMessage()}, {shouldFocus: true});
return actions.reject();
}

if (state.length === 0 && isStateRequired()) {
setError('state', {type: 'custom', message: getRequiredValidationMessage()}, {shouldFocus: true});
// As the state is a hidden field we need to use this workaround because the "shouldFocus" option does not work in hidden fields.
document.querySelector('.givewp-fields-select-state').scrollIntoView({behavior: 'smooth'});
return actions.reject();
}

if (postalCode.length === 0 && isZipRequired()) {
setError('zip', {type: 'custom', message: getRequiredValidationMessage()}, {shouldFocus: true});
return actions.reject();
}

orderCreated = true;
return actions.resolve();
},
Expand Down

0 comments on commit 4ace382

Please sign in to comment.