function receipt_page($order_id) { global $woocommerce; $order = new WC_Order($order_id); WC()->session->ppp_order_id = $order_id; $PaymentData = AngellEYE_Gateway_Paypal::calculate($order, true); $payment = new Payment(); $payment->setId(WC()->session->paymentId); $patchReplace = new \PayPal\Api\Patch(); $patchReplace->setOp('replace')->setPath('/transactions/0/amount')->setValue(json_decode('{ "total": "' . AngellEYE_Gateway_Paypal::number_format($order->get_total()) . '", "currency": "' . get_woocommerce_currency() . '", "details": { "subtotal": "' . $PaymentData['itemamt'] . '", "shipping": "' . $PaymentData['shippingamt'] . '", "tax":"' . $PaymentData['taxamt'] . '" } }')); $patchRequest = new \PayPal\Api\PatchRequest(); if ($order->needs_shipping_address() && !empty($order->shipping_country)) { //add shipping info $patchAdd = new \PayPal\Api\Patch(); $patchAdd->setOp('add')->setPath('/transactions/0/item_list/shipping_address')->setValue(json_decode('{ "recipient_name": "' . $order->shipping_first_name . ' ' . $order->shipping_last_name . '", "line1": "' . $order->shipping_address_1 . '", "city": "' . $order->shipping_city . '", "state": "' . $order->shipping_state . '", "postal_code": "' . $order->shipping_postcode . '", "country_code": "' . $order->shipping_country . '" }')); $patchRequest->setPatches(array($patchAdd, $patchReplace)); } else { $patchRequest->setPatches(array($patchReplace)); } try { $result = $payment->update($patchRequest, $this->getAuth()); $this->add_log(print_r($payment, true)); if ($result == true) { } ?> <script src="https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js"type="text/javascript"></script> <script> jQuery(document).ready(function () { jQuery.blockUI({ message: "<?php echo esc_js(__('Thank you for your order. We are now redirecting you to PayPal to make payment.', 'paypal-for-woocommerce')); ?> ", baseZ: 99999, overlayCSS: { background: "#fff", opacity: 0.6 }, css: { padding: "20px", zindex: "9999999", textAlign: "center", color: "#555", border: "3px solid #aaa", backgroundColor: "#fff", cursor: "wait", lineHeight: "24px" } }); PAYPAL.apps.PPP.doCheckout(); }); </script> <?php } catch (PayPal\Exception\PayPalConnectionException $ex) { wc_add_notice(__("Error processing checkout. Please try again. ", 'paypal-for-woocommerce'), 'error'); $this->add_log($ex->getData()); wp_redirect($woocommerce->cart->get_cart_url()); exit; } catch (Exception $ex) { wc_add_notice(__("Error processing checkout. Please try again. ", 'paypal-for-woocommerce'), 'error'); $this->add_log($ex->getData()); wp_redirect($woocommerce->cart->get_cart_url()); exit; } }
/** * Process a refund if supported * @param int $order_id * @param float $amount * @param string $reason * @return bool|wp_error True or false based on success, or a WP_Error object */ public function process_refund($order_id, $amount = null, $reason = '') { $order = wc_get_order($order_id); $this->add_log('Begin Refund'); $this->add_log('Order: ' . print_r($order, true)); $this->add_log('Transaction ID: ' . print_r($order->get_transaction_id(), true)); $this->add_log('API Username: '******'API Password: '******'API Signature: ' . print_r($this->api_signature, true)); if (!$order || !$order->get_transaction_id() || !$this->api_username || !$this->api_password || !$this->api_signature) { return false; } $this->add_log('Include Class Request'); /* * Check if the PayPal class has already been established. */ if (!class_exists('Angelleye_PayPal')) { require_once PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php'; } /* * Create PayPal object. */ $PayPalConfig = array('Sandbox' => $this->testmode == 'yes' ? TRUE : FALSE, 'APIUsername' => $this->api_username, 'APIPassword' => $this->api_password, 'APISignature' => $this->api_signature); $PayPal = new Angelleye_PayPal($PayPalConfig); if ($reason) { if (255 < strlen($reason)) { $reason = substr($reason, 0, 252) . '...'; } $reason = html_entity_decode($reason, ENT_NOQUOTES, 'UTF-8'); } // Prepare request arrays $RTFields = array('transactionid' => $order->get_transaction_id(), 'payerid' => '', 'invoiceid' => '', 'refundtype' => $order->get_total() == $amount ? 'Full' : 'Partial', 'amt' => AngellEYE_Gateway_Paypal::number_format($amount), 'currencycode' => $order->get_order_currency(), 'note' => $reason, 'retryuntil' => '', 'refundsource' => '', 'merchantstoredetail' => '', 'refundadvice' => '', 'refunditemdetails' => '', 'msgsubid' => '', 'storeid' => '', 'terminalid' => ''); $PayPalRequestData = array('RTFields' => $RTFields); $this->add_log('Refund Request: ' . print_r($PayPalRequestData, true)); // Pass data into class for processing with PayPal and load the response array into $PayPalResult $PayPalResult = $PayPal->RefundTransaction($PayPalRequestData); /** * cURL Error Handling #146 * @since 1.1.8 */ AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'RefundTransaction', $gateway = 'PayPal Express Checkout', $this->error_email_notify); $this->add_log('Refund Information: ' . print_r($PayPalResult, true)); if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) { $order->add_order_note('Refund Transaction ID:' . $PayPalResult['REFUNDTRANSACTIONID']); $max_remaining_refund = wc_format_decimal($order->get_total() - $order->get_total_refunded()); if (!$max_remaining_refund > 0) { $order->update_status('refunded'); } if (ob_get_length()) { ob_end_clean(); } return true; } else { $ec_message = apply_filters('ae_ppec_refund_error_message', $PayPalResult['L_LONGMESSAGE0'], $PayPalResult['L_ERRORCODE0'], $PayPalResult); return new WP_Error('ec_refund-error', $ec_message); } }
/** * do_payment * * Process the PayFlow transaction with PayPal. * * @access public * @param mixed $order * @param mixed $card_number * @param mixed $card_exp * @param mixed $card_csc * @param string $centinelPAResStatus (default: '') * @param string $centinelEnrolled (default: '') * @param string $centinelCavv (default: '') * @param string $centinelEciFlag (default: '') * @param string $centinelXid (default: '') * @return void */ function do_payment($order, $card_number, $card_exp, $card_csc, $centinelPAResStatus = '', $centinelEnrolled = '', $centinelCavv = '', $centinelEciFlag = '', $centinelXid = '') { /* * Display message to user if session has expired. */ if (sizeof(WC()->cart->get_cart()) == 0) { $fc_session_expired = apply_filters('angelleye_fc_session_expired', sprintf(__('Sorry, your session has expired. <a href=%s>Return to homepage →</a>', 'paypal-for-woocommerce'), '"' . home_url() . '"'), $this); wc_add_notice($fc_session_expired, "error"); } /* * Check if the PayPal_PayFlow class has already been established. */ if (!class_exists('Angelleye_PayPal_PayFlow')) { require_once 'lib/angelleye/paypal-php-library/includes/paypal.class.php'; require_once 'lib/angelleye/paypal-php-library/includes/paypal.payflow.class.php'; } /** * Create PayPal_PayFlow object. */ $PayPalConfig = array('Sandbox' => $this->testmode == 'yes' ? true : false, 'APIUsername' => $this->paypal_user, 'APIPassword' => trim($this->paypal_password), 'APIVendor' => $this->paypal_vendor, 'APIPartner' => $this->paypal_partner); $PayPal = new Angelleye_PayPal_PayFlow($PayPalConfig); /** * Pulled from original Woo extension. */ if (empty($GLOBALS['wp_rewrite'])) { $GLOBALS['wp_rewrite'] = new WP_Rewrite(); } if ($this->debug) { $this->add_log($order->get_checkout_order_received_url()); } try { /** * Parameter set by original Woo. I can probably ditch this, but leaving it for now. */ $url = $this->testmode == 'yes' ? $this->testurl : $this->liveurl; /** * PayPal PayFlow Gateway Request Params */ $PayPalRequestData = array('tender' => 'C', 'trxtype' => $this->payment_action == 'Authorization' ? 'A' : 'S', 'acct' => $card_number, 'expdate' => $card_exp, 'amt' => AngellEYE_Gateway_Paypal::number_format($order->get_total()), 'currency' => get_woocommerce_currency(), 'dutyamt' => '', 'freightamt' => '', 'taxamt' => '', 'taxexempt' => '', 'comment1' => $order->customer_note ? substr(preg_replace("/[^A-Za-z0-9 ]/", "", $order->customer_note), 0, 256) : '', 'comment2' => '', 'cvv2' => $card_csc, 'recurring' => '', 'swipe' => '', 'orderid' => preg_replace("/[^0-9,.]/", "", $order->get_order_number()), 'orderdesc' => 'Order ' . $order->get_order_number() . ' on ' . get_bloginfo('name'), 'billtoemail' => $order->billing_email, 'billtophonenum' => '', 'billtofirstname' => $order->billing_first_name, 'billtomiddlename' => '', 'billtolastname' => $order->billing_last_name, 'billtostreet' => $order->billing_address_1 . ' ' . $order->billing_address_2, 'billtocity' => $order->billing_city, 'billtostate' => $order->billing_state, 'billtozip' => $order->billing_postcode, 'billtocountry' => $order->billing_country, 'origid' => '', 'custref' => '', 'custcode' => '', 'custip' => $this->get_user_ip(), 'invnum' => $this->invoice_id_prefix . str_replace("#", "", $order->get_order_number()), 'ponum' => '', 'starttime' => '', 'endtime' => '', 'securetoken' => '', 'partialauth' => '', 'authcode' => ''); /** * Shipping info */ if ($order->shipping_address_1) { $PayPalRequestData['SHIPTOFIRSTNAME'] = $order->shipping_first_name; $PayPalRequestData['SHIPTOLASTNAME'] = $order->shipping_last_name; $PayPalRequestData['SHIPTOSTREET'] = $order->shipping_address_1 . ' ' . $order->shipping_address_2; $PayPalRequestData['SHIPTOCITY'] = $order->shipping_city; $PayPalRequestData['SHIPTOSTATE'] = $order->shipping_state; $PayPalRequestData['SHIPTOCOUNTRY'] = $order->shipping_country; $PayPalRequestData['SHIPTOZIP'] = $order->shipping_postcode; } $PaymentData = AngellEYE_Gateway_Paypal::calculate($order, $this->send_items); $OrderItems = array(); if ($this->send_items) { $item_loop = 0; foreach ($PaymentData['order_items'] as $_item) { $Item['L_NUMBER' . $item_loop] = $_item['number']; $Item['L_NAME' . $item_loop] = $_item['name']; $Item['L_COST' . $item_loop] = $_item['amt']; $Item['L_QTY' . $item_loop] = $_item['qty']; if ($_item['number']) { $Item['L_SKU' . $item_loop] = $_item['number']; } $OrderItems = array_merge($OrderItems, $Item); $item_loop++; } } /** * Shipping/tax/item amount */ $PayPalRequestData['taxamt'] = $PaymentData['taxamt']; $PayPalRequestData['freightamt'] = $PaymentData['shippingamt']; $PayPalRequestData['ITEMAMT'] = $PaymentData['itemamt']; if ($this->send_items) { $PayPalRequestData = array_merge($PayPalRequestData, $OrderItems); } $PayPalResult = $PayPal->ProcessTransaction($PayPalRequestData); /** * cURL Error Handling #146 * @since 1.1.8 */ AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'do_payment', $gateway = 'PayPal Payments Pro 2.0 (PayFlow)', $this->error_email_notify); /** * Log results */ if ($this->debug) { $this->add_log('PayFlow Endpoint: ' . $PayPal->APIEndPoint); $this->add_log(print_r($PayPalResult, true)); } /** * Error check */ if (empty($PayPalResult['RAWRESPONSE'])) { $fc_empty_response = apply_filters('ae_pppf_paypal_response_empty_message', __('Empty PayPal response.', 'paypal-for-woocommerce'), $PayPalResult); throw new Exception($fc_empty_response); } /** * More logs */ if ($this->debug) { $this->add_log(add_query_arg('key', $order->order_key, add_query_arg('order', $order->id))); } /** * Check for errors or fraud filter warnings and proceed accordingly. */ if (isset($PayPalResult['RESULT']) && ($PayPalResult['RESULT'] == 0 || $PayPalResult['RESULT'] == 126)) { // Add order note if ($PayPalResult['RESULT'] == 126) { $order->add_order_note($PayPalResult['RESPMSG']); $order->add_order_note($PayPalResult['PREFPSMSG']); $order->add_order_note("The payment was flagged by a fraud filter, please check your PayPal Manager account to review and accept or deny the payment."); } else { $order->add_order_note(sprintf(__('PayPal Pro payment completed (PNREF: %s)', 'paypal-for-woocommerce'), $PayPalResult['PNREF'])); /* Checkout Note */ if (isset($_POST) && !empty($_POST['order_comments'])) { // Update post 37 $checkout_note = array('ID' => $order->id, 'post_excerpt' => $_POST['order_comments']); wp_update_post($checkout_note); } } /** * Add order notes for AVS result */ $avs_address_response_code = isset($PayPalResult['AVSADDR']) ? $PayPalResult['AVSADDR'] : ''; $avs_zip_response_code = isset($PayPalResult['AVSZIP']) ? $PayPalResult['AVSZIP'] : ''; $avs_response_order_note = __('Address Verification Result', 'paypal-for-woocommerce'); $avs_response_order_note .= "\n"; $avs_response_order_note .= sprintf(__('Address Match: %s', 'paypal-for-woocommerce'), $avs_address_response_code); $avs_response_order_note .= "\n"; $avs_response_order_note .= sprintf(__('Postal Match: %s', 'paypal-for-woocommerce'), $avs_zip_response_code); $order->add_order_note($avs_response_order_note); /** * Add order notes for CVV2 result */ $cvv2_response_code = isset($PayPalResult['CVV2MATCH']) ? $PayPalResult['CVV2MATCH'] : ''; $cvv2_response_order_note = __('Card Security Code Result', 'paypal-for-woocommerce'); $cvv2_response_order_note .= "\n"; $cvv2_response_order_note .= sprintf(__('CVV2 Match: %s', 'paypal-for-woocommerce'), $cvv2_response_code); $order->add_order_note($cvv2_response_order_note); // Payment complete //$order->add_order_note("PayPal Result".print_r($PayPalResult,true)); $order->payment_complete($PayPalResult['PNREF']); // Remove cart WC()->cart->empty_cart(); // Return thank you page redirect return array('result' => 'success', 'redirect' => $this->get_return_url($order)); } else { $order->update_status('failed', __('PayPal Pro payment failed. Payment was rejected due to an error: ', 'paypal-for-woocommerce') . '(' . $PayPalResult['RESULT'] . ') ' . '"' . $PayPalResult['RESPMSG'] . '"'); // Generate error message based on Error Display Type setting if ($this->error_display_type == 'detailed') { $fc_error_display_type = __('Payment error:', 'paypal-for-woocommerce') . ' ' . $PayPalResult['RESULT'] . '-' . $PayPalResult['RESPMSG']; } else { $fc_error_display_type = __('Payment error:', 'paypal-for-woocommerce') . ' There was a problem processing your payment. Please try another method.'; } $fc_error_display_type = apply_filters('ae_pppf_error_user_display_message', $fc_error_display_type, $PayPalResult['RESULT'], $PayPalResult['RESPMSG'], $PayPalResult); wc_add_notice($fc_error_display_type, "error"); // Notice admin if has any issue from PayPal if ($this->error_email_notify) { $admin_email = get_option("admin_email"); $message = __("PayFlow API call failed.", "paypal-for-woocommerce") . "\n\n"; $message .= __('Error Code: ', 'paypal-for-woocommerce') . $PayPalResult['RESULT'] . "\n"; $message .= __('Detailed Error Message: ', 'paypal-for-woocommerce') . $PayPalResult['RESPMSG']; $message .= isset($PayPalResult['PREFPSMSG']) && $PayPalResult['PREFPSMSG'] != '' ? ' - ' . $PayPalResult['PREFPSMSG'] . "\n" : "\n"; $message .= __('User IP: ', 'paypal-for-woocommerce') . $this->get_user_ip() . "\n"; $message .= __('Order ID: ') . $order->id . "\n"; $message .= __('Customer Name: ') . $order->billing_first_name . ' ' . $order->billing_last_name . "\n"; $message .= __('Customer Email: ') . $order->billing_email . "\n"; $message = apply_filters('ae_pppf_error_email_message', $message); $subject = apply_filters('ae_pppf_error_email_subject', "PayPal Pro Error Notification"); wp_mail($admin_email, $subject, $message); } return; } } catch (Exception $e) { $fc_connect_error = apply_filters('angelleye_fc_connect_error', __('Connection error:', 'paypal-for-woocommerce') . ': "' . $e->getMessage() . '"', $e); wc_add_notice($fc_connect_error, "error"); return; } }