actions-abstract
2 years ago
assets
2 years ago
db-models
2 years ago
export
2 years ago
legacy
2 years ago
meta-boxes
2 years ago
pages
2 years ago
paypal
2 years ago
query-views
2 years ago
rest-api
2 years ago
scenarios-abstract
2 years ago
tab-handlers
2 years ago
table-views
2 years ago
base-gateway-action.php
2 years ago
base-gateway.php
2 years ago
base-scenario-gateway.php
2 years ago
gateways-editor-data.php
2 years ago
legacy-base-gateway.php
2 years ago
migrate-legacy-data.php
2 years ago
module.php
2 years ago
scenario-item.php
2 years ago
base-scenario-gateway.php
117 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Gateways; |
| 5 | |
| 6 | use Jet_Form_Builder\Actions\Action_Handler; |
| 7 | use Jet_Form_Builder\Db_Queries\Exceptions\Skip_Exception; |
| 8 | use Jet_Form_Builder\Exceptions\Gateway_Exception; |
| 9 | use Jet_Form_Builder\Exceptions\Repository_Exception; |
| 10 | use JFB_Modules\Gateways\Module as GM; |
| 11 | use JFB_Modules\Gateways\Paypal\Scenarios_Manager; |
| 12 | use JFB_Modules\Gateways\Scenarios_Abstract\Scenario_Logic_Base; |
| 13 | |
| 14 | // If this file is called directly, abort. |
| 15 | if ( ! defined( 'WPINC' ) ) { |
| 16 | die; |
| 17 | } |
| 18 | |
| 19 | abstract class Base_Scenario_Gateway extends \Jet_Form_Builder\Gateways\Base_Gateway { |
| 20 | |
| 21 | /** |
| 22 | * @return Scenario_Logic_Base |
| 23 | * @throws Repository_Exception |
| 24 | */ |
| 25 | public function get_scenario() { |
| 26 | return Scenarios_Manager::instance()->get_logic( $this ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @return Scenario_Logic_Base |
| 31 | * @throws Gateway_Exception |
| 32 | */ |
| 33 | public function query_scenario() { |
| 34 | return Scenarios_Manager::instance()->query_logic(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Prevent unnecessary notifications processing before form is send. |
| 39 | * |
| 40 | * @return void |
| 41 | * @throws Repository_Exception |
| 42 | */ |
| 43 | public function before_actions() { |
| 44 | $this->set_form_meta( GM::instance()->gateways() ); |
| 45 | $this->get_scenario()->before_actions(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @param Action_Handler $handler |
| 50 | * |
| 51 | * @throws Repository_Exception |
| 52 | */ |
| 53 | public function after_actions( Action_Handler $handler ) { |
| 54 | jet_fb_gateway_current()->get_scenario()->after_actions(); |
| 55 | } |
| 56 | |
| 57 | public function try_run_on_catch() { |
| 58 | try { |
| 59 | $scenario = $this->query_scenario(); |
| 60 | } catch ( Gateway_Exception $exception ) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | try { |
| 65 | /** set to $this->payment_token */ |
| 66 | $this->set_payment_token(); |
| 67 | |
| 68 | } catch ( Skip_Exception $exception ) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Init actions for correct migrating |
| 74 | * |
| 75 | * Later should be deprecated |
| 76 | */ |
| 77 | $scenario->init_request(); |
| 78 | $scenario->init_actions(); |
| 79 | |
| 80 | /** set to $this->gateways_meta */ |
| 81 | $this->set_form_gateways_meta(); |
| 82 | |
| 83 | $scenario->on_catch(); |
| 84 | } |
| 85 | |
| 86 | // statuses from scenario |
| 87 | |
| 88 | /** |
| 89 | * @return mixed |
| 90 | * @throws Gateway_Exception |
| 91 | */ |
| 92 | protected function retrieve_gateway_meta() { |
| 93 | return $this->query_scenario()->get_gateways_meta(); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @return string|void |
| 98 | * @throws Gateway_Exception |
| 99 | */ |
| 100 | public function get_payment_token() { |
| 101 | return $this->query_scenario()->get_queried_token(); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Apply macros in string |
| 106 | * |
| 107 | * @param null $content |
| 108 | * |
| 109 | * @return string [description] |
| 110 | * @throws Gateway_Exception |
| 111 | */ |
| 112 | public function apply_macros( $content = null ) { |
| 113 | return $this->query_scenario()->apply_macros( $content ); |
| 114 | } |
| 115 | |
| 116 | } |
| 117 |