Card element doesn't get destroyed when an anonymous session changes payment processor
Steps to reproduce
This issue is related but not the same as #123 (closed), and the steps to reproduce it are similar:
- create a contribution page with a Stripe payment processor by default and at least another one of a different type,
- open the contribution page with an anonymous session,
- switch to the other payment processor and try to complete the payment.
This was reproduced in a system that was using Stripe 6.3.2 and MJWShared 0.6 over CiviCRM 5.16.3. The additional payment processor was Smart Debit 1.35.
The issue
The issue is related with permissions to run the API PaymentProcessor
from an anonymous session, in particular, here:
CRM.api3('PaymentProcessor', 'getvalue', {
"return": "user_name",
"id": paymentProcessorID,
"payment_processor_type_id": CRM.vars.stripe.paymentProcessorTypeID,
})
The expected behaviour
When switching to the alternative payment processor, if JavaScript debugging is enabled, this messages are expected to be shown:
civicrm_stripe.js: payment processor changed to id: 5
civicrm_stripe.js: New payment processor is not Stripe, clearing CRM.vars.stripe
civicrm_stripe.js: destroying card element
The unexpected behaviour
If the test form is sent with an administrative session, the previous messages are shown. But if the form is sent with an anonymous session, only the first of them is shown, as the process gets stopped when the API call is done:
civicrm_stripe.js: payment processor changed to id: 5
A proposal
I've prepared a pull request where the public keys of active Stripe payment processors are directly published as JavaScript variables as CRM.vars.stripe_keys
.
The change also includes a change in civicrm_stripe.js
son the API call described above is removed as it's no longer needed.