chamilo / chamilo-lms

Chamilo is a learning management system focused on ease of use and accessibility
https://chamilo.org
GNU General Public License v3.0
792 stars 478 forks source link

shop plugin api or payment provider support. #2745

Closed spacecabbie closed 5 years ago

spacecabbie commented 5 years ago
`**Is your feature request related to a problem? Please describe.**`
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Shop module is limited. could use some more options

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

So the current plugin is a bit limited but it look really nice i like to keep using it but add payments for example some of the greater payment portals in holland for example mollie is very popular. So its 2 part request to include more payment providers in the next chamilo version or allow an api to interact with the shop. Also i think a feature like these could increase user base since we all in the end need to fund our endevours.

2 part is i like to see if i can program it my self a bit. But not sure where to start.

Coding conventions
Database structure

Helped so much in learning and understanding is there anything like this for the plugin ?

Ps. if the plugin is developed seperatly please point me to the developer.

opensourcecompany commented 5 years ago

You can use the prestashop plugin. There is NO limitation.

spacecabbie commented 5 years ago

You can use the prestashop plugin. There is NO limitation.

Ah din't see that one thank you for that one. I din't mean offense ? If it was received as such my appolidgies

ywarnier commented 5 years ago

@spacecabbie no worries, @opensourcecompany is used to a very direct language but he meant no offense either :smile:

There is no additional documentation for the "buy_course" plugin at the moment, sorry. It was developed a bit in a hurry and is being used only very recently on campus.chamilo.org (before that, it wasn't used internally, so chances are it will be improved over time now).

In our experience (with the Culqi payment system), integrating a new payment system and doing the testing takes about 20-30h of work (for a minimal integration) and we (the BeezNest team) haven't been able to do more work on this, but if you search through the issues queue, you will find requests to add several payment systems.

The buy_course plugin has several stuff that are not really included in the interface properly yet (with a nice UI), like the possibility of using recurring payments and pay teachers based on a commission on each sale, or the possibility to sell "services" (which are meant to be kind of plugins on the plugin).

Anyway, right now is not a very good time for us to help you out. With the management of 1.11.10 release preparation and the development of 2.0 in simultaneous + the end of year holiday, this is a very difficult time to ask us to document this plugin :smile:

In 2.0, we would like to have the buy_course plugin included as code in the core of Chamilo, but we're not sure yet we will have the luxury to do it. At least we hope we can do it. If so, that would mean the plugin tables would not be called "pluginbuycourse*" anymore but rather be included in the normal installation process of Chamilo.

What more can I say? It was originally contributed by @nosolored and then massively updated by BeezNest to become more secure, more usable and to include new features.

The most urgent thing for us at the moment is to include the generation of a kind of digital invoice. Then we would like to extend to a few additional payment systems (and that would probably lead us to simplify a bit the interface to connect payment systems).

Of course, feel free to check at the Culqi implementation, as this is the only new payment interface that has been added after the original version of the plugin. This should give you a good idea of what's needed (and it should also be relatively limited in scope).

The "install()" method of the plugin normally contains all the database creation code. Feel free to submit a pull request with just added comments in there and we'll fix that if they are wrong (but try to send that as a separate pull request in comparison to logic-changing pull requests - I think we have something about that in the coding conventions)

ywarnier commented 5 years ago

Regarding the comment about Prestashop: this is true, although I've received a report that the plugin doesn't work with Prestashop 1.7.

However, we prefer to be offering a more integrated system to receive payments, as we feel Prestashop is too complex to configure for most people dealing with a Chamilo portal: these are 2 different systems with 2 very different interfaces, so it may take a bit of time to get used to both systems, while the payment plugin in Chamilo offers a relatively smooth integration with no style change required and minimal setup time.

Clearly, for a more complete online shopping experience, Prestahop is better. These are just 2 different use cases.

spacecabbie commented 5 years ago

I am gonna give it a go converting the paypal call to the Mollie one they provide a basic php system ready made so even with my limited experience i might get something done. I am basically using chamilo to extend my knowledge of coding :) I am not comfortable pushing anything i made (you might laugh at me :) no seriously i feel that i am no where near that level i'll upload them at my respiratory then when things have callmed down i can push it don't wana stack on the workload. I agree that prestashop is overkill i really like the simple but beautiful interface of the plugin.

