Skip to content

Commit

Permalink
Lastest Cafe changes 5.0.13.p
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebblo committed Jan 16, 2024
1 parent 465a388 commit dcc737b
Show file tree
Hide file tree
Showing 105 changed files with 4,561 additions and 2,406 deletions.
34 changes: 33 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Releases

### [5.0.13]

#### Fixed
- [Set Defaults and Types for EE_Gateway Properties (#989)](https://github.com/eventespresso/cafe/pull/989)
- [Fix Escaping for [ESPRESSO_MY_EVENTS] Shortcode (#975)](https://github.com/eventespresso/cafe/pull/975)
- [Fix Messages Settings Admin Toggle Switch Display (#996)](https://github.com/eventespresso/cafe/pull/996)
- [Fix Event Registrations Report CSV (#988)](https://github.com/eventespresso/cafe/pull/988)
- [Relax Property Types in EE_Template_Config (#1007)](https://github.com/eventespresso/cafe/pull/1007)
- [Fix EE_Line_Item::desc() Return Type (#1009)](https://github.com/eventespresso/cafe/pull/1009)
- [Fix Country Settings Is EU Option Not Saving (#1017)](https://github.com/eventespresso/cafe/pull/1017)
- [Fix Registration List Table View Links When Filtered by Event (#1016)](https://github.com/eventespresso/cafe/pull/1016)
- [Fix Event List Registration Links (#1014)](https://github.com/eventespresso/cafe/pull/1014)
- [Fix Session Reset Keys Data Type (#1023)](https://github.com/eventespresso/cafe/pull/1023)
- [Fix Ticket Total with Taxes (#1018)](https://github.com/eventespresso/cafe/pull/1018)
- [Fix Undefined Constant and Uninitialized Properties (#1030)](https://github.com/eventespresso/cafe/pull/1030)
- [ES. Fix missing thank you page session (#1032)](https://github.com/eventespresso/cafe/pull/1032)
- [Fix Model Path for DTT_ID in addWhereParamsForFilters() (#1039)](https://github.com/eventespresso/cafe/pull/1039)
- [Fix RSS Feeds and UI Tweaks (#1045)](https://github.com/eventespresso/cafe/pull/1045)
- [Fix fatals/deprecated notices thrown during migrations (#1063)](https://github.com/eventespresso/cafe/pull/1063)

#### Changed
- [BM 5.0.12.p changes (#977)](https://github.com/eventespresso/cafe/pull/977)
- [Refactor How Database Table Indexes are Added (#983)](https://github.com/eventespresso/cafe/pull/983)
- [Check for Multiple @ Sign in Email Addresses (#973)](https://github.com/eventespresso/cafe/pull/973)
- [Move Venue Sorting into useVenues() Hook (Barista#1276) (#1000)](https://github.com/eventespresso/cafe/pull/1000)
- [PPC. Third party integration (#807)](https://github.com/eventespresso/cafe/pull/807)
- [Make M-Mode Changes Backwards Compatible (#979)](https://github.com/eventespresso/cafe/pull/979)
- [Dont Use Links to Close Notices (#1036)](https://github.com/eventespresso/cafe/pull/1036)
- [PPC. Fix not ACDC eligible behaviour (#1040)](https://github.com/eventespresso/cafe/pull/1040)
- [Protect Ticket Assignments Manager Layout from Other Plugin CSS (#1065)](https://github.com/eventespresso/cafe/pull/1065)


### [5.0.12]

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

#### Changed
- [Build Machine 5.0.9 changes (#828)](https://github.com/eventespresso/cafe/pull/828)
- [PayPal Commerce. Fix double opening clicks on SPCO](https://github.com/eventespresso/cafe/pull/827)
- [PayPal Commerce. Fix double](https://github.com/eventespresso/cafe/pull/827)
- [Don't apply payments to cancelled payments by default (#844)](https://github.com/eventespresso/cafe/pull/844)
- [Verify Core Config Loaded Before Showing Maintenance Mode Notice (#843)](https://github.com/eventespresso/cafe/pull/843)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,22 @@ class EEG_PayPalCheckout extends EE_Onsite_Gateway

/**
* @param EE_Payment|null $payment
* @param array|null $billing_info
* @param array|null $billing_info
* @return EE_Payment
* @throws EE_Error
* @throws ReflectionException
*/
public function do_direct_payment($payment, $billing_info = null)
{
$failed_status = $this->_pay_model->failed_status();
$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
// Check the payment.
$payment_valid = $this->validateThisPayment($payment, $request);
if ($payment_valid->details() === 'error' && $payment_valid->status() === $failed_status) {
return $payment_valid;
}
$payment_method = $payment->transaction()->payment_method();
$transaction = $payment->transaction();
$payment_method = $transaction->payment_method();

// Get saved order details.
try {
Expand All @@ -87,7 +88,7 @@ public function do_direct_payment($payment, $billing_info = null)
// Remove the saved order data.
PayPalExtraMetaManager::deletePmOption($payment_method, Domain::META_KEY_LAST_ORDER);
// Looks like all is good. Do a payment success.
return $this->setPaymentSuccess($payment, $order);
return $this->setPaymentSuccess($payment, $transaction, $order);
}


Expand All @@ -98,6 +99,7 @@ public function do_direct_payment($payment, $billing_info = null)
* @param RequestInterface $request
* @return EE_Payment
* @throws EE_Error
* @throws ReflectionException
*/
public function validateThisPayment(?EE_Payment $payment, RequestInterface $request): EE_Payment
{
Expand Down Expand Up @@ -131,7 +133,7 @@ public function validateThisPayment(?EE_Payment $payment, RequestInterface $requ
* Validate the Order.
*
* @param string $provided_order_id
* @param $order
* @param $order
* @return string string if error and empty if valid.
*/
public function orderInvalid(string $provided_order_id, $order): string
Expand Down Expand Up @@ -161,13 +163,13 @@ public function orderInvalid(string $provided_order_id, $order): string
* @param array|string $response_data
* @param string $err_message
* @return EE_Payment
* @throws EE_Error
* @throws EE_Error|ReflectionException
*/
public function setPaymentFailure(
EE_Payment $payment,
string $status,
$response_data,
string $err_message = ''
string $status,
$response_data,
string $err_message = ''
): EE_Payment {
$this->log(['Error request data:' => $response_data], $payment);
$payment->set_status($status);
Expand All @@ -180,19 +182,76 @@ public function setPaymentFailure(
/**
* Set the payment success.
*
* @param EE_Payment $payment
* @param array $order
* @param EE_Payment $payment
* @param EE_Transaction $transaction
* @param array $order
* @return EE_Payment
* @throws EE_Error
* @throws EE_Error|ReflectionException
*/
public function setPaymentSuccess(EE_Payment $payment, array $order): EE_Payment
public function setPaymentSuccess(EE_Payment $payment, EE_Transaction $transaction, array $order): EE_Payment
{
$amount = $order['purchase_units'][0]['payments']['captures'][0]['amount']['value'];
$amount = $order['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0;
if (! $amount) {
$this->log(['Success order but amount is 0 !' => $order], $payment);
}
$payment->set_status(EEM_Payment::status_id_approved);
$payment->set_amount((float) $amount);
$payment->set_txn_id_chq_nmbr($order['purchase_units'][0]['payments']['captures'][0]['id']);
$payment->set_details($order['payer']);
$payment->set_gateway_response($order['status']);
$payment->set_txn_id_chq_nmbr($order['purchase_units'][0]['payments']['captures'][0]['id'] ?? $order['id']);
$payment->set_gateway_response($order['status'] ?? 'success');
$this->saveBillingDetails($payment, $transaction, $order);
return $payment;
}


/**
* Save some transaction details, like billing information.
*
* @param EE_Payment $payment
* @param EE_Transaction $transaction
* @param array $order
* @return void
* @throws EE_Error|ReflectionException
*/
public function saveBillingDetails(EE_Payment $payment, EE_Transaction $transaction, array $order): void
{
$input_values = [];
$primary_reg = $transaction->primary_registration();
$attendee = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;
$transaction = $payment->transaction();
$payment_method = $transaction->payment_method();
$postmeta_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) {
// I guess we are done here then. Just save what we have.
$payment->set_details($order);
return;
}
// Do we have order information from the express checkout (PayPal button) ?
if (! empty($order['payment_source']['paypal'])) {
$payer = $order['payment_source']['paypal'];
$payer_name = $payer['name'] ?? '';
$input_values['first_name'] = $payer_name['given_name'] ?? $attendee->fname();
$input_values['last_name'] = $payer_name['surname'] ?? $attendee->lname();
$input_values['email'] = $payer_name['email_address'] ?? $attendee->email();
$input_values['address'] = $payer_name['address_line_1'] ?? $attendee->address();
$input_values['address2'] = $payer_name['address_line_2'] ?? $attendee->address2();
$input_values['city'] = $payer_name['admin_area_2'] ?? $attendee->city();
$input_values['country'] = $payer_name['country_code'] ?? $attendee->country();
$input_values['zip'] = $payer_name['postal_code'] ?? $attendee->zip();
}
// Or card information from ACDC ?
if (! empty($order['payment_source']['card'])) {
$payer_card = $order['payment_source']['card'];
if (! empty($payer_card['name'])) {
$full_name = explode(' ', $payer_card['name']);
// Don't need to save each field because others should be populated from the billing form.
$input_values['credit_card'] = $payer_card['last_digits'] ?? '';
$input_values['first_name'] = $full_name[0] ?? $attendee->fname();
$input_values['last_name'] = $full_name[1] ?? $attendee->lname();
}
}
update_post_meta($attendee->ID(), $postmeta_name, $input_values);
$attendee->save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use EventEspresso\core\services\loaders\LoaderFactory;
use EventEspresso\core\services\request\DataType;
use EventEspresso\core\services\request\Request;
use EventEspresso\core\services\request\RequestInterface;
use EventEspresso\PaymentMethods\PayPalCommerce\PayPalCheckout\forms\BillingForm;
use EventEspresso\PaymentMethods\PayPalCommerce\PayPalCheckout\forms\SettingsForm;
Expand Down Expand Up @@ -58,7 +59,6 @@ public function generate_new_settings_form()
{
// Settings form.
$settings_form = new SettingsForm($this, $this->_pm_instance);

// Filter the form contents.
return apply_filters(
'FHEE__EE_PMT_PayPalCheckout__generate_new_settings_form__form_filtering',
Expand All @@ -78,10 +78,26 @@ public function generate_new_settings_form()
* @throws EE_Error
* @throws ReflectionException
*/
public function generate_new_billing_form(EE_Transaction $transaction = null, $extra_args = [])
public function generate_new_billing_form(EE_Transaction $transaction = null, ?array $extra_args = [])
{
$request = LoaderFactory::getShared(Request::class);
$request_params = $request->requestParams();
// Return the default billing form for the postbox if this is a WP admin transaction info page.
if (! empty($request_params['page']) && $request_params['page'] === 'espresso_transactions') {
$default_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance, $extra_args);
$default_form->add_subsections(['credit_card' => new EE_Credit_Card_Input()]);
return $default_form;
}
// Just in case this is used on other admin pages.
if (empty($transaction) && ! empty($request_params['TXN_ID'])) {
$txn_instance = EEM_Transaction::instance()->get_one_by_ID($request_params['TXN_ID']);
$transaction = $txn_instance instanceof EE_Transaction ? $txn_instance : null;
}
$options = array_merge(
['transaction' => $transaction, 'template_path' => $this->_template_path],
[
'transaction' => $transaction,
'template_path' => $this->_template_path,
],
$extra_args
);
return new BillingForm($this->_pm_instance, $options);
Expand All @@ -94,7 +110,7 @@ public function generate_new_billing_form(EE_Transaction $transaction = null, $e
* @return array
* @see EE_PMT_Base::help_tabs_config()
*/
public function help_tabs_config()
public function help_tabs_config(): array
{
return [
$this->get_help_tab_name() => [
Expand Down Expand Up @@ -130,7 +146,7 @@ public static function refundNotice(bool $can_edit_payments)
}
// Try loading the template.
EE_Registry::instance()->load_helper('Template');
} catch (EE_Error | ReflectionException $e) {
} catch (EE_Error|ReflectionException $e) {
// Just return, adding nothing.
return;
}
Expand Down
Loading

0 comments on commit dcc737b

Please sign in to comment.