Score:0

How to dynamically set Test mode for a Webform_CiviCRM Contribution using Stripe Payment Processor

jp flag

This is in Drupal 9.5, CiviCRM 5.60, Webform 6.1, Webform_CiviCRM 6.2.

I have a webform which is allowing a Contact to make a CiviCRM Contribution - for example a simple Donation. If I manually set the Contribution into Test mode, then I can perform the payment process with a test card number, without actual money being involved. I would like to be able to programmatically set Test mode during the process, so that a particular Test User can make Test transactions while any other user is making live ones.

I can use hook_form_alter() to set 'is_test' and alter the Payment Processor to the test Id rather than the live one.

enter image description here

enter image description here

However, using hook_civicrm_alterPaymentProcessorParams() I can see that this has not propagated to the Payment Processor details. I can then alter the Payment Processor Id and 'is_test' in the rawParams array and also add these to cookedParams. (One cannot usefully alter the paymentObj parameter since it is not passed to the hook by reference.)

enter image description here

enter image description here

If I do all of these actions then the Test card number is accepted, and Stripe says 'Wait while we pre-authorise your card', but then gives an error saying:

No such payment_intent: 'pi_3N5W6IAQCXrpfr1t3tXQRdVm'; a similar object exists in test mode, but a live mode key was used to make this request.

I can also see that the paymentObj parameter contains the live PP Id, 'is_test' set to zero, and the live keys rather than test ones, which is clearly why it throws the error.

enter image description here

Is there any way of intervening earlier in the process so that live mode can be altered to test mode, and have that propagate into the Payment Processor details?

lk flag
if you've not done so already you might get a better response posting this question in https://civicrm.stackexchange.com
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.