WC_Gateway_Paypal_Response

Handles Responses.

Defined (1)

The class is defined in the following location(s).

/includes/gateways/paypal/includes/class-wc-gateway-paypal-response.php  
  1. abstract class WC_Gateway_Paypal_Response { 
  2.  
  3. /** @var bool Sandbox mode */ 
  4. protected $sandbox = false; 
  5.  
  6. /** 
  7. * Get the order from the PayPal 'Custom' variable. 
  8. * @param string $raw_custom JSON Data passed back by PayPal 
  9. * @return bool|WC_Order object 
  10. */ 
  11. protected function get_paypal_order( $raw_custom ) { 
  12. // We have the data in the correct format, so get the order. 
  13. if ( ( $custom = json_decode( $raw_custom ) ) && is_object( $custom ) ) { 
  14. $order_id = $custom->order_id; 
  15. $order_key = $custom->order_key; 
  16.  
  17. // Fallback to serialized data if safe. This is @deprecated in 2.3.11 
  18. } elseif ( preg_match( '/^a:2:{/', $raw_custom ) && ! preg_match( '/[CO]:\+?[0-9]+:"/', $raw_custom ) && ( $custom = maybe_unserialize( $raw_custom ) ) ) { 
  19. $order_id = $custom[0]; 
  20. $order_key = $custom[1]; 
  21.  
  22. // Nothing was found. 
  23. } else { 
  24. WC_Gateway_Paypal::log( 'Order ID and key were not found in "custom".', 'error' ); 
  25. return false; 
  26.  
  27. if ( ! $order = wc_get_order( $order_id ) ) { 
  28. // We have an invalid $order_id, probably because invoice_prefix has changed. 
  29. $order_id = wc_get_order_id_by_order_key( $order_key ); 
  30. $order = wc_get_order( $order_id ); 
  31.  
  32. if ( ! $order || $order->get_order_key() !== $order_key ) { 
  33. WC_Gateway_Paypal::log( 'Order Keys do not match.', 'error' ); 
  34. return false; 
  35.  
  36. return $order; 
  37.  
  38. /** 
  39. * Complete order, add transaction ID and note. 
  40. * @param WC_Order $order 
  41. * @param string $txn_id 
  42. * @param string $note 
  43. */ 
  44. protected function payment_complete( $order, $txn_id = '', $note = '' ) { 
  45. $order->add_order_note( $note ); 
  46. $order->payment_complete( $txn_id ); 
  47.  
  48. /** 
  49. * Hold order and add note. 
  50. * @param WC_Order $order 
  51. * @param string $reason 
  52. */ 
  53. protected function payment_on_hold( $order, $reason = '' ) { 
  54. $order->update_status( 'on-hold', $reason ); 
  55. wc_reduce_stock_levels( $order->get_id() ); 
  56. WC()->cart->empty_cart();