Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Waldstein committed May 4, 2023
2 parents b6eae22 + dbe9aa2 commit bab9171
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 206 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ on:
types: [ released ]

jobs:
test:
uses: impress-org/givewp-github-actions/.github/workflows/addon-tests.yml@master
with:
addon_slug: givewp-next-gen
givewp_branch: develop

build:
uses: impress-org/givewp-github-actions/.github/workflows/givewp-release.yml@master
needs: test
with:
plugin_slug: give-visual-form-builder
zip_name: give-visual-form-builder
Expand Down
6 changes: 3 additions & 3 deletions give-visual-form-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Plugin Name: Give - Visual Donation Form Builder
* Plugin URI: https://github.com/impress-org/givewp-next-gen
* Description: Create the donation form of your dreams using an easy-to-use visual donation form builder.
* Version: 0.3.2
* Version: 0.3.3
* Requires at least: 5.5
* Requires PHP: 7.2
* Author: GiveWP
Expand All @@ -31,8 +31,8 @@
define('GIVE_NEXT_GEN_NAME', 'Visual Form Builder');

// Versions
define('GIVE_NEXT_GEN_VERSION', '0.3.2');
define('GIVE_NEXT_GEN_MIN_GIVE_VERSION', '2.26.0');
define('GIVE_NEXT_GEN_VERSION', '0.3.3');
define('GIVE_NEXT_GEN_MIN_GIVE_VERSION', '2.27.0');

// Add-on paths
define('GIVE_NEXT_GEN_FILE', __FILE__);
Expand Down
3 changes: 2 additions & 1 deletion packages/form-builder/src/blocks/fields/amount/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const Edit = ({attributes, setAttributes}) => {
} = attributes;

const {gateways} = getFormBuilderData();
const isRecurringSupported = gateways.some((gateway) => gateway.supportsSubscriptions);

const isRecurringSupported = gateways.some((gateway) => gateway.enabled && gateway.supportsSubscriptions);
const isRecurring = isRecurringSupported && recurringEnabled;
const isMultiLevel = priceOption === 'multi';
const isFixedAmount = priceOption === 'set';
Expand Down
25 changes: 22 additions & 3 deletions packages/form-builder/src/blocks/fields/amount/inspector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ const Inspector = ({attributes, setAttributes}) => {
}
};

const {gateways} = getFormBuilderData();
const isRecurringSupported = gateways.some((gateway) => gateway.supportsSubscriptions);
const {gateways, recurringAddonData, gatewaySettingsUrl} = getFormBuilderData();
const enabledGateways = gateways.filter((gateway) => gateway.enabled);
const recurringGateways = gateways.filter((gateway) => gateway.supportsSubscriptions);
const isRecurringSupported = enabledGateways.some((gateway) => gateway.supportsSubscriptions);
const isRecurring = isRecurringSupported && recurringEnabled;

return (
Expand Down Expand Up @@ -164,7 +166,24 @@ const Inspector = ({attributes, setAttributes}) => {
</PanelBody>
)}
<PanelBody title={__('Recurring Donations', 'give')} initialOpen={false}>
{!isRecurringSupported && <RecurringDonationsPromo />}
{!isRecurringSupported && (
recurringAddonData.isInstalled
? <div style={{
fontSize: '13px',
lineHeight: '1.3em',
display: 'flex',
flexDirection: 'column',
gap: '12px',
padding: '6px 12px 12px 0',
}}>
<div>{__('None of the payment gateways currently enabled support Recurring Donations. To collect recurring donations, enable one of the following payment gateways:', 'give')}</div>
<ul style={{listStyleType: 'inherit', marginLeft: '12px'}}>
{recurringGateways.map((gateway) => <li key={gateway.id}>{gateway.label}</li>)}
</ul>
<a href={gatewaySettingsUrl} target="_blank" rel="noreferrer noopener">Go to Payment Gateway Settings</a>
</div>
: <RecurringDonationsPromo />
)}

