Skip to content

Commit

Permalink
WooCommerce 3.0.x / PayPal for Woo 1.4.x Compatibility, ref #760
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Jun 5, 2017
1 parent 0e6f5d6 commit 5f4a9de
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
20 changes: 12 additions & 8 deletions angelleye-includes/paypal-rest-api-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function create_payment($order, $card_data) {
$this->payment->create($this->getAuth());
} catch (PayPal\Exception\PayPalConnectionException $ex) {
$this->add_log($ex->getMessage());
if ($this->is_subscription($order_id)) {
if ($this->is_renewal($order_id)) {
return true;
}
wc_add_notice(__("Error processing checkout. Please try again. ", 'woo-paypal-plus'), 'error');
Expand All @@ -81,7 +81,7 @@ public function create_payment($order, $card_data) {
} catch (Exception $ex) {
$this->send_failed_order_email($order_id);
$this->add_log($ex->getMessage());
if ($this->is_subscription($order_id)) {
if ($this->is_renewal($order_id)) {
return true;
}
wc_add_notice(__("Error processing checkout. Please try again. ", 'woo-paypal-plus'), 'error');
Expand Down Expand Up @@ -137,7 +137,7 @@ public function create_payment($order, $card_data) {
} else {
update_post_meta( $order->get_id(), 'is_sandbox', $is_sandbox );
}
if ($this->is_subscription($order_id)) {
if ($this->is_renewal($order_id)) {
return true;
}
WC()->cart->empty_cart();
Expand Down Expand Up @@ -208,7 +208,7 @@ public function set_trnsaction_obj_value($order, $card_data) {
$this->fundingInstrument = new FundingInstrument();
$this->fundingInstrument->setCreditCardToken($this->CreditCardToken);
$this->save_payment_token($order, $token->get_token());
} else if ($this->is_subscription($order_id)) {
} else if ($this->is_renewal($order_id)) {
$payment_tokens = get_post_meta($order_id, '_payment_tokens_id', true);
$this->CreditCardToken = new CreditCardToken();
$this->CreditCardToken->setCreditCardId($payment_tokens);
Expand Down Expand Up @@ -662,7 +662,7 @@ public function save_payment_token($order, $payment_tokens_id) {
}
if (!empty($subscriptions)) {
foreach ($subscriptions as $subscription) {
$subscription_id = version_compare(WC_VERSION, '3.0', '<') ? $subscriptions->id : $subscriptions->get_id();
$subscription_id = version_compare(WC_VERSION, '3.0', '<') ? $subscription->id : $subscription->get_id();
update_post_meta($subscription_id, '_payment_tokens_id', $payment_tokens_id);
}
}
Expand Down Expand Up @@ -708,7 +708,7 @@ public function create_payment_with_zero_amount($order, $card_data) {
$order->payment_complete($creditcard_id);
$is_sandbox = $this->mode == 'SANDBOX' ? true : false;
update_post_meta($order_id, 'is_sandbox', $is_sandbox);
if ($this->is_subscription($order_id)) {
if ($this->is_renewal($order_id)) {
return true;
}
WC()->cart->empty_cart();
Expand All @@ -727,7 +727,7 @@ public function create_payment_with_zero_amount($order, $card_data) {
} catch (PayPal\Exception\PayPalConnectionException $ex) {
$this->send_failed_order_email($order_id);
$this->add_log($ex->getData());
if ($this->is_subscription($order_id)) {
if ($this->is_renewal($order_id)) {
return true;
}
wc_add_notice(__("Error processing checkout. Please try again. ", 'paypal-for-woocommerce'), 'error');
Expand All @@ -739,7 +739,7 @@ public function create_payment_with_zero_amount($order, $card_data) {
} catch (Exception $ex) {
$this->send_failed_order_email($order_id);
$this->add_log($ex->getMessage());
if ($this->is_subscription($order_id)) {
if ($this->is_renewal($order_id)) {
return true;
}
wc_add_notice(__("Error processing checkout. Please try again. ", 'paypal-for-woocommerce'), 'error');
Expand All @@ -757,5 +757,9 @@ public function send_failed_order_email($order_id) {
$emails['WC_Email_Failed_Order']->trigger($order_id);
}
}

public function is_renewal($order_id) {
return ( function_exists('wcs_order_contains_subscription') && wcs_order_contains_renewal($order_id) );
}

}
52 changes: 33 additions & 19 deletions paypal-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,26 +578,40 @@ public static function calculate($order, $send_items = false){
/**
* Add custom Woo cart fees as line items
*/
foreach (WC()->cart->get_fees() as $fee) {
$Item = array(
'name' => $fee->name, // Item name. 127 char max.
'desc' => '', // Item description. 127 char max.
'amt' => self::number_format($fee->amount, 2, '.', ''), // Cost of item.
'number' => $fee->id, // Item number. 127 char max.
'qty' => 1, // Item qty on order. Any positive integer.
);
/**
* The gift wrap amount actually has its own parameter in
* DECP, so we don't want to include it as one of the line
* items.
*/
if ($Item['number'] != 'gift-wrap') {
array_push($PaymentOrderItems, $Item);
$ITEMAMT += self::round($fee->amount);
} else {
$giftwrapamount = self::round($fee->amount);
if ($order){
foreach ($order->get_fees() as $fee_item_id => $fee_item) {
$Item = array(
'name' => $fee_item->get_name(), // Item name. 127 char max.
'desc' => '', // Item description. 127 char max.
'amt' => wc_format_decimal( $order->get_line_total( $fee_item ), 2 ), // Cost of item.
'number' => $fee_item_id, // Item number. 127 char max.
'qty' => 1, // Item qty on order. Any positive integer.
);
if ($Item['number'] != 'gift-wrap') {
array_push($PaymentOrderItems, $Item);
$ITEMAMT += self::round($Item['amt']);
} else {
$giftwrapamount = self::round($Item['amt']);
}
$ctr++;
}
} else {
foreach (WC()->cart->get_fees() as $fee) {
$Item = array(
'name' => $fee->name, // Item name. 127 char max.
'desc' => '', // Item description. 127 char max.
'amt' => self::number_format($fee->amount, 2, '.', ''), // Cost of item.
'number' => $fee->id, // Item number. 127 char max.
'qty' => 1, // Item qty on order. Any positive integer.
);
if ($Item['number'] != 'gift-wrap') {
array_push($PaymentOrderItems, $Item);
$ITEMAMT += self::round($fee->amount);
} else {
$giftwrapamount = self::round($fee->amount);
}
$ctr++;
}
$ctr++;
}
//caculate discount
if ($order){
Expand Down

0 comments on commit 5f4a9de

Please sign in to comment.