diff --git a/CRM/Stripe/Customer.php b/CRM/Stripe/Customer.php index 9b8d33025aed8f1c7e8d5b8935bec10eb52e6d87..92254ba6f7042973bd51da1f1762e34cc3888332 100644 --- a/CRM/Stripe/Customer.php +++ b/CRM/Stripe/Customer.php @@ -180,7 +180,7 @@ class CRM_Stripe_Customer { $stripeCustomerParams = self::getStripeCustomerMetadata($params); try { - $stripeCustomer = \Stripe\Customer::update($stripeCustomerID, $stripeCustomerParams); + $stripeCustomer = $stripe->stripeClient->customers->update($stripeCustomerID, $stripeCustomerParams); } catch (Exception $e) { $err = CRM_Core_Payment_Stripe::parseStripeException('create_customer', $e, FALSE); diff --git a/CRM/Stripe/Upgrader.php b/CRM/Stripe/Upgrader.php index c5cac2e7b5440df44727c7d3bfecd836df2106ee..549abd4b1f52d1e0b056116981903f917ee8125c 100644 --- a/CRM/Stripe/Upgrader.php +++ b/CRM/Stripe/Upgrader.php @@ -158,21 +158,22 @@ class CRM_Stripe_Upgrader extends CRM_Stripe_Upgrader_Base { $dbName = DB::connect($config->dsn)->_db; $null_count = CRM_Core_DAO::executeQuery('SELECT COUNT(*) FROM civicrm_stripe_subscriptions where subscription_id IS NULL'); - if ( $null_count == 0 ) { + if ($null_count == 0) { $this->ctx->log->info('Skipped civicrm_stripe update 5004. No nulls found in column subscription_id in our civicrm_stripe_subscriptions table.'); } else { $customer_infos = CRM_Core_DAO::executeQuery("SELECT customer_id,processor_id FROM `civicrm_stripe_subscriptions`;"); - while ( $customer_infos->fetch() ) { + while ($customer_infos->fetch()) { $processor_id = $customer_infos->processor_id; $customer_id = $customer_infos->customer_id; try { - $processor = new CRM_Core_Payment_Stripe('', civicrm_api3('PaymentProcessor', 'getsingle', ['id' => $processor_id])); + /** @var \CRM_Core_Payment_Stripe $paymentProcessor */ + $paymentProcessor = \Civi\Payment\System::singleton()->getById($processor_id); - $subscription = \Stripe\Subscription::all([ - 'customer'=> $customer_id, - 'limit'=>1, + $subscription = $paymentProcessor->stripeClient->subscriptions->all([ + 'customer' => $customer_id, + 'limit' => 1, ]); } catch (Exception $e) { diff --git a/stripe.php b/stripe.php index c7581cd25639dad497faccc6099f2417ba582f97..8339fbcf5bc537a561de1a063026f7aa83d206b7 100644 --- a/stripe.php +++ b/stripe.php @@ -150,7 +150,6 @@ function stripe_civicrm_buildForm($formName, &$form) { /** @var \CRM_Core_Payment_Stripe $paymentProcessor */ $paymentProcessor = \Civi\Payment\System::singleton()->getById($form->_paymentProcessor['id']); - $paymentProcessor->setAPIParams(); try { $jsVars = [ 'id' => $form->_paymentProcessor['id'], @@ -164,7 +163,7 @@ function stripe_civicrm_buildForm($formName, &$form) { switch (substr($paymentIntent['stripe_intent_id'], 0, 2)) { case 'pi': // pi_ Stripe PaymentIntent - $stripePaymentIntent = \Stripe\PaymentIntent::retrieve($paymentIntent['stripe_intent_id']); + $stripePaymentIntent = $paymentProcessor->stripeClient->paymentIntents->retrieve($paymentIntent['stripe_intent_id']); // We need the confirmation_method to decide whether to use handleCardAction (manual) or handleCardPayment (automatic) on the js side $jsVars['paymentIntentID'] = $stripePaymentIntent->id; $jsVars['intentStatus'] = $stripePaymentIntent->status; @@ -173,7 +172,7 @@ function stripe_civicrm_buildForm($formName, &$form) { case 'se': // seti_ Stripe SetupIntent - $stripeSetupIntent = \Stripe\SetupIntent::retrieve($paymentIntent['stripe_intent_id']); + $stripeSetupIntent = $paymentProcessor->stripeClient->setupIntents->retrieve($paymentIntent['stripe_intent_id']); $jsVars['setupIntentID'] = $stripeSetupIntent->id; $jsVars['setupIntentNextAction'] = $stripeSetupIntent->next_action; $jsVars['setupIntentClientSecret'] = $stripeSetupIntent->client_secret; diff --git a/utils/fix-issue-44.php b/utils/fix-issue-44.php index 966441d20fed7b0b6dad99b71dc17c20d5def4a0..60d149be674deb730a7f1684de6a0439492eb095 100644 --- a/utils/fix-issue-44.php +++ b/utils/fix-issue-44.php @@ -51,10 +51,12 @@ while ($dao->fetch()) { if (!$paymentProcessor) { echo "Failed to find a stripe payment processor for recurring contrib $dao->contribution_recur_id\n"; } - $processor = new CRM_Core_Payment_Stripe('', civicrm_api3('PaymentProcessor', 'getsingle', ['id' => $paymentProcessor['id']])); + + /** @var \CRM_Core_Payment_Stripe $processor */ + $processor = \Civi\Payment\System::singleton()->getById($paymentProcessor['id']); try { - $results = Charge::retrieve(['id' => $dao->trxn_id]); + $results = $processor->stripeClient->charges->retrieve($dao->trxn_id); //print json_encode($results, JSON_PRETTY_PRINT); if (empty($results->created)) { echo " Failed to retrieve a charge created date\n";