Skip to content

Commit

Permalink
Lastest cafe changes 5.0.18.p
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebblo committed Mar 12, 2024
1 parent 16aff5e commit c5f04b2
Show file tree
Hide file tree
Showing 126 changed files with 2,182 additions and 1,969 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Releases

### [5.0.18]

#### Added
- [PPC. Add not onboard validation and notice (#1130)](https://github.com/eventespresso/cafe/pull/1130)

#### Fixed
- [PPC. Fix payment inconsistencies (#1113)](https://github.com/eventespresso/cafe/pull/1113)
- [Fix Batch Message Modal Shortcodes (#1129)](https://github.com/eventespresso/cafe/pull/1129)
- [Refactor RequestTypeContextDetector to Handle Permalink Prefix (#1037)](https://github.com/eventespresso/cafe/pull/1037)
- [Fix Non-Code Promotions (#1112)](https://github.com/eventespresso/cafe/pull/1112)
- [PPC. Dont accept failed transactions as successful (#1142)](https://github.com/eventespresso/cafe/pull/1142)

#### Changed
- [BuildMachine 5.0.17 Changes. (#1103)](https://github.com/eventespresso/cafe/pull/1103)
- [Dont Block Restore Registration Action if Payments Exist (#1110)](https://github.com/eventespresso/cafe/pull/1110)
- [Refactor Feature Flags and Add New Flags (#1116)](https://github.com/eventespresso/cafe/pull/1116)
- [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)


### [5.0.17]

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

// Remove the saved order data.
Expand Down Expand Up @@ -134,24 +139,32 @@ public function validateThisPayment(?EE_Payment $payment, RequestInterface $requ
*
* @param string $provided_order_id
* @param $order
* @return string string if error and empty if valid.
* @return array [valid => {boolean}, message => {string}]
*/
public function orderInvalid(string $provided_order_id, $order): string
public function isOrderValid(string $provided_order_id, $order): array
{
// Check the provided order ID.
$conclusion = [
'valid' => false,
'message' => esc_html__('Could not validate this Order.', 'event_espresso'),
];
// Check the provided Order and order ID.
if (! $provided_order_id) {
return esc_html__('Invalid Order ID provided !', 'event_espresso');
$conclusion['message'] = esc_html__('Invalid Order ID provided !', 'event_espresso');
} elseif (! $order || ! is_array($order)) {
$conclusion['message'] = esc_html__('Order data 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');
} else {
// If we didn't fail on the above, the Order should be considered valid.
$conclusion['valid'] = true;
}
if (! $order || ! is_array($order)) {
return esc_html__('Order data in wrong format.', 'event_espresso');
}
if ($order['id'] !== $provided_order_id) {
return esc_html__('Order ID mismatch.', 'event_espresso');
}
if ($order['status'] !== 'COMPLETED') {
return esc_html__('Order not completed.', 'event_espresso');
}
return '';
return $conclusion;
}


Expand All @@ -172,8 +185,16 @@ public function setPaymentFailure(
string $err_message = ''
): EE_Payment {
$this->log(['Error request data:' => $response_data], $payment);
$err_message = $err_message ?: sprintf(
esc_html__(
'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.',
'event_espresso'
),
'<br/>',
EE_Registry::instance()->CFG->organization->get_pretty('email')
);
$payment->set_status($status);
$payment->set_details('error');
$payment->set_details($err_message);
$payment->set_gateway_response($err_message);
return $payment;
}
Expand All @@ -191,11 +212,13 @@ public function setPaymentFailure(
public function setPaymentSuccess(EE_Payment $payment, EE_Transaction $transaction, array $order): EE_Payment
{
$amount = $order['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0;
// Don't set the amount if there is no info on that with this order.
if (! $amount) {
$this->log(['Success order but amount is 0 !' => $order], $payment);
} else {
$payment->set_amount((float) $amount);
}
$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'] ?? $order['id']);
$payment->set_gateway_response($order['status'] ?? 'success');
$this->saveBillingDetails($payment, $transaction, $order);
Expand Down
21 changes: 12 additions & 9 deletions PaymentMethods/PayPalCommerce/PayPalCheckout/forms/BillingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,25 +492,25 @@ public function enqueue_js(): void


/**
* Get PayPal order ID if already created for this transaction.
* Get PayPal order if already created for this transaction and saved.
*
* @param string $transaction_id
* @return string
* @return array
*/
public function getPpOrderId(string $transaction_id): string
public function getPpOrder(string $transaction_id): array
{
try {
$pp_order = PayPalExtraMetaManager::getPmOption($this->paypal_pmt, Domain::META_KEY_LAST_ORDER);
$pp_order_txn_id = $pp_order['ee_txn_id'] ?? false;
if ($pp_order_txn_id != $transaction_id) {
if ($pp_order_txn_id !== $transaction_id) {
// Old order data, delete it.
PayPalExtraMetaManager::deletePmOption($this->paypal_pmt, Domain::META_KEY_LAST_ORDER);
return '';
return [];
}
} catch (Exception $exception) {
return '';
return [];
}
return $pp_order['id'] ?? '';
return (array) $pp_order;
}


Expand All @@ -535,7 +535,6 @@ public function localizeParameters(): array
'pm_slug' => $payment_method->slug(),
];
}

// Convert money for a display format.
$decimal_places = CurrencyManager::getDecimalPlaces();
$org_country = isset(EE_Registry::instance()->CFG->organization)
Expand All @@ -544,12 +543,16 @@ public function localizeParameters(): array
: 'US';
$transaction_id = $this->transaction instanceof EE_Transaction ? $this->transaction->ID() : 0;
$currency_code = CurrencyManager::currencyCode();
$paypal_order = empty($transaction_id) ? [] : $this->getPpOrder($transaction_id);
$order_amount = $paypal_order['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? '';
return [
'pm_versions' => $pm_versions,
'payment_currency' => $currency_code,
'checkout_type' => $this->checkout_type,
'currency_sign' => EE_Registry::instance()->CFG->currency->sign,
'pp_order_id' => $this->getPpOrderId($transaction_id),
'pp_order_id' => $paypal_order['id'] ?? '',
'pp_order_status' => $paypal_order['status'] ?? 'ORDER_STATUS_UNKNOWN',
'pp_order_amount' => $order_amount,
'pp_order_nonce' => wp_create_nonce(Domain::CAPTURE_ORDER_NONCE_NAME),
// The transaction ID is only used for logging errors.
'txn_id' => $transaction_id,
Expand Down
2 changes: 1 addition & 1 deletion PaymentMethods/PayPalCommerce/api/FirstPartyPayPalApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(string $client_id, string $client_secret, string $bn
public function sendRequest(array $body_parameters, string $endpoint, string $method = 'POST', array $headers = [])
{
$request_parameters = $this->getRequestParameters($body_parameters, $method, $headers);
return $this->response($endpoint, $request_parameters);
return $this->request($endpoint, $request_parameters);
}


Expand Down
2 changes: 1 addition & 1 deletion PaymentMethods/PayPalCommerce/api/PayPalApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(bool $sandbox_mode = true) {
* @param array $request_parameters
* @return Object|array
*/
public function response(string $endpoint, array $request_parameters)
public function request(string $endpoint, array $request_parameters)
{
// Sent the API request.
$response = wp_remote_request($endpoint, $request_parameters);
Expand Down
2 changes: 1 addition & 1 deletion PaymentMethods/PayPalCommerce/api/ThirdPartyPayPalApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
public function sendRequest(array $body_parameters, string $endpoint, string $method = 'POST', array $headers = [])
{
$request_parameters = $this->getRequestParameters($body_parameters, $method, $headers);
return $this->response($endpoint, $request_parameters);
return $this->request($endpoint, $request_parameters);
}


Expand Down
18 changes: 18 additions & 0 deletions PaymentMethods/PayPalCommerce/api/orders/CaptureOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function __construct(PayPalApi $api, EE_Transaction $transaction, string
{
parent::__construct($api);
$this->transaction = $transaction;
$this->order_id = $order_id;
$this->currency_code = CurrencyManager::currencyCode();
$this->request_url = $this->request_url . $order_id . '/capture';
}
Expand All @@ -69,12 +70,29 @@ public function capture(): array
*
* @param $response
* @return array
* @throws EE_Error
* @throws ReflectionException
*/
public function validateOrder($response): array
{
$message = esc_html__('Validating Order Capture:', 'event_espresso');
PayPalLogger::errorLog($message, [$this->request_url, $response], $this->transaction->payment_method());
// We got a direct error response. Not valid. Return that error.
if (! empty($response['error'])) {
return $response;
}
// This also could be a retry capture, so consider this valid, if order already captured.
if (! empty($response['message']['details']['issue'])
&& $response['message']['details']['issue'] === 'ORDER_ALREADY_CAPTURED'
) {
// Need to make sure we pass on the order ID.
if (empty($response['id'])) {
$response['id'] = $this->order_id;
}
$response['status'] = 'ORDER_ALREADY_CAPTURED';
return $response;
}
// A success capture should return the order ID.
if (! isset($response['id'])) {
$message = esc_html__('Unexpected response. No order returned.', 'event_espresso');
try {
Expand Down
4 changes: 4 additions & 0 deletions PaymentMethods/PayPalCommerce/api/orders/CreateOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,13 @@ protected function getBreakdown(): array
* @param $response
* @param $parameters
* @return array
* @throws EE_Error
* @throws ReflectionException
*/
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());
if (! empty($response['error'])) {
return $response;
}
Expand Down
5 changes: 5 additions & 0 deletions PaymentMethods/PayPalCommerce/api/orders/OrdersApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ abstract class OrdersApi
*/
protected string $request_url;

/**
* @var string
*/
protected string $order_id;


/**
* Orders API constructor.
Expand Down

0 comments on commit c5f04b2

Please sign in to comment.