Skip to content

Commit

Permalink
PayFlow : Woo subscription issue with renewal, ref #823
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Aug 19, 2017
1 parent 920e315 commit 75cccf0
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function add_subscription_payment_meta($payment_meta, $subscription) {

public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
if ($this->id === $payment_method_id) {
if (!empty($payment_meta['post_meta']['_payment_tokens_id']['value']) && empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
if (empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
throw new Exception('A "_payment_tokens_id" value is required.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
}

class WC_Gateway_PayPal_Advanced_Subscriptions_AngellEYE extends WC_Gateway_PayPal_Advanced_AngellEYE {

public $wc_pre_30;

public function __construct() {
parent::__construct();
if (class_exists('WC_Subscriptions_Order')) {
add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 3);
add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
add_action('woocommerce_subscription_failing_payment_method_updated_' . $this->id, array($this, 'update_failing_payment_method'), 10, 2);
}
$this->wc_pre_30 = version_compare( WC_VERSION, '3.0.0', '<' );
$this->wc_pre_30 = version_compare(WC_VERSION, '3.0.0', '<');
}

public function is_subscription($order_id) {
Expand All @@ -31,6 +33,7 @@ public function process_payment($order_id) {
}

public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
$this->angelleye_scheduled_subscription_payment_retry_compability($renewal_order);
parent::process_payment($renewal_order);
}

Expand All @@ -47,10 +50,17 @@ public function add_subscription_payment_meta($payment_meta, $subscription) {
return $payment_meta;
}

public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
public function validate_subscription_payment_meta($payment_method_id, $payment_meta, $subscription) {
if ($this->id === $payment_method_id) {
if (!empty($payment_meta['post_meta']['_payment_tokens_id']['value']) && empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
throw new Exception('A "_payment_tokens_id" value is required.');
if (empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
$subscription_parent_id = $this->wc_pre_30 ? $subscription->parent_id : $subscription->get_parent_id();
$payment_tokens_id = get_post_meta($subscription_parent_id, '_transaction_id', true);
if (!empty($payment_tokens_id)) {
update_post_meta($subscription_id, '_payment_tokens_id', $payment_tokens_id);
} else {
throw new Exception('A "_payment_tokens_id" value is required.');
}
}
}
}
Expand Down Expand Up @@ -80,8 +90,36 @@ public function delete_resubscribe_meta($resubscribe_order) {
}

public function update_failing_payment_method($subscription, $renewal_order) {
$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
update_post_meta($subscription_id, '_payment_tokens_id', $renewal_order->payment_tokens_id);
if ($this->wc_pre_30) {
update_post_meta($subscription->id, '_payment_tokens_id', $renewal_order->payment_tokens_id);
} else {
$subscription->update_meta_data('_payment_tokens_id', $renewal_order->get_meta('_payment_tokens_id', true));
}
}

public function angelleye_scheduled_subscription_payment_retry_compability($renewal_order) {
$renewal_order_id = $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id();
$payment_tokens_id = get_post_meta($renewal_order_id, '_payment_tokens_id', true);
if (empty($payment_tokens_id) || $payment_tokens_id == false) {
if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($renewal_order_id)) {
$subscriptions = wcs_get_subscriptions_for_order($renewal_order_id);
} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($renewal_order_id)) {
$subscriptions = wcs_get_subscriptions_for_renewal_order($renewal_order_id);
} else {
$subscriptions = array();
}
if (!empty($subscriptions)) {
foreach ($subscriptions as $subscription) {
$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
$subscription_parent_id = $this->wc_pre_30 ? $subscription->parent_id : $subscription->get_parent_id();
$payment_tokens_id = get_post_meta($subscription_parent_id, '_transaction_id', true);
if (!empty($payment_tokens_id)) {
update_post_meta($subscription_id, '_payment_tokens_id', $payment_tokens_id);
update_post_meta($renewal_order_id, '_payment_tokens_id', $payment_tokens_id);
}
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function add_subscription_payment_meta($payment_meta, $subscription) {

public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
if ($this->id === $payment_method_id) {
if (!empty($payment_meta['post_meta']['_payment_tokens_id']['value']) && empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
if (empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
throw new Exception('A "_payment_tokens_id" value is required.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function add_subscription_payment_meta($payment_meta, $subscription) {

public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
if ($this->id === $payment_method_id) {
if (!empty($payment_meta['post_meta']['_payment_tokens_id']['value']) && empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
if (empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
throw new Exception('A "_payment_tokens_id" value is required.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
}

class WC_Gateway_PayPal_Pro_PayFlow_Subscriptions_AngellEYE extends WC_Gateway_PayPal_Pro_PayFlow_AngellEYE {

public $wc_pre_30;

public function __construct() {
parent::__construct();
if (class_exists('WC_Subscriptions_Order')) {
add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 3);
add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
add_action('woocommerce_subscription_failing_payment_method_updated_' . $this->id, array($this, 'update_failing_payment_method'), 10, 2);
}
$this->wc_pre_30 = version_compare( WC_VERSION, '3.0.0', '<' );
$this->wc_pre_30 = version_compare(WC_VERSION, '3.0.0', '<');
}

public function is_subscription($order_id) {
Expand All @@ -31,6 +33,7 @@ public function process_payment($order_id) {
}

public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
$this->angelleye_scheduled_subscription_payment_retry_compability($renewal_order);
parent::process_subscription_payment($renewal_order, $amount_to_charge);
}

Expand All @@ -47,10 +50,17 @@ public function add_subscription_payment_meta($payment_meta, $subscription) {
return $payment_meta;
}

public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
public function validate_subscription_payment_meta($payment_method_id, $payment_meta, $subscription) {
if ($this->id === $payment_method_id) {
if (!empty($payment_meta['post_meta']['_payment_tokens_id']['value']) && empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
throw new Exception('A "_payment_tokens_id" value is required.');
if (empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
$subscription_parent_id = $this->wc_pre_30 ? $subscription->parent_id : $subscription->get_parent_id();
$payment_tokens_id = get_post_meta($subscription_parent_id, '_transaction_id', true);
if (!empty($payment_tokens_id)) {
update_post_meta($subscription_id, '_payment_tokens_id', $payment_tokens_id);
} else {
throw new Exception('A "_payment_tokens_id" value is required.');
}
}
}
}
Expand Down Expand Up @@ -80,8 +90,35 @@ public function delete_resubscribe_meta($resubscribe_order) {
}

public function update_failing_payment_method($subscription, $renewal_order) {
$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
update_post_meta($subscription_id, '_payment_tokens_id', $renewal_order->payment_tokens_id);
if ($this->wc_pre_30) {
update_post_meta($subscription->id, '_payment_tokens_id', $renewal_order->payment_tokens_id);
} else {
$subscription->update_meta_data('_payment_tokens_id', $renewal_order->get_meta('_payment_tokens_id', true));
}
}

}
public function angelleye_scheduled_subscription_payment_retry_compability($renewal_order) {
$renewal_order_id = $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id();
$payment_tokens_id = get_post_meta($renewal_order_id, '_payment_tokens_id', true);
if (empty($payment_tokens_id) || $payment_tokens_id == false) {
if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($renewal_order_id)) {
$subscriptions = wcs_get_subscriptions_for_order($renewal_order_id);
} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($renewal_order_id)) {
$subscriptions = wcs_get_subscriptions_for_renewal_order($renewal_order_id);
} else {
$subscriptions = array();
}
if (!empty($subscriptions)) {
foreach ($subscriptions as $subscription) {
$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
$subscription_parent_id = $this->wc_pre_30 ? $subscription->parent_id : $subscription->get_parent_id();
$payment_tokens_id = get_post_meta($subscription_parent_id, '_transaction_id', true);
if (!empty($payment_tokens_id)) {
update_post_meta($subscription_id, '_payment_tokens_id', $payment_tokens_id);
update_post_meta($renewal_order_id, '_payment_tokens_id', $payment_tokens_id);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
}

class WC_Gateway_PayPal_Pro_Subscriptions_AngellEYE extends WC_Gateway_PayPal_Pro_AngellEYE {

public $wc_pre_30;

public function __construct() {
parent::__construct();
if (class_exists('WC_Subscriptions_Order')) {
add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 3);
add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
add_action('woocommerce_subscription_failing_payment_method_updated_' . $this->id, array($this, 'update_failing_payment_method'), 10, 2);
}
$this->wc_pre_30 = version_compare( WC_VERSION, '3.0.0', '<' );
$this->wc_pre_30 = version_compare(WC_VERSION, '3.0.0', '<');
}

public function is_subscription($order_id) {
Expand All @@ -35,6 +37,7 @@ public function process_payment($order_id) {
}

public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
$this->angelleye_scheduled_subscription_payment_retry_compability($renewal_order);
parent::process_subscription_payment($renewal_order, $amount_to_charge);
}

Expand All @@ -51,10 +54,17 @@ public function add_subscription_payment_meta($payment_meta, $subscription) {
return $payment_meta;
}

public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
public function validate_subscription_payment_meta($payment_method_id, $payment_meta, $subscription) {
if ($this->id === $payment_method_id) {
if (!empty($payment_meta['post_meta']['_payment_tokens_id']['value']) && empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
throw new Exception('A "_payment_tokens_id" value is required.');
if (empty($payment_meta['post_meta']['_payment_tokens_id']['value'])) {
$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
$subscription_parent_id = $this->wc_pre_30 ? $subscription->parent_id : $subscription->get_parent_id();
$payment_tokens_id = get_post_meta($subscription_parent_id, '_transaction_id', true);
if (!empty($payment_tokens_id)) {
update_post_meta($subscription_id, '_payment_tokens_id', $payment_tokens_id);
} else {
throw new Exception('A "_payment_tokens_id" value is required.');
}
}
}
}
Expand Down Expand Up @@ -84,8 +94,11 @@ public function delete_resubscribe_meta($resubscribe_order) {
}

public function update_failing_payment_method($subscription, $renewal_order) {
$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
update_post_meta($subscription_id, '_payment_tokens_id', $renewal_order->payment_tokens_id);
if ($this->wc_pre_30) {
update_post_meta($subscription->id, '_payment_tokens_id', $renewal_order->payment_tokens_id);
} else {
$subscription->update_meta_data('_payment_tokens_id', $renewal_order->get_meta('_payment_tokens_id', true));
}
}

public function free_signup_with_token_payment_tokenization($order_id) {
Expand All @@ -98,4 +111,29 @@ public function free_signup_with_token_payment_tokenization($order_id) {
return false;
}

public function angelleye_scheduled_subscription_payment_retry_compability($renewal_order) {
$renewal_order_id = $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id();
$payment_tokens_id = get_post_meta($renewal_order_id, '_payment_tokens_id', true);
if (empty($payment_tokens_id) || $payment_tokens_id == false) {
if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($renewal_order_id)) {
$subscriptions = wcs_get_subscriptions_for_order($renewal_order_id);
} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($renewal_order_id)) {
$subscriptions = wcs_get_subscriptions_for_renewal_order($renewal_order_id);
} else {
$subscriptions = array();
}
if (!empty($subscriptions)) {
foreach ($subscriptions as $subscription) {
$subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id();
$subscription_parent_id = $this->wc_pre_30 ? $subscription->parent_id : $subscription->get_parent_id();
$payment_tokens_id = get_post_meta($subscription_parent_id, '_transaction_id', true);
if (!empty($payment_tokens_id)) {
update_post_meta($subscription_id, '_payment_tokens_id', $payment_tokens_id);
update_post_meta($renewal_order_id, '_payment_tokens_id', $payment_tokens_id);
}
}
}
}
}

}

0 comments on commit 75cccf0

Please sign in to comment.