Skip to content

Commit

Permalink
Lastest cafe changes 5.0.27.p
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebblo committed Sep 18, 2024
1 parent 8b94c8a commit 7c4e778
Show file tree
Hide file tree
Showing 233 changed files with 1,334 additions and 1,285 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Releases

### [5.0.27]

#### Added
- [Add Venmo funding option to PayPal Commerce (#1522)](https://github.com/eventespresso/cafe/pull/1522)

#### Fixed
- [Dont replace checkout type with PPC funding options in extra meta inputs (#1534)](https://github.com/eventespresso/cafe/pull/1534)
- [Add Billing Form Instance Check (#1537)](https://github.com/eventespresso/cafe/pull/1537)
- [Fix GraphQL requests when WP is installed in a subdirectory (#1531)](https://github.com/eventespresso/cafe/pull/1531)

#### Changed
- [Fix phpdoc tags (#1505)](https://github.com/eventespresso/cafe/pull/1505)
- [auto lint fixes (#1358)](https://github.com/eventespresso/cafe/pull/1358)


### [5.0.26]


#### Fixed
- Fixed PHP 7.4 Incompatible Code in InterfaceManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ public static function createPayment(EE_Transaction $transaction, EE_Payment_Met
*/
public static function updatePaymentStatus(
EE_Payment $payment,
string $status,
$response_data,
string $update_message = ''
string $status,
$response_data,
string $update_message = ''
): EE_Payment {
$paypal_pm = ! empty($payment->payment_method())
? EEM_Payment_Method::instance()->get_one_by_slug($payment->payment_method()->name())
Expand Down Expand Up @@ -195,10 +195,10 @@ public static function updatePaymentStatus(
* @throws ReflectionException
*/
public static function saveBillingDetails(
EE_Payment $payment,
EE_Payment $payment,
EE_Transaction $transaction,
array $order,
array $billing_info
array $order,
array $billing_info
): void {
$primary_reg = $transaction->primary_registration();
$attendee = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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 Expand Up @@ -174,12 +174,12 @@ public static function refundNotice(bool $can_edit_payments)
*/
public function process_payment(
EE_Transaction $transaction,
$amount = null,
$billing_info = null,
$return_url = null,
$fail_url = '',
$method = 'CART',
$by_admin = false
$amount = null,
$billing_info = null,
$return_url = null,
$fail_url = '',
$method = 'CART',
$by_admin = false
): EE_Payment {
// This payment should have been processed in the background, while the Order was created and charged.
// So simply return the last payment. Unless it's somehow missing.
Expand Down
56 changes: 45 additions & 11 deletions PaymentMethods/PayPalCommerce/PayPalCheckout/forms/BillingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
*/
class BillingForm extends EE_Billing_Attendee_Info_Form
{

protected EE_Payment_Method $paypal_pmt;

protected ?EE_Transaction $transaction = null;
Expand Down Expand Up @@ -216,7 +215,8 @@ public static function excludeBillingFormFields(
}
// Make sure the billing form subsections have correct names.
$inputs = $billing_form->inputs_in_subsections();
if (! empty($request_params['process_form_submission'])
if (
! empty($request_params['process_form_submission'])
&& $request_params['process_form_submission'] === '1'
&& ! empty($request_params['eep_ppc_skip_form_validation'])
) {
Expand Down Expand Up @@ -460,22 +460,56 @@ public function addDataTagsToScript($tag, $handle): string
*/
public function enqueue_js(): void
{
$third_party = EED_PayPalCommerce::isThirdParty($this->_pm_instance);
$currency = CurrencyManager::currencyCode();
// Setup default values
$client_id_key = Domain::META_KEY_CLIENT_ID;
// Scripts.
$scripts_src = 'https://www.paypal.com/sdk/js?components=buttons,hosted-fields&intent=capture';
if ($third_party) {
$merchant_id = false;
$funding_options = ['venmo', 'paylater'];

// Override the above if thrid party integration
if (EED_PayPalCommerce::isThirdParty($this->_pm_instance)) {
$client_id_key = Domain::META_KEY_PARTNER_CLIENT_ID;
$merchant_id = PayPalExtraMetaManager::getPmOption(
$this->_pm_instance,
Domain::META_KEY_SELLER_MERCHANT_ID
);
$scripts_src .= "&merchant-id=$merchant_id";
}
$client_id = PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key);
$scripts_src .= "&client-id=$client_id&currency=$currency";
wp_enqueue_script('eea_paypal_commerce_js_lib', $scripts_src, [], null);

// Setup query args
$url_params = [
'client-id' => PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key),
'currency' => CurrencyManager::currencyCode(),
'components' => implode(',', ['buttons','hosted-fields']),
'intent' => 'capture',
'merchant-id' => $merchant_id,
];

// Which funding methods are active?
$enabled_funding = $this->_pm_instance->get_extra_meta(Domain::META_KEY_FUNDING_OPTIONS, true, $funding_options);

// Any funding method not enabled should be disabled.
$disabled_funding = array_diff(
$funding_options,
$enabled_funding
);

// Any funding options enabled?
if (count($enabled_funding) > 0) {
$url_params['enable-funding'] = implode(',', $enabled_funding);
}

// Any funding options disabled?
if (count($disabled_funding) > 0) {
$url_params['disable-funding'] = implode(',', $disabled_funding);
}

// Enqueue the PayPal JS
wp_enqueue_script(
'eea_paypal_commerce_js_lib',
add_query_arg($url_params, 'https://www.paypal.com/sdk/js'),
[],
null
);

wp_enqueue_script(
'eea_paypal_commerce_js',
EEP_PAYPAL_COMMERCE_URL . 'assets/js/paypal-commerce-payments.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public function paymentOptionsHtml(): string
'',
'',
'',
'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug .'-express_checkout"'
'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug . '-express_checkout"'
);
$ppcp_lbl = EEH_HTML::label(
esc_html__('Accept credit and debit card payments with PayPal ', 'event_espresso')
Expand All @@ -368,7 +368,7 @@ public function paymentOptionsHtml(): string
'',
'',
'',
'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug .'-ppcp"'
'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug . '-ppcp"'
);
$checkbox = new EE_Checkbox_Multi_Input(
[
Expand Down
66 changes: 47 additions & 19 deletions PaymentMethods/PayPalCommerce/PayPalCheckout/forms/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use EE_Error;
use EE_Form_Section_HTML;
use EE_Select_Input;
use EE_Checkbox_Multi_Input;
use EED_PayPalOnboard;
use EEH_HTML;
use EventEspresso\PaymentMethods\PayPalCommerce\domain\Domain;
Expand Down Expand Up @@ -57,6 +58,7 @@ public function __construct(EE_PMT_PayPalCheckout $payment_method, EE_Payment_Me
$is_onboard = EED_PayPalOnboard::isOnboard($pm_instance);
if ($is_onboard && ($allowed_type === 'ppcp' || $allowed_type === 'all')) {
$form_parameters = $this->addCheckoutTypeSelect($form_parameters);
$form_parameters = $this->addFundingOptions($form_parameters);
}
// Build the PM form.
parent::__construct($form_parameters);
Expand Down Expand Up @@ -159,27 +161,53 @@ public function addFeesNotice(): void
public function addCheckoutTypeSelect(array $form_parameters): array
{
$pm_slug = $this->pm_instance->slug();
$allowed_checkout_type = PayPalExtraMetaManager::getPmOption(
$this->pm_instance,
Domain::META_KEY_ALLOWED_CHECKOUT_TYPE
// Section to be displayed if onboard.
$form_parameters['extra_meta_inputs'][Domain::META_KEY_CHECKOUT_TYPE] = new EE_Select_Input(
[
'express_checkout' => esc_html__('Express Checkout', 'event_espresso'),
'ppcp' => esc_html__('Advanced Credit and Debit Card payments', 'event_espresso'),
'all' => esc_html__('Both, ACDC and Express Checkout', 'event_espresso'),
],
[
'html_name' => "eep_checkout_type_option_$pm_slug",
'html_id' => "eep_checkout_type_option_$pm_slug",
'html_class' => "eep-checkout-type-option-$pm_slug",
'required' => true,
'default' => PayPalExtraMetaManager::getPmOption(
$this->pm_instance,
Domain::META_KEY_ALLOWED_CHECKOUT_TYPE
),
]
);
return $form_parameters;
}


/**
* Add a checkout type select.
*
* @param array $form_parameters
* @return array
* @throws EE_Error
* @throws ReflectionException
*/
public function addFundingOptions(array $form_parameters): array
{
$pm_slug = $this->pm_instance->slug();
// Section to be displayed if onboard.
$form_parameters['extra_meta_inputs'] = [
Domain::META_KEY_CHECKOUT_TYPE => new EE_Select_Input(
[
'express_checkout' => esc_html__('Express Checkout', 'event_espresso'),
'ppcp' => esc_html__('Advanced Credit and Debit Card payments', 'event_espresso'),
'all' => esc_html__('Both, ACDC and Express Checkout', 'event_espresso'),
],
[
'html_name' => 'eep_checkout_type_option_' . $pm_slug,
'html_id' => 'eep_checkout_type_option_' . $pm_slug,
'html_class' => 'eep-checkout-type-option-' . $pm_slug,
'required' => true,
'default' => $allowed_checkout_type,
]
),
];
$form_parameters['extra_meta_inputs'][Domain::META_KEY_FUNDING_OPTIONS] = new EE_Checkbox_Multi_Input(
[
'venmo' => esc_html__('Venmo', 'event_espresso'),
'paylater' => esc_html__('PayLater', 'event_espresso'),
],
[
'html_name' => "eep_checkout_funding_options_$pm_slug",
'html_id' => "eep_checkout_funding_options_$pm_slug",
'html_class' => "eep-checkout-funding-options-$pm_slug",
'html_label_text' => esc_html__('Enable PayPal funding options:', 'event_espresso'),
'default' => ['venmo', 'paylater'],
]
);
return $form_parameters;
}

Expand Down
3 changes: 2 additions & 1 deletion PaymentMethods/PayPalCommerce/api/orders/CaptureOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public function validateOrder($response): array
return $response;
}
// This also could be a retry capture, so consider this valid, if order already captured.
if (! empty($response['message']['details']['issue'])
if (
! empty($response['message']['details']['issue'])
&& $response['message']['details']['issue'] === 'ORDER_ALREADY_CAPTURED'
) {
// Need to make sure we pass on the order ID.
Expand Down
5 changes: 5 additions & 0 deletions PaymentMethods/PayPalCommerce/domain/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class Domain
*/
public const META_KEY_CHECKOUT_TYPE = 'checkout_type';

/**
* Name of the extra meta that stores the selected PP function options.
*/
public const META_KEY_FUNDING_OPTIONS = 'funding_options';

/**
* Name of the PayPal API parameter that holds the auth code.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ public static function createOrder(
public static function captureOrder(
EE_Transaction $transaction,
EE_Payment_Method $paypal_pm,
string $order_id,
array $billing_info
string $order_id,
array $billing_info
): array {
$capture_order_api = EED_PayPalCommerce::getCaptureOrderApi($transaction, $paypal_pm, $order_id);
if (! $capture_order_api instanceof CaptureOrder) {
Expand Down Expand Up @@ -349,7 +349,11 @@ public static function getPayPalApi(EE_Payment_Method $paypal_pm): ?PayPalApi
$partner_client_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PARTNER_CLIENT_ID) ?: '';
$payer_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_SELLER_MERCHANT_ID) ?: '';
return new ThirdPartyPayPalApi(
$access_token, $bn_code, $partner_client_id, $payer_id, $paypal_pm->debug_mode()
$access_token,
$bn_code,
$partner_client_id,
$payer_id,
$paypal_pm->debug_mode()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use EventEspresso\PaymentMethods\PayPalCommerce\tools\currency\CurrencyManager;
use Exception;


/**
* Class PartnerPaymentFees
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function errorLog(
if ($popup_log) {
PayPalLogger::logInWindow(json_encode($data));
}
} catch (ReflectionException|EE_Error $error) {
} catch (ReflectionException | EE_Error $error) {
new ExceptionLogger($error);
return false;
}
Expand Down
1 change: 1 addition & 0 deletions admin_pages/about/templates/whats_new.template.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

// comment out the following two lines if version is a major release
use EventEspresso\core\domain\services\database\MaintenanceStatus;

Expand Down
Loading

0 comments on commit 7c4e778

Please sign in to comment.