Creating a view to map payment methods (PlugSales)
Payment methods on PlugSales must have the following information:
- ID
- Numeric field of type inteiro that identifies the type of payment. This field is returned in the request.
- NAME
- texto field with the name of the payment method. Examples: Cash, Credit Card, Boleto.
To adapt to the PlugSales format, it is not necessary for you to create a new payment methods table with these columns and start registering from scratch.
Just create a view in your database, which will return records with the columns needed by PlugSales.
What is a view?
Section titled “What is a view?”In practice, a view is a virtual table in which its records are the results of a SELECT defined at the time of its creation.
For example, to create a view that simulates a table that displays only VIP customers:
CREATE VIEW ClientesVIP AS SELECT FirstName1, LastName1 FROM Customers WHERE VIP = ‘S’;
And the query from VIP customers about this view would simply be:
SELECT * FROMClientsVIP;
Creating a Payment Methods view for PlugSales
Section titled “Creating a Payment Methods view for PlugSales”Example: MySQL
Section titled “Example: MySQL”To create the payment methods view that PlugSales needs, imagine that you have the following table in your database:

PlugSales needs information that is, in this scenario, in this table but with column names different from the necessary fields.
To solve this and give PlugSales the information it needs about payment methods, you can write a SQL query passing alias names to the columns, which will be executed every time PlugBot needs to read information about your payment methods.
Or you can create an view that will bring the data in the correct format all at once to PlugSales.
To create the view that serves PlugSales in this table structure, the SQL would be as follows:
CREATE OR REPLACE VIEW VwFormasPagamentoPlugSales AS SELECT payment_code AS id, payment_description AS name FROM tbformaspagamento;
Once the VwFormasPagamentoPlugSales view is created, you can select this view in the dashboard and PlugBot can simply perform a simple SELECT * FROM VwFormasPagamentoPlugSales to obtain the necessary data.

And when loading the data from this view, whether directly from the table, or using an SQL query, the data will already be formatted correctly in the columns that PlugSales expects!
