================ Payment gateways ================ In order to receive payment from clients payment gateways should be configured. Enabling and configuring payment gateways ========================================= Configuration templates for payment gateway settings are present in ``settings.py`` file. If nothing related to gateways is present in the ``settings.py`` then probably you upgraded your Fleio installation and you will need to copy the settings template from ``settings.template`` file. .. _enable-gateway: Enabling a payment gateway ========================== In order to enable a payment gateway you need to edit the settings.py file and uncomment and edit the settings related to the payment gateway that needs to be enabled. Once you finish editing the ``settings.py`` file restart the fleio backend webserver and navigate to ``Billing/Gateways`` section in staff panel - the enabled payment gateway should be detected and displayed there. For specific configuration parameters details for a payment gateway see instructions below: * ``Paypal`` - visit https://developer.paypal.com/developer/applications/ log-in with your account and generate credentials at ``Rest API Apps`` section then edit ``PAYPAL_SETTINGS`` in ``settings.py`` ( you can generate credentials both for testing and live transactions ) Note: Make sure you set the payment receiver account to accept all currencies configured in fleio Use *https://fleio_url/backend/api/billing/gateway/paypal/callback* for webhooks to get event notifications * ``Romcard`` - you need to contact romcard via https://romcard.ro to obtain your API credentials then edit ``ROMCARD_SETTINGS`` in ``settings.py`` * ``Stripe`` - login to http://stripe.com go to ``API`` menu and you should find the API keys then edit ``STRIPE_SETTINGS`` in ``settings.py``. * ``PayU`` - You need to register at PayU for api credentials then edit ``PAYU_SETTINGS`` in ``settings.py``. * ``PayURO`` - you need to contact PayURO in order to obtain the api credentials then edit ``PAYURO_SETTINGS`` in ``settings.py``. Notes: * to get the ``signing_secret`` key you first need to create a webhook to *https://fleio_url/backend/api/billing/gateway/stripe/callback* on the stripe dashboard's webhooks section * Stripe should listen to all events related to Payment Intents: - ``payment_intent.amount_capturable_updated`` - ``payment_intent.canceled`` - ``payment_intent.created`` - ``payment_intent.payment_failed`` - ``payment_intent.succeeded`` * In order to fully use stripe with recurring payments you need to use at least the ``2019-09-09`` api version, configurable at stripe.com .. warning:: After you have enabled the gateway we will have to manually run the migrations in order to add the necessary fields in the database. First of all, you should consider making a backup of your database before doing any kind of changes to the DB. After you saved the backup, you will have to activate the environment by running the following command and manually run the django migrate command: .. code-block:: bash fleio django migrate After the migration is completed, you should restart all fleio services. Please see :ref:`restart-fleio`. Configuring a payment gateway ============================= After a gateway is enabled you can configure it from Billing/Gateways. The following options are available for a gateway: * ``Enabled`` - when enabled is checked the payment gateway can be used by staff to add manual payments * ``Visible to user`` - when visible to user is checked the payment gateway will appear in the payment options available to regular users * ``Fixed fee`` & ``Percent fee`` - the fees used by the payment gateway for each transactions - these will be stored in journal entries related to transactions Configuring a gateway for recurring payments ============================================ If you want to enable recurring payments for a gateway, you will have to first enable and configure the payment gateway as described above. You will also have to enable ``billing.recurring_payments`` in ``settings.py`` file. Some payment gateways will ned additional fields in the Fleio database, so you will need to re-run the migrations as you did in the previous step while enabling the payment gateway. First of all, you should consider making a backup of your database before doing any kind of changes to the DB. After you saved the backup, you will have to activate the environment by running the following command and manually run the django migrate command: .. code-block:: bash fleio django migrate After the migration is completed, you should restart all fleio services. Please see :ref:`restart-fleio`. The next step will be to enable the recurring payments from frontend. Just log in as staff in Fleio, go to Billing -> Gateways, click on the desired gateway and check the box "Enable recurring payments". Lastly, if you want to enable recurring payments for Stripe/PayuRO, you will have to configure the notification URL in the Stripe/PayuRO panel. The notification URL should be the same as the callback URL that was configured previously (:ref:`enable-gateway`). Bellow you can find an example for Stripe and PayuRO. .. image:: /_static/images/billing/gateway-configuration/stripe.png .. image:: /_static/images/billing/gateway-configuration/payuro.png