Skip to content

Commit

Permalink
Merge branch 'develop' into feature/fields-api-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloiankoski committed Aug 7, 2023
2 parents b69a6a7 + 0c3d477 commit 257813a
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 82 deletions.
131 changes: 73 additions & 58 deletions assets/src/js/frontend/give-stripe-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,67 +308,82 @@ class GiveStripeElements {
* @param setupStripeElement
* @param cardElements
*
* @unreleased Scrolls Stripe checkout modal into view for all screen sizes.
*
* @since 2.8.0
*/
triggerStripeModal( formElement, stripeElements, setupStripeElement, cardElements ) {
const idPrefixElement = formElement.querySelector( 'input[name="give-form-id-prefix"]' );
const stripeModalDonateBtn = formElement.querySelector( `#give-stripe-checkout-modal-donate-button-${ idPrefixElement.value }` );
const cardholderName = formElement.querySelector( 'input[name="card_name"]' );
const completeCardElements = {};
let completeCardStatus = false;

cardElements.forEach( ( cardElement ) => {
completeCardElements.cardName = false;

cardElement.addEventListener( 'ready', ( e ) => {
completeCardElements[ e.elementType ] = false;
completeCardElements.cardName = 'card' === e.elementType;
} );

cardElement.addEventListener( 'change', ( e ) => {
completeCardElements[ e.elementType ] = e.complete;
completeCardStatus = Object.values( completeCardElements ).every( ( string ) => {
return true === string;
} );

completeCardStatus ? stripeModalDonateBtn.removeAttribute( 'disabled' ) : stripeModalDonateBtn.setAttribute( 'disabled', 'disabled' );
} );
} );

if ( null !== cardholderName ) {
cardholderName.addEventListener( 'keyup', ( e ) => {
completeCardElements.cardName = '' !== e.target.value;
completeCardStatus = Object.values( completeCardElements ).every( ( string ) => {
return true === string;
} );
completeCardStatus ? stripeModalDonateBtn.removeAttribute( 'disabled' ) : stripeModalDonateBtn.setAttribute( 'disabled', 'disabled' );
} );
}

if ( null !== stripeModalDonateBtn ) {
// Process donation on the click of the modal donate button.
stripeModalDonateBtn.addEventListener( 'click', ( e ) => {
const currentModalDonateBtn = e.target;
const loadingAnimationElement = currentModalDonateBtn.nextElementSibling;
const isLegacyForm = stripeModalDonateBtn.getAttribute( 'data-is_legacy_form' );

if ( isLegacyForm ) {
currentModalDonateBtn.value = give_global_vars.purchase_loading;
loadingAnimationElement.style.display = 'inline-block';
} else {
currentModalDonateBtn.value = '';
loadingAnimationElement.classList.add( 'sequoia-loader' );
loadingAnimationElement.classList.add( 'spinning' );
loadingAnimationElement.classList.remove( 'give-loading-animation' );
}

// Create Payment Method.
stripeElements.createPaymentMethod( formElement, setupStripeElement, cardElements );

e.preventDefault();
} );
}
}
const idPrefixElement = formElement.querySelector('input[name="give-form-id-prefix"]');
const stripeModalDonateBtn = formElement.querySelector(
`#give-stripe-checkout-modal-donate-button-${idPrefixElement.value}`
);
const cardholderName = formElement.querySelector('input[name="card_name"]');
const stripeModalContent = document.querySelector('.give-stripe-checkout-modal-container');
const purchaseButton = document.querySelector('#give-purchase-button');
const completeCardElements = {};
let completeCardStatus = false;

// Scroll checkout modal container into view.
purchaseButton.addEventListener('click', function () {
stripeModalContent.scrollIntoView({behavior: 'smooth'});
});

cardElements.forEach((cardElement) => {
completeCardElements.cardName = false;

cardElement.addEventListener('ready', (e) => {
completeCardElements[e.elementType] = false;
completeCardElements.cardName = 'card' === e.elementType;
});

cardElement.addEventListener('change', (e) => {
completeCardElements[e.elementType] = e.complete;
completeCardStatus = Object.values(completeCardElements).every((string) => {
return true === string;
});

completeCardStatus
? stripeModalDonateBtn.removeAttribute('disabled')
: stripeModalDonateBtn.setAttribute('disabled', 'disabled');
});
});

if (null !== cardholderName) {
cardholderName.addEventListener('keyup', (e) => {
completeCardElements.cardName = '' !== e.target.value;
completeCardStatus = Object.values(completeCardElements).every((string) => {
return true === string;
});
completeCardStatus
? stripeModalDonateBtn.removeAttribute('disabled')
: stripeModalDonateBtn.setAttribute('disabled', 'disabled');
});
}

if (null !== stripeModalDonateBtn) {
// Process donation on the click of the modal donate button.
stripeModalDonateBtn.addEventListener('click', (e) => {
const currentModalDonateBtn = e.target;
const loadingAnimationElement = currentModalDonateBtn.nextElementSibling;
const isLegacyForm = stripeModalDonateBtn.getAttribute('data-is_legacy_form');

if (isLegacyForm) {
currentModalDonateBtn.value = give_global_vars.purchase_loading;
loadingAnimationElement.style.display = 'inline-block';
} else {
currentModalDonateBtn.value = '';
loadingAnimationElement.classList.add('sequoia-loader');
loadingAnimationElement.classList.add('spinning');
loadingAnimationElement.classList.remove('give-loading-animation');
}

// Create Payment Method.
stripeElements.createPaymentMethod(formElement, setupStripeElement, cardElements);

e.preventDefault();
});
}
}
}

