Skip to content

Commit

Permalink
Merge branch 'release' into PFW-1651
Browse files Browse the repository at this point in the history
# Conflicts:
#	i18n/languages/paypal-for-woocommerce-de_DE_formal.po
#	i18n/languages/paypal-for-woocommerce-fr_FR.mo
#	i18n/languages/paypal-for-woocommerce-fr_FR.po
#	i18n/languages/paypal-for-woocommerce-it_IT.po
#	i18n/languages/paypal-for-woocommerce.pot
  • Loading branch information
deepakmaurya committed Nov 8, 2023
2 parents a95ebc8 + 2c1f727 commit c5136fb
Show file tree
Hide file tree
Showing 77 changed files with 24,982 additions and 18,845 deletions.
264 changes: 110 additions & 154 deletions angelleye-includes/angelleye-admin-order-payment-process.php

Large diffs are not rendered by default.

29 changes: 26 additions & 3 deletions angelleye-includes/angelleye-functions.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
/**
* Functions used by plugins
*/

/**
* Queue updates for the Angell EYE Updater
*/
Expand Down Expand Up @@ -80,12 +81,34 @@ function angell_updater_notice() {
}
echo '<div id="angelleye-updater-notice" class="updated notice updater-dismissible"><p>' . $message . '</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>' . "\n";
}

function angelleye_updater_dismissible_admin_notice() {
set_transient( 'angelleye_updater_notice_hide', 'yes', MONTH_IN_SECONDS );
}
if ( false === ( $angelleye_updater_notice_hide = get_transient( 'angelleye_updater_notice_hide' ) ) ) {
add_action('admin_notices', 'angell_updater_notice');
}
add_action( 'wp_ajax_angelleye_updater_dismissible_admin_notice', 'angelleye_updater_dismissible_admin_notice' );
}
}

if (!function_exists('ae_get_shop_order_screen_id')) {
function ae_get_shop_order_screen_id()
{
return wc_get_container()->get(CustomOrdersTableController::class)->custom_orders_table_usage_is_enabled()
? wc_get_page_screen_id('shop-order') : 'shop_order';
}
}

if (!function_exists('ae_is_active_screen')) {
/**
* Returns True if the current active screen matches to one of the array elements
* @param string $screen
* @return bool
*/
function ae_is_active_screen(string $screen): bool
{
$current_screen = get_current_screen();
$screen_id = $current_screen ? $current_screen->id : '';
return $screen_id == $screen;
}
}
18 changes: 0 additions & 18 deletions angelleye-includes/angelleye-session-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,6 @@ function angelleye_unset_session($key) {
}
}

if (!function_exists('angelleye_session_init')) {

function angelleye_session_init() {
if (is_admin()) {
return false;
}
$old_wc = version_compare(WC_VERSION, '3.0', '<');
if(!$old_wc) {
$session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler');
$session = new $session_class();
$session->init();
} else {
return false;
}
}

}

