Once a site has been connected to a Stripe platform via #2957541: Create a site-wide Stripe Connect form, it should be possible to select that connected account in the Stripe payment method configuration form. When the form is built, we should check to see if we find any site-wide credentials and if so add radio buttons above the normal API credentials elements. These radio buttons should read:
- Key: 'none' - Value: 'Input API credentials for this payment method.'
- Key: 'site account' - Value: 'Use the site-wide account identified via Stripe Connect.
If the second option is chosen, the normal API credentials fields should disappear. This is made possible via form states, but we may need to address the required boolean on elements ... not sure how the config is now, but even if hidden, a required field would fail validation if empty.
Note that this field needs to become part of the payment method configuration so we can detect in the future that the 'site account' has been specified and retrieve the API credentials as needed for submitting API requests.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 2958942-6.use_connected_account.patch | 3.75 KB | rszrama |
Comments
Comment #2
lisastreeter commentedIn Stripe Connect issue #2957470 (Merge default values into the $settings array in commerce_stripe_settings_form), the Stripe API settings were separated from the Payment Method settings. So the changes for this issue were applied to that separate Stripe configuration form rather than to the payment method configuration form.
When the "site account" option is selected, the api credentials for the connected account are copied into the "public key" and "secret key" Stripe settings so that they will be used for all API requests instead of the values input directly.
This patch builds upon the work done in previous patches and should only be applied after this patch: connect_form-2957541-4.patch
Comment #3
lisastreeter commentedNow that Issue #2957470: Merge default values into the $settings array in commerce_stripe_settings_form() has been scaled back to the originally proposed scope, site-wide "commerce stripe" settings no longer exist. This patch uses commerce_stripe_set_setting() to override the commerce stripe site-wide 'secret_key' and 'public_key' with the connected account credentials. So this patch is no longer functional.
Having the settings remain in the payment method configuration rather than moving into site-wide global settings may also necessitate eliminating the commerce_stripe_connect submodule and instead making it fully integrated/required by commerce stripe.
In the commerce_stripe.module
commerce_stripe_libraries_postload_callback()and_commerce_stripe_set_api_keyfunctions, the following line:\Stripe\Stripe::setApiKey(trim($payment_method['settings']['secret_key']));needs to be preceded by a check for the
use_connected_accountconnect setting.Also, in
commerce_stripe_payment_currencies, the following line:if (!empty($payment_method['settings']['secret_key']))needs to be preceded by a check for the
use_connected_accountconnect setting.In the commerce_stripe.module
commerce_stripe_settings_form()function, whenever the connected account is being used, the 'secret_key' and 'public_key' elements should disappear as described in the original issue description. (These settings were removed in the patch that created site-wide settings.)Then in /includes/commerce_stripe.admin.inc, connected account checks need to be made in commerce_stripe_refund_form() and commerce_stripe_refund_form_submit() prior to:
Stripe\Stripe::setApiKey(trim($payment_method['settings']['secret_key']));So essentially, changes that were made to the module in the Merge default values into the settings array patch now need to be made here instead. And... since the Stripe module code now needs to directly access a Stripe Connect setting, the Stripe Connect code cannot be segregated into a submodule.
Comment #4
rszrama commentedThis is a quick reroll to accommodate some changes I made in another patch. Now reviewing Lisa's comments to see if we do need to relocate this code or not. As far as I'm concerned, it's ok for there to be a tight coupling and even optional interdependency between the modules ... in other words, we can use a module_exists() check in commerce_stripe.module for the time being with a @todo about resolving that once we have a site-wide Stripe configuration.
Comment #5
rszrama commentedOk, reviewing this patch further now, I see what you mean, Lisa.
Right now this is looking for the connected account setting when the Oauth connection is made, but we really want the opposite - once you've connected the site to a Stripe account, it should give you the option on the payment method configuration to use that rather than input the API parameters. (At least, that's the workflow I had in mind ... connect the site first then configure the payment method ... but I can see it working this way too.)
I'm going to move your form element and form states into the primary module with a module_exists() check and a connected_account_id check as well. Will attach a follow-up shortly.
Comment #6
rszrama commentedPatch attached that reduces the scope of the previous one a little further. We don't actually need to set the API credentials here. In fact, it's possibly better in the event the connected account changes ... but the idea is that anywhere the API credentials are loaded, we check the "use_connected_account" variable there and load in the Stripe Connect values instead. Will take care of that in #2958943: Submit API requests using connected account credentials.
This also helps us sidestep the fact that we don't really have a great way to alter on a submit handler to the settings form. Will see what other issues this creates for us as a result. :-/
Comment #8
rszrama commentedCommitted.