webdna / commerce-braintree

Braintree gateway for Craft Commerce
Other
2 stars 10 forks source link

use environment settings for plugin config #8

Closed oddnavy closed 5 years ago

oddnavy commented 5 years ago

It would be great if the inputs for the plugin configuration could be switched to the autosuggestField instead of of the textField. This would allow environment settings to be used.

https://docs.craftcms.com/v3/extend/environmental-settings.html#autosuggest-inputs

{% from "_includes/forms" import autosuggestField, lightswitchField %}

{{ autosuggestField({
    label: 'Merchant Id'|t('commerce'),
    id: 'merchantId',
    class: 'ltr',
    name: 'merchantId',
    value: gateway.merchantId,
    errors: gateway.getErrors('merchantId'),
    suggestEnvVars: true
}) }}

{{ autosuggestField({
    label: 'Public Key'|t('commerce'),
    id: 'publicKey',
    class: 'ltr',
    name: 'publicKey',
    value: gateway.publicKey,
    errors: gateway.getErrors('publicKey'),
    suggestEnvVars: true,
}) }}

{{ autosuggestField({
    label: 'Private Key'|t('commerce'),
    id: 'privateKey',
    class: 'ltr',
    name: 'privateKey',
    value: gateway.privateKey,
    errors: gateway.getErrors('privateKey'),
    suggestEnvVars: true
}) }}

The plugin could then use the parseEnv method in Craft to retrieve the setting.

https://docs.craftcms.com/v3/extend/environmental-settings.html

 Craft::parseEnv($this->merchantId)

This would also the public / private keys to be set via environment variables rather than them being stored in the project config like it is currently.

image

samuelbirch commented 5 years ago

released in v2.2.1

zackspear commented 5 years ago

This has been a great addition for us as we're soon to go live and have been testing pretty thorough across our environments; including real CCs and PayPal accounts.

One additional item that's related to the original issue here would be to somehow have a way of setting "Test Mode" based on the environment.

Because as of right now changes to the Test Mode setting is updating the project config. Which means we have to turn off Test Mode locally. Commit to Git. Then finally deploy the change to project.yaml and sync the changes at /admin after the deployment is finished.

It would be great if there was some way to have the Test Mode setting be environment specific. This way local can stay in Test Mode while staging and production can be based on whatever we need for those envs.

samuelbirch commented 5 years ago

you can set the test mode as well as the other setting for each environment via the braintree config file.

zackspear commented 5 years ago

thanks @samuelbirch. some documentation for that in the README would be helpful for those that aren't as backend centric.

samuelbirch commented 5 years ago

@zackspear thanks for the feedback, i'll get that added in but also see if there is an easier way to do it via environment variables.