Skip to content

Commit

Permalink
Lastest cafe changes 5.0.22.p
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebblo committed Aug 8, 2024
1 parent fade6db commit 1098674
Show file tree
Hide file tree
Showing 100 changed files with 3,194 additions and 1,424 deletions.
1 change: 0 additions & 1 deletion .VERSION

This file was deleted.

35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Releases

### [5.0.22]

#### Added
- [PPC. Add partner Fees (#1355)](https://github.com/eventespresso/cafe/pull/1355)
- [Allow Advanced Editor in Decaf (#1430)](https://github.com/eventespresso/cafe/pull/1430)

#### Fixed
- [Fix Merge Garbage (#1396)](https://github.com/eventespresso/cafe/pull/1396)
- [Remove Return Type From create_attendee_from_billing_form_data() (#1386)](https://github.com/eventespresso/cafe/pull/1386)
- [Fix Decaf Issues (#1410)](https://github.com/eventespresso/cafe/pull/1410)
- [PPC. Fix payments getting mixed (#1415)](https://github.com/eventespresso/cafe/pull/1415)
- [Remove EE version number form PayPal Commerce fee notice (#1418)](https://github.com/eventespresso/cafe/pull/1418)
- [Fix Ticket Selector JS Missing Event Var (#1424)](https://github.com/eventespresso/cafe/pull/1424)
- [Fix Fatal Error if Payment Log is Missing (#1426)](https://github.com/eventespresso/cafe/pull/1426)
- [Fix Log Key (#1420)](https://github.com/eventespresso/cafe/pull/1420)
- [Fix Legacy Event Editor Duplicating Tickets on Update (#1435)](https://github.com/eventespresso/cafe/pull/1435)
- [Fix Trash Ticket UI in Decaf (#1417)](https://github.com/eventespresso/cafe/pull/1417)
- [Fix Errors During Plugin Update (#1437)](https://github.com/eventespresso/cafe/pull/1437)
- [PPC. Fix for the re-try payments (#1436)](https://github.com/eventespresso/cafe/pull/1436)
- [Son of Fix Datepicker Input Format (#1392)](https://github.com/eventespresso/cafe/pull/1392)
- [Fix Event Editor Timezone Selector (#1442)](https://github.com/eventespresso/cafe/pull/1442)

#### Changed
- [Remove Use Advanced EDTR Feature Flag (#1388)](https://github.com/eventespresso/cafe/pull/1388)
- [Toggle EDD Licensing within PUE when ready (#1353)](https://github.com/eventespresso/cafe/pull/1353)
- [Set USE_PAYMENT_PROCESSOR_FEES feature flag to be true by default (#1416)](https://github.com/eventespresso/cafe/pull/1416)
- [Update Cafe Readme file for Decaf (#1397)](https://github.com/eventespresso/cafe/pull/1397)
- [Add option to delete contacts if the contact has no related registrations (#1378)](https://github.com/eventespresso/cafe/pull/1378)
- [Catch Billing Form Errors if Payment Method Deactivated (#1434)](https://github.com/eventespresso/cafe/pull/1434)
- [Advanced Editor Changes for Decaf (Barista#1330) (#1439)](https://github.com/eventespresso/cafe/pull/1439)
- [Decaf 5.0.22 Update readme.txt (#1448)](https://github.com/eventespresso/cafe/pull/1448)


### [5.0.21]

#### Fixed
Expand Down Expand Up @@ -35,6 +68,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Use get_post_meta() for Featured Image Alt Tag (#1342)](https://github.com/eventespresso/cafe/pull/1342)
- [Optimize Event list table datetime and ticket query (#1348)](https://github.com/eventespresso/cafe/pull/1348)
- [Reduce Vendor Folder Size (#1349)](https://github.com/eventespresso/cafe/pull/1349)
- [BuildMachine 5.0.21 changes (#1374)](https://github.com/eventespresso/cafe/pull/1374)
- [PPC. Add partner Fees (#1355)](https://github.com/eventespresso/cafe/pull/1355)


### [5.0.20]
Expand Down
3 changes: 2 additions & 1 deletion PaymentMethods/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function registerPaymentMethod(
if (! class_exists($pm_object)) {
return false;
}
new $pm_object();
$payment_menthod = new $pm_object();
$payment_menthod->initialize();
return true;
}

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

use EventEspresso\core\services\loaders\LoaderFactory;
use EventEspresso\core\services\request\DataType;
use EventEspresso\core\services\request\RequestInterface;
use EventEspresso\PaymentMethods\PayPalCommerce\domain\Domain;
use EventEspresso\PaymentMethods\PayPalCommerce\tools\extra_meta\PayPalExtraMetaManager;
use EventEspresso\PaymentMethods\PayPalCommerce\tools\logging\PayPalLogger;
Expand Down Expand Up @@ -62,91 +59,7 @@ class EEG_PayPalCheckout extends EE_Onsite_Gateway
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. But we should double-check just to be safe.
if ($payment->status() === EEM_Payment::status_id_approved) {
// Looks like the Payment was already approved. This is a success.
return $payment;
}
$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
// 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 saved order details.
try {
$order = PayPalExtraMetaManager::getPmOption($payment_method, Domain::META_KEY_LAST_ORDER);
} catch (Exception $exception) {
return EEG_PayPalCheckout::updatePaymentStatus(
$payment,
EEM_Payment::status_id_failed,
$request->postParams(),
$exception->getMessage()
);
}
$order_id = $request->getRequestParam('pp_order_id');
$order_status = $this->isOrderCompleted($order, $order_id);
if (! $order_status['completed']) {
return EEG_PayPalCheckout::updatePaymentStatus(
$payment,
EEM_Payment::status_id_failed,
[$order, $request->postParams()],
$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.
$this->saveBillingDetails($payment, $transaction, $order, $billing_info);
return EEG_PayPalCheckout::updatePaymentStatus($payment, EEM_Payment::status_id_approved, $order);
}


/**
* Validate the payment.
*
* @param mixed $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
);
}
// Check for the payment nonce.
// $order_nonce = $request->getRequestParam('pp_order_nonce');
// if (empty($order_nonce) || ! wp_verify_nonce($order_nonce, Domain::CAPTURE_ORDER_NONCE_NAME)) {
// $error_message = esc_html__('No or incorrect order capture nonce provided !', 'event_espresso');
// return EEG_PayPalCheckout::updatePaymentStatus($payment, $failed_status, $request->postParams(), $error_message);
// }
// along with the PP Order Charge.
return $payment;
}

Expand All @@ -164,7 +77,7 @@ public static function isOrderCompleted($order, $provided_order_id = null): arra
'completed' => false,
'message' => esc_html__('Could not validate this Order.', 'event_espresso'),
];
if (! empty($provided_order_id) && $order['id'] !== $provided_order_id) {
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)) {
Expand Down Expand Up @@ -263,7 +176,7 @@ public static function updatePaymentStatus(
);
}
$log_message = $update_message ?: $default_message;
PayPalLogger::errorLog($log_message, $response_data, $paypal_pm);
PayPalLogger::errorLog($log_message, $response_data, $paypal_pm, false, $payment->transaction());
$payment->set_status($status);
$payment->set_details($log_message);
$payment->set_gateway_response($log_message);
Expand All @@ -272,6 +185,63 @@ public static function updatePaymentStatus(
}


/**
* Get PayPal order if already created for this transaction and saved.
*
* @param EE_Payment_Method $paypal_pm
* @param int $TXN_ID
* @return array
*/
public static function getPpOrder(EE_Payment_Method $paypal_pm, int $TXN_ID): array
{
try {
$pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? [];
return $pp_orders[ $TXN_ID ] ?? [];
} catch (Exception $exception) {
return [];
}
}


/**
* Update PayPal order for this transaction.
*
* @param $order
* @param EE_Payment_Method $paypal_pm
* @param int $TXN_ID
* @return bool
*/
public static function updatePpOrder($order, EE_Payment_Method $paypal_pm, int $TXN_ID): bool
{
try {
$pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? [];
$pp_orders[ $TXN_ID ] = $order;
return PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS, $pp_orders);
} catch (Exception $exception) {
return false;
}
}


/**
* Delete PP Order associated with the provided transaction.
*
* @param EE_Payment_Method $paypal_pm
* @param int $TXN_ID
* @return bool
*/
public static function deletePpOrder(EE_Payment_Method $paypal_pm, int $TXN_ID): bool
{
try {
$pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? [];
unset($pp_orders[ $TXN_ID ]);
return PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS, $pp_orders);
} catch (Exception $exception) {
return false;
}
}


/**
* Save some transaction details, like billing information.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function generate_new_billing_form(EE_Transaction $transaction = null, ?a
],
$extra_args
);
return new BillingForm($this->_pm_instance, $options);
return LoaderFactory::getNew(BillingForm::class, [$this->_pm_instance, $options]);
}


Expand Down
Loading

0 comments on commit 1098674

Please sign in to comment.