@automattic/newspack-blocks 2.6.2 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cache/babel/135eb7c6e583be53418b26a29fcc4d81.json.gz +0 -0
- package/.cache/babel/2bec24377bb9890c2268bcd4c8f3953c.json.gz +0 -0
- package/.cache/babel/9ba57ee86df44178ceb255eaf0e770e3.json.gz +0 -0
- package/.cache/babel/a804bf1963e56137e59e37a567cb5e2e.json.gz +0 -0
- package/.cache/babel/b94e6dc0852876a37bd23ec88c5b2583.json.gz +0 -0
- package/.cache/babel/c04d2af94bb0f10f408a15534301cc86.json.gz +0 -0
- package/.cache/babel/c8d4b9ae4be3002e8507d71f1136ebc6.json.gz +0 -0
- package/.cache/babel/d21f5515648ce2a2349b0ee5cc787fce.json.gz +0 -0
- package/.cache/babel/d3eee0c40fc44bc734dee21a645a4f7d.json.gz +0 -0
- package/.cache/babel/d661309b03e38954105e706a32ef09f6.json.gz +0 -0
- package/.cache/babel/e2dd36051554e75a2bf087b85c11e43d.json.gz +0 -0
- package/.hooks/pre-push +2 -2
- package/CHANGELOG.md +21 -0
- package/composer.lock +38 -36
- package/dist/donate/view.asset.php +1 -1
- package/dist/donate/view.css +1 -1
- package/dist/donate/view.rtl.css +1 -1
- package/dist/editor.asset.php +1 -1
- package/dist/editor.css +1 -1
- package/dist/editor.js +11 -11
- package/dist/editor.rtl.css +1 -1
- package/dist/frequencyBased.asset.php +1 -1
- package/dist/frequencyBased.css +1 -1
- package/dist/frequencyBased.rtl.css +1 -1
- package/dist/modalCheckout.asset.php +1 -1
- package/dist/modalCheckout.css +1 -1
- package/dist/modalCheckout.rtl.css +1 -1
- package/dist/tiersBased.asset.php +1 -1
- package/dist/tiersBased.css +1 -1
- package/dist/tiersBased.js +1 -1
- package/dist/tiersBased.rtl.css +1 -1
- package/includes/class-modal-checkout.php +11 -14
- package/includes/class-newspack-blocks.php +87 -43
- package/languages/newspack-blocks-de_DE.po +0 -40
- package/languages/newspack-blocks-es_ES.po +0 -40
- package/languages/newspack-blocks-fr_BE.po +0 -40
- package/languages/newspack-blocks-pt_PT.po +0 -40
- package/languages/newspack-blocks.pot +0 -38
- package/newspack-blocks.php +2 -14
- package/package.json +7 -8
- package/src/blocks/checkout-button/edit.js +5 -1
- package/src/blocks/donate/block.json +0 -12
- package/src/blocks/donate/edit/FrequencyBasedLayout.tsx +61 -106
- package/src/blocks/donate/edit/TierBasedLayout.tsx +7 -26
- package/src/blocks/donate/edit/components/index.tsx +0 -1
- package/src/blocks/donate/edit/index.tsx +157 -152
- package/src/blocks/donate/frequency-based/style.scss +5 -0
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-base.php +33 -147
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-frequency-based.php +21 -10
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-tiers-based.php +3 -50
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer.php +1 -14
- package/src/blocks/donate/styles/editor.scss +6 -28
- package/src/blocks/donate/styles/style-variations.scss +17 -8
- package/src/blocks/donate/styles/view.scss +9 -0
- package/src/blocks/donate/tiers-based/style.scss +0 -11
- package/src/blocks/donate/tiers-based/utils.test.js +38 -0
- package/src/blocks/donate/tiers-based/utils.ts +1 -2
- package/src/blocks/donate/tiers-based/view.ts +0 -33
- package/src/blocks/donate/types.ts +0 -16
- package/src/blocks/donate/utils.ts +31 -0
- package/src/blocks/homepage-articles/block.json +18 -0
- package/src/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php +1 -1
- package/src/blocks/homepage-articles/edit.js +3 -0
- package/src/blocks/homepage-articles/utils.ts +4 -0
- package/src/blocks/homepage-articles/view.php +4 -4
- package/src/components/query-controls.js +41 -8
- package/src/modal-checkout/checkout.scss +4 -5
- package/src/types/index.d.ts +4 -3
- package/vendor/autoload.php +1 -1
- package/vendor/composer/autoload_real.php +4 -4
- package/vendor/composer/autoload_static.php +2 -2
- package/vendor/composer/installed.php +2 -2
- package/webpack.config.js +0 -1
- package/.cache/babel/18dda1142078f066419138e7284f03bf.json.gz +0 -0
- package/.cache/babel/1f43960564787ebde7c6d44957cddf0e.json.gz +0 -0
- package/.cache/babel/225618337c609eed2be110274ff82be1.json.gz +0 -0
- package/.cache/babel/29d960d2fc51492a4bea1f4f165810fb.json.gz +0 -0
- package/.cache/babel/2f22325668b5763f8f2c9557833af36f.json.gz +0 -0
- package/.cache/babel/39bcc541624feefe54d1493493ae1ce8.json.gz +0 -0
- package/.cache/babel/4d450b37d365154f05b17cbf6a009255.json.gz +0 -0
- package/.cache/babel/87e2dc4a961b25b0de8d1a8ac88eea13.json.gz +0 -0
- package/.cache/babel/91884d41523f3790da70ea305ee187f2.json.gz +0 -0
- package/.cache/babel/b1ac90699e641ff99e1449b5d7b686e5.json.gz +0 -0
- package/.cache/babel/c5a441fdf7d90d45d2cbeb89967c61fe.json.gz +0 -0
- package/.cache/babel/c7cfb8590e887722a3e715c72ee99bac.json.gz +0 -0
- package/.cache/babel/e1d8932bb19afa36f476f107dbc6ca39.json.gz +0 -0
- package/.cache/babel/f60f8c23ec2b4448cb2815d79207d8c0.json.gz +0 -0
- package/dist/donateStreamlined.asset.php +0 -1
- package/dist/donateStreamlined.css +0 -1
- package/dist/donateStreamlined.js +0 -1
- package/dist/donateStreamlined.rtl.css +0 -1
- package/src/blocks/donate/class-wp-rest-newspack-donate-controller.php +0 -206
- package/src/blocks/donate/edit/components/AdditionalFields.tsx +0 -282
- package/src/blocks/donate/streamlined/index.test.js +0 -132
- package/src/blocks/donate/streamlined/index.ts +0 -356
- package/src/blocks/donate/streamlined/style.scss +0 -306
- package/src/blocks/donate/streamlined/utils.test.js +0 -18
- package/src/blocks/donate/streamlined/utils.ts +0 -217
- package/src/blocks/donate/tiers-based/view.test.js +0 -209
|
@@ -38,7 +38,7 @@ import type {
|
|
|
38
38
|
} from '../types';
|
|
39
39
|
import TierBasedLayout from './TierBasedLayout';
|
|
40
40
|
import FrequencyBasedLayout from './FrequencyBasedLayout';
|
|
41
|
-
import { AmountValueInput
|
|
41
|
+
import { AmountValueInput } from './components';
|
|
42
42
|
import {
|
|
43
43
|
FREQUENCIES,
|
|
44
44
|
FREQUENCY_SLUGS,
|
|
@@ -141,19 +141,23 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
|
|
|
141
141
|
return <Placeholder icon={ <Spinner /> } className="component-placeholder__align-center" />;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
const
|
|
144
|
+
const canUseNameYourPrice = window.newspack_blocks_data?.can_use_name_your_price;
|
|
145
|
+
const isManual = attributes.manual && canUseNameYourPrice;
|
|
146
|
+
const isTiered = isManual ? attributes.tiered : settings.tiered;
|
|
145
147
|
const isTierBasedLayoutEnabled = isTiered && attributes.layoutOption === 'tiers';
|
|
146
148
|
|
|
147
|
-
const amounts =
|
|
149
|
+
const amounts = isManual ? attributes.amounts : settings.amounts;
|
|
150
|
+
|
|
148
151
|
const availableFrequencies = FREQUENCY_SLUGS.filter( slug =>
|
|
149
|
-
attributes.
|
|
150
|
-
? ! attributes.disabledFrequencies[ slug ]
|
|
151
|
-
: ! settings.disabledFrequencies[ slug ]
|
|
152
|
+
isManual ? ! attributes.disabledFrequencies[ slug ] : ! settings.disabledFrequencies[ slug ]
|
|
152
153
|
);
|
|
153
154
|
|
|
154
155
|
// Editor bug – initially, the default style is selected, but the class not applied.
|
|
155
156
|
if ( className.indexOf( 'is-style' ) === -1 ) {
|
|
156
|
-
className
|
|
157
|
+
className += ' is-style-default';
|
|
158
|
+
}
|
|
159
|
+
if ( ! canUseNameYourPrice ) {
|
|
160
|
+
className += ' wpbnbd--nyp-disabled';
|
|
157
161
|
}
|
|
158
162
|
const getWrapperClassNames = ( classes: string[] = [] ) =>
|
|
159
163
|
classNames(
|
|
@@ -165,7 +169,7 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
|
|
|
165
169
|
`wpbnbd-frequencies--${ availableFrequencies.length }`
|
|
166
170
|
);
|
|
167
171
|
|
|
168
|
-
const minimumDonation =
|
|
172
|
+
const minimumDonation = isManual ? attributes.minimumDonation : settings.minimumDonation;
|
|
169
173
|
const displayedAmounts = { ...amounts };
|
|
170
174
|
Object.keys( amounts ).forEach( frequency => {
|
|
171
175
|
const amountsWithMinimum = amounts[ frequency ].map( amount =>
|
|
@@ -215,25 +219,27 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
|
|
|
215
219
|
|
|
216
220
|
<InspectorControls>
|
|
217
221
|
<PanelBody title={ __( 'Layout', 'newspack-blocks' ) }>
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
222
|
+
{ canUseNameYourPrice && (
|
|
223
|
+
<div className="newspack-blocks-donate__layout-selector">
|
|
224
|
+
{ LAYOUT_OPTIONS.map( ( { label, key } ) => {
|
|
225
|
+
const isSelected =
|
|
226
|
+
key === 'tiers' ? isTierBasedLayoutEnabled : ! isTierBasedLayoutEnabled;
|
|
227
|
+
return (
|
|
228
|
+
<Button
|
|
229
|
+
key={ key }
|
|
230
|
+
variant={ isSelected ? 'primary' : 'secondary' }
|
|
231
|
+
isPressed={ isSelected }
|
|
232
|
+
onClick={ () => setAttributes( { layoutOption: key } ) }
|
|
233
|
+
aria-current={ isSelected }
|
|
234
|
+
disabled={ key === 'tiers' && ! isTiered }
|
|
235
|
+
>
|
|
236
|
+
{ label }
|
|
237
|
+
</Button>
|
|
238
|
+
);
|
|
239
|
+
} ) }
|
|
240
|
+
</div>
|
|
241
|
+
) }
|
|
242
|
+
{ canUseNameYourPrice && ! isTiered && (
|
|
237
243
|
<Notice isDismissible={ false } className="newspack-blocks-donate__notice">
|
|
238
244
|
{ __(
|
|
239
245
|
'Tiers layout is disabled if the block is set to render untiered.',
|
|
@@ -255,126 +261,133 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
|
|
|
255
261
|
/>
|
|
256
262
|
) }
|
|
257
263
|
</PanelBody>
|
|
258
|
-
|
|
259
|
-
<
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
<
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
264
|
+
{ canUseNameYourPrice && (
|
|
265
|
+
<PanelBody title={ __( 'Suggested Donations', 'newspack-blocks' ) }>
|
|
266
|
+
<ToggleControl
|
|
267
|
+
checked={ Boolean( isManual ) }
|
|
268
|
+
onChange={ () => setAttributes( { manual: ! attributes.manual } ) }
|
|
269
|
+
label={ __( 'Configure manually', 'newspack-blocks' ) }
|
|
270
|
+
/>
|
|
271
|
+
{ isManual ? (
|
|
272
|
+
<>
|
|
273
|
+
<ToggleControl
|
|
274
|
+
checked={ Boolean( isTiered ) }
|
|
275
|
+
onChange={ () => setAttributes( { tiered: ! attributes.tiered } ) }
|
|
276
|
+
label={ __( 'Tiered', 'newspack-blocks' ) }
|
|
277
|
+
/>
|
|
278
|
+
{ isTiered ? (
|
|
279
|
+
<>
|
|
280
|
+
<div className="components-frequency-donations">
|
|
281
|
+
{ FREQUENCY_SLUGS.map( ( frequency: DonationFrequencySlug ) => {
|
|
282
|
+
const isFrequencyDisabled = attributes.disabledFrequencies[ frequency ];
|
|
283
|
+
const disabledDisplayedFrequencyCount = Object.values(
|
|
284
|
+
pick( attributes.disabledFrequencies, FREQUENCY_SLUGS )
|
|
285
|
+
).filter( Boolean ).length;
|
|
286
|
+
const isOnlyOneFrequencyActive =
|
|
287
|
+
FREQUENCY_SLUGS.length - disabledDisplayedFrequencyCount === 1;
|
|
288
|
+
return (
|
|
289
|
+
<Fragment key={ frequency }>
|
|
290
|
+
<CheckboxControl
|
|
291
|
+
label={ FREQUENCIES[ frequency ] }
|
|
292
|
+
checked={ ! isFrequencyDisabled }
|
|
293
|
+
disabled={ ! isFrequencyDisabled && isOnlyOneFrequencyActive }
|
|
294
|
+
onChange={ () => {
|
|
295
|
+
setAttributes( {
|
|
296
|
+
disabledFrequencies: {
|
|
297
|
+
...attributes.disabledFrequencies,
|
|
298
|
+
[ frequency ]: ! isFrequencyDisabled,
|
|
299
|
+
},
|
|
300
|
+
} );
|
|
301
|
+
} }
|
|
302
|
+
/>
|
|
303
|
+
{ ! isFrequencyDisabled && (
|
|
304
|
+
<div className="wp-block-newspack-blocks-donate__panel-inputs">
|
|
305
|
+
{ amounts[ frequency ].reduce(
|
|
306
|
+
( acc: boolean, suggestedAmount: number ) =>
|
|
307
|
+
! suggestedAmount || suggestedAmount < minimumDonation
|
|
308
|
+
? true
|
|
309
|
+
: acc,
|
|
310
|
+
false
|
|
311
|
+
) && renderMinAmountWarning() }
|
|
303
312
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
313
|
+
{ amounts[ frequency ].map( ( suggestedAmount, tierIndex ) => {
|
|
314
|
+
// The "Other" tier is no longer customizable and should always render empty for tiered layout.
|
|
315
|
+
if ( tierIndex === 3 ) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
return (
|
|
319
|
+
<AmountValueInput
|
|
320
|
+
ignoreMinimumAmount
|
|
321
|
+
{ ...componentProps }
|
|
322
|
+
key={ `amount-${ frequency }-${ tierIndex }` }
|
|
323
|
+
frequencySlug={ frequency }
|
|
324
|
+
tierIndex={ tierIndex }
|
|
325
|
+
label={ TIER_LABELS[ tierIndex ] }
|
|
326
|
+
id={ `${ frequency }-${ tierIndex }-amount` }
|
|
327
|
+
disabled={
|
|
328
|
+
isTierBasedLayoutEnabled &&
|
|
329
|
+
tierIndex === DISABLED_IN_TIERS_BASED_LAYOUT_TIER_INDEX
|
|
330
|
+
}
|
|
331
|
+
/>
|
|
332
|
+
);
|
|
333
|
+
} ) }
|
|
334
|
+
</div>
|
|
335
|
+
) }
|
|
336
|
+
</Fragment>
|
|
337
|
+
);
|
|
338
|
+
} ) }
|
|
339
|
+
</div>
|
|
340
|
+
</>
|
|
341
|
+
) : (
|
|
342
|
+
<div className="components-frequency-donations">
|
|
343
|
+
<div className="wp-block-newspack-blocks-donate__panel-inputs">
|
|
344
|
+
{ FREQUENCY_SLUGS.reduce(
|
|
345
|
+
( acc: boolean, frequencySlug: DonationFrequencySlug ) =>
|
|
346
|
+
! amounts[ frequencySlug ][ 3 ] ||
|
|
347
|
+
amounts[ frequencySlug ][ 3 ] < attributes.minimumDonation
|
|
348
|
+
? true
|
|
349
|
+
: acc,
|
|
350
|
+
false
|
|
351
|
+
) && renderMinAmountWarning() }
|
|
340
352
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
353
|
+
{ FREQUENCY_SLUGS.map( ( frequencySlug: DonationFrequencySlug ) => (
|
|
354
|
+
<AmountValueInput
|
|
355
|
+
ignoreMinimumAmount
|
|
356
|
+
{ ...componentProps }
|
|
357
|
+
key={ frequencySlug }
|
|
358
|
+
frequencySlug={ frequencySlug }
|
|
359
|
+
tierIndex={ 3 }
|
|
360
|
+
label={ FREQUENCIES[ frequencySlug ] }
|
|
361
|
+
id={ `${ frequencySlug }-${ 3 }-amount` }
|
|
362
|
+
/>
|
|
363
|
+
) ) }
|
|
364
|
+
</div>
|
|
352
365
|
</div>
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
</
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
366
|
+
) }
|
|
367
|
+
<TextControl
|
|
368
|
+
className="components-frequency-donations__minimum-donation"
|
|
369
|
+
type="number"
|
|
370
|
+
label={ __( 'Minimum donation', 'newspack-blocks' ) }
|
|
371
|
+
min={ 1 }
|
|
372
|
+
onChange={ ( value: number ) => setAttributes( { minimumDonation: value } ) }
|
|
373
|
+
value={ attributes.minimumDonation }
|
|
374
|
+
/>
|
|
375
|
+
</>
|
|
376
|
+
) : (
|
|
377
|
+
<p>
|
|
378
|
+
{ __(
|
|
379
|
+
'The Donate Block allows you to collect donations from readers. The fields are automatically defined based on your donation settings.',
|
|
380
|
+
'newspack-blocks'
|
|
381
|
+
) }
|
|
382
|
+
<br />
|
|
383
|
+
<br />
|
|
384
|
+
<ExternalLink href="/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/donations">
|
|
385
|
+
{ __( 'Edit donation settings', 'newspack-blocks' ) }
|
|
386
|
+
</ExternalLink>
|
|
387
|
+
</p>
|
|
388
|
+
) }
|
|
389
|
+
</PanelBody>
|
|
390
|
+
) }
|
|
378
391
|
<PanelBody title={ __( 'Styling', 'newspack-blocks' ) } initialOpen={ false }>
|
|
379
392
|
<ColorPaletteControl
|
|
380
393
|
value={ attributes.buttonColor }
|
|
@@ -382,14 +395,6 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
|
|
|
382
395
|
label={ __( 'Button Color', 'newspack-blocks' ) }
|
|
383
396
|
/>
|
|
384
397
|
</PanelBody>
|
|
385
|
-
{ 'stripe' === settings.platform && (
|
|
386
|
-
<PanelBody
|
|
387
|
-
title={ __( 'Additional data fields', 'newspack-blocks' ) }
|
|
388
|
-
initialOpen={ false }
|
|
389
|
-
>
|
|
390
|
-
<AdditionalFields attributes={ attributes } setAttributes={ setAttributes } />
|
|
391
|
-
</PanelBody>
|
|
392
|
-
) }
|
|
393
398
|
<PanelBody title={ __( 'Campaign', 'newspack-blocks' ) } initialOpen={ false }>
|
|
394
399
|
<TextControl
|
|
395
400
|
label={ __( 'Campaign ID', 'newspack-blocks' ) }
|
|
@@ -16,6 +16,25 @@ abstract class Newspack_Blocks_Donate_Renderer_Base {
|
|
|
16
16
|
|
|
17
17
|
private static $configurations_cache = []; // phpcs:ignore Squiz.Commenting.VariableComment.Missing
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Get translatable frequency label.
|
|
21
|
+
*
|
|
22
|
+
* @param string $frequency_slug Frequency slug.
|
|
23
|
+
* @param bool $hide_once_label Whether to hide the "once" label.
|
|
24
|
+
*
|
|
25
|
+
* @return string
|
|
26
|
+
*/
|
|
27
|
+
public static function get_frequency_label( $frequency_slug, $hide_once_label = false ) {
|
|
28
|
+
switch ( $frequency_slug ) {
|
|
29
|
+
case 'once':
|
|
30
|
+
return $hide_once_label ? '' : ' ' . __( 'once', 'newspack-blocks' );
|
|
31
|
+
case 'month':
|
|
32
|
+
return ' ' . __( 'per month', 'newspack-blocks' );
|
|
33
|
+
case 'year':
|
|
34
|
+
return ' ' . __( 'per year', 'newspack-blocks' );
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
19
38
|
/**
|
|
20
39
|
* Get configuration, based on block attributes and global settings.
|
|
21
40
|
*
|
|
@@ -34,7 +53,7 @@ abstract class Newspack_Blocks_Donate_Renderer_Base {
|
|
|
34
53
|
$configuration['defaultFrequency'] = $attributes['defaultFrequency'];
|
|
35
54
|
|
|
36
55
|
/* If block is in "manual" mode, override certain state properties with values stored in attributes */
|
|
37
|
-
if ( $attributes['manual']
|
|
56
|
+
if ( Newspack_Blocks::can_use_name_your_price() && ! empty( $attributes['manual'] ) ) {
|
|
38
57
|
// Migrate old attributes.
|
|
39
58
|
if ( empty( $attributes['amounts'] ) && isset( $attributes['suggestedAmounts'] ) ) {
|
|
40
59
|
$other_amount = $configuration['amounts']['month'][3];
|
|
@@ -59,9 +78,7 @@ abstract class Newspack_Blocks_Donate_Renderer_Base {
|
|
|
59
78
|
'year' => $multiplied_amounts,
|
|
60
79
|
];
|
|
61
80
|
}
|
|
62
|
-
|
|
63
|
-
$configuration['tiered'] = $attributes['tiered'];
|
|
64
|
-
}
|
|
81
|
+
$configuration['tiered'] = $attributes['tiered'] && Newspack_Blocks::can_use_name_your_price();
|
|
65
82
|
if ( isset( $attributes['amounts'] ) && ! empty( $attributes['amounts'] ) ) {
|
|
66
83
|
$configuration['amounts'] = $attributes['amounts'];
|
|
67
84
|
}
|
|
@@ -112,50 +129,20 @@ abstract class Newspack_Blocks_Donate_Renderer_Base {
|
|
|
112
129
|
$classname = 'is-style-default';
|
|
113
130
|
}
|
|
114
131
|
|
|
115
|
-
$layout_version
|
|
116
|
-
$
|
|
117
|
-
'
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
'wpbnbd-frequencies--' . count( $configuration['frequencies'] ),
|
|
125
|
-
]
|
|
126
|
-
);
|
|
127
|
-
$configuration['container_classnames'] = $container_classnames;
|
|
128
|
-
|
|
129
|
-
$configuration['is_rendering_stripe_payment_form'] = false;
|
|
130
|
-
|
|
131
|
-
if ( Newspack_Blocks::is_rendering_stripe_payment_form() ) {
|
|
132
|
-
$stripe_data = \Newspack\Stripe_Connection::get_stripe_data();
|
|
133
|
-
$currency = $stripe_data['currency'];
|
|
134
|
-
$captcha_site_key = null;
|
|
135
|
-
|
|
136
|
-
if ( method_exists( '\Newspack\Recaptcha', 'can_use_captcha' ) && \Newspack\Recaptcha::can_use_captcha() ) {
|
|
137
|
-
$captcha_site_key = \Newspack\Recaptcha::get_setting( 'site_key' );
|
|
138
|
-
}
|
|
132
|
+
$layout_version = ( $is_tiers_based ? 'tiers' : 'frequency' );
|
|
133
|
+
$class_names = [
|
|
134
|
+
'wp-block-newspack-blocks-donate',
|
|
135
|
+
'wpbnbd',
|
|
136
|
+
'wpbnbd--' . $layout_version . '-based',
|
|
137
|
+
'wpbnbd--platform-' . $configuration['platform'],
|
|
138
|
+
$classname,
|
|
139
|
+
'wpbnbd-frequencies--' . count( $configuration['frequencies'] ),
|
|
140
|
+
];
|
|
139
141
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
$configuration['currencySymbol'],
|
|
143
|
-
get_bloginfo( 'name' ),
|
|
144
|
-
Newspack\Stripe_Connection::is_currency_zero_decimal( $currency ),
|
|
145
|
-
$stripe_data['location_code'],
|
|
146
|
-
$configuration['frequencies'],
|
|
147
|
-
$stripe_data['fee_multiplier'],
|
|
148
|
-
$stripe_data['fee_static'],
|
|
149
|
-
$stripe_data['usedPublishableKey'],
|
|
150
|
-
$attributes['paymentRequestType'],
|
|
151
|
-
$captcha_site_key,
|
|
152
|
-
$configuration['minimumDonation'],
|
|
153
|
-
];
|
|
154
|
-
$configuration['is_rendering_stripe_payment_form'] = true;
|
|
155
|
-
} else {
|
|
156
|
-
$configuration_for_streamlined = [];
|
|
142
|
+
if ( ! Newspack_Blocks::can_use_name_your_price() ) {
|
|
143
|
+
$class_names[] = 'wpbnbd--nyp-disabled';
|
|
157
144
|
}
|
|
158
|
-
$configuration['
|
|
145
|
+
$configuration['container_classnames'] = implode( ' ', $class_names );
|
|
159
146
|
|
|
160
147
|
if ( isset( $configuration['minimumDonation'] ) ) {
|
|
161
148
|
foreach ( $configuration['amounts'] as $frequency => $amounts ) {
|
|
@@ -188,107 +175,6 @@ abstract class Newspack_Blocks_Donate_Renderer_Base {
|
|
|
188
175
|
}
|
|
189
176
|
}
|
|
190
177
|
|
|
191
|
-
/**
|
|
192
|
-
* Render hidden form input indentifying a donate form submission.
|
|
193
|
-
*
|
|
194
|
-
* @param array $attributes The block attributes.
|
|
195
|
-
*
|
|
196
|
-
* @return string
|
|
197
|
-
*/
|
|
198
|
-
protected static function render_streamlined_payment_ui( $attributes ) {
|
|
199
|
-
$is_rendering_newsletter_list_opt_in = false;
|
|
200
|
-
$user_email = '';
|
|
201
|
-
$user_display_name = '';
|
|
202
|
-
|
|
203
|
-
$stripe_data = \Newspack\Stripe_Connection::get_stripe_data();
|
|
204
|
-
$is_rendering_fee_checkbox = 0 < (float) $stripe_data['fee_multiplier'] + (float) $stripe_data['fee_static'];
|
|
205
|
-
if ( class_exists( 'Newspack_Newsletters' ) ) {
|
|
206
|
-
$is_rendering_newsletter_list_opt_in = isset( $stripe_data['newsletter_list_id'] ) && ! empty( $stripe_data['newsletter_list_id'] );
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
$current_user = wp_get_current_user();
|
|
210
|
-
if ( 0 !== $current_user->ID ) {
|
|
211
|
-
$user_email = $current_user->user_email;
|
|
212
|
-
$user_display_name = trim( $current_user->first_name . ' ' . $current_user->last_name );
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
$button_style_attr = 'style="' . self::get_button_style( $attributes ) . '"';
|
|
216
|
-
|
|
217
|
-
ob_start();
|
|
218
|
-
?>
|
|
219
|
-
<div class="wp-block-newspack-blocks-donate__stripe stripe-payment stripe-payment--invisible stripe-payment--disabled">
|
|
220
|
-
<div class="stripe-payment__inputs stripe-payment--hidden">
|
|
221
|
-
<div class="stripe-payment__row">
|
|
222
|
-
<div class="stripe-payment__element stripe-payment__card"></div>
|
|
223
|
-
</div>
|
|
224
|
-
<div class="stripe-payment__row stripe-payment__row--flex">
|
|
225
|
-
<input
|
|
226
|
-
required
|
|
227
|
-
placeholder="<?php echo esc_html__( 'Email', 'newspack-blocks' ); ?>"
|
|
228
|
-
type="email"
|
|
229
|
-
name="email"
|
|
230
|
-
value="<?php echo esc_attr( $user_email ); ?>"
|
|
231
|
-
<?php if ( '' !== $user_email ) : ?>
|
|
232
|
-
readonly
|
|
233
|
-
<?php endif; ?>
|
|
234
|
-
>
|
|
235
|
-
<input
|
|
236
|
-
required
|
|
237
|
-
placeholder="<?php echo esc_html__( 'Full Name', 'newspack-blocks' ); ?>"
|
|
238
|
-
type="text"
|
|
239
|
-
name="full_name"
|
|
240
|
-
value="<?php echo esc_attr( $user_display_name ); ?>"
|
|
241
|
-
>
|
|
242
|
-
</div>
|
|
243
|
-
<div class="stripe-payment__row stripe-payment__row--additional-fields">
|
|
244
|
-
<?php foreach ( $attributes['additionalFields'] as $field ) : ?>
|
|
245
|
-
<input
|
|
246
|
-
data-is-additional-field
|
|
247
|
-
type="<?php echo esc_attr( $field['type'] ); ?>"
|
|
248
|
-
name="<?php echo esc_attr( $field['name'] ); ?>"
|
|
249
|
-
placeholder="<?php echo esc_attr( $field['label'] ); ?>"
|
|
250
|
-
style="width: calc(<?php echo esc_attr( $field['width'] ); ?>% - 0.5rem);"
|
|
251
|
-
<?php if ( $field['isRequired'] ) : ?>
|
|
252
|
-
required
|
|
253
|
-
<?php endif; ?>
|
|
254
|
-
>
|
|
255
|
-
<?php endforeach; ?>
|
|
256
|
-
</div>
|
|
257
|
-
</div>
|
|
258
|
-
<?php if ( $is_rendering_fee_checkbox ) : ?>
|
|
259
|
-
<div class="stripe-payment__row stripe-payment__row--small" id="stripe-fees-amount-container">
|
|
260
|
-
<label class="stripe-payment__checkbox">
|
|
261
|
-
<input type="checkbox" name="agree_to_pay_fees" checked value="true"><?php echo esc_html__( 'Agree to pay fees?', 'newspack-blocks' ); ?>
|
|
262
|
-
<span id="stripe-fees-amount">($0)</span>
|
|
263
|
-
</label>
|
|
264
|
-
<div class="stripe-payment__info"><?php echo esc_html__( 'Paying the transaction fee is not required, but it directs more money in support of our mission.', 'newspack-blocks' ); ?></div>
|
|
265
|
-
</div>
|
|
266
|
-
<?php endif; ?>
|
|
267
|
-
<?php if ( $is_rendering_newsletter_list_opt_in ) : ?>
|
|
268
|
-
<div class="stripe-payment__row stripe-payment__row--small">
|
|
269
|
-
<label class="stripe-payment__checkbox">
|
|
270
|
-
<input type="checkbox" name="newsletter_opt_in" checked value="true"><?php echo esc_html__( 'Sign up for our newsletter', 'newspack-blocks' ); ?>
|
|
271
|
-
</label>
|
|
272
|
-
</div>
|
|
273
|
-
<?php endif; ?>
|
|
274
|
-
<div class="stripe-payment__messages">
|
|
275
|
-
<div class="type-error"></div>
|
|
276
|
-
<div class="type-success"></div>
|
|
277
|
-
<div class="type-info"></div>
|
|
278
|
-
</div>
|
|
279
|
-
<div class="stripe-payment__row stripe-payment__row--flex stripe-payment__footer">
|
|
280
|
-
<div class="stripe-payment__methods">
|
|
281
|
-
<div class="stripe-payment__request-button stripe-payment--hidden stripe-payment__request-button--invisible stripe-payment--transition"></div>
|
|
282
|
-
<button type='submit' <?php echo $button_style_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
|
283
|
-
<?php echo esc_html( $attributes['buttonWithCCText'] ); ?>
|
|
284
|
-
</button>
|
|
285
|
-
</div>
|
|
286
|
-
</div>
|
|
287
|
-
</div>
|
|
288
|
-
<?php
|
|
289
|
-
return ob_get_clean();
|
|
290
|
-
}
|
|
291
|
-
|
|
292
178
|
/**
|
|
293
179
|
* Render hidden form inputs.
|
|
294
180
|
*
|