abstract-wc-legacy-payment-token.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit;
  4. }
  5. /**
  6. * Legacy Payment Tokens.
  7. * Payment Tokens were introduced in 2.6.0 with create and update as methods.
  8. * Major CRUD changes occurred in 3.0, so these were deprecated (save and delete still work).
  9. * This legacy class is for backwards compatibility in case any code called ->read, ->update or ->create
  10. * directly on the object.
  11. *
  12. * @version 3.0.0
  13. * @package WooCommerce/Classes
  14. * @category Class
  15. * @author WooCommerce
  16. */
  17. abstract class WC_Legacy_Payment_Token extends WC_Data {
  18. /**
  19. * Sets the type of this payment token (CC, eCheck, or something else).
  20. *
  21. * @param string Payment Token Type (CC, eCheck)
  22. */
  23. public function set_type( $type ) {
  24. wc_deprecated_function( 'WC_Payment_Token::set_type', '3.0.0', 'Type cannot be overwritten.' );
  25. }
  26. /**
  27. * Read a token by ID.
  28. * @deprecated 3.0.0 - Init a token class with an ID.
  29. *
  30. * @param int $token_id
  31. */
  32. public function read( $token_id ) {
  33. wc_deprecated_function( 'WC_Payment_Token::read', '3.0.0', 'a new token class initialized with an ID.' );
  34. $this->set_id( $token_id );
  35. $data_store = WC_Data_Store::load( 'payment-token' );
  36. $data_store->read( $this );
  37. }
  38. /**
  39. * Update a token.
  40. * @deprecated 3.0.0 - Use ::save instead.
  41. */
  42. public function update() {
  43. wc_deprecated_function( 'WC_Payment_Token::update', '3.0.0', 'WC_Payment_Token::save instead.' );
  44. $data_store = WC_Data_Store::load( 'payment-token' );
  45. try {
  46. $data_store->update( $this );
  47. } catch ( Exception $e ) {
  48. return false;
  49. }
  50. }
  51. /**
  52. * Create a token.
  53. * @deprecated 3.0.0 - Use ::save instead.
  54. */
  55. public function create() {
  56. wc_deprecated_function( 'WC_Payment_Token::create', '3.0.0', 'WC_Payment_Token::save instead.' );
  57. $data_store = WC_Data_Store::load( 'payment-token' );
  58. try {
  59. $data_store->create( $this );
  60. } catch ( Exception $e ) {
  61. return false;
  62. }
  63. }
  64. }