Skip to content

Commit

Permalink
Express Checkout - Invalid Token, ref #337
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Apr 28, 2017
1 parent e1e0ad6 commit cca6be2
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 424 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function ec_get_checkout_url($action) {
}

public function ec_is_express_checkout() {
return isset(WC()->session->paypal_express_checkout);
$paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' );
return isset($paypal_express_checkout);
}

public function ec_notice_count($notice_type = '') {
Expand All @@ -67,7 +68,7 @@ public function ec_redirect_after_checkout() {
'redirect' => $this->ec_get_checkout_url('set_express_checkout'),
);
if (isset($_POST['terms']) && wc_get_page_id('terms') > 0) {
WC()->session->paypal_express_terms = 1;
WC()->session->set( 'paypal_express_terms', 1);
}
if (is_ajax()) {
if ($this->ec_is_version_gte_2_4()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function buy_now_button() {

public function angelleye_paypal_express_checkout_redirect_to_paypal() {
try {
WC()->session->post_data = $_POST;
WC()->session->set( 'post_data', $_POST);
if (isset($_POST['payment_method']) && 'paypal_express' === $_POST['payment_method'] && $this->function_helper->ec_notice_count('error') == 0) {
$this->function_helper->ec_redirect_after_checkout();
}
Expand All @@ -150,7 +150,7 @@ public function add_to_cart_redirect($url = null) {
if (isset($_REQUEST['express_checkout']) || isset($_REQUEST['express_checkout_x'])) {
wc_clear_notices();
if( isset($_POST['wc-paypal_express-new-payment-method']) && $_POST['wc-paypal_express-new-payment-method'] = 'on' ) {
WC()->session->ec_save_to_account = 'on';
WC()->session->set( 'ec_save_to_account', 'on');
}
$url = esc_url_raw(add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/'))));
}
Expand All @@ -162,11 +162,9 @@ public function add_to_cart_redirect($url = null) {

public function ec_get_session_data($key = '') {
try {
$session_data = null;
if (empty($key)) {
$session_data = WC()->session->paypal_express_checkout;
} elseif (isset(WC()->session->paypal_express_checkout[$key])) {
$session_data = WC()->session->paypal_express_checkout[$key];
$session_data = WC()->session->get( 'paypal_express_checkout' );
if (isset($session_data[$key])) {
$session_data = $session_data[$key];
}
return $session_data;
} catch (Exception $ex) {
Expand All @@ -192,12 +190,10 @@ public function ec_set_checkout_post_data() {
$_POST['billing_' . $field] = $value;
}
}
$order_note = WC()->session->post_data['order_comments'];
if (!empty($order_note)) {
$_POST['order_comments'] = $order_note;
}
if( !empty(WC()->session->post_data) ) {
foreach (WC()->session->post_data as $key => $value) {
$post_data = WC()->session->get( 'post_data' );
$_POST['order_comments'] = isset($post_data['order_comments']) ? $post_data['order_comments'] : '';
if( !empty($post_data) ) {
foreach ($post_data as $key => $value) {
$_POST[$key] = $value;
}
}
Expand Down Expand Up @@ -277,9 +273,10 @@ public function ec_disable_gateways($gateways) {

public function ec_add_body_class($classes) {
try {
$paypal_express_terms = WC()->session->get( 'paypal_express_terms' );
if ($this->ec_is_checkout() && $this->function_helper->ec_is_express_checkout()) {
$classes[] = 'express-checkout';
if ($this->show_on_checkout && isset(WC()->session->paypal_express_terms)) {
if ($this->show_on_checkout && isset($paypal_express_terms)) {
$classes[] = 'express-hide-terms';
}
}
Expand All @@ -306,7 +303,8 @@ public function ec_terms_express_checkout($checked_default) {
if (!$this->ec_is_available() || !$this->function_helper->ec_is_express_checkout()) {
return $checked_default;
}
if ($this->show_on_checkout && isset(WC()->session->paypal_express_terms)) {
$paypal_express_terms = WC()->session->get( 'paypal_express_terms' );
if ($this->show_on_checkout && isset($paypal_express_terms)) {
$checked_default = true;
}
return $checked_default;
Expand All @@ -327,8 +325,9 @@ public function ec_is_checkout() {
}

public function ec_order_received_text($text, $order) {
if ($order && $order->has_status('on-hold') && isset(WC()->session->held_order_received_text)) {
$text = WC()->session->held_order_received_text;
$held_order_received_text = WC()->session->get( 'held_order_received_text' );
if ($order && $order->has_status('on-hold') && isset($held_order_received_text)) {
$text = $held_order_received_text;
unset(WC()->session->held_order_received_text);
}
return $text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public function __construct($gateway) {

public function angelleye_redirect() {
if (!empty($this->paypal_response['L_ERRORCODE0']) && $this->paypal_response['L_ERRORCODE0'] == '10486') {
$payPalURL = $this->PAYPAL_URL . WC()->session->paypal_express_checkout['token'];
$paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' );
$token = isset($paypal_express_checkout['token']) ? $paypal_express_checkout['token'] : '';
$payPalURL = $this->PAYPAL_URL . $token;
wp_redirect($payPalURL, 302);
exit;
}
Expand Down Expand Up @@ -135,16 +137,17 @@ public function angelleye_get_express_checkout_details() {
$this->paypal_response = $this->paypal->GetExpresscheckoutDetails($token);
$this->angelleye_write_paypal_request_log($paypal_action_name = 'GetExpresscheckoutDetails');
if ($this->response_helper->ec_is_response_success($this->paypal_response)) {
WC()->session->paypal_express_checkout = array(
$paypal_express_checkout = array(
'token' => $token,
'shipping_details' => $this->response_helper->ec_get_shipping_details($this->paypal_response),
'order_note' => $this->response_helper->ec_get_note_text($this->paypal_response),
'payer_id' => $this->response_helper->ec_get_payer_id($this->paypal_response),
'ExpresscheckoutDetails' => $this->paypal_response
);
WC()->session->shiptoname = $this->paypal_response['FIRSTNAME'] . ' ' . $this->paypal_response['LASTNAME'];
WC()->session->payeremail = $this->paypal_response['EMAIL'];
WC()->session->chosen_payment_method = get_class($this->gateway);
WC()->session->set( 'paypal_express_checkout', $paypal_express_checkout );
WC()->session->set( 'shiptoname', $this->paypal_response['FIRSTNAME'] . ' ' . $this->paypal_response['LASTNAME'] );
WC()->session->set( 'payeremail', $this->paypal_response['EMAIL'] );
WC()->session->set( 'chosen_payment_method', $this->gateway->id );
if ($this->angelleye_ec_force_to_display_checkout_page()) {
wp_redirect(WC()->cart->get_checkout_url());
exit();
Expand All @@ -171,7 +174,8 @@ public function angelleye_do_express_checkout_payment() {
if( $order->get_total() > 0 ) {
$this->angelleye_do_express_checkout_payment_request();
} else {
$this->paypal_response = $this->paypal->CreateBillingAgreement(WC()->session->paypal_express_checkout['token']);
$paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' );
$this->paypal_response = $this->paypal->CreateBillingAgreement($paypal_express_checkout['token']);
}
$this->angelleye_add_order_note($order);
$this->angelleye_add_extra_order_meta($order);
Expand Down Expand Up @@ -274,9 +278,10 @@ public function angelleye_do_express_checkout_payment_request() {

}
$this->order_param = $this->gateway_calculation->order_calculation($this->confirm_order_id);
$paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' );
$DECPFields = array(
'token' => WC()->session->paypal_express_checkout['token'],
'payerid' => (!empty(WC()->session->paypal_express_checkout['payer_id']) ) ? WC()->session->paypal_express_checkout['payer_id'] : null,
'token' => $paypal_express_checkout['token'],
'payerid' => (!empty($paypal_express_checkout['payer_id']) ) ? $paypal_express_checkout['payer_id'] : null,
'returnfmfdetails' => 1,
'buyermarketingemail' => '',
'allowedpaymentmethod' => ''
Expand Down Expand Up @@ -312,7 +317,8 @@ public function angelleye_do_express_checkout_payment_request() {
$Payment['taxamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['taxamt']);
$Payment['shippingamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['shippingamt']);
$Payment['itemamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['itemamt']);
$REVIEW_RESULT = !empty(WC()->session->paypal_express_checkout['ExpresscheckoutDetails']) ? WC()->session->paypal_express_checkout['ExpresscheckoutDetails'] : array();

$REVIEW_RESULT = !empty($paypal_express_checkout['ExpresscheckoutDetails']) ? $paypal_express_checkout['ExpresscheckoutDetails'] : array();
$PaymentRedeemedOffers = array();
if ((isset($REVIEW_RESULT) && !empty($REVIEW_RESULT)) && isset($REVIEW_RESULT['WALLETTYPE0'])) {
$i = 0;
Expand Down Expand Up @@ -354,7 +360,7 @@ public function angelleye_do_express_checkout_payment_request() {
'shiptostate' => $shipping_state,
'shiptozip' => $shipping_postcode,
'shiptocountrycode' => $shipping_country,
'shiptophonenum' => ( WC()->session->post_data['billing_phone'] ) ? WC()->session->post_data['billing_phone'] : '',
'shiptophonenum' => ( $paypal_express_checkout['billing_phone'] ) ? $paypal_express_checkout['billing_phone'] : '',
);
array_push($Payments, $Payment);
}
Expand Down Expand Up @@ -472,7 +478,8 @@ public function angelleye_add_billing_agreement_param($PayPalRequestData, $token
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
$product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key);
$_paypal_billing_agreement = get_post_meta($product_id, '_paypal_billing_agreement', true);
if ($_paypal_billing_agreement == 'yes' || ( isset(WC()->session->ec_save_to_account) && WC()->session->ec_save_to_account == 'on')) {
$ec_save_to_account = WC()->session->get( 'ec_save_to_account' );
if ($_paypal_billing_agreement == 'yes' || ( isset($ec_save_to_account) && $ec_save_to_account == 'on')) {
$BillingAgreements = array();
$Item = array(
'l_billingtype' => '',
Expand Down Expand Up @@ -570,17 +577,19 @@ public function update_payment_status_by_paypal_responce($orderid, $result) {
public function angelleye_add_extra_order_meta($order) {
$order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id();
if (!empty($this->gateway->payment_action) && $this->gateway->payment_action != 'Sale') {
$payment_order_meta = array('_transaction_id' => $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'], '_payment_action' => $this->gateway->payment_action, '_express_checkout_token' => WC()->session->paypal_express_checkout['token'], '_first_transaction_id' => $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']);
$paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' );
$payment_order_meta = array('_transaction_id' => $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'], '_payment_action' => $this->gateway->payment_action, '_express_checkout_token' => $paypal_express_checkout['token'], '_first_transaction_id' => $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']);
AngellEYE_Utility::angelleye_add_order_meta($order_id, $payment_order_meta);
}
}

public function angelleye_add_order_note($order) {
if (!empty(WC()->session->paypal_express_checkout['ExpresscheckoutDetails']['PAYERSTATUS'])) {
$order->add_order_note(sprintf(__('Payer Status: %s', 'paypal-for-woocommerce'), '<strong>' . WC()->session->paypal_express_checkout['ExpresscheckoutDetails']['PAYERSTATUS'] . '</strong>'));
$paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' );
if (!empty($paypal_express_checkout['ExpresscheckoutDetails']['PAYERSTATUS'])) {
$order->add_order_note(sprintf(__('Payer Status: %s', 'paypal-for-woocommerce'), '<strong>' . $paypal_express_checkout['ExpresscheckoutDetails']['PAYERSTATUS'] . '</strong>'));
}
if (!empty(WC()->session->paypal_express_checkout['ExpresscheckoutDetails']['ADDRESSSTATUS'])) {
$order->add_order_note(sprintf(__('Address Status: %s', 'paypal-for-woocommerce'), '<strong>' . WC()->session->paypal_express_checkout['ExpresscheckoutDetails']['ADDRESSSTATUS'] . '</strong>'));
if (!empty($paypal_express_checkout['ExpresscheckoutDetails']['ADDRESSSTATUS'])) {
$order->add_order_note(sprintf(__('Address Status: %s', 'paypal-for-woocommerce'), '<strong>' . $paypal_express_checkout['ExpresscheckoutDetails']['ADDRESSSTATUS'] . '</strong>'));
}
}

Expand Down Expand Up @@ -834,11 +843,12 @@ public function angelleye_ec_get_customer_email_address($order_id) {
if (!empty($_billing_email)) {
$this->user_email_address = $_billing_email;
} else {
$this->user_email_address = WC()->session->payeremail;
$payeremail = WC()->session->get( 'payeremail' );
$this->user_email_address = $payeremail;
if ($old_wc) {
update_post_meta($order_id, '_billing_email', WC()->session->payeremail);
update_post_meta($order_id, '_billing_email', $payeremail);
} else {
update_post_meta( $order->get_id(), '_billing_email', WC()->session->payeremail );
update_post_meta( $order->get_id(), '_billing_email', $payeremail );
}
}
}
Expand Down Expand Up @@ -962,12 +972,13 @@ public function angelleye_ec_force_to_display_checkout_page() {
if ($this->must_create_account) {
return apply_filters('angelleye_ec_force_to_display_checkout_page', true);
}
$paypal_express_terms = WC()->session->get( 'paypal_express_terms' );
if (wc_get_page_id('terms') > 0 && apply_filters('woocommerce_checkout_show_terms', true)) {
if ($this->disable_term) {
return apply_filters('angelleye_ec_force_to_display_checkout_page', false);
} elseif (isset($_POST['terms']) && $_POST['terms'] == 'on') {
return apply_filters('angelleye_ec_force_to_display_checkout_page', false);
} elseif (!empty(WC()->session->paypal_express_terms && WC()->session->paypal_express_terms == true)) {
} elseif (!empty($paypal_express_terms && $paypal_express_terms == true)) {
return apply_filters('angelleye_ec_force_to_display_checkout_page', false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions classes/wc-gateway-braintree-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public function process_payment($order_id) {
'redirect' => $this->get_return_url($order)
);
} else {
WC()->session->reload_checkout = true;
WC()->session->set( 'reload_checkout', true );
return array(
'result' => 'fail',
'redirect' => ''
Expand Down Expand Up @@ -1344,7 +1344,7 @@ public function subscription_process_payment($order_id) {
exit;
}
} else {
WC()->session->reload_checkout = true;
WC()->session->set( 'reload_checkout', true );
return array(
'result' => 'fail',
'redirect' => ''
Expand Down
Loading

0 comments on commit cca6be2

Please sign in to comment.