Skip to content

Commit

Permalink
Feature: Add support for integrating Blink Payment with the Donor Das…
Browse files Browse the repository at this point in the history
…hboard (#7632)

Co-authored-by: Jon Waldstein <[email protected]>
  • Loading branch information
pauloiankoski and jonwaldstein authored Dec 2, 2024
1 parent 9f915d2 commit a20c9d8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/DonorDashboards/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ public function getLoaderTemplatePath()
/**
* Enqueue assets for front-end donor dashboards
*
* @unreleased Add action to allow enqueueing additional assets.
* @since 2.11.0 Set script translations.
* @since 2.10.0
* @since 2.11.0 Set script translations.
*
* @return void
*/
Expand Down Expand Up @@ -175,6 +176,8 @@ public function loadAssets()
[],
null
);

do_action('give_donor_dashboard_enqueue_assets');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import SubscriptionCancelModal from '../subscription-cancel-modal';
*/
const normalizeAmount = (float, decimals) => Number.parseFloat(float).toFixed(decimals);

/**
* @unreleased Add support for hiding amount controls via filter
*/
const SubscriptionManager = ({id, subscription}) => {
const gatewayRef = useRef();
const [isPauseModalOpen, setIsPauseModalOpen] = useState(false);
Expand All @@ -37,6 +40,8 @@ const SubscriptionManager = ({id, subscription}) => {

const subscriptionStatus = subscription.payment.status?.id || subscription.payment.status.label.toLowerCase();

const showAmountControls = subscription.gateway.can_update;
const showPaymentMethodControls = subscription.gateway.can_update_payment_method ?? showAmountControls;
const showPausingControls =
subscription.gateway.can_pause && !['Quarterly', 'Yearly'].includes(subscription.payment.frequency);

Expand Down Expand Up @@ -95,19 +100,23 @@ const SubscriptionManager = ({id, subscription}) => {

return (
<div className={'give-donor-dashboard__subscription-manager'}>
<AmountControl
currency={subscription.payment.currency}
options={options}
max={max}
min={min}
value={amount}
onChange={setAmount}
/>
<PaymentMethodControl
forwardedRef={gatewayRef}
label={__('Payment Method', 'give')}
gateway={subscription.gateway}
/>
{showAmountControls && (
<AmountControl
currency={subscription.payment.currency}
options={options}
max={max}
min={min}
value={amount}
onChange={setAmount}
/>
)}
{showPaymentMethodControls && (
<PaymentMethodControl
forwardedRef={gatewayRef}
label={__('Payment Method', 'give')}
gateway={subscription.gateway}
/>
)}

{loading && <DashboardLoadingSpinner />}

Expand Down Expand Up @@ -135,7 +144,11 @@ const SubscriptionManager = ({id, subscription}) => {
</>
)}

<Button disabled={subscriptionStatus !== 'active'} classnames={subscriptionStatus !== 'active' && 'disabled'} onClick={handleUpdate}>
<Button
disabled={subscriptionStatus !== 'active'}
classnames={subscriptionStatus !== 'active' && 'disabled'}
onClick={handleUpdate}
>
{updated ? (
<Fragment>
{__('Updated', 'give')} <FontAwesomeIcon icon="check" fixedWidth />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React from 'react';

import AuthorizeControl from './authorize-control';
import SquareControl from './square-control';
import StripeControl from './stripe-control';
import CardControl from './card-control';

import './style.scss';

/**
* @unreleased Add controller for Blink payment method.
*/
const PaymentMethodControl = (props) => {
switch (props.gateway.id) {
case 'stripe':
Expand All @@ -23,6 +28,11 @@ const PaymentMethodControl = (props) => {
case 'paypalpro': {
return <CardControl {...props} />;
}
case 'blink': {
// Donor Dashboard currently loads its own version of React so we need to pass it to the component
const Element = wp.hooks.applyFilters('give_donor_dashboard_blink_payment_method_control', null, props);
return Element && <Element {...props} React={React} />;
}
default: {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import {__} from '@wordpress/i18n';
import {useWindowSize} from '../../hooks';
import SubscriptionCancelModal from '../subscription-cancel-modal';

import "./style.scss";
import './style.scss';

const SubscriptionRow = ({subscription}) => {
const [isCancelModalOpen, setIsCancelModalOpen] = useState<boolean>(false);

const {width} = useWindowSize();
const {id, payment, form, gateway} = subscription;

const gatewayCanUpdateSubscription = gateway.can_update || gateway.can_update_payment_method;

return (
<div className="give-donor-dashboard-table__row">
<div className="give-donor-dashboard-table__column">
Expand Down Expand Up @@ -52,14 +54,14 @@ const SubscriptionRow = ({subscription}) => {
{__('View Subscription', 'give')} <FontAwesomeIcon icon="arrow-right" />
</Link>
</div>
{gateway.can_update && (
{gatewayCanUpdateSubscription && (
<div className="give-donor-dashboard-table__donation-receipt">
<Link to={`/recurring-donations/manage/${id}`}>
{__('Manage Subscription', 'give')} <FontAwesomeIcon icon="arrow-right" />
</Link>
</div>
)}
{gateway.can_cancel && !gateway.can_update && (
{gateway.can_cancel && !gatewayCanUpdateSubscription && (
<>
{isCancelModalOpen && (
<SubscriptionCancelModal
Expand All @@ -69,7 +71,12 @@ const SubscriptionRow = ({subscription}) => {
/>
)}
<div className="give-donor-dashboard-table__donation-receipt">
<a className={'give-donor-dashboard-table__donation-receipt__cancel'} onClick={() => setIsCancelModalOpen(true)}>{__('Cancel Subscription', 'give')}</a>
<a
className={'give-donor-dashboard-table__donation-receipt__cancel'}
onClick={() => setIsCancelModalOpen(true)}
>
{__('Cancel Subscription', 'give')}
</a>
</div>
</>
)}
Expand Down

0 comments on commit a20c9d8

Please sign in to comment.