/**
* Stores the PayPal Express Checkout sessions data as backup before the YITH Deposit plugin creates sub-order
*/
Expand Down
1,442 changes: 692 additions & 750 deletions angelleye-includes/angelleye-utility.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public function has_token($order) {

$order_id = $order->get_id();

$token = get_post_meta($order_id, '_payment_tokens_id', true);
$token = $order->get_meta( '_payment_tokens_id', true);

if (empty($token)) {
$token = get_post_meta($order_id, '_payment_tokens_id', true);
$token = $order->get_meta( '_payment_tokens_id', true);
}

if (!empty($token)) {
Expand All @@ -112,92 +112,67 @@ public function has_token($order) {
* @return array
*/
public function process_offer_payment($order, $product) {

try {

$is_successful = false;
if (!$this->has_token($order)) {
return $is_successful;
}

$gateway = $this->get_wc_gateway();

$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
$order_id = $order->get_id();
$request_data = array();
$gateway->angelleye_braintree_lib($order_id);
$billing_company = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_company : $order->get_billing_company();
$billing_first_name = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
$billing_last_name = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
$billing_address_1 = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1();
$billing_address_2 = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2();
$billing_city = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_city : $order->get_billing_city();
$billing_postcode = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_postcode : $order->get_billing_postcode();
$billing_country = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_country : $order->get_billing_country();
$billing_state = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_state : $order->get_billing_state();

$request_data['billing'] = array(
'firstName' => $billing_first_name,
'lastName' => $billing_last_name,
'company' => $billing_company,
'streetAddress' => $billing_address_1,
'extendedAddress' => $billing_address_2,
'locality' => $billing_city,
'region' => $billing_state,
'postalCode' => $billing_postcode,
'countryCodeAlpha2' => $billing_country,
'firstName' => $order->get_billing_first_name(),
'lastName' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'streetAddress' => $order->get_billing_address_1(),
'extendedAddress' => $order->get_billing_address_2(),
'locality' => $order->get_billing_city(),
'region' => $order->get_billing_state(),
'postalCode' => $order->get_billing_postcode(),
'countryCodeAlpha2' => $order->get_billing_country(),
);

$request_data['shipping'] = array(
'firstName' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_first_name : $order->get_shipping_first_name(),
'lastName' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_last_name : $order->get_shipping_last_name(),
'company' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_company : $order->get_shipping_company(),
'streetAddress' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_address_1 : $order->get_shipping_address_1(),
'extendedAddress' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_address_2 : $order->get_shipping_address_2(),
'locality' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_city : $order->get_shipping_city(),
'region' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_state : $order->get_shipping_state(),
'postalCode' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_postcode : $order->get_shipping_postcode(),
'countryCodeAlpha2' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_country : $order->get_shipping_country(),
'firstName' => $order->get_shipping_first_name(),
'lastName' => $order->get_shipping_last_name(),
'company' => $order->get_shipping_company(),
'streetAddress' => $order->get_shipping_address_1(),
'extendedAddress' => $order->get_shipping_address_2(),
'locality' => $order->get_shipping_city(),
'region' => $order->get_shipping_state(),
'postalCode' => $order->get_shipping_postcode(),
'countryCodeAlpha2' => $order->get_shipping_country(),
);

$request_data['paymentMethodToken'] = get_post_meta($order_id, '_payment_tokens_id', true);

$request_data['paymentMethodToken'] = $order->get_meta( '_payment_tokens_id', true);
if (is_user_logged_in()) {
$customer_id = get_current_user_id();
$braintree_customer_id = get_user_meta($customer_id, 'braintree_customer_id', true);
if (!empty($braintree_customer_id)) {
$request_data['customerId'] = $braintree_customer_id;
} else {
$request_data['customer'] = array(
'firstName' => version_compare(WC_VERSION, '3.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(),
'lastName' => version_compare(WC_VERSION, '3.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(),
'company' => version_compare(WC_VERSION, '3.0', '<') ? $order->billing_company : $order->get_billing_company(),
'phone' => version_compare(WC_VERSION, '3.0', '<') ? $order->billing_phone : $order->get_billing_phone(),
'email' => version_compare(WC_VERSION, '3.0', '<') ? $order->billing_email : $order->get_billing_email(),
'firstName' => $order->get_billing_first_name(),
'lastName' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'phone' => $order->get_billing_phone(),
'email' => $order->get_billing_email(),
);
}
}

$request_data['amount'] = number_format($product['price'], 2, '.', '');

$gateway->merchant_account_id = $gateway->angelleye_braintree_get_merchant_account_id($order_id);

if (isset($gateway->merchant_account_id) && !empty($gateway->merchant_account_id)) {
$request_data['merchantAccountId'] = $gateway->merchant_account_id;
}

$request_data['orderId'] = $order->get_order_number() . '-' . $product['step_id'];

$request_data['options'] = $gateway->get_braintree_options();

if ($gateway->enable_braintree_drop_in == false && $gateway->threed_secure_enabled === false) {
$request_data['creditCard']['cardholderName'] = $order->get_formatted_billing_full_name();
}

if ($gateway->debug) {
$gateway->add_log('Begin Braintree_Transaction::sale request');
$gateway->add_log('Order: ' . print_r($order->get_order_number(), true));
}

try {
$gateway->response = $gateway->braintree_gateway->transaction()->sale($request_data);
do_action('angelleye_paypal_response_data', $gateway->response, $request_data, '1', $gateway->sandbox, false, 'braintree');
Expand All @@ -220,39 +195,28 @@ public function process_offer_payment($order, $product) {
$gateway->add_log('Error: Unable to complete transaction. Reason: ' . $e->getMessage());
return $success = false;
}

if (!$gateway->response->success) {
$gateway->add_log("Error: Unable to complete transaction. Reason: {$gateway->response->message}");
return $success = false;
}

$gateway->add_log('Braintree_Transaction::sale Response code: ' . print_r($gateway->get_status_code(), true));

$gateway->add_log('Braintree_Transaction::sale Response message: ' . print_r($gateway->get_status_message(), true));

$maybe_settled_later = array(
'settling',
'settlement_pending',
'submitted_for_settlement',
);

if (in_array($gateway->response->transaction->status, $maybe_settled_later)) {
update_post_meta($order_id, 'is_sandbox', $gateway->sandbox);
$order->update_meta_data('is_sandbox', $gateway->sandbox);
$order->add_order_note(sprintf(__('%s payment approved! Transaction ID: %s', 'paypal-for-woocommerce'), $gateway->title, $gateway->response->transaction->id));
$this->store_offer_transaction($order, $gateway->response->transaction->id, $product);
$order->save();
return true;
} else {
$gateway->add_log(sprintf('Info: unhandled transaction id = %s, status = %s', $gateway->response->transaction->id, $gateway->response->transaction->status));
$order->add_order_note(sprintf(__('Transaction was submitted to PayPal Braintree but not handled by WooCommerce order, transaction_id: %s, status: %s. Order was put in-hold.', 'paypal-for-woocommerce'), $gateway->response->transaction->id, $gateway->response->transaction->status));
$old_wc = version_compare(WC_VERSION, '3.0', '<');
$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
if ($old_wc) {
if (!get_post_meta($order_id, '_order_stock_reduced', true)) {
$order->reduce_order_stock();
}
} else {
wc_maybe_reduce_stock_levels($order_id);
}
$order_id = $order->get_id();
wc_maybe_reduce_stock_levels($order_id);
$this->store_offer_transaction($order, $gateway->response->transaction->id, $product);
return true;
}
Expand Down Expand Up @@ -288,8 +252,9 @@ public function process_offer_refund($order, $offer_data) {
$braintree_refunded_id = array();
$braintree_refunded_id[$result->transaction->id] = $result->transaction->id;
$order->add_order_note(sprintf(__('Refunded %s - Transaction ID: %s', 'paypal-for-woocommerce'), wc_price(number_format($refund_amount, 2, '.', '')), $result->transaction->id));
update_post_meta($order_id, 'Refund Transaction ID', $result->transaction->id);
update_post_meta($order_id, 'braintree_refunded_id', $braintree_refunded_id);
$order->update_meta_data('Refund Transaction ID', $result->transaction->id);
$order->update_meta_data('braintree_refunded_id', $braintree_refunded_id);
$order->save();
$response_id = $result->transaction->id;
}
} catch (Braintree\Exception\NotFound $e) {
Expand All @@ -303,7 +268,8 @@ public function process_offer_refund($order, $offer_data) {
if ($result->success) {
$braintree_refunded_id = array();
$braintree_refunded_id[$result->transaction->id] = $result->transaction->id;
update_post_meta($order_id, 'braintree_refunded_id', $braintree_refunded_id);
$order->update_meta_data('braintree_refunded_id', $braintree_refunded_id);
$order->save();
$order->add_order_note(sprintf(__('Refunded %s - Transaction ID: %s', 'paypal-for-woocommerce'), wc_price(number_format($refund_amount, 2, '.', '')), $result->transaction->id));
$response_id = $result->transaction->id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,11 @@ public function create_billing_agreement() {
$order->set_payment_method('paypal');

// Store the billing agreement ID on the order and subscriptions.
update_post_meta(wcf_pro()->wc_common->get_order_id($order), '_paypal_subscription_id', $this->get_value_from_response($billing_agreement_response, 'BILLINGAGREEMENTID'));
$order->update_meta_data('_paypal_subscription_id', $this->get_value_from_response($billing_agreement_response, 'BILLINGAGREEMENTID'));

$order->payment_complete($billing_agreement_response['PAYMENTINFO_0_TRANSACTIONID']);

$order->save();
$redirect_url = add_query_arg('utm_nooverride', '1', $order->get_checkout_order_received_url());

// redirect customer to order received page.
Expand Down Expand Up @@ -1212,9 +1213,9 @@ public function get_wc_gateway() {
public function add_subscription_payment_meta_for_paypal_express($subscription, $order, $offer_product) {

if ('paypal_express' === $order->get_payment_method()) {
$subscription_id = $subscription->get_id();
update_post_meta($subscription_id, '_payment_tokens_id', $order->get_meta('BILLINGAGREEMENTID', true));
update_post_meta($subscription_id, 'BILLINGAGREEMENTID', $order->get_meta('BILLINGAGREEMENTID', true));
$subscription->update_meta_data('_payment_tokens_id', $order->get_meta('BILLINGAGREEMENTID', true));
$subscription->update_meta_data('BILLINGAGREEMENTID', $order->get_meta('BILLINGAGREEMENTID', true));
$subscription->save_meta_data();
}
}

Expand Down
Loading

0 comments on commit c5136fb

Please sign in to comment.