| Conditions | 9 |
| Paths | 144 |
| Total Lines | 106 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 68 | public function start( Payment $payment ) { |
||
| 69 | $ogone_data = new Data(); |
||
| 70 | |||
| 71 | // General. |
||
| 72 | $ogone_data_general = new DataGeneralHelper( $ogone_data ); |
||
| 73 | |||
| 74 | $ogone_data_general |
||
| 75 | ->set_psp_id( $this->client->psp_id ) |
||
|
|
|||
| 76 | ->set_order_id( $payment->format_string( $this->config->order_id ) ) |
||
| 77 | ->set_order_description( $payment->get_description() ) |
||
| 78 | ->set_param_plus( 'payment_id=' . $payment->get_id() ) |
||
| 79 | ->set_currency( $payment->get_total_amount()->get_currency()->get_alphabetic_code() ) |
||
| 80 | ->set_amount( $payment->get_total_amount()->get_cents() ); |
||
| 81 | |||
| 82 | $customer = $payment->get_customer(); |
||
| 83 | |||
| 84 | if ( null !== $customer ) { |
||
| 85 | // Localised language. |
||
| 86 | $ogone_data_general->set_language( $customer->get_locale() ); |
||
| 87 | } |
||
| 88 | |||
| 89 | // Customer. |
||
| 90 | $ogone_data_customer = new DataCustomerHelper( $ogone_data ); |
||
| 91 | |||
| 92 | if ( null !== $customer ) { |
||
| 93 | $name = $customer->get_name(); |
||
| 94 | |||
| 95 | if ( null !== $name ) { |
||
| 96 | $ogone_data_customer->set_name( strval( $name ) ); |
||
| 97 | } |
||
| 98 | |||
| 99 | $ogone_data_customer->set_email( $customer->get_email() ); |
||
| 100 | } |
||
| 101 | |||
| 102 | $billing_address = $payment->get_billing_address(); |
||
| 103 | |||
| 104 | if ( null !== $billing_address ) { |
||
| 105 | $ogone_data_customer |
||
| 106 | ->set_address( $billing_address->get_line_1() ) |
||
| 107 | ->set_zip( $billing_address->get_postal_code() ) |
||
| 108 | ->set_town( $billing_address->get_city() ) |
||
| 109 | ->set_country( $billing_address->get_country_code() ) |
||
| 110 | ->set_telephone_number( $billing_address->get_phone() ); |
||
| 111 | } |
||
| 112 | |||
| 113 | // DirectLink. |
||
| 114 | $ogone_data_directlink = new DataHelper( $ogone_data ); |
||
| 115 | |||
| 116 | $ogone_data_directlink |
||
| 117 | ->set_user_id( $this->client->user_id ) |
||
| 118 | ->set_password( $this->client->password ); |
||
| 119 | |||
| 120 | // Credit card. |
||
| 121 | $ogone_data_credit_card = new DataCreditCardHelper( $ogone_data ); |
||
| 122 | |||
| 123 | $credit_card = $payment->get_credit_card(); |
||
| 124 | |||
| 125 | if ( $credit_card ) { |
||
| 126 | $ogone_data_credit_card |
||
| 127 | ->set_number( $credit_card->get_number() ) |
||
| 128 | ->set_expiration_date( $credit_card->get_expiration_date() ) |
||
| 129 | ->set_security_code( $credit_card->get_security_code() ); |
||
| 130 | } |
||
| 131 | |||
| 132 | $ogone_data->set_field( 'OPERATION', 'SAL' ); |
||
| 133 | |||
| 134 | // 3-D Secure |
||
| 135 | if ( $this->config->enabled_3d_secure ) { |
||
| 136 | $secure_data_helper = new SecureDataHelper( $ogone_data ); |
||
| 137 | |||
| 138 | $secure_data_helper |
||
| 139 | ->set_3d_secure_flag( true ) |
||
| 140 | ->set_http_accept( Server::get( 'HTTP_ACCEPT' ) ) |
||
| 141 | ->set_http_user_agent( Server::get( 'HTTP_USER_AGENT' ) ) |
||
| 142 | ->set_window( 'MAINW' ); |
||
| 143 | |||
| 144 | $ogone_data->set_field( 'ACCEPTURL', $payment->get_return_url() ); |
||
| 145 | $ogone_data->set_field( 'DECLINEURL', $payment->get_return_url() ); |
||
| 146 | $ogone_data->set_field( 'EXCEPTIONURL', $payment->get_return_url() ); |
||
| 147 | $ogone_data->set_field( 'COMPLUS', '' ); |
||
| 148 | } |
||
| 149 | |||
| 150 | // Signature. |
||
| 151 | $calculation_fields = Security::get_calculations_parameters_in(); |
||
| 152 | |||
| 153 | $fields = Security::get_calculation_fields( $calculation_fields, $ogone_data->get_fields() ); |
||
| 154 | |||
| 155 | $signature = Security::get_signature( $fields, $this->config->sha_in_pass_phrase, $this->config->hash_algorithm ); |
||
| 156 | |||
| 157 | $ogone_data->set_field( 'SHASIGN', $signature ); |
||
| 158 | |||
| 159 | // Order. |
||
| 160 | $result = $this->client->order_direct( $ogone_data->get_fields() ); |
||
| 161 | |||
| 162 | $error = $this->client->get_error(); |
||
| 163 | |||
| 164 | if ( is_wp_error( $error ) ) { |
||
| 165 | $this->error = $error; |
||
| 166 | } else { |
||
| 167 | $payment->set_transaction_id( $result->pay_id ); |
||
| 168 | $payment->set_action_url( $payment->get_return_url() ); |
||
| 169 | $payment->set_status( Statuses::transform( $result->status ) ); |
||
| 170 | |||
| 171 | if ( ! empty( $result->html_answer ) ) { |
||
| 172 | $payment->set_meta( 'ogone_directlink_html_answer', $result->html_answer ); |
||
| 173 | $payment->set_action_url( add_query_arg( 'payment_redirect', $payment->get_id(), home_url( '/' ) ) ); |
||
| 174 | } |
||
| 202 |