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.
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.)
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.
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?