| Conditions | 9 |
| Paths | 51 |
| Total Lines | 139 |
| Lines | 15 |
| Ratio | 10.79 % |
| 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 |
||
| 141 | public function process_payment( $donation_data ) { |
||
| 142 | |||
| 143 | // Bailout, if the current gateway and the posted gateway mismatched. |
||
| 144 | if ( 'stripe' !== $donation_data['post_data']['give-gateway'] ) { |
||
| 145 | return; |
||
| 146 | } |
||
| 147 | |||
| 148 | // Make sure we don't have any left over errors present. |
||
| 149 | give_clear_errors(); |
||
| 150 | |||
| 151 | $payment_method_id = ! empty( $donation_data['post_data']['give_stripe_payment_method'] ) |
||
| 152 | ? $donation_data['post_data']['give_stripe_payment_method'] |
||
| 153 | : $this->check_for_source( $donation_data ); |
||
| 154 | |||
| 155 | // Any errors? |
||
| 156 | $errors = give_get_errors(); |
||
| 157 | |||
| 158 | // No errors, proceed. |
||
| 159 | if ( ! $errors ) { |
||
| 160 | |||
| 161 | $form_id = ! empty( $donation_data['post_data']['give-form-id'] ) ? intval( $donation_data['post_data']['give-form-id'] ) : 0; |
||
| 162 | $price_id = ! empty( $donation_data['post_data']['give-price-id'] ) ? $donation_data['post_data']['give-price-id'] : 0; |
||
| 163 | $donor_email = ! empty( $donation_data['post_data']['give_email'] ) ? $donation_data['post_data']['give_email'] : 0; |
||
| 164 | $donation_summary = give_payment_gateway_donation_summary( $donation_data, false ); |
||
| 165 | |||
| 166 | // Get an existing Stripe customer or create a new Stripe Customer and attach the source to customer. |
||
| 167 | $give_stripe_customer = new Give_Stripe_Customer( $donor_email, $payment_method_id ); |
||
| 168 | $stripe_customer = $give_stripe_customer->customer_data; |
||
| 169 | $stripe_customer_id = $give_stripe_customer->get_id(); |
||
| 170 | |||
| 171 | // We have a Stripe customer, charge them. |
||
| 172 | if ( $stripe_customer_id ) { |
||
| 173 | |||
| 174 | // Proceed to get stripe source/payment method details. |
||
| 175 | $payment_method = $give_stripe_customer->attached_payment_method; |
||
| 176 | $payment_method_id = $payment_method->id; |
||
| 177 | |||
| 178 | // Setup the payment details. |
||
| 179 | $payment_data = array( |
||
| 180 | 'price' => $donation_data['price'], |
||
| 181 | 'give_form_title' => $donation_data['post_data']['give-form-title'], |
||
| 182 | 'give_form_id' => $form_id, |
||
| 183 | 'give_price_id' => $price_id, |
||
| 184 | 'date' => $donation_data['date'], |
||
| 185 | 'user_email' => $donation_data['user_email'], |
||
| 186 | 'purchase_key' => $donation_data['purchase_key'], |
||
| 187 | 'currency' => give_get_currency( $form_id ), |
||
| 188 | 'user_info' => $donation_data['user_info'], |
||
| 189 | 'status' => 'pending', |
||
| 190 | 'gateway' => $this->id, |
||
| 191 | ); |
||
| 192 | |||
| 193 | // Record the pending payment in Give. |
||
| 194 | $donation_id = give_insert_payment( $payment_data ); |
||
| 195 | |||
| 196 | // Assign required data to array of donation data for future reference. |
||
| 197 | $donation_data['donation_id'] = $donation_id; |
||
| 198 | $donation_data['description'] = $donation_summary; |
||
| 199 | $donation_data['source_id'] = $payment_method_id; |
||
| 200 | |||
| 201 | // Save Stripe Customer ID to Donation note, Donor and Donation for future reference. |
||
| 202 | give_insert_payment_note( $donation_id, 'Stripe Customer ID: ' . $stripe_customer_id ); |
||
| 203 | $this->save_stripe_customer_id( $stripe_customer_id, $donation_id ); |
||
| 204 | give_update_meta( $donation_id, '_give_stripe_customer_id', $stripe_customer_id ); |
||
| 205 | |||
| 206 | // Save Source ID to donation note and DB. |
||
| 207 | give_insert_payment_note( $donation_id, 'Stripe Source/Payment Method ID: ' . $payment_method_id ); |
||
| 208 | give_update_meta( $donation_id, '_give_stripe_source_id', $payment_method_id ); |
||
| 209 | |||
| 210 | // Save donation summary to donation. |
||
| 211 | give_update_meta( $donation_id, '_give_stripe_donation_summary', $donation_summary ); |
||
| 212 | |||
| 213 | |||
| 214 | if ( give_stripe_is_checkout_enabled() ) { |
||
| 215 | |||
| 216 | // Process charge w/ support for preapproval. |
||
| 217 | $charge = $this->process_charge( $donation_data, $stripe_customer_id ); |
||
| 218 | |||
| 219 | // Verify the Stripe payment. |
||
| 220 | $this->verify_payment( $donation_id, $stripe_customer_id, $charge ); |
||
| 221 | } else { |
||
| 222 | |||
| 223 | /** |
||
| 224 | * This filter hook is used to update the payment intent arguments. |
||
| 225 | * |
||
| 226 | * @since 2.5.0 |
||
| 227 | */ |
||
| 228 | $intent_args = apply_filters( |
||
| 229 | 'give_stripe_create_intent_args', |
||
| 230 | array( |
||
| 231 | 'amount' => $this->format_amount( $donation_data['price'] ), |
||
| 232 | 'currency' => give_get_currency( $form_id ), |
||
| 233 | 'payment_method_types' => [ 'card' ], |
||
| 234 | 'statement_descriptor' => give_stripe_get_statement_descriptor(), |
||
| 235 | 'receipt_email' => $donation_data['user_email'], |
||
| 236 | 'description' => give_payment_gateway_donation_summary( $donation_data ), |
||
| 237 | 'metadata' => $this->prepare_metadata( $donation_id ), |
||
| 238 | 'customer' => $stripe_customer_id, |
||
| 239 | 'payment_method' => $payment_method_id, |
||
| 240 | 'confirm' => true, |
||
| 241 | 'return_url' => give_get_success_page_uri(), |
||
| 242 | ) |
||
| 243 | ); |
||
| 244 | $intent = $this->payment_intent->create( $intent_args ); |
||
| 245 | |||
| 246 | // Save Payment Intent Client Secret to donation note and DB. |
||
| 247 | give_insert_payment_note( $donation_id, 'Stripe Payment Intent Client Secret: ' . $intent->client_secret ); |
||
| 248 | give_update_meta( $donation_id, '_give_stripe_payment_intent_client_secret', $intent->client_secret ); |
||
| 249 | |||
| 250 | // Set Payment Intent ID as transaction ID for the donation. |
||
| 251 | give_set_payment_transaction_id( $donation_id, $intent->id ); |
||
| 252 | give_insert_payment_note( $donation_id, 'Stripe Charge/Payment Intent ID: ' . $intent->id ); |
||
| 253 | |||
| 254 | // Process additional steps for SCA or 3D secure. |
||
| 255 | give_stripe_process_additional_authentication( $donation_id, $intent ); |
||
| 256 | |||
| 257 | // Send them to success page. |
||
| 258 | give_send_to_success_page(); |
||
| 259 | |||
| 260 | } |
||
| 261 | View Code Duplication | } else { |
|
| 262 | |||
| 263 | // No customer, failed. |
||
| 264 | give_record_gateway_error( |
||
| 265 | __( 'Stripe Customer Creation Failed', 'give' ), |
||
| 266 | sprintf( |
||
| 267 | /* translators: %s Donation Data */ |
||
| 268 | __( 'Customer creation failed while processing the donation. Details: %s', 'give' ), |
||
| 269 | wp_json_encode( $donation_data ) |
||
| 270 | ) |
||
| 271 | ); |
||
| 272 | give_set_error( 'stripe_error', __( 'The Stripe Gateway returned an error while processing the donation.', 'give' ) ); |
||
| 273 | give_send_back_to_checkout( '?payment-mode=' . give_clean( $_GET['payment-mode'] ) ); |
||
| 274 | |||
| 275 | } // End if(). |
||
| 276 | } else { |
||
| 277 | give_send_back_to_checkout( '?payment-mode=' . give_clean( $_GET['payment-mode'] ) ); |
||
| 278 | } // End if(). |
||
| 279 | } |
||
| 280 | |||
| 373 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.