{isRecurringSupported && (
<PanelRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function Edit(props: BlockEditProps<any>) {
}}
>
<div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
{gateways.map((gateway) => (
{gateways.filter(gateway => gateway.enabled).map((gateway) => (
<GatewayItem
key={gateway.id}
label={gateway.label}
Expand Down
4 changes: 4 additions & 0 deletions packages/form-builder/src/common/getWindowData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ declare global {
},
formBuilderData?: {
gateways: Gateway[];
recurringAddonData?: {
isInstalled: boolean;
},
gatewaySettingsUrl: string;
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/form-builder/src/settings/styles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CustomStyleSettings = () => {
right: '0',
}}>
<div style={{
margin: '-25px -31px -23px -31px', // Offset the modal padding in order to fill the available space.
margin: '0 -31px -23px -31px', // Offset the modal padding in order to fill the available space.
}}>
<CustomStyleCodeControl />
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/form-builder/src/types/gateways.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type Gateway = {
id: string;
enabled: boolean;
label: string;
supportsSubscriptions: boolean;
}
16 changes: 13 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ Tags: givewp, donation, donations, donation plugin, wordpress donation plugin, w
Requires at least: 5.5
Tested up to: 6.0
Requires PHP: 7.2
Stable tag: 0.3.2
Requires Give: 2.26.0
Stable tag: 0.3.3
Requires Give: 2.27.0
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Create the donation form of your dreams using an easy-to-use visual donation form builder.

= 0.3.3: May 4th, 2023 =
* Enhancement: The GiveWP Jedi high council is hosting a beta focus group on May 11th 2023 to provide focused feedback about our new visual donation form builder. We updated the welcome banner to announce this.
* Enhancement: Updated donation form compatibility with GiveWP 2.27.0 gateway api updates
* New: Added notice for recurring gateways in the form builder
* Fix: Improvements to custom styles modal
* Fix: Amount field now uses label attribute setting
* Fix: Resolved issue with adding empty sections in the form builder
* Fix: Updated subscription amount label in confirmation page & donation summary


= 0.3.2: April 12th, 2023 =
* Enhancement: Added licensing to receive future updates from givewp.com.
* Enhancement: Improved error handling when the donation form crashes.
* Fix: Prevent a crash when the form is fixed recurring and donor choice.

= 0.3.1: April 10th, 2023 =
* Enhancmenet: Improvements to the welcome banner content.
* Enhancement: Improvements to the welcome banner content.
* Fix: Prevent a fatal error when activating without GiveWP already active.
* Fix: Prevent errors from breaking the entire donation form.

Expand Down
20 changes: 15 additions & 5 deletions src/FormBuilder/Routes/RegisterFormBuilderPageRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Give\Framework\EnqueueScript;

use Give\Framework\PaymentGateways\Contracts\NextGenPaymentGatewayInterface;
use Give\Framework\PaymentGateways\PaymentGatewayRegister;
use Give\NextGen\DonationForm\Repositories\DonationFormRepository;

use function wp_enqueue_style;
Expand Down Expand Up @@ -85,20 +86,24 @@ public function renderPage()

$formBuilderStorage->loadInFooter()->enqueue();

$enabledGateways = array_filter(
give(DonationFormRepository::class)->getEnabledPaymentGateways($donationFormId),
$enabledGateways = array_keys(give_get_option('gateways'));

$supportedGateways = array_filter(
give(PaymentGatewayRegister::class)->getPaymentGateways(),
static function ($gateway) {
return $gateway instanceof NextGenPaymentGatewayInterface;
return is_a($gateway, NextGenPaymentGatewayInterface::class, true);
}
);

$builderPaymentGatewayData = array_map(function ($gateway) {
$builderPaymentGatewayData = array_map(static function ($gatewayClass) use ($enabledGateways) {
$gateway = give($gatewayClass);
return [
'id' => $gateway::id(),
'enabled' => in_array($gateway::id(), $enabledGateways, true),
'label' => give_get_gateway_checkout_label($gateway::id()) ?? $gateway->getPaymentMethodLabel(),
'supportsSubscriptions' => $gateway->supportsSubscriptions(),
];
}, $enabledGateways);
}, $supportedGateways);

(new EnqueueScript(
'@givewp/form-builder/script',
Expand All @@ -109,6 +114,11 @@ static function ($gateway) {
))->loadInFooter()
->registerLocalizeData('formBuilderData', [
'gateways' => array_values($builderPaymentGatewayData),
'isRecurringEnabled' => defined('GIVE_RECURRING_VERSION') ? GIVE_RECURRING_VERSION : null,
'recurringAddonData' => [
'isInstalled' => defined('GIVE_RECURRING_VERSION') ,
],
'gatewaySettingsUrl' => admin_url('edit.php?post_type=give_forms&page=give-settings&tab=gateways'),
])
->enqueue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __invoke(BlockModel $block, string $currency): DonationAmount
/** @var Amount $amountNode */
$amountNode = $group->getNodeByName('amount');
$amountNode
->label(__('Donation Amount', 'give'))
->label($block->getAttribute('label'))
->levels(...array_map('absint', $block->getAttribute('levels')))
->allowLevels($block->getAttribute('priceOption') === 'multi')
->allowCustomAmount($block->getAttribute('customAmount'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ConvertDonationFormBlocksToFieldsApi
protected $currency;

/**
* @since 0.3.3 conditionally append blocks if block has inner blocks
* @since 0.1.0
*
* @throws TypeNotSupported|NameCollisionException
Expand All @@ -45,28 +46,33 @@ public function __invoke(BlockCollection $blocks, int $formId): Form
$blockIndex = 0;
foreach ($blocks->getBlocks() as $block) {
$blockIndex++;
$form->append($this->convertTopLevelBlockToSection($block, $blockIndex));
$section = $this->convertTopLevelBlockToSection($block, $blockIndex);

if ($block->innerBlocks) {
$section->append(...array_map([$this, 'convertInnerBlockToNode'], $block->innerBlocks->getBlocks()));
}

$form->append($section);
}

return $form;
}

/**
* @since 0.3.3 remove innerBlock appending
* @since 0.1.0
* @throws NameCollisionException
*/
protected function convertTopLevelBlockToSection(BlockModel $block, int $blockIndex): Section
{
return Section::make($block->getShortName() . '-' . $blockIndex)
->label($block->getAttribute('title'))
->description($block->getAttribute('description'))
->append(...array_map([$this, 'convertInnerBlockToNode'], $block->innerBlocks->getBlocks()));
->description($block->getAttribute('description'));
}

/**
* @since 0.1.0
*
* @throws EmptyNameException
* @throws EmptyNameException|NameCollisionException
*/
protected function convertInnerBlockToNode(BlockModel $block): Node
{
Expand Down
23 changes: 21 additions & 2 deletions src/NextGen/DonationForm/Controllers/DonateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Exception;
use Give\Donors\Models\Donor;
use Give\Framework\PaymentGateways\Controllers\GatewayPaymentController;
use Give\Framework\PaymentGateways\Controllers\GatewaySubscriptionController;
use Give\Framework\PaymentGateways\Exceptions\PaymentGatewayException;
use Give\Framework\PaymentGateways\PaymentGateway;
use Give\NextGen\DonationForm\DataTransferObjects\DonateControllerData;
use Give\PaymentGateways\Actions\GetGatewayDataFromRequest;

/**
* @since 0.1.0
Expand All @@ -16,6 +19,7 @@ class DonateController
/**
* First we create a donation and/or subscription, then move on to the gateway processing
*
* @since 0.3.3 use gateway controllers
* @since 0.3.0 add support for subscriptions
* @since 0.1.0
*
Expand All @@ -37,7 +41,14 @@ public function donate(DonateControllerData $formData, PaymentGateway $registere

do_action('givewp_donate_controller_donation_created', $formData, $donation);

$registeredGateway->handleCreatePayment($donation);
$gatewayData = apply_filters(
"givewp_create_payment_gateway_data_{$registeredGateway::id()}",
(new GetGatewayDataFromRequest)(),
$donation
);

$controller = new GatewayPaymentController($registeredGateway);
$controller->create($donation, $gatewayData);
}

if ($formData->donationType->isSubscription()) {
Expand All @@ -53,7 +64,15 @@ public function donate(DonateControllerData $formData, PaymentGateway $registere

do_action('givewp_donate_controller_subscription_created', $formData, $subscription, $donation);

$registeredGateway->handleCreateSubscription($donation, $subscription);
$gatewayData = apply_filters(
"givewp_create_subscription_gateway_data_{$registeredGateway::id()}",
(new GetGatewayDataFromRequest)(),
$donation,
$subscription
);

$controller = new GatewaySubscriptionController($registeredGateway);
$controller->create($donation, $subscription, $gatewayData);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import {__} from '@wordpress/i18n';
import useCurrencyFormatter from '@givewp/forms/app/hooks/useCurrencyFormatter';
import {isSubscriptionPeriod, SubscriptionPeriod} from '../groups/DonationAmount/subscriptionPeriod';
import {useCallback} from 'react';
import {ReactElement, useCallback} from 'react';
import {createInterpolateElement} from '@wordpress/element';

/**
* @since 0.3.3 update subscription frequency label
* @since 0.1.0
*/
export default function DonationSummary() {
const {useWatch} = window.givewp.form.hooks;
const currency = useWatch({name: 'currency'});
const amount = useWatch({name: 'amount'});
const period = useWatch({name: 'subscriptionPeriod'});
const frequency = useWatch({name: 'subscriptionFrequency'});
const formatter = useCurrencyFormatter(currency, {});

const givingFrequency = useCallback(() => {
if (isSubscriptionPeriod(period)) {
return new SubscriptionPeriod(period).label().capitalize().adjective();
const subscriptionPeriod = new SubscriptionPeriod(period);

if (frequency > 1) {
return createInterpolateElement(__('Every <period />', 'give'), {
period: <span>{`${frequency} ${subscriptionPeriod.label().plural()}`}</span>,
});
}

return subscriptionPeriod.label().capitalize().adjective();
}

return __('One time', 'give');
Expand All @@ -33,7 +44,7 @@ export default function DonationSummary() {
/**
* @since 0.1.0
*/
const LineItem = ({label, value}: {label: string; value: string}) => {
const LineItem = ({label, value}: { label: string; value: string | ReactElement }) => {
return (
<li className="givewp-elements-donationSummary__list-item">
<div>{label}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ private function fillAdditionalDetails(DonationReceipt $receipt)
}

/**
* @since 0.3.3 update subscription amount label with frequency
* @since 0.1.0
*
* @return void
Expand All @@ -157,6 +158,10 @@ private function fillSubscriptionDetails(DonationReceipt $receipt)
{
if ($receipt->donation->subscriptionId) {
$subscription = $receipt->donation->subscription;
$subscriptionAmountLabel = sprintf(
$subscription->period->label($subscription->frequency),
$subscription->frequency
);

$receipt->subscriptionDetails->addDetails([
new ReceiptDetail(
Expand All @@ -166,7 +171,7 @@ private function fillSubscriptionDetails(DonationReceipt $receipt)
sprintf(
'%s / %s',
$subscription->amount->formatToDecimal(),
$subscription->period->getValue()
$subscriptionAmountLabel
)
]
),
Expand Down
1 change: 0 additions & 1 deletion src/NextGen/WelcomeBanner/Actions/DisplayWelcomeBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public function __construct() {

public function __invoke() {
wp_enqueue_style('givewp-design-system-foundation');
echo View::load('NextGen/WelcomeBanner.components/newsletter');
echo View::load('NextGen/WelcomeBanner.welcome-banner', $this->data);
}
}
Loading

0 comments on commit bab9171

Please sign in to comment.