Issue can be closed although i am not sure what the preverance is so i leave to you.

tian2992 commented 5 years ago

I am quite interested as well in following this ticket. I have considered working on the implementation of another payment gateway, but I have found support and documentation quite lacking. I would like to help, and contribute, however I would need to know more before being able to aid. Sorry if it is hijacking the thread, @ywarnier but If you have any more info on the process that was involved in making Culqui or a generalist approach on integration I would be really thankful.

Cheers!

ywarnier commented 5 years ago

This issue can stay open, and even be transformed into a pull request (although I'm not sure this is the best way in this case).

The right way to contribute here (even with bad code initially) is to fork this project in Github and launch a new branch from branch 1.11.x in your fork. Then you can submit your branch as a pull request against branch 1.11.x of Chamilo. This is highly simplified through Github's interface (there's always an option to do what you need), so I would recommend trying the process here before trying to do that through git commands locally. Creating a pull request can only be done through Github's interface anyway.

Regarding the Culqi integration, you can simply search for the "culqi" string in plugin/buycourse/.

You will find the required table creation for culqi info in plugin/buycourse/database.php. At the moment, this means that each payment service has its own table, which is clearly not ideal (as it requires more tables for each payment method) but we can do with that for now (we could do an upgrade process later on) as there are only currently 3 payment methods (bank payment, paypal and culqi).

database.php might look for constants like BuyCoursesPlugin::TABLE_CULQI. These are defined in the main plugin class: src/buy_courseplugin.class.php. All plugin tables MUST start with "plugin[name_ofplugin]", so make sure you respect that.

In https://github.com/chamilo/chamilo-lms/blob/1.11.x/plugin/buycourses/src/service_process_confirm.php#L185, you will find an example of a full section dealing with the specific behaviour of Culqi. There are different files in src/ that will have similar sections.

https://github.com/chamilo/chamilo-lms/blob/814049e5bd5317d761dda0ebbbc519cb2a64ab6c/plugin/buycourses/src/service_process_confirm.php#L185-L189

New language terms have to be called differently in TPL (template files using Twig) and direct PHP code. It is a bit difficult at first to deal with templates, but there are numerous maintainability advantages of doing so, so using templates is a requirement for plugins integration, but you will see that the many examples will help you out, and it is very likely that you won't even need to create a single .tpl file.

For TPL files, language terms are defined and translated like this:

    <h3>{{ 'PurchaseData'|get_plugin_lang('BuyCoursesPlugin') }}</h3>

Where PurchaseData is an internal language variable name (that you give yourself in English) and get_plugin_lang() is the function that will call the translation of that term depending on the language of the user's interface. Finally, BuyCoursesPlugin is just the name of the plugin and it tells the function where to look for translations. In simple .php files, you will find calls like:

$form->addHeader($plugin->get_lang('SearchFilter'));

The important part here is the $plugin->... part, where get_lang() is the method of the Plugin class and SearchFilter is the internal name for that variable.

