Version Description
- Fix - Add cancel link on checkout page when session for PPEC is active
- Fix - In-context mini browser keeps spinning because failure xhr response is not handled properly
Download this release
Release Info
Developer | akeda |
Plugin | WooCommerce PayPal Express Checkout Payment Gateway |
Version | 0.2.0 |
Comparing to | |
See all releases |
Code changes from version 0.1.0 to 0.2.0
- assets/css/wc-gateway-ppec-frontend-checkout.css +6 -0
- assets/js/wc-gateway-ppec-frontend-checkout.js +10 -10
- includes/abstracts/abstract-wc-gateway-ppec.php +1 -1
- includes/class-wc-gateway-ppec-admin-handler.php +11 -5
- includes/class-wc-gateway-ppec-checkout-handler.php +197 -113
- includes/functions.php +1 -1
- readme.txt +5 -1
- woocommerce-gateway-paypal-express-checkout.php +2 -2
assets/css/wc-gateway-ppec-frontend-checkout.css
CHANGED
@@ -5,3 +5,9 @@
|
|
5 |
.payment_method_ppec_paypal img {
|
6 |
max-height: 68px !important;
|
7 |
}
|
|
|
|
|
|
|
|
|
|
|
|
5 |
.payment_method_ppec_paypal img {
|
6 |
max-height: 68px !important;
|
7 |
}
|
8 |
+
|
9 |
+
.wc-gateway-ppec-cancel {
|
10 |
+
display: block;
|
11 |
+
text-align: center;
|
12 |
+
padding: 10px;
|
13 |
+
}
|
assets/js/wc-gateway-ppec-frontend-checkout.js
CHANGED
@@ -1,3 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
var woo_pp_icc_started = false;
|
2 |
window.paypalCheckoutReady = function() {
|
3 |
paypal.checkout.setup( wc_ppec.payer_id, {
|
@@ -17,19 +24,12 @@ jQuery( document ).ajaxComplete( function( event, xhr, settings ) {
|
|
17 |
return;
|
18 |
}
|
19 |
|
20 |
-
var
|
21 |
-
if (
|
22 |
-
return;
|
23 |
-
}
|
24 |
-
if( c.indexOf( '<!--WC_END-->' ) < 0 ) {
|
25 |
return;
|
26 |
}
|
27 |
|
28 |
-
|
29 |
-
if( !d ) {
|
30 |
-
return;
|
31 |
-
}
|
32 |
-
if( 'success' != d.result ) {
|
33 |
paypal.checkout.closeFlow();
|
34 |
woo_pp_icc_started = false;
|
35 |
}
|
1 |
+
/**
|
2 |
+
* globals jQuery, wc_ppec, window.
|
3 |
+
*
|
4 |
+
* This script only enqueued when buyer start checkout from checkout. In this
|
5 |
+
* case buyer needs to fill billing fields then proceed to login through PayPal.
|
6 |
+
*/
|
7 |
+
|
8 |
var woo_pp_icc_started = false;
|
9 |
window.paypalCheckoutReady = function() {
|
10 |
paypal.checkout.setup( wc_ppec.payer_id, {
|
24 |
return;
|
25 |
}
|
26 |
|
27 |
+
var resp = jQuery.parseJSON( xhr.responseText );
|
28 |
+
if ( ! resp ) {
|
|
|
|
|
|
|
29 |
return;
|
30 |
}
|
31 |
|
32 |
+
if( 'success' !== resp.result ) {
|
|
|
|
|
|
|
|
|
33 |
paypal.checkout.closeFlow();
|
34 |
woo_pp_icc_started = false;
|
35 |
}
|
includes/abstracts/abstract-wc-gateway-ppec.php
CHANGED
@@ -116,7 +116,7 @@ abstract class WC_Gateway_PPEC extends WC_Payment_Gateway {
|
|
116 |
! $session->payerID ) {
|
117 |
// Redirect them over to PayPal.
|
118 |
try {
|
119 |
-
$redirect_url = $checkout->
|
120 |
$settings = wc_gateway_ppec()->settings->loadSettings();
|
121 |
if ( $settings->enableInContextCheckout && $settings->getActiveApiCredentials()->get_payer_id() ) {
|
122 |
$redirect_url = 'javascript:woo_pp_checkout_callback("' . urlencode( $redirect_url ) . '");';
|
116 |
! $session->payerID ) {
|
117 |
// Redirect them over to PayPal.
|
118 |
try {
|
119 |
+
$redirect_url = $checkout->start_checkout_from_checkout( $order_id, 'ppec_paypal_credit' === $this->id );
|
120 |
$settings = wc_gateway_ppec()->settings->loadSettings();
|
121 |
if ( $settings->enableInContextCheckout && $settings->getActiveApiCredentials()->get_payer_id() ) {
|
122 |
$redirect_url = 'javascript:woo_pp_checkout_callback("' . urlencode( $redirect_url ) . '");';
|
includes/class-wc-gateway-ppec-admin-handler.php
CHANGED
@@ -32,23 +32,29 @@ class WC_Gateway_PPEC_Admin_Handler {
|
|
32 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
33 |
}
|
34 |
|
35 |
-
public function add_capture_charge_order_action() {
|
36 |
if ( ! isset( $_REQUEST['post'] ) ) {
|
37 |
-
return;
|
38 |
}
|
39 |
|
40 |
$order = wc_get_order( $_REQUEST['post'] );
|
41 |
|
42 |
// bail if the order wasn't paid for with this gateway
|
43 |
if ( 'ppec_paypal' !== $order->payment_method ) {
|
44 |
-
return;
|
45 |
}
|
46 |
|
47 |
if ( 'yes' === get_post_meta( $order->id, '_ppec_charge_captured', true ) ) {
|
48 |
-
return;
|
49 |
}
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
|
54 |
/**
|
32 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
33 |
}
|
34 |
|
35 |
+
public function add_capture_charge_order_action( $actions ) {
|
36 |
if ( ! isset( $_REQUEST['post'] ) ) {
|
37 |
+
return $actions;
|
38 |
}
|
39 |
|
40 |
$order = wc_get_order( $_REQUEST['post'] );
|
41 |
|
42 |
// bail if the order wasn't paid for with this gateway
|
43 |
if ( 'ppec_paypal' !== $order->payment_method ) {
|
44 |
+
return $actions;
|
45 |
}
|
46 |
|
47 |
if ( 'yes' === get_post_meta( $order->id, '_ppec_charge_captured', true ) ) {
|
48 |
+
return $actions;
|
49 |
}
|
50 |
|
51 |
+
if ( ! is_array( $actions ) ) {
|
52 |
+
$actions = array();
|
53 |
+
}
|
54 |
+
|
55 |
+
$actions['ppec_capture_charge'] = esc_html__( 'Capture Charge', 'woocommerce-gateway-paypal-express-checkout' );
|
56 |
+
|
57 |
+
return $actions;
|
58 |
}
|
59 |
|
60 |
/**
|
includes/class-wc-gateway-ppec-checkout-handler.php
CHANGED
@@ -40,12 +40,15 @@ class WC_Gateway_PPEC_Checkout_Handler {
|
|
40 |
add_action( 'woocommerce_init', array( $this, 'init' ) );
|
41 |
|
42 |
add_action( 'wp', array( $this, 'maybe_return_from_paypal' ) );
|
|
|
|
|
43 |
|
44 |
add_action( 'woocommerce_before_checkout_process', array( $this, 'before_checkout_process' ) );
|
45 |
add_filter( 'woocommerce_checkout_fields', array( $this, 'make_billing_address_optional' ) );
|
46 |
add_action( 'woocommerce_after_checkout_form', array( $this, 'after_checkout_form' ) );
|
47 |
add_action( 'woocommerce_available_payment_gateways', array( $this, 'maybe_disable_other_gateways' ) );
|
48 |
add_action( 'woocommerce_available_payment_gateways', array( $this, 'maybe_disable_paypal_credit' ) );
|
|
|
49 |
|
50 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
51 |
}
|
@@ -62,101 +65,97 @@ class WC_Gateway_PPEC_Checkout_Handler {
|
|
62 |
}
|
63 |
|
64 |
public function maybe_return_from_paypal() {
|
65 |
-
if (
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
&& ! empty( $_GET['token'] )
|
72 |
-
&& ! empty( $_GET['PayerID'] ) ) {
|
73 |
|
74 |
-
|
75 |
-
|
76 |
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
-
|
80 |
-
|
|
|
81 |
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
|
|
|
|
84 |
try {
|
85 |
-
$
|
86 |
-
|
87 |
-
|
88 |
-
return;
|
89 |
-
} catch( PayPal_Missing_Session_Exception $e ) {
|
90 |
-
wc_add_notice( __( 'Your PayPal checkout session has expired. Please check out again.', 'woocommerce-gateway-paypal-express-checkout' ), 'error' );
|
91 |
-
return;
|
92 |
-
}
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
100 |
|
101 |
-
|
102 |
-
|
103 |
|
104 |
-
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
WC()->session->chosen_payment_method = 'ppec_paypal';
|
110 |
-
}
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
$order->payment_complete( $transaction_id );
|
122 |
-
$order->add_order_note( sprintf( __( 'PayPal transaction completed; transaction ID = %s', 'woocommerce-gateway-paypal-express-checkout' ), $transaction_id ) );
|
123 |
-
$order->reduce_order_stock();
|
124 |
-
WC()->cart->empty_cart();
|
125 |
-
unset( WC()->session->paypal );
|
126 |
-
|
127 |
-
wp_safe_redirect( $order->get_checkout_order_received_url() );
|
128 |
-
exit;
|
129 |
-
} catch( PayPal_Missing_Session_Exception $e ) {
|
130 |
-
// For some reason, our session data is missing. Generally, if we've made it this far,
|
131 |
-
// this shouldn't happen.
|
132 |
-
wc_add_notice( __( 'Sorry, an error occurred while trying to process your payment. Please try again.', 'woocommerce-gateway-paypal-express-checkout' ), 'error' );
|
133 |
-
} catch( PayPal_API_Exception $e ) {
|
134 |
-
// Did we get a 10486 or 10422 back from PayPal? If so, this means we need to send the buyer back over to
|
135 |
-
// PayPal to have them pick out a new funding method.
|
136 |
-
$need_to_redirect_back = false;
|
137 |
-
foreach ( $e->errors as $error ) {
|
138 |
-
if ( '10486' == $error->error_code || '10422' == $error->error_code ) {
|
139 |
-
$need_to_redirect_back = true;
|
140 |
-
}
|
141 |
}
|
|
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
}
|
156 |
-
$final_output .= '</ul>';
|
157 |
-
wc_add_notice( __( 'Payment error:', 'woocommerce-gateway-paypal-express-checkout' ) . $final_output, 'error' );
|
158 |
-
return;
|
159 |
}
|
|
|
|
|
|
|
160 |
}
|
161 |
}
|
162 |
}
|
@@ -273,10 +272,8 @@ class WC_Gateway_PPEC_Checkout_Handler {
|
|
273 |
* @return array Available gateways
|
274 |
*/
|
275 |
public function maybe_disable_other_gateways( $gateways ) {
|
276 |
-
$session = WC()->session->paypal;
|
277 |
-
|
278 |
// Unset all other gateways after checking out from cart.
|
279 |
-
if (
|
280 |
foreach ( $gateways as $id => $gateway ) {
|
281 |
if ( 'ppec_paypal' !== $id ) {
|
282 |
unset( $gateways[ $id ] );
|
@@ -308,6 +305,99 @@ class WC_Gateway_PPEC_Checkout_Handler {
|
|
308 |
return $gateways;
|
309 |
}
|
310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
public function enablePayPalCredit( $enable = true ) {
|
312 |
$this->_enablePayPalCredit = $enable;
|
313 |
}
|
@@ -406,35 +496,29 @@ class WC_Gateway_PPEC_Checkout_Handler {
|
|
406 |
}
|
407 |
}
|
408 |
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
$url .= 'woo-paypal-return=true';
|
419 |
-
|
420 |
-
return $url;
|
421 |
}
|
422 |
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
$url .= 'woo-paypal-cancel=true';
|
433 |
-
|
434 |
-
return $url;
|
435 |
}
|
436 |
|
437 |
-
public function
|
438 |
|
439 |
wc_gateway_ppec()->cart->loadCartDetails();
|
440 |
|
@@ -461,8 +545,8 @@ class WC_Gateway_PPEC_Checkout_Handler {
|
|
461 |
$params['BRANDNAME'] = $brand_name;
|
462 |
}
|
463 |
|
464 |
-
$params['RETURNURL'] = $this->
|
465 |
-
$params['CANCELURL'] = $this->
|
466 |
|
467 |
if ( $this->_requestBillingAgreement ) {
|
468 |
$params['BILLINGTYPE'] = 'MerchantInitiatedBilling';
|
@@ -487,7 +571,7 @@ class WC_Gateway_PPEC_Checkout_Handler {
|
|
487 |
}
|
488 |
}
|
489 |
|
490 |
-
public function
|
491 |
|
492 |
wc_gateway_ppec()->cart->loadOrderDetails( $order_id );
|
493 |
|
@@ -522,8 +606,8 @@ class WC_Gateway_PPEC_Checkout_Handler {
|
|
522 |
$params['BRANDNAME'] = $brand_name;
|
523 |
}
|
524 |
|
525 |
-
$params['RETURNURL'] = $this->
|
526 |
-
$params['CANCELURL'] = $this->
|
527 |
|
528 |
if ( $this->_requestBillingAgreement ) {
|
529 |
$params['BILLINGTYPE'] = 'MerchantInitiatedBilling';
|
40 |
add_action( 'woocommerce_init', array( $this, 'init' ) );
|
41 |
|
42 |
add_action( 'wp', array( $this, 'maybe_return_from_paypal' ) );
|
43 |
+
add_action( 'wp', array( $this, 'maybe_cancel_checkout_with_paypal' ) );
|
44 |
+
add_action( 'woocommerce_cart_emptied', array( $this, 'maybe_clear_session_data' ) );
|
45 |
|
46 |
add_action( 'woocommerce_before_checkout_process', array( $this, 'before_checkout_process' ) );
|
47 |
add_filter( 'woocommerce_checkout_fields', array( $this, 'make_billing_address_optional' ) );
|
48 |
add_action( 'woocommerce_after_checkout_form', array( $this, 'after_checkout_form' ) );
|
49 |
add_action( 'woocommerce_available_payment_gateways', array( $this, 'maybe_disable_other_gateways' ) );
|
50 |
add_action( 'woocommerce_available_payment_gateways', array( $this, 'maybe_disable_paypal_credit' ) );
|
51 |
+
add_action( 'woocommerce_review_order_after_submit', array( $this, 'maybe_render_cancel_link' ) );
|
52 |
|
53 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
54 |
}
|
65 |
}
|
66 |
|
67 |
public function maybe_return_from_paypal() {
|
68 |
+
if ( empty( $_GET['woo-paypal-return'] ) ) {
|
69 |
+
return;
|
70 |
+
}
|
71 |
|
72 |
+
// If the token and payer ID aren't there, just ignore this request
|
73 |
+
if ( empty( $_GET['token'] ) || empty( $_GET['PayerID'] ) ) {
|
74 |
+
return;
|
75 |
+
}
|
|
|
|
|
76 |
|
77 |
+
$token = $_GET['token'];
|
78 |
+
$payer_id = $_GET['PayerID'];
|
79 |
|
80 |
+
try {
|
81 |
+
$checkout_details = $this->getCheckoutDetails( $token );
|
82 |
+
} catch( PayPal_API_Exception $e ) {
|
83 |
+
wc_add_notice( __( 'Sorry, an error occurred while trying to retrieve your information from PayPal. Please try again.', 'woocommerce-gateway-paypal-express-checkout' ), 'error' );
|
84 |
+
return;
|
85 |
+
} catch( PayPal_Missing_Session_Exception $e ) {
|
86 |
+
wc_add_notice( __( 'Your PayPal checkout session has expired. Please check out again.', 'woocommerce-gateway-paypal-express-checkout' ), 'error' );
|
87 |
+
return;
|
88 |
+
}
|
89 |
+
|
90 |
+
if ( $this->session_has_expired( $token ) ) {
|
91 |
+
wc_add_notice( __( 'Your PayPal checkout session has expired. Please check out again.', 'woocommerce-gateway-paypal-express-checkout' ), 'error' );
|
92 |
+
return;
|
93 |
+
}
|
94 |
|
95 |
+
$session = WC()->session->paypal;
|
96 |
+
$session->checkout_completed = true;
|
97 |
+
$session->payerID = $payer_id;
|
98 |
|
99 |
+
WC()->session->paypal = $session;
|
100 |
+
|
101 |
+
if ( $session->using_ppc ) {
|
102 |
+
WC()->session->chosen_payment_method = 'ppec_paypal_credit';
|
103 |
+
} else {
|
104 |
+
WC()->session->chosen_payment_method = 'ppec_paypal';
|
105 |
+
}
|
106 |
|
107 |
+
if ( 'order' == $session->leftFrom && $session->order_id ) {
|
108 |
+
// Try to complete the payment now.
|
109 |
try {
|
110 |
+
$order_id = $session->order_id;
|
111 |
+
$payment_details = $this->completePayment( $order_id, $session->token, $session->payerID );
|
112 |
+
$transaction_id = $payment_details->payments[0]->transaction_id;
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
+
// TODO: Handle things like eChecks, giropay, etc.
|
115 |
+
$order = wc_get_order( $order_id );
|
116 |
+
$order->payment_complete( $transaction_id );
|
117 |
+
$order->add_order_note( sprintf( __( 'PayPal transaction completed; transaction ID = %s', 'woocommerce-gateway-paypal-express-checkout' ), $transaction_id ) );
|
118 |
+
$order->reduce_order_stock();
|
119 |
+
WC()->cart->empty_cart();
|
120 |
+
unset( WC()->session->paypal );
|
121 |
|
122 |
+
wp_safe_redirect( $order->get_checkout_order_received_url() );
|
123 |
+
exit;
|
124 |
|
125 |
+
} catch( PayPal_Missing_Session_Exception $e ) {
|
126 |
|
127 |
+
// For some reason, our session data is missing. Generally,
|
128 |
+
// if we've made it this far, this shouldn't happen.
|
129 |
+
wc_add_notice( __( 'Sorry, an error occurred while trying to process your payment. Please try again.', 'woocommerce-gateway-paypal-express-checkout' ), 'error' );
|
|
|
|
|
130 |
|
131 |
+
} catch( PayPal_API_Exception $e ) {
|
132 |
+
|
133 |
+
// Did we get a 10486 or 10422 back from PayPal? If so,
|
134 |
+
// this means we need to send the buyer back over to PayPal
|
135 |
+
// to have them pick out a new funding method.
|
136 |
+
$need_to_redirect_back = false;
|
137 |
+
foreach ( $e->errors as $error ) {
|
138 |
+
if ( '10486' == $error->error_code || '10422' == $error->error_code ) {
|
139 |
+
$need_to_redirect_back = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
}
|
141 |
+
}
|
142 |
|
143 |
+
if ( $need_to_redirect_back ) {
|
144 |
+
$settings = wc_gateway_ppec()->settings->loadSettings();
|
145 |
+
$session->checkout_completed = false;
|
146 |
+
$session->leftFrom = 'order';
|
147 |
+
$session->order_id = $order_id;
|
148 |
+
WC()->session->paypal = $session;
|
149 |
+
wp_safe_redirect( $settings->getPayPalRedirectUrl( $session->token, true ) );
|
150 |
+
exit;
|
151 |
+
} else {
|
152 |
+
$final_output = '<ul>';
|
153 |
+
foreach ( $e->errors as $error ) {
|
154 |
+
$final_output .= '<li>' . __( $error->maptoBuyerFriendlyError(), 'woocommerce-gateway-paypal-express-checkout' ) . '</li>';
|
|
|
|
|
|
|
|
|
155 |
}
|
156 |
+
$final_output .= '</ul>';
|
157 |
+
wc_add_notice( __( 'Payment error:', 'woocommerce-gateway-paypal-express-checkout' ) . $final_output, 'error' );
|
158 |
+
return;
|
159 |
}
|
160 |
}
|
161 |
}
|
272 |
* @return array Available gateways
|
273 |
*/
|
274 |
public function maybe_disable_other_gateways( $gateways ) {
|
|
|
|
|
275 |
// Unset all other gateways after checking out from cart.
|
276 |
+
if ( $this->has_active_session() ) {
|
277 |
foreach ( $gateways as $id => $gateway ) {
|
278 |
if ( 'ppec_paypal' !== $id ) {
|
279 |
unset( $gateways[ $id ] );
|
305 |
return $gateways;
|
306 |
}
|
307 |
|
308 |
+
/**
|
309 |
+
* When cart based Checkout with PPEC is in effect, we need to include
|
310 |
+
* a Cancel button on the checkout form to give the user a means to throw
|
311 |
+
* away the session provided and possibly select a different payment
|
312 |
+
* gateway.
|
313 |
+
*
|
314 |
+
* @since 1.0.0
|
315 |
+
*
|
316 |
+
* @return void
|
317 |
+
*/
|
318 |
+
public function maybe_render_cancel_link() {
|
319 |
+
if ( $this->has_active_session() ) {
|
320 |
+
printf(
|
321 |
+
'<a href="%s" class="wc-gateway-ppec-cancel">%s</a>',
|
322 |
+
esc_url( add_query_arg( 'wc-gateway-ppec-clear-session', true, WC()->cart->get_cart_url() ) ),
|
323 |
+
esc_html__( 'Cancel', 'woocommerce-gateway-paypal-express-checkout' )
|
324 |
+
);
|
325 |
+
}
|
326 |
+
}
|
327 |
+
|
328 |
+
public function maybe_cancel_checkout_with_paypal() {
|
329 |
+
if ( is_cart() && ! empty( $_GET['wc-gateway-ppec-clear-session'] ) ) {
|
330 |
+
$this->maybe_clear_session_data();
|
331 |
+
wc_add_notice( __( 'You have cancelled Checkout with PayPal. Please try to process your order again.', 'woocommerce-gateway-paypal-express-checkout' ), 'notice' );
|
332 |
+
}
|
333 |
+
}
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Used when cart based Checkout with PayPal is in effect. Hooked to woocommerce_cart_emptied
|
337 |
+
* Also called by WC_PayPal_Braintree_Loader::possibly_cancel_checkout_with_paypal
|
338 |
+
*
|
339 |
+
* @since 1.0.0
|
340 |
+
*/
|
341 |
+
public function maybe_clear_session_data() {
|
342 |
+
if ( $this->has_active_session() ) {
|
343 |
+
unset( WC()->session->paypal );
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
/**
|
348 |
+
* Checks whether session with passed token has expired.
|
349 |
+
*
|
350 |
+
* @since 1.0.0
|
351 |
+
*
|
352 |
+
* @param string $token Token
|
353 |
+
*
|
354 |
+
* @return bool
|
355 |
+
*/
|
356 |
+
public function session_has_expired( $token ) {
|
357 |
+
$session = WC()->session->paypal;
|
358 |
+
|
359 |
+
return (
|
360 |
+
! $session
|
361 |
+
||
|
362 |
+
! is_a( $session, 'WC_Gateway_PPEC_Session_Data' )
|
363 |
+
||
|
364 |
+
$session->expiry_time < time()
|
365 |
+
||
|
366 |
+
$token !== $session->token
|
367 |
+
);
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Checks whether there's active session from cart-based checkout with PPEC.
|
372 |
+
*
|
373 |
+
* @since 1.0.0
|
374 |
+
*
|
375 |
+
* @return bool Returns true if PPEC session exists and still valid
|
376 |
+
*/
|
377 |
+
public function has_active_session() {
|
378 |
+
$session = WC()->session->paypal;
|
379 |
+
|
380 |
+
return ( is_a( $session, 'WC_Gateway_PPEC_Session_Data' ) && $session->payerID && $session->expiry_time > time() );
|
381 |
+
}
|
382 |
+
|
383 |
+
/**
|
384 |
+
* Get token from session.
|
385 |
+
*
|
386 |
+
* @since 1.0.0
|
387 |
+
*
|
388 |
+
* @return string Token from session
|
389 |
+
*/
|
390 |
+
public function get_token_from_session() {
|
391 |
+
$token = '';
|
392 |
+
$session = WC()->session->paypal;
|
393 |
+
|
394 |
+
if ( is_a( $session, 'WC_Gateway_PPEC_Session_Data' ) && $session->token ) {
|
395 |
+
$token = $session->token;
|
396 |
+
}
|
397 |
+
|
398 |
+
return $token;
|
399 |
+
}
|
400 |
+
|
401 |
public function enablePayPalCredit( $enable = true ) {
|
402 |
$this->_enablePayPalCredit = $enable;
|
403 |
}
|
496 |
}
|
497 |
}
|
498 |
|
499 |
+
/**
|
500 |
+
* Get return URL.
|
501 |
+
*
|
502 |
+
* The URL to return from express checkout.
|
503 |
+
*
|
504 |
+
* @return string Return URL
|
505 |
+
*/
|
506 |
+
protected function get_return_url() {
|
507 |
+
return add_query_arg( 'woo-paypal-return', 'true', WC()->cart->get_checkout_url() );
|
|
|
|
|
|
|
508 |
}
|
509 |
|
510 |
+
/**
|
511 |
+
* Get cancel URL.
|
512 |
+
*
|
513 |
+
* The URL to return when canceling the express checkout.
|
514 |
+
*
|
515 |
+
* @return string Cancel URL
|
516 |
+
*/
|
517 |
+
protected function get_cancel_url() {
|
518 |
+
return add_query_arg( 'woo-paypal-cancel', 'true', WC()->cart->get_cart_url() );
|
|
|
|
|
|
|
519 |
}
|
520 |
|
521 |
+
public function start_checkout_from_cart() {
|
522 |
|
523 |
wc_gateway_ppec()->cart->loadCartDetails();
|
524 |
|
545 |
$params['BRANDNAME'] = $brand_name;
|
546 |
}
|
547 |
|
548 |
+
$params['RETURNURL'] = $this->get_return_url();
|
549 |
+
$params['CANCELURL'] = $this->get_cancel_url();
|
550 |
|
551 |
if ( $this->_requestBillingAgreement ) {
|
552 |
$params['BILLINGTYPE'] = 'MerchantInitiatedBilling';
|
571 |
}
|
572 |
}
|
573 |
|
574 |
+
public function start_checkout_from_checkout( $order_id, $use_ppc = false ) {
|
575 |
|
576 |
wc_gateway_ppec()->cart->loadOrderDetails( $order_id );
|
577 |
|
606 |
$params['BRANDNAME'] = $brand_name;
|
607 |
}
|
608 |
|
609 |
+
$params['RETURNURL'] = $this->get_return_url();
|
610 |
+
$params['CANCELURL'] = $this->get_cancel_url();
|
611 |
|
612 |
if ( $this->_requestBillingAgreement ) {
|
613 |
$params['BILLINGTYPE'] = 'MerchantInitiatedBilling';
|
includes/functions.php
CHANGED
@@ -4,7 +4,7 @@ function woo_pp_start_checkout() {
|
|
4 |
$checkout = wc_gateway_ppec()->checkout;
|
5 |
|
6 |
try {
|
7 |
-
$redirect_url = $checkout->
|
8 |
wp_safe_redirect( $redirect_url );
|
9 |
exit;
|
10 |
} catch( PayPal_API_Exception $e ) {
|
4 |
$checkout = wc_gateway_ppec()->checkout;
|
5 |
|
6 |
try {
|
7 |
+
$redirect_url = $checkout->start_checkout_from_cart();
|
8 |
wp_safe_redirect( $redirect_url );
|
9 |
exit;
|
10 |
} catch( PayPal_API_Exception $e ) {
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: automattic, woothemes, akeda, allendav, slash1andy, woosteve, spra
|
|
3 |
Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal
|
4 |
Requires at least: 4.4
|
5 |
Tested up to: 4.4
|
6 |
-
Stable tag: 0.
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
@@ -80,5 +80,9 @@ New feature requests and bugs reports can be made in the plugin forum.
|
|
80 |
|
81 |
== Changelog ==
|
82 |
|
|
|
|
|
|
|
|
|
83 |
= 0.1.0 =
|
84 |
* Beta release
|
3 |
Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal
|
4 |
Requires at least: 4.4
|
5 |
Tested up to: 4.4
|
6 |
+
Stable tag: 0.2.0
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
80 |
|
81 |
== Changelog ==
|
82 |
|
83 |
+
= 0.2.0 =
|
84 |
+
* Fix - Add cancel link on checkout page when session for PPEC is active
|
85 |
+
* Fix - In-context mini browser keeps spinning because failure xhr response is not handled properly
|
86 |
+
|
87 |
= 0.1.0 =
|
88 |
* Beta release
|
woocommerce-gateway-paypal-express-checkout.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WooCommerce PayPal Express Checkout Gateway
|
4 |
* Plugin URI: https://woothemes.com
|
5 |
* Description: A payment gateway for PayPal Express Checkout ( https://www.paypal.com/us/webapps/mpp/express-checkout ). Requires WC 2.5+
|
6 |
-
* Version: 0.
|
7 |
* Author: Automattic/WooCommerce
|
8 |
* Author URI: https://woocommerce.com
|
9 |
* Copyright: © 2016 WooCommerce / PayPal.
|
@@ -36,7 +36,7 @@ function wc_gateway_ppec() {
|
|
36 |
if ( ! isset( $plugin ) ) {
|
37 |
require_once( 'includes/class-wc-gateway-ppec-plugin.php' );
|
38 |
|
39 |
-
$plugin = new WC_Gateway_PPEC_Plugin( __FILE__, '0.
|
40 |
}
|
41 |
|
42 |
return $plugin;
|
3 |
* Plugin Name: WooCommerce PayPal Express Checkout Gateway
|
4 |
* Plugin URI: https://woothemes.com
|
5 |
* Description: A payment gateway for PayPal Express Checkout ( https://www.paypal.com/us/webapps/mpp/express-checkout ). Requires WC 2.5+
|
6 |
+
* Version: 0.2.0
|
7 |
* Author: Automattic/WooCommerce
|
8 |
* Author URI: https://woocommerce.com
|
9 |
* Copyright: © 2016 WooCommerce / PayPal.
|
36 |
if ( ! isset( $plugin ) ) {
|
37 |
require_once( 'includes/class-wc-gateway-ppec-plugin.php' );
|
38 |
|
39 |
+
$plugin = new WC_Gateway_PPEC_Plugin( __FILE__, '0.2.0' );
|
40 |
}
|
41 |
|
42 |
return $plugin;
|