Merge pull request #7775 from aelia-co/master
Modified PayPal Standard gateway to make it easier to extend
This commit is contained in:
commit
3b1cb9844d
|
@ -95,7 +95,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
* @param string $country
|
||||
* @return string
|
||||
*/
|
||||
private function get_icon_url( $country ) {
|
||||
protected function get_icon_url( $country ) {
|
||||
switch ( $country ) {
|
||||
case 'MX' :
|
||||
case 'ZA' :
|
||||
|
@ -114,7 +114,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
* @param string $country
|
||||
* @return array of image URLs
|
||||
*/
|
||||
private function get_icon_image( $country ) {
|
||||
protected function get_icon_image( $country ) {
|
||||
switch ( $country ) {
|
||||
case 'US' :
|
||||
case 'NZ' :
|
||||
|
|
|
@ -12,7 +12,7 @@ include_once( 'class-wc-gateway-paypal-response.php' );
|
|||
class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
||||
|
||||
/** @var string Receiver email address to validate */
|
||||
private $receiver_email;
|
||||
protected $receiver_email;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -109,7 +109,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Check for a valid transaction type
|
||||
* @param string $txn_type
|
||||
*/
|
||||
private function validate_transaction_type( $txn_type ) {
|
||||
protected function validate_transaction_type( $txn_type ) {
|
||||
$accepted_types = array( 'cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money' );
|
||||
|
||||
if ( ! in_array( strtolower( $txn_type ), $accepted_types ) ) {
|
||||
|
@ -123,7 +123,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* @param WC_Order $order
|
||||
* @param string $currency
|
||||
*/
|
||||
private function validate_currency( $order, $currency ) {
|
||||
protected function validate_currency( $order, $currency ) {
|
||||
// Validate currency
|
||||
if ( $order->get_order_currency() != $currency ) {
|
||||
$this->log( 'Payment error: Currencies do not match (sent "' . $order->get_order_currency() . '" | returned "' . $currency . '")' );
|
||||
|
@ -138,7 +138,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Check payment amount from IPN matches the order
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function validate_amount( $order, $amount ) {
|
||||
protected function validate_amount( $order, $amount ) {
|
||||
if ( number_format( $order->get_total(), 2, '.', '' ) != number_format( $amount, 2, '.', '' ) ) {
|
||||
$this->log( 'Payment error: Amounts do not match (gross ' . $amount . ')' );
|
||||
|
||||
|
@ -152,7 +152,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Check payment amount from IPN matches the order
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function validate_receiver_email( $order, $receiver_email ) {
|
||||
protected function validate_receiver_email( $order, $receiver_email ) {
|
||||
if ( strcasecmp( trim( $receiver_email ), trim( $this->receiver_email ) ) != 0 ) {
|
||||
$this->log( "IPN Response is for another account: {$receiver_email}. Your email is {$this->receiver_email}" );
|
||||
|
||||
|
@ -167,7 +167,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Handle a completed payment
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function payment_status_completed( $order, $posted ) {
|
||||
protected function payment_status_completed( $order, $posted ) {
|
||||
if ( $order->has_status( 'completed' ) ) {
|
||||
$this->log( 'Aborting, Order #' . $order->id . ' is already complete.' );
|
||||
exit;
|
||||
|
@ -190,7 +190,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Handle a pending payment
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function payment_status_pending( $order, $posted ) {
|
||||
protected function payment_status_pending( $order, $posted ) {
|
||||
$this->payment_status_completed( $order, $posted );
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Handle a failed payment
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function payment_status_failed( $order, $posted ) {
|
||||
protected function payment_status_failed( $order, $posted ) {
|
||||
$order->update_status( 'failed', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), wc_clean( $posted['payment_status'] ) ) );
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Handle a denied payment
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function payment_status_denied( $order, $posted ) {
|
||||
protected function payment_status_denied( $order, $posted ) {
|
||||
$this->payment_status_failed( $order, $posted );
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Handle an expired payment
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function payment_status_expired( $order, $posted ) {
|
||||
protected function payment_status_expired( $order, $posted ) {
|
||||
$this->payment_status_failed( $order, $posted );
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Handle a voided payment
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function payment_status_voided( $order, $posted ) {
|
||||
protected function payment_status_voided( $order, $posted ) {
|
||||
$this->payment_status_failed( $order, $posted );
|
||||
}
|
||||
|
||||
|
@ -230,7 +230,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Handle a refunded order
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function payment_status_refunded( $order, $posted ) {
|
||||
protected function payment_status_refunded( $order, $posted ) {
|
||||
// Only handle full refunds, not partial
|
||||
if ( $order->get_total() == ( $posted['mc_gross'] * -1 ) ) {
|
||||
|
||||
|
@ -248,7 +248,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Handle a reveral
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function payment_status_reversed( $order, $posted ) {
|
||||
protected function payment_status_reversed( $order, $posted ) {
|
||||
$order->update_status( 'on-hold', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), wc_clean( $posted['payment_status'] ) ) );
|
||||
|
||||
$this->send_ipn_email_notification(
|
||||
|
@ -261,7 +261,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Handle a cancelled reveral
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function payment_status_canceled_reversal( $order, $posted ) {
|
||||
protected function payment_status_canceled_reversal( $order, $posted ) {
|
||||
$this->send_ipn_email_notification(
|
||||
sprintf( __( 'Reversal cancelled for order #%s', 'woocommerce' ), $order->get_order_number() ),
|
||||
sprintf( __( 'Order #%s has had a reversal cancelled. Please check the status of payment and update the order status accordingly here: %s', 'woocommerce' ), $order->get_order_number(), esc_url( admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ) )
|
||||
|
@ -272,7 +272,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* Save important data from the IPN to the order
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
private function save_paypal_meta_data( $order, $posted ) {
|
||||
protected function save_paypal_meta_data( $order, $posted ) {
|
||||
if ( ! empty( $posted['payer_email'] ) ) {
|
||||
update_post_meta( $order->id, 'Payer PayPal address', wc_clean( $posted['payer_email'] ) );
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
|
|||
* @param string $subject
|
||||
* @param string $message
|
||||
*/
|
||||
private function send_ipn_email_notification( $subject, $message ) {
|
||||
protected function send_ipn_email_notification( $subject, $message ) {
|
||||
$new_order_settings = get_option( 'woocommerce_new_order_settings', array() );
|
||||
$mailer = WC()->mailer();
|
||||
$message = $mailer->wrap_message( $subject, $message );
|
||||
|
|
|
@ -12,7 +12,7 @@ include_once( 'class-wc-gateway-paypal-response.php' );
|
|||
class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
|
||||
|
||||
/** @var string identity_token for PDT support */
|
||||
private $identity_token;
|
||||
protected $identity_token;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -29,7 +29,7 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
|
|||
* @param string $transaction
|
||||
* @return bool
|
||||
*/
|
||||
private function validate_transaction( $transaction ) {
|
||||
protected function validate_transaction( $transaction ) {
|
||||
$pdt = array(
|
||||
'body' => array(
|
||||
'cmd' => '_notify-synch',
|
||||
|
|
Loading…
Reference in New Issue