Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| 1 | <?php |
| 2 | /** |
| 3 | * Functions implemented by Background_Jobs class to hand WordPress actions |
| 4 | * |
| 5 | * @package brianhenryie/bh-wp-bitcoin-gateway |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\WP_Bitcoin_Gateway\Action_Scheduler; |
| 9 | |
| 10 | use BrianHenryIE\WP_Bitcoin_Gateway\BH_WP_Bitcoin_Gateway; |
| 11 | |
| 12 | /** |
| 13 | * `do_action( HOOK_NAME )` is called by Action Scheduler / wp_cron to run these tasks. |
| 14 | * We `add_action( HOOK_NAME )` to our implementations of the functions below to handle them. |
| 15 | * |
| 16 | * @see BH_WP_Bitcoin_Gateway::define_action_scheduler_hooks() |
| 17 | */ |
| 18 | interface Background_Jobs_Actions_Interface { |
| 19 | |
| 20 | /** |
| 21 | * The hook name for updating exchange rates. |
| 22 | */ |
| 23 | const string UPDATE_EXCHANGE_RATE_HOOK = 'bh_wp_bitcoin_gateway_update_exchange_rate'; |
| 24 | |
| 25 | /** |
| 26 | * The hook name for regularly ensuring there is an unused payment address available. |
| 27 | */ |
| 28 | const string RECURRING_ENSURE_UNUSED_ADDRESSES_HOOK = 'bh_wp_bitcoin_gateway_recurring_ensure_unused_addresses'; |
| 29 | |
| 30 | /** |
| 31 | * The hook name for a single check to ensure there is an unused address available, use e.g. immediately after |
| 32 | * one is assigned to an order. |
| 33 | */ |
| 34 | const string SINGLE_ENSURE_UNUSED_ADDRESSES_HOOK = 'bh_wp_bitcoin_gateway_single_ensure_unused_addresses'; |
| 35 | |
| 36 | /** |
| 37 | * Fetch all addresses pending payment ("assigned") and query remote API for payments. Handle rate limited responses. |
| 38 | * Reschedule a check in ten minutes for addresses still unpaid. This is a non-repeating action when there are no addresses with 'assigned' status. |
| 39 | */ |
| 40 | const string CHECK_ASSIGNED_ADDRESSES_TRANSACTIONS_HOOK = 'bh_wp_bitcoin_gateway_check_assigned_addresses_transactions'; |
| 41 | |
| 42 | /** |
| 43 | * Generating new addresses is math-heavy so we do it in a background task. |
| 44 | */ |
| 45 | const string GENERATE_NEW_ADDRESSES_HOOK = 'bh_wp_bitcoin_gateway_generate_new_addresses'; |
| 46 | |
| 47 | /** |
| 48 | * Every hour we should check the address that will be used next to ensure it is still unused. |
| 49 | */ |
| 50 | const string CHECK_NEW_ADDRESSES_TRANSACTIONS_HOOK = 'bh_wp_bitcoin_gateway_check_new_addresses_transactions'; |
| 51 | |
| 52 | /** |
| 53 | * @hooked action_scheduler_run_recurring_actions_schedule_hook |
| 54 | */ |
| 55 | public function add_action_scheduler_repeating_actions(): void; |
| 56 | |
| 57 | /** |
| 58 | * Handler for recurring job to update the exchange rate. |
| 59 | * |
| 60 | * @hooked bh_wp_bitcoin_gateway_update_exchange_rate |
| 61 | * @see self::UPDATE_EXCHANGE_RATE_HOOK |
| 62 | */ |
| 63 | public function update_exchange_rate(): void; |
| 64 | |
| 65 | /** |
| 66 | * Handler for recurring job to check we have addresses ready for new orders. |
| 67 | */ |
| 68 | public function ensure_unused_addresses(): void; |
| 69 | |
| 70 | /** |
| 71 | * Handler for one-off checks for available addresses (called after an address has been used). |
| 72 | * |
| 73 | * @param int $wallet_post_id Id of the wallet to check. |
| 74 | */ |
| 75 | public function single_ensure_unused_addresses( int $wallet_post_id ): void; |
| 76 | |
| 77 | /** |
| 78 | * @see self::CHECK_ASSIGNED_ADDRESSES_TRANSACTIONS_HOOK |
| 79 | */ |
| 80 | public function check_assigned_addresses_for_transactions(): void; |
| 81 | |
| 82 | /** |
| 83 | * @see self::GENERATE_NEW_ADDRESSES_HOOK |
| 84 | */ |
| 85 | public function generate_new_addresses(): void; |
| 86 | |
| 87 | /** |
| 88 | * @see self::CHECK_NEW_ADDRESSES_TRANSACTIONS_HOOK |
| 89 | */ |
| 90 | public function check_new_addresses_for_transactions(): void; |
| 91 | } |