Title: Gateway Code is messy
Last modified: May 19, 2021

---

# Gateway Code is messy

 *  Resolved [mikeknappe](https://wordpress.org/support/users/mikeknappe/)
 * (@mikeknappe)
 * [5 years ago](https://wordpress.org/support/topic/gateway-code-is-messy/)
 * Hi Patterson,
 * I’ve looked into the code, because one thing didn’t worked for me.
 * For example: If I turn on Paypal in the contact form and use a selection where
   paypal, stripe and transaction are inserted, choose transaction and on submit
   I will be redirected to Paypal. There shouldn’t be any redirection at this point.
 * This behaviour is mainly based on two things:
    1. cf7pp_before_send_mail in redirect_methods.
   php: Somewhere around line 150
 *     ```
       if ($enable == '1') {
           $gateway = 'paypal';
       }
   
       if ($enable_stripe == '1') {
           $gateway = 'stripe';			
       }
   
       if ($enable == '1' && $enable_stripe == '1') {
           $gateway = $posted_data[$gateway_orig][0];
       }
       ```
   
 * The gateway check is not well here.
    You don’t check against $posted_data, if
   only one payment is active. You need to check against it always.
 * Something like this would fix the failure:
 *     ```
       $gateway_data = strtolower(get_post_meta($post_id, "_cf7pp_gateway", true));
       $gateway = '';
       $gw = strtolower($posted_data[$gateway_data][0]);
       if ( ($enable_paypal == '1' && $gw == 'paypal') ||
            ($enable_stripe == '1' && $gw == 'stripe') ){
            $gateway = $gw;
       }
       ```
   
 * 2.
    Based on the fix in redirect_methods.php we have this code-snippet here: 
   assets/js/redirect_method.js: Around Line 91
 *     ```
       // gateway chooser
       if (cf7pp_gateway != null)
       ```
   
 * The redirection will be done, more or less regardless of the gateway.
    The else-
   tree needs to terminate the action, because the posted gateway leads not to any
   gateway. On the other hand, if so, use the normal if-tree statements.
 * Best regards,
    Mike

The topic ‘Gateway Code is messy’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7-paypal-add-on/assets/icon-256x256.png?rev
   =3095880)
 * [Contact Form 7 - PayPal & Stripe Add-on](https://wordpress.org/plugins/contact-form-7-paypal-add-on/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7-paypal-add-on/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7-paypal-add-on/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7-paypal-add-on/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7-paypal-add-on/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7-paypal-add-on/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [mikeknappe](https://wordpress.org/support/users/mikeknappe/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/gateway-code-is-messy/)
 * Status: resolved