Skip to content

Commit

Permalink
Lastest cafe changes 5.0.28.p
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebblo committed Oct 9, 2024
1 parent 24c3ebb commit b54b4f5
Show file tree
Hide file tree
Showing 102 changed files with 3,060 additions and 1,338 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Releases

### [5.0.28]

#### Added
- [New Ticket Selector Checkbox and Form Styles (#1527)](https://github.com/eventespresso/cafe/pull/1527)
- [Add Payment Method Deprecation Notices (#1564)](https://github.com/eventespresso/cafe/pull/1564)
- [Bypass Payment Processing if Too Many Payment Attempts (#1577)](https://github.com/eventespresso/cafe/pull/1577)

#### Fixed
- [PPC. Fix success payment set as pending (#1538)](https://github.com/eventespresso/cafe/pull/1538)
- [Ensure EE_AUTOSAVE_IDS is Defined (#1471)](https://github.com/eventespresso/cafe/pull/1471)
- [PPC. Fix an issue with a missing checkout type meta (#1548)](https://github.com/eventespresso/cafe/pull/1548)
- [Fix meta caps for Registration Form caps (#1546)](https://github.com/eventespresso/cafe/pull/1546)
- [Fix CSS Output in iFrames (#1552)](https://github.com/eventespresso/cafe/pull/1552)
- [Fix venue not being unassigned in EDTR (GraphQL) (#1561)](https://github.com/eventespresso/cafe/pull/1561)
- [Fix Missing Check-ins Bulk Actions (#1549)](https://github.com/eventespresso/cafe/pull/1549)
- [Fix Typing for EE_Datetime_Field::_prepare_for_display() (#1570)](https://github.com/eventespresso/cafe/pull/1570)
- [Fix List Table Views (#1576)](https://github.com/eventespresso/cafe/pull/1576)
- [Fix MER Max Ticket Quantity Violations (#1567)](https://github.com/eventespresso/cafe/pull/1567)

#### Changed
- [ Loosen Upcoming Events Widget Permissions (#1554)](https://github.com/eventespresso/cafe/pull/1554)
- [When copying datetime include venue id (Barista#1338) (#1568)](https://github.com/eventespresso/cafe/pull/1568)
- [Ensure WordPress Options Are Saved (#1574)](https://github.com/eventespresso/cafe/pull/1574)


### [5.0.27]

#### Added
Expand Down Expand Up @@ -33,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### [5.0.25]


#### Changed
- [BuildMachine changes - 5.0.24.p (#1486)](https://github.com/eventespresso/cafe/pull/1486)
- [Fix and Split Up PHP Unit Tests (#1354)](https://github.com/eventespresso/cafe/pull/1354)
Expand Down
30 changes: 19 additions & 11 deletions PaymentMethods/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ public function registerPaymentMethod(
*/
public static function hidePaymentMethods(array $pms_to_list): array
{
foreach (self::$pms_can_hide as $pm_name => $pm_option) {
$pms_can_hide = apply_filters(
'FHEE__EventEspresso_PaymentMethods_Manager__hidePaymentMethods__pms_can_hide',
self::$pms_can_hide
);
foreach ($pms_can_hide as $pm_name => $pm_option) {
// Can we deregister this PM ?
if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) {
unset($pms_to_list[ $pm_name ]);
Expand Down Expand Up @@ -204,16 +208,20 @@ public static function adminNotice()
*/
public static function usePayPalCommerceNotice()
{
echo '<div class="error"><p>'
. sprintf(
esc_html__(
'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.',
'event_espresso'
),
'<strong>',
'</strong>'
)
. '</p></div>';
echo '
<div class="notice ee-status-outline ee-status-outline--ok ee-status-bg--ok">
<p class="big-text">
<span class="dashicons dashicons-info"></span> &nbsp; '
. sprintf(
esc_html__(
'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.',
'event_espresso'
),
'<strong>',
'</strong>'
) . '
</p>
</div>';
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use EventEspresso\PaymentMethods\PayPalCommerce\domain\Domain;
use EventEspresso\PaymentMethods\PayPalCommerce\tools\extra_meta\PayPalExtraMetaManager;
use EventEspresso\core\services\loaders\LoaderFactory;
use EventEspresso\core\services\request\RequestInterface;
use EventEspresso\PaymentMethods\PayPalCommerce\tools\logging\PayPalLogger;

/**
Expand Down Expand Up @@ -53,56 +53,99 @@ class EEG_PayPalCheckout extends EE_Onsite_Gateway
* @param EE_Payment|null $payment
* @param array|null $billing_info
* @return EE_Payment
* @throws EE_Error|ReflectionException
*/
public function do_direct_payment($payment, $billing_info = null)
{
// Normally we shouldn't be getting here because the payment should have been processed
// along with the PP Order Charge.
return $payment;
$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
$post_parameters = $request->postParams();
// Check the payment.
$payment = $this->validatePayment($payment, $request);
if ($payment->details() === 'error' && $payment->status() === EEM_Payment::status_id_failed) {
return $payment;
}
$transaction = $payment->transaction();
$payment_method = $transaction->payment_method();
// Get the order details.
$order_id = $request->getRequestParam('pp_order_id');
if (! $order_id) {
return EEG_PayPalCheckout::updatePaymentStatus(
$payment,
EEM_Payment::status_id_failed,
$post_parameters,
esc_html__('Can\'t charge the Order. The Order ID is missing.', 'event_espresso')
);
}
// Capture the order.
$capture_status = EED_PayPalCommerce::captureOrder($transaction, $payment_method, $order_id);
// Check the order status.
$order_status = $this->isOrderCompleted($order_id, $transaction, $payment_method);
if (! $order_status['completed']) {
return EEG_PayPalCheckout::updatePaymentStatus(
$payment,
EEM_Payment::status_id_failed,
$order_status,
$order_status['message'] ?? ''
);
}
// Looks like all is good. Mark payment as a success.
$this->saveBillingDetails($payment, $transaction, $order_status['details'], $billing_info);
return EEG_PayPalCheckout::updatePaymentStatus($payment, EEM_Payment::status_id_approved, $capture_status);
}


/**
* Validate the Order.
*
* @param $order
* @param null $provided_order_id
* @param string $order_id
* @param EE_Transaction $transaction
* @param EE_Payment_Method $payment_method
* @return array ['completed' => {boolean}, 'message' => {string}]
* @throws EE_Error
* @throws ReflectionException
*/
public static function isOrderCompleted($order, $provided_order_id = null): array
public static function isOrderCompleted(
string $order_id,
EE_Transaction $transaction,
EE_Payment_Method $payment_method
): array
{
$order_details = EED_PayPalCommerce::getOrderDetails($order_id, $transaction, $payment_method);
$conclusion = [
'completed' => false,
'message' => esc_html__('Could not validate this Order.', 'event_espresso'),
'details' => $order_details,
];
if (! empty($order) && ! empty($provided_order_id) && $order['id'] !== $provided_order_id) {
$conclusion['message'] = esc_html__('Order ID mismatch.', 'event_espresso');
}
if (! $order || ! is_array($order)) {
$conclusion['message'] = esc_html__('The Order data is incorrectly formatted.', 'event_espresso');
} elseif (empty($order['status'])) {
if (! $order_details) {
$conclusion['message'] = esc_html__(
'Could not validate this payment. The Order details were empty.',
'event_espresso'
);
} elseif (! empty($order_details['error'])) {
$conclusion['message'] = $order_details['message'] ?? $order_details['error'];
} elseif (empty($order_details['status'])) {
$conclusion['message'] = esc_html__(
'There was an error with this payment. The status of the Order could not be determined.',
'event_espresso'
);
} elseif ($order['status'] !== 'COMPLETED') {
} elseif ($order_details['status'] !== 'COMPLETED') {
$conclusion['message'] = esc_html__(
'There was an error with this payment. Order was not approved.',
'event_espresso'
);
} elseif (empty($order['purchase_units'][0]['payments']['captures'][0]['status'])) {
} elseif (empty($order_details['purchase_units'][0]['payments']['captures'][0]['status'])) {
$conclusion['message'] = esc_html__(
'There was an error with this payment. The status of the Payment could not be determined.',
'event_espresso'
);
} elseif ($order['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') {
} elseif ($order_details['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') {
$conclusion['message'] = esc_html__(
'This payment was declined or failed validation. Please check the billing information you provided.',
'event_espresso'
);
} else {
// If we didn't fail on the above, the Order should be considered valid.
$conclusion['completed'] = true;
$conclusion['message'] = esc_html__('Order Valid.', 'event_espresso');
}
return $conclusion;
}
Expand Down Expand Up @@ -161,7 +204,7 @@ public static function updatePaymentStatus(
$payment->set_amount((float) $amount);
}
$payment->set_txn_id_chq_nmbr(
$order['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id']
$response_data['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id']
);
} else {
$default_message = sprintf(
Expand All @@ -183,6 +226,47 @@ public static function updatePaymentStatus(
}


/**
* Validate the payment.
*
* @param EE_Payment|null $payment
* @param RequestInterface $request
* @return EE_Payment
* @throws EE_Error
* @throws ReflectionException
*/
public function validatePayment(?EE_Payment $payment, RequestInterface $request): EE_Payment
{
$failed_status = $this->_pay_model->failed_status();
// Check the payment.
if (! $payment instanceof EE_Payment) {
$payment = EE_Payment::new_instance();
$error_message = esc_html__('Error. No associated payment was found.', 'event_espresso');
return EEG_PayPalCheckout::updatePaymentStatus(
$payment,
$failed_status,
$request->postParams(),
$error_message
);
}
// Check the transaction.
$transaction = $payment->transaction();
if (! $transaction instanceof EE_Transaction) {
$error_message = esc_html__(
'Could not process this payment because it has no associated transaction.',
'event_espresso'
);
return EEG_PayPalCheckout::updatePaymentStatus(
$payment,
$failed_status,
$request->postParams(),
$error_message
);
}
return $payment;
}


/**
* Save some transaction details, like billing information.
*
Expand All @@ -203,7 +287,7 @@ public static function saveBillingDetails(
$primary_reg = $transaction->primary_registration();
$attendee = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;
$payment_method = $transaction->payment_method();
$postmeta_name = $payment_method->type_obj() instanceof EE_PMT_Base
$post_meta_name = $payment_method->type_obj() instanceof EE_PMT_Base
? 'billing_info_' . $payment_method->type_obj()->system_name()
: '';
if (empty($order['payment_source']) || ! $attendee instanceof EE_Attendee) {
Expand All @@ -218,8 +302,8 @@ public static function saveBillingDetails(
if (! empty($billing_info['address'])) {
$attendee->set_address($billing_info['address']);
}
if (! empty($billing_info['address_2'])) {
$attendee->set_address2($billing_info['address_2']);
if (! empty($billing_info['address2'])) {
$attendee->set_address2($billing_info['address2']);
}
if (! empty($billing_info['city'])) {
$attendee->set_city($billing_info['city']);
Expand All @@ -233,7 +317,8 @@ public static function saveBillingDetails(
if (! empty($billing_info['zip'])) {
$attendee->set_zip($billing_info['zip']);
}
// Or card information from ACDC ?
// Or card information from advanced card fields ?
$billing_info['credit_card'] = '';
if (! empty($order['payment_source']['card'])) {
$payer_card = $order['payment_source']['card'];
if (! empty($payer_card['name'])) {
Expand All @@ -244,7 +329,8 @@ public static function saveBillingDetails(
$billing_info['last_name'] = $full_name[1] ?? $attendee->lname();
}
}
update_post_meta($attendee->ID(), $postmeta_name, $billing_info);
// Update attendee billing info in the transaction details.
update_post_meta($attendee->ID(), $post_meta_name, $billing_info);
$attendee->save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,46 +156,4 @@ public static function refundNotice(bool $can_edit_payments)
);
echo $html;
}


/**
* Override the parent.
*
* @param EE_Transaction $transaction
* @param float|null $amount
* @param EE_Billing_Info_Form|null $billing_info
* @param string|null $return_url
* @param string $fail_url
* @param string $method
* @param bool $by_admin
* @return EE_Payment
* @throws EE_Error
* @throws ReflectionException
*/
public function process_payment(
EE_Transaction $transaction,
$amount = null,
$billing_info = null,
$return_url = null,
$fail_url = '',
$method = 'CART',
$by_admin = false
): EE_Payment {
// This payment should have been processed in the background, while the Order was created and charged.
// So simply return the last payment. Unless it's somehow missing.
$payment = $transaction->last_payment();
if (empty($payment) || $payment->status() === EEM_Payment::status_id_failed) {
// Then we try processing the payment as usual.
return parent::process_payment(
$transaction,
$amount,
$billing_info,
$return_url,
$fail_url,
$method,
$by_admin
);
}
return $transaction->last_payment();
}
}
16 changes: 6 additions & 10 deletions PaymentMethods/PayPalCommerce/PayPalCheckout/forms/BillingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use EE_Text_Input;
use EE_Transaction;
use EED_PayPalCommerce;
use EEG_PayPalCheckout;
use EEH_HTML;
use EEM_Payment_Method;
use EventEspresso\core\services\loaders\LoaderFactory;
Expand Down Expand Up @@ -66,7 +65,11 @@ public function __construct(EE_Payment_Method $payment_method, array $options)
// Can't be too careful.
$this->transaction = $options['transaction'] ?? null;
$this->template_path = $options['template_path'] ?? '';
$this->checkout_type = $payment_method->get_extra_meta(Domain::META_KEY_CHECKOUT_TYPE, true, '');
$this->checkout_type = $payment_method->get_extra_meta(
Domain::META_KEY_CHECKOUT_TYPE,
true,
'express_checkout'
);
$pm_slug = $payment_method->slug();
$parameters = array_replace_recursive(
$options,
Expand Down Expand Up @@ -103,13 +106,6 @@ public function __construct(EE_Payment_Method $payment_method, array $options)
'default' => '',
]
),
'pp_order_amount' => new EE_Hidden_Input(
[
'html_id' => 'eea-' . $pm_slug . '-order-amount',
'html_name' => 'pp_order_amount',
'default' => '',
]
),
],
]
);
Expand Down Expand Up @@ -141,7 +137,7 @@ public function addPaymentSections(): void
]
);
// Add PayPal Hosted Fields.
if ($this->checkout_type !== 'express_checkout') {
if (! empty($this->checkout_type) && $this->checkout_type !== 'express_checkout') {
$this->addAdvancedCardFields();
}
// Add payment types separator, if both are enabled.
Expand Down
Loading

0 comments on commit b54b4f5

Please sign in to comment.