fixed the indentation in includes/gateways/paypal/class-wc-gateway-paypal.php
This commit is contained in:
parent
0b13814aac
commit
bf81f45abc
|
@ -17,21 +17,21 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
|
||||
var $notify_url;
|
||||
|
||||
/**
|
||||
* Constructor for the gateway.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
* Constructor for the gateway.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->id = 'paypal';
|
||||
$this->icon = apply_filters( 'woocommerce_paypal_icon', WC()->plugin_url() . '/assets/images/icons/paypal.png' );
|
||||
$this->has_fields = false;
|
||||
$this->liveurl = 'https://www.paypal.com/cgi-bin/webscr';
|
||||
$this->id = 'paypal';
|
||||
$this->icon = apply_filters( 'woocommerce_paypal_icon', WC()->plugin_url() . '/assets/images/icons/paypal.png' );
|
||||
$this->has_fields = false;
|
||||
$this->liveurl = 'https://www.paypal.com/cgi-bin/webscr';
|
||||
$this->testurl = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
|
||||
$this->method_title = __( 'PayPal', 'woocommerce' );
|
||||
$this->notify_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_Paypal', home_url( '/' ) ) );
|
||||
$this->method_title = __( 'PayPal', 'woocommerce' );
|
||||
$this->notify_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_Paypal', home_url( '/' ) ) );
|
||||
|
||||
// Load the settings.
|
||||
$this->init_form_fields();
|
||||
|
@ -66,19 +66,19 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
add_action( 'woocommerce_api_wc_gateway_paypal', array( $this, 'check_ipn_response' ) );
|
||||
|
||||
if ( !$this->is_valid_for_use() ) $this->enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this gateway is enabled and available in the user's country
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function is_valid_for_use() {
|
||||
if ( ! in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB' ) ) ) ) return false;
|
||||
/**
|
||||
* Check if this gateway is enabled and available in the user's country
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function is_valid_for_use() {
|
||||
if ( ! in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB' ) ) ) ) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Panel Options
|
||||
|
@ -92,30 +92,30 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
<h3><?php _e( 'PayPal standard', 'woocommerce' ); ?></h3>
|
||||
<p><?php _e( 'PayPal standard works by sending the user to PayPal to enter their payment information.', 'woocommerce' ); ?></p>
|
||||
|
||||
<?php if ( $this->is_valid_for_use() ) : ?>
|
||||
<?php if ( $this->is_valid_for_use() ) : ?>
|
||||
|
||||
<table class="form-table">
|
||||
<?php
|
||||
// Generate the HTML For the settings form.
|
||||
$this->generate_settings_html();
|
||||
// Generate the HTML For the settings form.
|
||||
$this->generate_settings_html();
|
||||
?>
|
||||
</table><!--/.form-table-->
|
||||
|
||||
<?php else : ?>
|
||||
<div class="inline error"><p><strong><?php _e( 'Gateway Disabled', 'woocommerce' ); ?></strong>: <?php _e( 'PayPal does not support your store currency.', 'woocommerce' ); ?></p></div>
|
||||
<div class="inline error"><p><strong><?php _e( 'Gateway Disabled', 'woocommerce' ); ?></strong>: <?php _e( 'PayPal does not support your store currency.', 'woocommerce' ); ?></p></div>
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise Gateway Settings Form Fields
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function init_form_fields() {
|
||||
/**
|
||||
* Initialise Gateway Settings Form Fields
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function init_form_fields() {
|
||||
|
||||
$this->form_fields = array(
|
||||
$this->form_fields = array(
|
||||
'enabled' => array(
|
||||
'title' => __( 'Enable/Disable', 'woocommerce' ),
|
||||
'type' => 'checkbox',
|
||||
|
@ -231,7 +231,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
'description' => sprintf( __( 'Log PayPal events, such as IPN requests, inside <code>woocommerce/logs/paypal-%s.txt</code>', 'woocommerce' ), sanitize_file_name( wp_hash( 'paypal' ) ) ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal Args for passing to PP
|
||||
|
@ -411,14 +411,14 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
return $paypal_args;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Generate the paypal button link
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $order_id
|
||||
* @return string
|
||||
*/
|
||||
function generate_paypal_form( $order_id ) {
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $order_id
|
||||
* @return string
|
||||
*/
|
||||
function generate_paypal_form( $order_id ) {
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
|
||||
|
@ -446,15 +446,15 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
opacity: 0.6
|
||||
},
|
||||
css: {
|
||||
padding: "20px",
|
||||
zindex: "9999999",
|
||||
textAlign: "center",
|
||||
color: "#555",
|
||||
border: "3px solid #aaa",
|
||||
backgroundColor:"#fff",
|
||||
cursor: "wait",
|
||||
lineHeight: "24px",
|
||||
}
|
||||
padding: "20px",
|
||||
zindex: "9999999",
|
||||
textAlign: "center",
|
||||
color: "#555",
|
||||
border: "3px solid #aaa",
|
||||
backgroundColor:"#fff",
|
||||
cursor: "wait",
|
||||
lineHeight: "24px",
|
||||
}
|
||||
});
|
||||
jQuery("#submit_paypal_payment_form").click();
|
||||
' );
|
||||
|
@ -472,13 +472,13 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the payment and return the result
|
||||
*
|
||||
* @access public
|
||||
* @param int $order_id
|
||||
* @return array
|
||||
*/
|
||||
/**
|
||||
* Process the payment and return the result
|
||||
*
|
||||
* @access public
|
||||
* @param int $order_id
|
||||
* @return array
|
||||
*/
|
||||
function process_payment( $order_id ) {
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
|
@ -511,12 +511,12 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Output for the order received page.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
* Output for the order received page.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function receipt_page( $order ) {
|
||||
|
||||
echo '<p>'.__( 'Thank you - your order is now pending payment. You should be automatically redirected to PayPal to make payment.', 'woocommerce' ).'</p>';
|
||||
|
@ -530,7 +530,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
function check_ipn_request_is_valid() {
|
||||
|
||||
// Get url
|
||||
if ( $this->testmode == 'yes' )
|
||||
if ( $this->testmode == 'yes' )
|
||||
$paypal_adr = $this->testurl;
|
||||
else
|
||||
$paypal_adr = $this->liveurl;
|
||||
|
@ -538,44 +538,44 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Checking IPN response is valid via ' . $paypal_adr . '...' );
|
||||
|
||||
// Get recieved values from post data
|
||||
// Get recieved values from post data
|
||||
$received_values = array( 'cmd' => '_notify-validate' );
|
||||
$received_values += stripslashes_deep( $_POST );
|
||||
|
||||
// Send back post vars to paypal
|
||||
$params = array(
|
||||
'body' => $received_values,
|
||||
'sslverify' => false,
|
||||
'timeout' => 60,
|
||||
'httpversion' => '1.1',
|
||||
'user-agent' => 'WooCommerce/' . WC()->version
|
||||
);
|
||||
// Send back post vars to paypal
|
||||
$params = array(
|
||||
'body' => $received_values,
|
||||
'sslverify' => false,
|
||||
'timeout' => 60,
|
||||
'httpversion' => '1.1',
|
||||
'user-agent' => 'WooCommerce/' . WC()->version
|
||||
);
|
||||
|
||||
if ( 'yes' == $this->debug )
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'IPN Request: ' . print_r( $params, true ) );
|
||||
|
||||
// Post back to get a response
|
||||
$response = wp_remote_post( $paypal_adr, $params );
|
||||
$response = wp_remote_post( $paypal_adr, $params );
|
||||
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'IPN Response: ' . print_r( $response, true ) );
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'IPN Response: ' . print_r( $response, true ) );
|
||||
|
||||
// check to see if the request was valid
|
||||
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && ( strcmp( $response['body'], "VERIFIED" ) == 0 ) ) {
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Received valid response from PayPal' );
|
||||
// check to see if the request was valid
|
||||
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && ( strcmp( $response['body'], "VERIFIED" ) == 0 ) ) {
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Received valid response from PayPal' );
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( 'yes' == $this->debug ) {
|
||||
$this->log->add( 'paypal', 'Received invalid response from PayPal' );
|
||||
if ( is_wp_error( $response ) )
|
||||
$this->log->add( 'paypal', 'Error response: ' . $response->get_error_message() );
|
||||
}
|
||||
if ( 'yes' == $this->debug ) {
|
||||
$this->log->add( 'paypal', 'Received invalid response from PayPal' );
|
||||
if ( is_wp_error( $response ) )
|
||||
$this->log->add( 'paypal', 'Error response: ' . $response->get_error_message() );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for PayPal IPN Response
|
||||
|
@ -587,17 +587,17 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
|
||||
@ob_clean();
|
||||
|
||||
if ( ! empty( $_POST ) && $this->check_ipn_request_is_valid() ) {
|
||||
if ( ! empty( $_POST ) && $this->check_ipn_request_is_valid() ) {
|
||||
|
||||
header( 'HTTP/1.1 200 OK' );
|
||||
header( 'HTTP/1.1 200 OK' );
|
||||
|
||||
do_action( "valid-paypal-standard-ipn-request", $_POST );
|
||||
do_action( "valid-paypal-standard-ipn-request", $_POST );
|
||||
|
||||
} else {
|
||||
|
||||
wp_die( "PayPal IPN Request Failure", "PayPal IPN", array( 'response' => 200 ) );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -613,38 +613,38 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
$posted = stripslashes_deep( $posted );
|
||||
|
||||
// Custom holds post ID
|
||||
if ( ! empty( $posted['invoice'] ) && ! empty( $posted['custom'] ) ) {
|
||||
if ( ! empty( $posted['invoice'] ) && ! empty( $posted['custom'] ) ) {
|
||||
|
||||
$order = $this->get_paypal_order( $posted['custom'], $posted['invoice'] );
|
||||
$order = $this->get_paypal_order( $posted['custom'], $posted['invoice'] );
|
||||
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Found order #' . $order->id );
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Found order #' . $order->id );
|
||||
|
||||
// Lowercase returned variables
|
||||
$posted['payment_status'] = strtolower( $posted['payment_status'] );
|
||||
$posted['txn_type'] = strtolower( $posted['txn_type'] );
|
||||
// Lowercase returned variables
|
||||
$posted['payment_status'] = strtolower( $posted['payment_status'] );
|
||||
$posted['txn_type'] = strtolower( $posted['txn_type'] );
|
||||
|
||||
// Sandbox fix
|
||||
if ( $posted['test_ipn'] == 1 && $posted['payment_status'] == 'pending' )
|
||||
$posted['payment_status'] = 'completed';
|
||||
// Sandbox fix
|
||||
if ( $posted['test_ipn'] == 1 && $posted['payment_status'] == 'pending' )
|
||||
$posted['payment_status'] = 'completed';
|
||||
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Payment status: ' . $posted['payment_status'] );
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Payment status: ' . $posted['payment_status'] );
|
||||
|
||||
// We are here so lets check status and do actions
|
||||
switch ( $posted['payment_status'] ) {
|
||||
case 'completed' :
|
||||
case 'pending' :
|
||||
// We are here so lets check status and do actions
|
||||
switch ( $posted['payment_status'] ) {
|
||||
case 'completed' :
|
||||
case 'pending' :
|
||||
|
||||
// Check order not already completed
|
||||
if ( $order->status == 'completed' ) {
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Aborting, Order #' . $order->id . ' is already complete.' );
|
||||
exit;
|
||||
}
|
||||
// Check order not already completed
|
||||
if ( $order->status == 'completed' ) {
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Aborting, Order #' . $order->id . ' is already complete.' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check valid txn_type
|
||||
$accepted_types = array( 'cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money' );
|
||||
// Check valid txn_type
|
||||
$accepted_types = array( 'cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money' );
|
||||
if ( ! in_array( $posted['txn_type'], $accepted_types ) ) {
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Aborting, Invalid type:' . $posted['txn_type'] );
|
||||
|
@ -652,185 +652,185 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
}
|
||||
|
||||
// Validate Amount
|
||||
if ( $order->get_total() != $posted['mc_gross'] ) {
|
||||
if ( $order->get_total() != $posted['mc_gross'] ) {
|
||||
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Payment error: Amounts do not match (gross ' . $posted['mc_gross'] . ')' );
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Payment error: Amounts do not match (gross ' . $posted['mc_gross'] . ')' );
|
||||
|
||||
// Put this order on-hold for manual checking
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'woocommerce' ), $posted['mc_gross'] ) );
|
||||
// Put this order on-hold for manual checking
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'woocommerce' ), $posted['mc_gross'] ) );
|
||||
|
||||
exit;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate Email Address
|
||||
// Validate Email Address
|
||||
if ( strcasecmp( trim( $posted['receiver_email'] ), trim( $this->receiver_email ) ) != 0 ) {
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', "IPN Response is for another one: {$posted['receiver_email']} our email is {$this->receiver_email}" );
|
||||
|
||||
// Put this order on-hold for manual checking
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'woocommerce' ), $posted['receiver_email'] ) );
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'woocommerce' ), $posted['receiver_email'] ) );
|
||||
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
// Store PP Details
|
||||
if ( ! empty( $posted['payer_email'] ) )
|
||||
update_post_meta( $order->id, 'Payer PayPal address', $posted['payer_email'] );
|
||||
if ( ! empty( $posted['txn_id'] ) )
|
||||
update_post_meta( $order->id, 'Transaction ID', $posted['txn_id'] );
|
||||
if ( ! empty( $posted['first_name'] ) )
|
||||
update_post_meta( $order->id, 'Payer first name', $posted['first_name'] );
|
||||
if ( ! empty( $posted['last_name'] ) )
|
||||
update_post_meta( $order->id, 'Payer last name', $posted['last_name'] );
|
||||
if ( ! empty( $posted['payment_type'] ) )
|
||||
update_post_meta( $order->id, 'Payment type', $posted['payment_type'] );
|
||||
if ( ! empty( $posted['payer_email'] ) )
|
||||
update_post_meta( $order->id, 'Payer PayPal address', $posted['payer_email'] );
|
||||
if ( ! empty( $posted['txn_id'] ) )
|
||||
update_post_meta( $order->id, 'Transaction ID', $posted['txn_id'] );
|
||||
if ( ! empty( $posted['first_name'] ) )
|
||||
update_post_meta( $order->id, 'Payer first name', $posted['first_name'] );
|
||||
if ( ! empty( $posted['last_name'] ) )
|
||||
update_post_meta( $order->id, 'Payer last name', $posted['last_name'] );
|
||||
if ( ! empty( $posted['payment_type'] ) )
|
||||
update_post_meta( $order->id, 'Payment type', $posted['payment_type'] );
|
||||
|
||||
if ( $posted['payment_status'] == 'completed' ) {
|
||||
$order->add_order_note( __( 'IPN payment completed', 'woocommerce' ) );
|
||||
$order->payment_complete();
|
||||
} else {
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Payment pending: %s', 'woocommerce' ), $posted['pending_reason'] ) );
|
||||
}
|
||||
if ( $posted['payment_status'] == 'completed' ) {
|
||||
$order->add_order_note( __( 'IPN payment completed', 'woocommerce' ) );
|
||||
$order->payment_complete();
|
||||
} else {
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Payment pending: %s', 'woocommerce' ), $posted['pending_reason'] ) );
|
||||
}
|
||||
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Payment complete.' );
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Payment complete.' );
|
||||
|
||||
break;
|
||||
case 'denied' :
|
||||
case 'expired' :
|
||||
case 'failed' :
|
||||
case 'voided' :
|
||||
// Order failed
|
||||
$order->update_status( 'failed', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), strtolower( $posted['payment_status'] ) ) );
|
||||
break;
|
||||
case "refunded" :
|
||||
break;
|
||||
case 'denied' :
|
||||
case 'expired' :
|
||||
case 'failed' :
|
||||
case 'voided' :
|
||||
// Order failed
|
||||
$order->update_status( 'failed', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), strtolower( $posted['payment_status'] ) ) );
|
||||
break;
|
||||
case "refunded" :
|
||||
|
||||
// Only handle full refunds, not partial
|
||||
if ( $order->get_total() == ( $posted['mc_gross'] * -1 ) ) {
|
||||
// Only handle full refunds, not partial
|
||||
if ( $order->get_total() == ( $posted['mc_gross'] * -1 ) ) {
|
||||
|
||||
// Mark order as refunded
|
||||
$order->update_status( 'refunded', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), strtolower( $posted['payment_status'] ) ) );
|
||||
// Mark order as refunded
|
||||
$order->update_status( 'refunded', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), strtolower( $posted['payment_status'] ) ) );
|
||||
|
||||
$mailer = WC()->mailer();
|
||||
$mailer = WC()->mailer();
|
||||
|
||||
$message = $mailer->wrap_message(
|
||||
__( 'Order refunded/reversed', 'woocommerce' ),
|
||||
sprintf( __( 'Order %s has been marked as refunded - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), $posted['reason_code'] )
|
||||
$message = $mailer->wrap_message(
|
||||
__( 'Order refunded/reversed', 'woocommerce' ),
|
||||
sprintf( __( 'Order %s has been marked as refunded - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), $posted['reason_code'] )
|
||||
);
|
||||
|
||||
$mailer->send( get_option( 'admin_email' ), sprintf( __( 'Payment for order %s refunded/reversed', 'woocommerce' ), $order->get_order_number() ), $message );
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
case "reversed" :
|
||||
break;
|
||||
case "reversed" :
|
||||
|
||||
// Mark order as refunded
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), strtolower( $posted['payment_status'] ) ) );
|
||||
// Mark order as refunded
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), strtolower( $posted['payment_status'] ) ) );
|
||||
|
||||
$mailer = WC()->mailer();
|
||||
$mailer = WC()->mailer();
|
||||
|
||||
$message = $mailer->wrap_message(
|
||||
__( 'Order reversed', 'woocommerce' ),
|
||||
sprintf(__( 'Order %s has been marked on-hold due to a reversal - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), $posted['reason_code'] )
|
||||
$message = $mailer->wrap_message(
|
||||
__( 'Order reversed', 'woocommerce' ),
|
||||
sprintf(__( 'Order %s has been marked on-hold due to a reversal - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), $posted['reason_code'] )
|
||||
);
|
||||
|
||||
$mailer->send( get_option( 'admin_email' ), sprintf( __( 'Payment for order %s reversed', 'woocommerce' ), $order->get_order_number() ), $message );
|
||||
|
||||
break;
|
||||
case "canceled_reversal" :
|
||||
break;
|
||||
case "canceled_reversal" :
|
||||
|
||||
$mailer = WC()->mailer();
|
||||
$mailer = WC()->mailer();
|
||||
|
||||
$message = $mailer->wrap_message(
|
||||
__( 'Reversal Cancelled', 'woocommerce' ),
|
||||
sprintf( __( 'Order %s has had a reversal cancelled. Please check the status of payment and update the order status accordingly.', 'woocommerce' ), $order->get_order_number() )
|
||||
$message = $mailer->wrap_message(
|
||||
__( 'Reversal Cancelled', 'woocommerce' ),
|
||||
sprintf( __( 'Order %s has had a reversal cancelled. Please check the status of payment and update the order status accordingly.', 'woocommerce' ), $order->get_order_number() )
|
||||
);
|
||||
|
||||
$mailer->send( get_option( 'admin_email' ), sprintf( __( 'Reversal cancelled for order %s', 'woocommerce' ), $order->get_order_number() ), $message );
|
||||
|
||||
break;
|
||||
default :
|
||||
// No action
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
// No action
|
||||
break;
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return handler
|
||||
*
|
||||
* Alternative to IPN
|
||||
*/
|
||||
public function pdt_return_handler() {
|
||||
/**
|
||||
* Return handler
|
||||
*
|
||||
* Alternative to IPN
|
||||
*/
|
||||
public function pdt_return_handler() {
|
||||
$posted = stripslashes_deep( $_REQUEST );
|
||||
|
||||
if ( ! empty( $this->identity_token ) && ! empty( $posted['cm'] ) ) {
|
||||
if ( ! empty( $this->identity_token ) && ! empty( $posted['cm'] ) ) {
|
||||
|
||||
$order = $this->get_paypal_order( $posted['cm'] );
|
||||
$order = $this->get_paypal_order( $posted['cm'] );
|
||||
|
||||
if ( $order->status != 'pending' )
|
||||
if ( $order->status != 'pending' )
|
||||
return false;
|
||||
|
||||
$posted['st'] = strtolower( $posted['st'] );
|
||||
$posted['st'] = strtolower( $posted['st'] );
|
||||
|
||||
switch ( $posted['st'] ) {
|
||||
case 'completed' :
|
||||
case 'completed' :
|
||||
|
||||
// Validate transaction
|
||||
if ( $this->testmode == 'yes' )
|
||||
// Validate transaction
|
||||
if ( $this->testmode == 'yes' )
|
||||
$paypal_adr = $this->testurl;
|
||||
else
|
||||
$paypal_adr = $this->liveurl;
|
||||
|
||||
$pdt = array(
|
||||
'body' => array(
|
||||
'cmd' => '_notify-synch',
|
||||
'tx' => $posted['tx'],
|
||||
'at' => $this->identity_token
|
||||
),
|
||||
'sslverify' => false,
|
||||
'timeout' => 60,
|
||||
'httpversion' => '1.1',
|
||||
'user-agent' => 'WooCommerce/' . WC_VERSION
|
||||
);
|
||||
$pdt = array(
|
||||
'body' => array(
|
||||
'cmd' => '_notify-synch',
|
||||
'tx' => $posted['tx'],
|
||||
'at' => $this->identity_token
|
||||
),
|
||||
'sslverify' => false,
|
||||
'timeout' => 60,
|
||||
'httpversion' => '1.1',
|
||||
'user-agent' => 'WooCommerce/' . WC_VERSION
|
||||
);
|
||||
|
||||
// Post back to get a response
|
||||
$response = wp_remote_post( $paypal_adr, $pdt );
|
||||
$response = wp_remote_post( $paypal_adr, $pdt );
|
||||
|
||||
if ( is_wp_error( $response ) )
|
||||
return false;
|
||||
if ( is_wp_error( $response ) )
|
||||
return false;
|
||||
|
||||
if ( ! strpos( $response['body'], "SUCCESS" ) === 0 )
|
||||
return false;
|
||||
if ( ! strpos( $response['body'], "SUCCESS" ) === 0 )
|
||||
return false;
|
||||
|
||||
// Validate Amount
|
||||
if ( $order->get_total() != $posted['amt'] ) {
|
||||
// Validate Amount
|
||||
if ( $order->get_total() != $posted['amt'] ) {
|
||||
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Payment error: Amounts do not match (amt ' . $posted['amt'] . ')' );
|
||||
if ( 'yes' == $this->debug )
|
||||
$this->log->add( 'paypal', 'Payment error: Amounts do not match (amt ' . $posted['amt'] . ')' );
|
||||
|
||||
// Put this order on-hold for manual checking
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal amounts do not match (amt %s).', 'woocommerce' ), $posted['amt'] ) );
|
||||
return true;
|
||||
// Put this order on-hold for manual checking
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal amounts do not match (amt %s).', 'woocommerce' ), $posted['amt'] ) );
|
||||
return true;
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
// Store PP Details
|
||||
update_post_meta( $order->id, 'Transaction ID', $posted['tx'] );
|
||||
|
||||
$order->add_order_note( __( 'PDT payment completed', 'woocommerce' ) );
|
||||
$order->payment_complete();
|
||||
return true;
|
||||
}
|
||||
$order->payment_complete();
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -845,15 +845,15 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
private function get_paypal_order( $custom, $invoice = '' ) {
|
||||
$custom = maybe_unserialize( $custom );
|
||||
|
||||
// Backwards comp for IPN requests
|
||||
if ( is_numeric( $custom ) ) {
|
||||
$order_id = (int) $custom;
|
||||
$order_key = $invoice;
|
||||
} elseif( is_string( $custom ) ) {
|
||||
$order_id = (int) str_replace( $this->invoice_prefix, '', $custom );
|
||||
$order_key = $custom;
|
||||
} else {
|
||||
list( $order_id, $order_key ) = $custom;
|
||||
// Backwards comp for IPN requests
|
||||
if ( is_numeric( $custom ) ) {
|
||||
$order_id = (int) $custom;
|
||||
$order_key = $invoice;
|
||||
} elseif( is_string( $custom ) ) {
|
||||
$order_id = (int) str_replace( $this->invoice_prefix, '', $custom );
|
||||
$order_key = $custom;
|
||||
} else {
|
||||
list( $order_id, $order_key ) = $custom;
|
||||
}
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
|
@ -866,11 +866,11 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
|
||||
// Validate key
|
||||
if ( $order->order_key !== $order_key ) {
|
||||
if ( $this->debug=='yes' )
|
||||
$this->log->add( 'paypal', 'Error: Order Key does not match invoice.' );
|
||||
exit;
|
||||
}
|
||||
if ( $this->debug=='yes' )
|
||||
$this->log->add( 'paypal', 'Error: Order Key does not match invoice.' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return $order;
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue