Skip to content

Commit b54b4f5

Browse files
committed
Lastest cafe changes 5.0.28.p
1 parent 24c3ebb commit b54b4f5

File tree

102 files changed

+3060
-1338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+3060
-1338
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Releases
88

9+
### [5.0.28]
10+
11+
#### Added
12+
- [New Ticket Selector Checkbox and Form Styles (#1527)](https://github.com/eventespresso/cafe/pull/1527)
13+
- [Add Payment Method Deprecation Notices (#1564)](https://github.com/eventespresso/cafe/pull/1564)
14+
- [Bypass Payment Processing if Too Many Payment Attempts (#1577)](https://github.com/eventespresso/cafe/pull/1577)
15+
16+
#### Fixed
17+
- [PPC. Fix success payment set as pending (#1538)](https://github.com/eventespresso/cafe/pull/1538)
18+
- [Ensure EE_AUTOSAVE_IDS is Defined (#1471)](https://github.com/eventespresso/cafe/pull/1471)
19+
- [PPC. Fix an issue with a missing checkout type meta (#1548)](https://github.com/eventespresso/cafe/pull/1548)
20+
- [Fix meta caps for Registration Form caps (#1546)](https://github.com/eventespresso/cafe/pull/1546)
21+
- [Fix CSS Output in iFrames (#1552)](https://github.com/eventespresso/cafe/pull/1552)
22+
- [Fix venue not being unassigned in EDTR (GraphQL) (#1561)](https://github.com/eventespresso/cafe/pull/1561)
23+
- [Fix Missing Check-ins Bulk Actions (#1549)](https://github.com/eventespresso/cafe/pull/1549)
24+
- [Fix Typing for EE_Datetime_Field::_prepare_for_display() (#1570)](https://github.com/eventespresso/cafe/pull/1570)
25+
- [Fix List Table Views (#1576)](https://github.com/eventespresso/cafe/pull/1576)
26+
- [Fix MER Max Ticket Quantity Violations (#1567)](https://github.com/eventespresso/cafe/pull/1567)
27+
28+
#### Changed
29+
- [ Loosen Upcoming Events Widget Permissions (#1554)](https://github.com/eventespresso/cafe/pull/1554)
30+
- [When copying datetime include venue id (Barista#1338) (#1568)](https://github.com/eventespresso/cafe/pull/1568)
31+
- [Ensure WordPress Options Are Saved (#1574)](https://github.com/eventespresso/cafe/pull/1574)
32+
33+
934
### [5.0.27]
1035

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

3459
### [5.0.25]
3560

61+
3662
#### Changed
3763
- [BuildMachine changes - 5.0.24.p (#1486)](https://github.com/eventespresso/cafe/pull/1486)
3864
- [Fix and Split Up PHP Unit Tests (#1354)](https://github.com/eventespresso/cafe/pull/1354)

PaymentMethods/Manager.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public function registerPaymentMethod(
120120
*/
121121
public static function hidePaymentMethods(array $pms_to_list): array
122122
{
123-
foreach (self::$pms_can_hide as $pm_name => $pm_option) {
123+
$pms_can_hide = apply_filters(
124+
'FHEE__EventEspresso_PaymentMethods_Manager__hidePaymentMethods__pms_can_hide',
125+
self::$pms_can_hide
126+
);
127+
foreach ($pms_can_hide as $pm_name => $pm_option) {
124128
// Can we deregister this PM ?
125129
if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) {
126130
unset($pms_to_list[ $pm_name ]);
@@ -204,16 +208,20 @@ public static function adminNotice()
204208
*/
205209
public static function usePayPalCommerceNotice()
206210
{
207-
echo '<div class="error"><p>'
208-
. sprintf(
209-
esc_html__(
210-
'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.',
211-
'event_espresso'
212-
),
213-
'<strong>',
214-
'</strong>'
215-
)
216-
. '</p></div>';
211+
echo '
212+
<div class="notice ee-status-outline ee-status-outline--ok ee-status-bg--ok">
213+
<p class="big-text">
214+
<span class="dashicons dashicons-info"></span> &nbsp; '
215+
. sprintf(
216+
esc_html__(
217+
'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.',
218+
'event_espresso'
219+
),
220+
'<strong>',
221+
'</strong>'
222+
) . '
223+
</p>
224+
</div>';
217225
}
218226

219227

PaymentMethods/PayPalCommerce/PayPalCheckout/EEG_PayPalCheckout.gateway.php

Lines changed: 110 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
use EventEspresso\PaymentMethods\PayPalCommerce\domain\Domain;
4-
use EventEspresso\PaymentMethods\PayPalCommerce\tools\extra_meta\PayPalExtraMetaManager;
3+
use EventEspresso\core\services\loaders\LoaderFactory;
4+
use EventEspresso\core\services\request\RequestInterface;
55
use EventEspresso\PaymentMethods\PayPalCommerce\tools\logging\PayPalLogger;
66

77
/**
@@ -53,56 +53,99 @@ class EEG_PayPalCheckout extends EE_Onsite_Gateway
5353
* @param EE_Payment|null $payment
5454
* @param array|null $billing_info
5555
* @return EE_Payment
56+
* @throws EE_Error|ReflectionException
5657
*/
5758
public function do_direct_payment($payment, $billing_info = null)
5859
{
59-
// Normally we shouldn't be getting here because the payment should have been processed
60-
// along with the PP Order Charge.
61-
return $payment;
60+
$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
61+
$post_parameters = $request->postParams();
62+
// Check the payment.
63+
$payment = $this->validatePayment($payment, $request);
64+
if ($payment->details() === 'error' && $payment->status() === EEM_Payment::status_id_failed) {
65+
return $payment;
66+
}
67+
$transaction = $payment->transaction();
68+
$payment_method = $transaction->payment_method();
69+
// Get the order details.
70+
$order_id = $request->getRequestParam('pp_order_id');
71+
if (! $order_id) {
72+
return EEG_PayPalCheckout::updatePaymentStatus(
73+
$payment,
74+
EEM_Payment::status_id_failed,
75+
$post_parameters,
76+
esc_html__('Can\'t charge the Order. The Order ID is missing.', 'event_espresso')
77+
);
78+
}
79+
// Capture the order.
80+
$capture_status = EED_PayPalCommerce::captureOrder($transaction, $payment_method, $order_id);
81+
// Check the order status.
82+
$order_status = $this->isOrderCompleted($order_id, $transaction, $payment_method);
83+
if (! $order_status['completed']) {
84+
return EEG_PayPalCheckout::updatePaymentStatus(
85+
$payment,
86+
EEM_Payment::status_id_failed,
87+
$order_status,
88+
$order_status['message'] ?? ''
89+
);
90+
}
91+
// Looks like all is good. Mark payment as a success.
92+
$this->saveBillingDetails($payment, $transaction, $order_status['details'], $billing_info);
93+
return EEG_PayPalCheckout::updatePaymentStatus($payment, EEM_Payment::status_id_approved, $capture_status);
6294
}
6395

6496

6597
/**
6698
* Validate the Order.
6799
*
68-
* @param $order
69-
* @param null $provided_order_id
100+
* @param string $order_id
101+
* @param EE_Transaction $transaction
102+
* @param EE_Payment_Method $payment_method
70103
* @return array ['completed' => {boolean}, 'message' => {string}]
104+
* @throws EE_Error
105+
* @throws ReflectionException
71106
*/
72-
public static function isOrderCompleted($order, $provided_order_id = null): array
107+
public static function isOrderCompleted(
108+
string $order_id,
109+
EE_Transaction $transaction,
110+
EE_Payment_Method $payment_method
111+
): array
73112
{
113+
$order_details = EED_PayPalCommerce::getOrderDetails($order_id, $transaction, $payment_method);
74114
$conclusion = [
75115
'completed' => false,
76-
'message' => esc_html__('Could not validate this Order.', 'event_espresso'),
116+
'details' => $order_details,
77117
];
78-
if (! empty($order) && ! empty($provided_order_id) && $order['id'] !== $provided_order_id) {
79-
$conclusion['message'] = esc_html__('Order ID mismatch.', 'event_espresso');
80-
}
81-
if (! $order || ! is_array($order)) {
82-
$conclusion['message'] = esc_html__('The Order data is incorrectly formatted.', 'event_espresso');
83-
} elseif (empty($order['status'])) {
118+
if (! $order_details) {
119+
$conclusion['message'] = esc_html__(
120+
'Could not validate this payment. The Order details were empty.',
121+
'event_espresso'
122+
);
123+
} elseif (! empty($order_details['error'])) {
124+
$conclusion['message'] = $order_details['message'] ?? $order_details['error'];
125+
} elseif (empty($order_details['status'])) {
84126
$conclusion['message'] = esc_html__(
85127
'There was an error with this payment. The status of the Order could not be determined.',
86128
'event_espresso'
87129
);
88-
} elseif ($order['status'] !== 'COMPLETED') {
130+
} elseif ($order_details['status'] !== 'COMPLETED') {
89131
$conclusion['message'] = esc_html__(
90132
'There was an error with this payment. Order was not approved.',
91133
'event_espresso'
92134
);
93-
} elseif (empty($order['purchase_units'][0]['payments']['captures'][0]['status'])) {
135+
} elseif (empty($order_details['purchase_units'][0]['payments']['captures'][0]['status'])) {
94136
$conclusion['message'] = esc_html__(
95137
'There was an error with this payment. The status of the Payment could not be determined.',
96138
'event_espresso'
97139
);
98-
} elseif ($order['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') {
140+
} elseif ($order_details['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') {
99141
$conclusion['message'] = esc_html__(
100142
'This payment was declined or failed validation. Please check the billing information you provided.',
101143
'event_espresso'
102144
);
103145
} else {
104146
// If we didn't fail on the above, the Order should be considered valid.
105147
$conclusion['completed'] = true;
148+
$conclusion['message'] = esc_html__('Order Valid.', 'event_espresso');
106149
}
107150
return $conclusion;
108151
}
@@ -161,7 +204,7 @@ public static function updatePaymentStatus(
161204
$payment->set_amount((float) $amount);
162205
}
163206
$payment->set_txn_id_chq_nmbr(
164-
$order['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id']
207+
$response_data['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id']
165208
);
166209
} else {
167210
$default_message = sprintf(
@@ -183,6 +226,47 @@ public static function updatePaymentStatus(
183226
}
184227

185228

229+
/**
230+
* Validate the payment.
231+
*
232+
* @param EE_Payment|null $payment
233+
* @param RequestInterface $request
234+
* @return EE_Payment
235+
* @throws EE_Error
236+
* @throws ReflectionException
237+
*/
238+
public function validatePayment(?EE_Payment $payment, RequestInterface $request): EE_Payment
239+
{
240+
$failed_status = $this->_pay_model->failed_status();
241+
// Check the payment.
242+
if (! $payment instanceof EE_Payment) {
243+
$payment = EE_Payment::new_instance();
244+
$error_message = esc_html__('Error. No associated payment was found.', 'event_espresso');
245+
return EEG_PayPalCheckout::updatePaymentStatus(
246+
$payment,
247+
$failed_status,
248+
$request->postParams(),
249+
$error_message
250+
);
251+
}
252+
// Check the transaction.
253+
$transaction = $payment->transaction();
254+
if (! $transaction instanceof EE_Transaction) {
255+
$error_message = esc_html__(
256+
'Could not process this payment because it has no associated transaction.',
257+
'event_espresso'
258+
);
259+
return EEG_PayPalCheckout::updatePaymentStatus(
260+
$payment,
261+
$failed_status,
262+
$request->postParams(),
263+
$error_message
264+
);
265+
}
266+
return $payment;
267+
}
268+
269+
186270
/**
187271
* Save some transaction details, like billing information.
188272
*
@@ -203,7 +287,7 @@ public static function saveBillingDetails(
203287
$primary_reg = $transaction->primary_registration();
204288
$attendee = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;
205289
$payment_method = $transaction->payment_method();
206-
$postmeta_name = $payment_method->type_obj() instanceof EE_PMT_Base
290+
$post_meta_name = $payment_method->type_obj() instanceof EE_PMT_Base
207291
? 'billing_info_' . $payment_method->type_obj()->system_name()
208292
: '';
209293
if (empty($order['payment_source']) || ! $attendee instanceof EE_Attendee) {
@@ -218,8 +302,8 @@ public static function saveBillingDetails(
218302
if (! empty($billing_info['address'])) {
219303
$attendee->set_address($billing_info['address']);
220304
}
221-
if (! empty($billing_info['address_2'])) {
222-
$attendee->set_address2($billing_info['address_2']);
305+
if (! empty($billing_info['address2'])) {
306+
$attendee->set_address2($billing_info['address2']);
223307
}
224308
if (! empty($billing_info['city'])) {
225309
$attendee->set_city($billing_info['city']);
@@ -233,7 +317,8 @@ public static function saveBillingDetails(
233317
if (! empty($billing_info['zip'])) {
234318
$attendee->set_zip($billing_info['zip']);
235319
}
236-
// Or card information from ACDC ?
320+
// Or card information from advanced card fields ?
321+
$billing_info['credit_card'] = '';
237322
if (! empty($order['payment_source']['card'])) {
238323
$payer_card = $order['payment_source']['card'];
239324
if (! empty($payer_card['name'])) {
@@ -244,7 +329,8 @@ public static function saveBillingDetails(
244329
$billing_info['last_name'] = $full_name[1] ?? $attendee->lname();
245330
}
246331
}
247-
update_post_meta($attendee->ID(), $postmeta_name, $billing_info);
332+
// Update attendee billing info in the transaction details.
333+
update_post_meta($attendee->ID(), $post_meta_name, $billing_info);
248334
$attendee->save();
249335
}
250336
}

PaymentMethods/PayPalCommerce/PayPalCheckout/EE_PMT_PayPalCheckout.pm.php

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -156,46 +156,4 @@ public static function refundNotice(bool $can_edit_payments)
156156
);
157157
echo $html;
158158
}
159-
160-
161-
/**
162-
* Override the parent.
163-
*
164-
* @param EE_Transaction $transaction
165-
* @param float|null $amount
166-
* @param EE_Billing_Info_Form|null $billing_info
167-
* @param string|null $return_url
168-
* @param string $fail_url
169-
* @param string $method
170-
* @param bool $by_admin
171-
* @return EE_Payment
172-
* @throws EE_Error
173-
* @throws ReflectionException
174-
*/
175-
public function process_payment(
176-
EE_Transaction $transaction,
177-
$amount = null,
178-
$billing_info = null,
179-
$return_url = null,
180-
$fail_url = '',
181-
$method = 'CART',
182-
$by_admin = false
183-
): EE_Payment {
184-
// This payment should have been processed in the background, while the Order was created and charged.
185-
// So simply return the last payment. Unless it's somehow missing.
186-
$payment = $transaction->last_payment();
187-
if (empty($payment) || $payment->status() === EEM_Payment::status_id_failed) {
188-
// Then we try processing the payment as usual.
189-
return parent::process_payment(
190-
$transaction,
191-
$amount,
192-
$billing_info,
193-
$return_url,
194-
$fail_url,
195-
$method,
196-
$by_admin
197-
);
198-
}
199-
return $transaction->last_payment();
200-
}
201159
}

PaymentMethods/PayPalCommerce/PayPalCheckout/forms/BillingForm.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use EE_Text_Input;
1818
use EE_Transaction;
1919
use EED_PayPalCommerce;
20-
use EEG_PayPalCheckout;
2120
use EEH_HTML;
2221
use EEM_Payment_Method;
2322
use EventEspresso\core\services\loaders\LoaderFactory;
@@ -66,7 +65,11 @@ public function __construct(EE_Payment_Method $payment_method, array $options)
6665
// Can't be too careful.
6766
$this->transaction = $options['transaction'] ?? null;
6867
$this->template_path = $options['template_path'] ?? '';
69-
$this->checkout_type = $payment_method->get_extra_meta(Domain::META_KEY_CHECKOUT_TYPE, true, '');
68+
$this->checkout_type = $payment_method->get_extra_meta(
69+
Domain::META_KEY_CHECKOUT_TYPE,
70+
true,
71+
'express_checkout'
72+
);
7073
$pm_slug = $payment_method->slug();
7174
$parameters = array_replace_recursive(
7275
$options,
@@ -103,13 +106,6 @@ public function __construct(EE_Payment_Method $payment_method, array $options)
103106
'default' => '',
104107
]
105108
),
106-
'pp_order_amount' => new EE_Hidden_Input(
107-
[
108-
'html_id' => 'eea-' . $pm_slug . '-order-amount',
109-
'html_name' => 'pp_order_amount',
110-
'default' => '',
111-
]
112-
),
113109
],
114110
]
115111
);
@@ -141,7 +137,7 @@ public function addPaymentSections(): void
141137
]
142138
);
143139
// Add PayPal Hosted Fields.
144-
if ($this->checkout_type !== 'express_checkout') {
140+
if (! empty($this->checkout_type) && $this->checkout_type !== 'express_checkout') {
145141
$this->addAdvancedCardFields();
146142
}
147143
// Add payment types separator, if both are enabled.

0 commit comments

Comments
 (0)