The language files themselves are very easy to understand and extend and can be found in plugin/buycourses/lang/. If your language is not supported, you can simply copy english.php to yourlanguage.php (where yourlanguage has to be the same as one of the folders inside the main/lang/ folder.

The rest is pretty much just looking around for the right thing to do, doing some copy-paste and adapting along (and testing a lot). Initially (in your merge request) you can put the provider-specific library (if these are Open Source and compatible with GNU/GPLv3 - usually they are released as MIT or LGPL, which are compatible) in plugin/buycourses/src/vendor/, and we will try to generate a proper dependency when we integrate it by moving the library files to chamilo/vendor (adding them to composer.json) but if you get to a working version by using plugin/buycourses/src/vendor/, we don't mind the extra work of dealing with the dependency ourselves.

Any additional question, just let me know. We could later transform this issue into a wiki page if you feel the explanations have helped.

ywarnier commented 5 years ago

It is better to submit a pull request early: pull requests are stuff we can work on together, they are dynamic. It's not just something you send and that we either dump or take. We can make comments, you can fix them through new commits to the same branch in your fork of Chamilo and we see them progressing.

opensourcecompany commented 5 years ago

@spacecabbie Yes it wasn't meant offensive :-) I just answered short because i was in a hurry but wanted to point you in the right direction.

spacecabbie commented 5 years ago

I am quite interested as well in following this ticket. I have considered working on the implementation of another payment gateway, but I have found support and documentation quite lacking. I would like to help, and contribute, however I would need to know more before being able to aid. Sorry if it is hijacking the thread, @ywarnier but If you have any more info on the process that was involved in making Culqui or a generalist approach on integration I would be really thankful.

Do you want collaborate with me ? I have setup a vps as a dev environment so we can git linked site there to test ? I really could use some help after reading the explanation from the master :) i am a bit scarred is harder then i thought. i have forked the project into: https://github.com/spacecabbie/Chammilo-fork-1.11.x/

spacecabbie commented 5 years ago

SO i have started (f.me coding f.ing addictive) https://github.com/spacecabbie/Chammilo-fork-1.11.x/tree/master/plugin/buycourses

Atm i am basicaly hacking and slashing current Culqi part of the plugin. I got it to offer a payment to mollie (ideal only) and return a status. no i made adjustment to proccess.php to include bank selector.,

There is a allot to do but i am happy i got sofar so be gentle and don't laugh to hard at the code 📦 when i have a basic working and striped the code apart from the existing files i will oferf it as pull

Also @ywarnier do you prefer a separate plugin ? it would be in essence a copy of the plugin with only mollie ideal payment or shall i add it to current plugin ?

Also do i place a tag with my name in the code to refer i made those adjustment or leave that up to git ?

ywarnier commented 5 years ago

It would be much better to have it as an addition to the current plugin. As you will see, in the current plugin you can choose to enable Culqi or not. This should be the case for all payment methods, and it should reuse as much existing code as possible, of course.

spacecabbie commented 5 years ago

Yes that is how i want to implent it but as i am new i do not know if thats alowed to reuse or add to current code Thats why i figured i ask permission.

I am now gutting the culqi and replacing all those with the ideal stuff since it comes close to the ideal api. So when i want to push it: All i have to do is reset the original code and and add the new ideal payment sections.

It gives me a nice guideline how its done :)

ywarnier commented 5 years ago

Alright, that's a good question. Chamilo is using the GNU/GPLv3 license, which allows you to use, modify, copy and distribute modified copies of the code. So yes, you are totally allowed to copy existing code.

If the technique of replacing works for you, that's fine, but I would suggest you copy the corresponding sections first and then gut the copy, so you avoid affecting any currently-working code (and do not have to do the work twice before you send a PR).

ywarnier commented 5 years ago

Just in case: by contributing to Chamilo, you also explicitely agree that your code will be published under the same license terms.

spacecabbie commented 5 years ago

Just in case: by contributing to Chamilo, you also explicitely agree that your code will be published under the same license terms.

No problem at all.

https://github.com/spacecabbie/Chammilo-fork-1.11.x/tree/master/plugin my progress if any one want to have a look and give me pointers are welkome.

ywarnier commented 5 years ago

the branch is not available anymore. I'm closing the issue but feel free to contribute whenever you have time.

spacecabbie commented 5 years ago

Yes for sure i got quite far but my life toke a whirlwind and back working witch leaves me very limited in time :( branch was renamed. https://github.com/spacecabbie/Chammilo-fork-1.11.x

I still am commited but it wil take quite long the code is free there for people to help or take and finish. I am sorry for the lack of progress.

ywarnier commented 5 years ago

No problem @spacecabbie, this is not a priority for us. It's just good for us to be aware. Thanks and good luck.