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