Skip to content

Commit

Permalink
Lastest cafe changes 5.0.19.p
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebblo committed Mar 20, 2024
1 parent d4ace23 commit 3169fd5
Show file tree
Hide file tree
Showing 40 changed files with 592 additions and 451 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Releases

### [5.0.19]

#### Fixed
- [PPC. Fix instantiating wrong extra metadata (#1150)](https://github.com/eventespresso/cafe/pull/1150)
- [Fix Status Codes Notice Container (#1156)](https://github.com/eventespresso/cafe/pull/1156)
- [Fix People Admin List Table Filters (#1139)](https://github.com/eventespresso/cafe/pull/1139)
- [Espresso Custom Post Type Fixes (#1163)](https://github.com/eventespresso/cafe/pull/1163)
- [PPC. Fix partial payments (#1134)](https://github.com/eventespresso/cafe/pull/1134)

#### Changed
- [Build Machine 5.0.18.p changes (#1146)](https://github.com/eventespresso/cafe/pull/1146)
- [PPC. Add transaction to the logs (#1158)](https://github.com/eventespresso/cafe/pull/1158)
- [PPC. Update order status/error messages (#1162)](https://github.com/eventespresso/cafe/pull/1162)
- [Prevent fatal error from get_edit_post_link returning null (#1166)](https://github.com/eventespresso/cafe/pull/1166)
- [Remove Serialized Objects from Registration Report Requests (#1154)](https://github.com/eventespresso/cafe/pull/1154)


### [5.0.18]

#### Added
Expand All @@ -25,7 +42,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Improve AJAX Response Handling in SPCO (#1119)](https://github.com/eventespresso/cafe/pull/1119)
- [Refactor Reg Admin List Table Columns (#1099)](https://github.com/eventespresso/cafe/pull/1099)
- [Remove TAB Transaction Registrations from Reg Report CSV (#1093)](https://github.com/eventespresso/cafe/pull/1093)
- [Improve Custom Post Type Defense Against Hostile Themes - MOD Plugins (#1136)](https://github.com/eventespresso/cafe/pull/1136)
- [Improve Custom Post Type Defense Against Hostile Themes - [Build Machine 5.0.18.p changes (#1146)](https://github.com/eventespresso/cafe/pull/1146)
- [PPC. Add transaction to the logs (#1158)](https://github.com/eventespresso/cafe/pull/1158)
- [PPC. Update order status/error messages (#1162)](https://github.com/eventespresso/cafe/pull/1162)
- [Prevent fatal error from get_edit_post_link returning null (#1166)](https://github.com/eventespresso/cafe/pull/1166)
- [Remove Serialized Objects from Registration Report Requests (#1154)](https://github.com/eventespresso/cafe/pull/1154)
- MOD Plugins (#1136)](https://github.com/eventespresso/cafe/pull/1136)


### [5.0.17]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,16 @@ public function do_direct_payment($payment, $billing_info = null)
$exception->getMessage()
);
}
$order_id = $request->getRequestParam('pp_order_id', '', DataType::STRING);
$is_order_valid = $this->isOrderValid($order_id, $order);
if (! $is_order_valid['valid']) {
$order_id = $request->getRequestParam('pp_order_id', '', DataType::STRING);
$order_status = $this->isOrderCompleted($order_id, $order);
if (! $order_status['completed']) {
return $this->setPaymentFailure(
$payment,
$failed_status,
[$order, $request->postParams()],
$is_order_valid['message']
$order_status['message']
);
}

// Remove the saved order data.
PayPalExtraMetaManager::deletePmOption($payment_method, Domain::META_KEY_LAST_ORDER);
// Looks like all is good. Do a payment success.
Expand Down Expand Up @@ -139,30 +138,47 @@ public function validateThisPayment(?EE_Payment $payment, RequestInterface $requ
*
* @param string $provided_order_id
* @param $order
* @return array [valid => {boolean}, message => {string}]
* @return array ['completed' => {boolean}, 'message' => {string}]
*/
public function isOrderValid(string $provided_order_id, $order): array
public function isOrderCompleted(string $provided_order_id, $order): array
{
$conclusion = [
'valid' => false,
'message' => esc_html__('Could not validate this Order.', 'event_espresso'),
'completed' => false,
'message' => esc_html__('Could not validate this Order.', 'event_espresso'),
];
// Check the provided Order and order ID.
if (! $provided_order_id) {
$conclusion['message'] = esc_html__('Invalid Order ID provided !', 'event_espresso');
$conclusion['message'] = esc_html__(
'Invalid Order ID provided! Not able to confirm the order',
'event_espresso'
);
} elseif (! $order || ! is_array($order)) {
$conclusion['message'] = esc_html__('Order data in wrong format.', 'event_espresso');
$conclusion['message'] = esc_html__('Order data is in wrong format.', 'event_espresso');
} elseif ($order['id'] !== $provided_order_id) {
$conclusion['message'] = esc_html__('Order ID mismatch.', 'event_espresso');
} elseif (empty($order['status'])
|| $order['status'] !== 'COMPLETED'
|| empty($order['purchase_units'][0]['payments']['captures'][0]['status'])
|| $order['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED'
) {
$conclusion['message'] = esc_html__('Order not completed.', 'event_espresso');
} elseif (empty($order['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') {
$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'])) {
$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') {
$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['valid'] = true;
$conclusion['completed'] = true;
}
return $conclusion;
}
Expand Down
8 changes: 7 additions & 1 deletion PaymentMethods/PayPalCommerce/api/orders/CaptureOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ public function capture(): array
public function validateOrder($response): array
{
$message = esc_html__('Validating Order Capture:', 'event_espresso');
PayPalLogger::errorLog($message, [$this->request_url, $response], $this->transaction->payment_method());
PayPalLogger::errorLog(
$message,
[$this->request_url, $response],
$this->transaction->payment_method(),
false,
$this->transaction
);
// We got a direct error response. Not valid. Return that error.
if (! empty($response['error'])) {
return $response;
Expand Down
21 changes: 17 additions & 4 deletions PaymentMethods/PayPalCommerce/api/orders/CreateOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function getParameters(): array
'description' => substr(wp_strip_all_tags($description), 0, 125),
'items' => $this->getLineItems(),
'amount' => [
'value' => $this->transaction->total(),
'value' => $this->transaction->remaining(),
'currency_code' => $this->currency_code,
'breakdown' => $this->getBreakdown(),
],
Expand Down Expand Up @@ -174,7 +174,10 @@ protected function getLineItems(): array
$event_line_items = $this->transaction->items_purchased();
// List actual line items.
foreach ($event_line_items as $line_item) {
if ($line_item instanceof EE_Line_Item && $line_item->OBJ_type() !== 'Promotion') {
if ($line_item instanceof EE_Line_Item
&& $line_item->OBJ_type() !== 'Promotion'
&& $line_item->quantity() > 0
) {
$item_money = $line_item->unit_price();
$li_description = $line_item->desc() ?? esc_html__('Event Ticket', 'event_espresso');
$line_items [] = [
Expand All @@ -189,14 +192,18 @@ protected function getLineItems(): array
];
// Line item total.
$this->items_total += $line_item->pretaxTotal();
} elseif ($line_item->OBJ_type() === 'Promotion') {
} elseif ($line_item->OBJ_type() === 'Promotion' && $line_item->quantity() > 0) {
// Promotions total.
$this->promos_total += $line_item->total();
}
}
// Make sure we have an absolute number with only two decimal laces.
$this->items_total = CurrencyManager::normalizeValue($this->items_total);
$this->promos_total = CurrencyManager::normalizeValue($this->promos_total);
// If this is a partial payment, apply the paid amount as a promo.
if ($this->transaction->paid() > 0) {
$this->promos_total += CurrencyManager::normalizeValue($this->transaction->paid());
}
$this->countTaxTotal();
return $line_items;
}
Expand Down Expand Up @@ -255,7 +262,13 @@ protected function getBreakdown(): array
public function validateOrder($response, $parameters): array
{
$message = esc_html__('Validating Order Create:', 'event_espresso');
PayPalLogger::errorLog($message, [$this->request_url, $response], $this->transaction->payment_method());
PayPalLogger::errorLog(
$message,
[$this->request_url, $response],
$this->transaction->payment_method(),
false,
$this->transaction
);
if (! empty($response['error'])) {
return $response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ jQuery(document).ready(function ($) {
if (is_valid && typeof callback !== 'undefined' && callback) {
// Run the callback if there are no errors.
callback(this_pm, response);
} else {
this_pm.processing_icon.fadeOut('fast');
}
if (update_ui) {
this_pm.updateOnboardingUI(this_pm, false);
Expand Down
6 changes: 3 additions & 3 deletions PaymentMethods/PayPalCommerce/domain/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Domain
public const META_KEY_SANDBOX_MODE = 'sandbox_mode';

/**
* Name of the extra meta that stores the PayPal Access Token that is used get onboarding URL.
* Name of the extra meta that stores the Access Token that is used to auth in API requests to PayPal.
*/
public const META_KEY_ACCESS_TOKEN = 'access_token';

Expand All @@ -55,9 +55,9 @@ class Domain
public const META_KEY_CLIENT_SECRET = 'client_secret';

/**
* Name of the extra meta that stores the expiration date of the client ID.
* Name of the extra meta that stores the expiration date of the Access Token.
*/
public const META_KEY_EXPIRES_IN = 'expires_in';
public const META_KEY_TOKEN_EXPIRES_IN = 'expires_in';

/**
* Name of the extra meta that holds the partner client ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public static function getPartnerAccessToken(EE_Payment_Method $paypal_pm): stri
*/
public static function partnerAccessTokenExpired(EE_Payment_Method $paypal_pm): bool
{
$expires_at = (int) PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_EXPIRES_IN);
$expires_at = (int) PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_TOKEN_EXPIRES_IN);
if (! $expires_at) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class PayPalExtraMeta
* Class constructor.
*
* @param EE_Payment_Method $pm_instance
* @throws EE_Error
* @throws ReflectionException
*/
public function __construct(EE_Payment_Method $pm_instance)
{
Expand Down Expand Up @@ -89,9 +91,9 @@ public function getOption(string $option_name)
* Get PM metadata.
* Return the metadata array if all good. False otherwise.
*
* @return array|bool
* @return array
*/
public function getMetaData()
public function getMetaData(): array
{
try {
return $this->pm->get_extra_meta($this->metadata_key, true, []);
Expand All @@ -101,7 +103,7 @@ public function getMetaData()
$e->getMessage()
);
PayPalLogger::errorLog($err_msg, [], $this->pm);
return false;
return [];
}
}

Expand All @@ -119,7 +121,6 @@ public function saveOption(string $name, $value): bool
if (! $meta_data) {
$meta_data = [];
}

$meta_data[ $name ] = $value;
return $this->saveMetaData($meta_data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function savePmOptions(EE_Payment_Method $paypal_pm, array $option
* @return bool
*/
public static function deletePmOption(EE_Payment_Method $paypal_pm, string $option_name): bool
{
{
$pp_meta_data = self::extraMeta($paypal_pm);
return $pp_meta_data->deleteOption($option_name);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ public static function updateDebugMode(EE_Payment_Method $paypal_pm, array $requ
&& $paypal_pm->debug_mode() !== (bool) $request_data['sandbox_mode']
) {
try {
$paypal_pm->save(['PMD_debug_mode' => $request_data['sandbox_mode']]);
$paypal_pm->save(['PMD_debug_mode' => (bool) $request_data['sandbox_mode']]);
} catch (EE_Error $e) {
$err_msg = sprintf(
esc_html__('Note, debug mode not saved ! %1$s', 'event_espresso'),
Expand All @@ -156,7 +156,7 @@ public static function savePartnerAccessToken(EE_Payment_Method $paypal_pm, arra
$paypal_data = [];
$expected_parameters = [
Domain::META_KEY_ACCESS_TOKEN,
Domain::META_KEY_EXPIRES_IN,
Domain::META_KEY_TOKEN_EXPIRES_IN,
Domain::META_KEY_APP_ID,
Domain::META_KEY_PARTNER_CLIENT_ID,
Domain::META_KEY_PARTNER_MERCHANT_ID,
Expand All @@ -173,7 +173,7 @@ public static function savePartnerAccessToken(EE_Payment_Method $paypal_pm, arra
case Domain::META_KEY_PARTNER_MERCHANT_ID:
$paypal_data[ $api_key ] = self::encryptString($response[ $api_key ], $paypal_pm);
break;
case Domain::META_KEY_EXPIRES_IN:
case Domain::META_KEY_TOKEN_EXPIRES_IN:
$paypal_data[ $api_key ] = time() + (int) sanitize_key($response[ $api_key ]);
break;
default:
Expand Down Expand Up @@ -253,10 +253,12 @@ public static function parseAndSaveOptions(EE_Payment_Method $paypal_pm, array $
*
* @param EE_Payment_Method $paypal_pm
* @return PayPalExtraMeta
* @throws EE_Error
* @throws ReflectionException
*/
public static function extraMeta(EE_Payment_Method $paypal_pm): PayPalExtraMeta
{
return LoaderFactory::getLoader()->getShared(PayPalExtraMeta::class, [$paypal_pm]);
return new PayPalExtraMeta($paypal_pm);
}


Expand All @@ -266,6 +268,8 @@ public static function extraMeta(EE_Payment_Method $paypal_pm): PayPalExtraMeta
* @param string $text
* @param EE_Payment_Method $paypal_pm
* @return string|null
* @throws EE_Error
* @throws ReflectionException
*/
public static function encryptString(string $text, EE_Payment_Method $paypal_pm): ?string
{
Expand Down
20 changes: 6 additions & 14 deletions admin_pages/events/Events_Admin_List_Table.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@
* Class for preparing the table listing all the events
* note: anywhere there are no php docs it is because the docs are available in the parent class.
*
* @package Events_Admin_List_Table
* @subpackage includes/core/admin/events/Events_Admin_List_Table.class.php
* @author Darren Ethier
* @package Events_Admin_List_Table
* @subpackage includes/core/admin/events/Events_Admin_List_Table.class.php
* @author Darren Ethier
* @property Events_Admin_Page $_admin_page
*/
class Events_Admin_List_Table extends EE_Admin_List_Table
{
/**
* @var Events_Admin_Page
*/
protected EE_Admin_Page $_admin_page;

/**
* @var EE_Datetime
*/
private $_dtt;
private ?EE_Datetime $_dtt = null;


/**
Expand Down Expand Up @@ -97,8 +90,7 @@ protected function _get_table_filters()
* @throws InvalidInterfaceException
* @throws InvalidArgumentException
* @throws EE_Error
* @throws EE_Error
* @throws EE_Error
* @throws ReflectionException
*/
protected function _add_view_counts()
{
Expand Down

0 comments on commit 3169fd5

Please sign in to comment.