export { GiveStripeElements };
2 changes: 1 addition & 1 deletion blocks/donation-form-grid/edit/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const Inspector = ({attributes, setAttributes}) => {
</PanelBody>
</Panel>
<Panel>
<PanelBody title= {__('Grid Settings', 'give')} initialOpen={ true }>
<PanelBody className="give-donation-form-grid--grid-settings" title= {__('Grid Settings', 'give')} initialOpen={ true }>
<SelectControl
className="give-form-grid-inspector"
label={__('Order By', 'give')}
Expand Down
16 changes: 8 additions & 8 deletions blocks/donation-form-grid/edit/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.give-form-grid-inspector{
.give-form-grid-inspector {
flex-direction: row !important;
align-items: center !important;
justify-content: space-between !important;
Expand All @@ -14,8 +14,6 @@
margin: -15px 0 15px 0 !important;
}



.components-base-control__label {
margin: 0 !important;
}
Expand All @@ -36,7 +34,7 @@
align-items: center !important;
justify-content: center !important;

.components-input-control__label{
.components-input-control__label {
flex: 1 !important;
margin: 0 !important;
}
Expand All @@ -45,18 +43,20 @@
.components-input-control__container {
max-width: 135px !important;

> select {
line-height: 1.2 !important;
}
> select {
line-height: 1.2 !important;
}
}
}

.components-form-token-field{
.give-donation-form-grid--grid-settings {
.components-form-token-field {
label { display: none !important;}
}

.exclude__form {
margin-top: 20px !important;
border: 1px solid transparent;
}
}

2 changes: 1 addition & 1 deletion blocks/donor-wall/edit/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const { donorsPerPage,
</PanelBody>
</Panel>
<Panel>
<PanelBody title= {__('Wall Settings', 'give')} initialOpen={ false }>
<PanelBody className="give-wall--wall-settings" title= {__('Wall Settings', 'give')} initialOpen={ false }>
<SelectControl
className="give-donor-wall-inspector"
label={ __( 'Sort By', 'give' ) }
Expand Down
16 changes: 9 additions & 7 deletions blocks/donor-wall/edit/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.give-donor-wall-inspector{
.give-donor-wall-inspector {
flex-direction: row !important;
align-items: center !important;
justify-content: space-between !important;
Expand Down Expand Up @@ -32,13 +32,15 @@
.components-input-control__container {
max-width: 165px !important;

> select {
line-height: 1.2 !important;
}
> select {
line-height: 1.2 !important;
}
}
}

.components-form-token-field {
margin-top: -18px !important;
label { display: none !important;}
.give-wall--wall-settings {
.components-form-token-field {
margin-top: -18px !important;
label { display: none !important;}
}
}
10 changes: 8 additions & 2 deletions includes/class-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public function render_admin_notices() {
/**
* Render give frontend notices.
*
* @unreleased Display registered error on donation form.
* @since 1.8.9
* @access public
*
Expand All @@ -295,8 +296,13 @@ public function render_frontend_notices( $form_id = 0 ) {

$request_form_id = isset( $_REQUEST['form-id'] ) ? absint( $_REQUEST['form-id'] ) : 0;

// Sanity checks first: Ensure that gateway returned errors display on the appropriate form.
if ( ! isset( $_POST['give_ajax'] ) && $request_form_id !== $form_id ) {
// Sanity checks first:
// - Ensure that gateway returned errors display on the appropriate form.
// - Error should not display on AJAX request.
if (
isset( $_POST['give_ajax'] )
|| ( $request_form_id && $request_form_id !== $form_id )
) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Framework/FieldsAPI/Concerns/NameCollision.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ public function checkNameCollisionDeep(Node $node)
}

/**
* @unreleased add existing and incoming nodes to exception
* @since 2.10.2
*
* @throws NameCollisionException
*/
public function checkNameCollision(Node $node)
{
if ($this->getNodeByName($node->getName())) {
throw new NameCollisionException($node->getName());
if ($existingNode = $this->getNodeByName($node->getName())) {
throw new NameCollisionException($node->getName(), $existingNode, $node);
}
}
}
51 changes: 50 additions & 1 deletion src/Framework/FieldsAPI/Exceptions/NameCollisionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,64 @@
namespace Give\Framework\FieldsAPI\Exceptions;

use Give\Framework\Exceptions\Primitives\Exception;
use Give\Framework\FieldsAPI\Contracts\Node;

/**
* @unreleased add existing and incoming nodes to exception
* @since 2.10.2
*/
class NameCollisionException extends Exception
{
public function __construct($name, $code = 0, Exception $previous = null)
/**
* @var string
*/
protected $nodeNameCollision;
/**
* @var Node
*/
protected $existingNode;
/**
* @var Node
*/
protected $incomingNode;

public function __construct(
string $name,
Node $existingNode,
Node $incomingNode,
int $code = 0,
Exception $previous = null
)
{
$this->nodeNameCollision = $name;
$this->existingNode = $existingNode;
$this->incomingNode = $incomingNode;

$message = "Node name collision for $name";
parent::__construct($message, $code, $previous);
}

/**
* @unreleased
*/
public function getNodeNameCollision(): string
{
return $this->nodeNameCollision;
}

/**
* @unreleased
*/
public function getIncomingNode(): Node
{
return $this->incomingNode;
}

/**
* @unreleased
*/
public function getExistingNode(): Node
{
return $this->existingNode;
}
}
19 changes: 18 additions & 1 deletion src/Framework/PaymentGateways/Traits/HandleHttpResponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ trait HandleHttpResponses
/**
* Handle Response
*
* @unreleased added check for responding with json
* @since 2.27.0 add support for json content-type
* @since 2.18.0
*
Expand All @@ -19,7 +20,7 @@ trait HandleHttpResponses
public function handleResponse($type)
{
if ($type instanceof RedirectResponse) {
if (isset($_SERVER['CONTENT_TYPE']) && str_contains($_SERVER['CONTENT_TYPE'], "application/json")) {
if ($this->wantsJson()) {
wp_send_json([
'type' => 'redirect',
'data' => [
Expand Down Expand Up @@ -60,4 +61,20 @@ public function handleExceptionResponse(\Exception $exception, string $message)
give_set_error('PaymentGatewayException', $message);
give_send_back_to_checkout();
}

/**
* This checks the server headers for 'application/json' to determine if it should respond with json.
*
* @unreleased
*
* @return bool
*/
protected function wantsJson(): bool
{
if (isset($_SERVER['HTTP_ACCEPT']) && str_contains($_SERVER['HTTP_ACCEPT'], 'application/json')) {
return true;
}

return isset($_SERVER['CONTENT_TYPE']) && str_contains($_SERVER['CONTENT_TYPE'], 'application/json');
}
}
Loading

0 comments on commit 257813a

Please sign in to comment.