mecachisenros / cf-civicrm

Caldera Forms CiviCRM Integration
GNU Affero General Public License v3.0
30 stars 26 forks source link

Stripe Processor Broken Redirect #170

Open gvanhoy opened 4 years ago

gvanhoy commented 4 years ago

Describe the bug Using Stripe Payment Processor on any form yields an error after submitting payment.

Other Information The payment successfully goes through, but redirecting back to the form causes a critical error on the site. I am not redirecting using a processor. I only have a stripe payment processor. The only reason I am posting here is because disabling this plugin allows payments to successfully redirect back to pages.

To Reproduce Steps to reproduce the behavior:

  1. Create a form with first name, last name, and email from scratch
  2. Use ONLY a stripe payment processor with valid keys.

Expected behavior I expect to be redirected back to the form page after successful payment.

Errors

Notice: Undefined index: stripe in /var/www/html/wp-content/plugins/cf-civicrm/processors/order/class-order-processor.php on line 608 
Notice: Trying to get property 'balance_transaction' of non-object in /var/www/html/wp-content/plugins/cf-civicrm/processors/order/class-order-processor.php on line 608 

Fatal error: Uncaught Stripe\Error\InvalidRequest: Could not determine which URL to request: Stripe\BalanceTransaction instance has invalid ID: in /var/www/html/wp-content/plugins/cf-stripe/vendor/stripe/stripe-php/lib/ApiResource.php:97 

Full Stack-Trace

#0 /var/www/html/wp-content/plugins/cf-stripe/vendor/stripe/stripe-php/lib/ApiResource.php(110): Stripe\ApiResource::resourceUrl(NULL) 
#1 /var/www/html/wp-content/plugins/cf-stripe/vendor/stripe/stripe-php/lib/ApiResource.php(56): Stripe\ApiResource->instanceUrl() 
#2 /var/www/html/wp-content/plugins/cf-stripe/vendor/stripe/stripe-php/lib/ApiOperations/Retrieve.php(24): Stripe\ApiResource->refresh() 
#3 /var/www/html/wp-content/plugins/cf-civicrm/processors/order/class-order-processor.php(611): Stripe\BalanceTransaction::retrieve(NULL) 
#4 /var/www/html/wp-includes/class-wp-hook.php(287): CiviCRM_Caldera_Forms_Order_Processor->{closure}(Array, Array, Array, Array) 
#5 /var/www/html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array) 
#6 /var/www/html/wp-includes in /var/www/html/wp-content/plugins/cf-stripe/vendor/stripe/stripe-php/lib/ApiResource.php on line 97

Software Versions WordPress Version: 5.4.2 PHP Version: 7.3.19 MySQL Version: 5.5.5 Server Software: nginx/1.17.6 Your User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Session Save Path: Session Save Path Exists: No Session Save Path Writeable: No Session Max Lifetime: 1440 Opcode Cache: Apc: No Memcached: No Redis: No Object Cache: Apc: No Apcu: No Memcache: No Memcached: No Redis: No WPDB Prefix: wp_

WP Multisite Mode: No WP Memory Limit: 40M Currently Active Theme: Divi: 4.5.1

Plugins: Caldera Forms: 1.9.1 Active Caldera Forms Stripe: 1.4.11 Active Caldera Forms Style Customizer (CFSC) for Divi & Extra: 1.0.3 Active Caldera Forms Users: 1.3.10 Active CalderaWP License Manager: 1.2.10 Active CF CiviCRM: 1.0.5 Active CiviCRM: 5.27.0 Active Mail Templates For Caldera Forms: 1.0.4 Active Really Simple SSL: 3.3.4 Active WP Mail SMTP: 2.2.1 Active WP Rollback: 1.7.0 Active

gvanhoy commented 4 years ago

Additional information: By flushing the cache and deleting all transients, this error does not occur for at least one form submission.

twocs commented 4 years ago

on line 608 of class-order-processor.php $transdata['stripe']->balance_transaction is accessed.

But nowhere else in the code is the value of $transdata['stripe'] set to a thing... What is going on with this variable?

twocs commented 4 years ago

We found an older version of cf-stripe 1.4.7 on a client's server so looked at its code.

They have updated cf-stripe, so it no longer stores its data in $transdata. Here's an example of old version (1.4.7 can work with cf-civicrm) and new version (1.4.11, utterly broken with cf-civicrm)

1.4.7: cf_stripe_process_token assigns $transdata: $transdata['stripe'] = $charge; 1.4.11: No assignment of anything to $transdata['stripe']

/**
 * Returns the Stripe payment data if successful
 *
 * @since 1.0.0
 *
 *
 * @param array     $config     processors config array
 * @param array     $form       forms full config array
 *
 * @return array    transaction data
 */
function cf_stripe_return_charge( $config, $form ){
    global $transdata;

    if( !empty( $transdata['stripe'] ) ){

        // is a recurring
        if( $config['type'] == 'plan' ){

            $return_charge = array(
                'ID'        =>  $transdata['stripe']->id,
                'live'      =>  ( $transdata['stripe']->livemode ? 'Yes' : 'No' ),
                'Plan'      =>  $transdata['stripe']->subscriptions->data[0]->plan->name,
                'Amount'    =>  $transdata['stripe']->subscriptions->data[0]->plan->amount / 100,
                'Currency'  =>  $transdata['stripe']->subscriptions->data[0]->plan->currency,
                'Interval'  =>  $transdata['stripe']->subscriptions->data[0]->plan->interval,
                'Count'     =>  $transdata['stripe']->subscriptions->data[0]->plan->interval_count,
                'Trial_Days'=>  $transdata['stripe']->subscriptions->data[0]->plan->trial_period_days,
                'Created'   =>  date( 'r', $transdata['stripe']->subscriptions->data[0]->plan->created ),
                'subscription_id' => $transdata['stripe']->subscriptions->data[0]->id,
            );

        }else{

            $return_charge = array(
                'ID'        =>  $transdata['stripe']->id,
                'live'      =>  ( $transdata['stripe']->livemode ? 'Yes' : 'No' ),
                'Amount'    =>  $transdata['stripe']->amount / 100,
                'Currency'  =>  $transdata['stripe']->currency,
                'Created'   =>  date( 'r', $transdata['stripe']->created ),
            );
        }

        /**
         * Runs after a successful charge is made.
         *
         * Note: Use $return_charge[ 'ID' ] for the customer ID.
         * Note: For recurring charges, use $return_charge[ 'subscription_id' ] for subscription plan ID.
         *
         * @since 1.4.0
         *
         * @param array $return_charge Data about the successful charge, returned from stripe.
         * @param array $transdata Data used to create transaction.
         * @param array $config The processor's configuration.
         * @param array $form The current form.
         */
        do_action( 'cf_stripe_post_successful_charge', $return_charge, $transdata, $config, $form );
        return $return_charge;
    }
}
twocs commented 4 years ago

Stripe\BalanceTransaction::retrieve(NULL) This line of the output shows that there's no Stripe data in $transdata['stripe']

Is there another branch of the repo that handles this plugin? Not really clear from the Readme if cf-stripe 1.4.9+ is not supported.