Adding a payment gateway

Adding a payment gateway

by Ross Quinnell -
Number of replies: 19

Hello,


I am looking for a way, to add a payment gateway to a moodle block.


In this case, I am using PayTabs. They have provided me javascript that loads a checkout button on the page, then shows a  form for an individual to processes a payment.


Moodle version 3.6.2 (Build: 20190114)

Average of ratings: -
In reply to Ross Quinnell

Re: Adding a payment gateway

by Garrett Boone -
Can you post the javascript? I'm not familiar with PayTabs.
In reply to Garrett Boone

Re: Adding a payment gateway

by Ross Quinnell -

So this is the javascript have to add to the page,  Which I had done successfully, but I need to be able to place this in a Moodle block.


<link rel="stylesheet" href="https://www.paytabs.com/express/express.css">
<script src="https://www.paytabs.com/theme/express_checkout/js/jquery-1.11.1.min.js"></script>
<script src="https://www.paytabs.com/express/express_checkout_v3.js"></script>
<!-- Button Code for PayTabs Express Checkout -->
<div class="PT_express_checkout"></div>
<script type="text/javascript">
    Paytabs("#express_checkout").expresscheckout({
        settings:{
            secret_key: "YOUR_SECRET_KEY",
            merchant_id: "YOUR_PAYTABS_MERCHANT_ID eg 10001234",
            amount: "10.00",
            currency: "USD",
            title: "Test Express Checkout Transaction",
            product_names: "Product1,Product2,Product3",
            order_id: 25,
            url_redirect: "https://www.YOURWEBSITE.com/return_url/"
        }
    });
</script>

In reply to Ross Quinnell

Re: Adding a payment gateway

by Garrett Boone -

https://docs.moodle.org/dev/Blocks

There's this on how to build a block. Are you wanting to add to an existing block or a new one?

When payment is successful, what are you wanting to happen after that? My guess is the url_redirect allows access to whatever is next.

In reply to Garrett Boone

Re: Adding a payment gateway

by Ross Quinnell -

Preferably an existing block.


And yes, once payment is successful will then return to a custom URL to say payment was successful 

In reply to Ross Quinnell

Re: Adding a payment gateway

by Garrett Boone -
I'm sorry, here is what I meant: what are you wanting to have a user pay to do? Access a course? See a file? Something that already exists? Something you are going to make that does not exist?

What's the end goal?

On January 21, 2019 3:50:37 PM EST, "Ross Quinnell (via Moodle.org)" <noreply@moodle.org> wrote:
Picture of Ross Quinnell
Re: Adding a payment gateway
by Ross Quinnell - Monday, January 21, 2019, 3:17 PM
 

Preferably an existing block.


And yes, once payment is successful will then return to a custom URL to say payment was successful 


You can reply to this via email.

In reply to Ross Quinnell

Re: Adding a payment gateway

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I assume what you want is to enrol them when they have paid. 

What I think you really want is a custom enrolment plugin. Although, I'm less than clear from your description. 

The critical thing is what you want to happen after they've paid. 

In reply to Howard Miller

Re: Adding a payment gateway

by Ross Quinnell -

Sorry about that,


Mainly it will be accessible to anyone who accesses Moodle.


The idea behind it is that were charging students for reassessment fee, once they have paid we check on the payment gateway, to see if they have paid, if so then they are allowed to take a reassessment.

In reply to Ross Quinnell

Re: Adding a payment gateway

by Garrett Boone -

What is the reassessment? A course? Or, an activity within a course where they already took the course and then took the assessment, but there is a fee to take the assessment again?


If it were me, I would create a course with one activity, just the reassessment. (Maybe the assessment is in a course with other activities as well, but there doesn't need to be a gateway for that one.)


You'll have to share more. But, the idea of a separate course would separate the users who need reassessment from those who did not, and you could make the gateway for just that course, specific to the reassessment. Like Howard was saying, if you want the payment to go with enrollment into that course.


But you are describing a manual process of "seeing if they paid" through the mechanism of somehow what your "gateway" produces to you, and then you "let them in" or enroll them, or whatever.


Key question: are you trying to automate enrollment with a payment, or simply figure out how to get yourself a usable response from your gateway code and then manually go from there? Because custom code may be needed for either option. However, if you are automating there is more involved though it could be started with existing code for automatic enrollment through existing plugins, etc. If you're going manual in the enrollment process, it is simpler and you may just need to work out how you want the PayTabs response to get to the user who reviews student payments, etc.


Please share your decision regarding which direction you are trying to go.



(Edited by Howard Miller to remove quoted text- original submission Tuesday, 22 January 2019, 11:50 PM)

Average of ratings: Useful (1)
In reply to Garrett Boone

Re: Adding a payment gateway

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yeh - we need to find a way to "translate this into Moodle". Moodle doesn't have a thing called "reassessment", so what will that actually be. 

In reply to Garrett Boone

Re: Adding a payment gateway

by Ross Quinnell -

Ok yes,


So I am looking for nothing spectacular, no automation or any kind of enrollment on to the course or anything like that. All I am looking for is means to paste the code mentioned above in this thread into a block, and that is it. So then all that is showed is the payment gateway button and some text to say what it is for.


Regarding reassessment, I am not particularly sure myself as to what students need to be reassessed on. But for what I am planning to do, it is irrelevant. Students just need to see the pay button somewhere in Moodle, like in a block. So that they can then pay for one and that's is all there is to it.

In reply to Ross Quinnell

Re: Adding a payment gateway

by Garrett Boone -

Ok, so other than following the blocks guide in the link above and reporting back if you are stuck on any steps, then I would make a jump and assume the following two things:

  1. The return URL will go to the message page you create for the student which says that they have paid successfully. This could be a one-off page that is not within Moodle, maybe, but still in the same domain. The page has a message you create and then a redirect link for them to select to take them back to where they were before. Where they were before is wherever the block is you decide to use.
  2. My second assumption is that PayTabs notifies you by email or something that they paid.
In reply to Garrett Boone

Re: Adding a payment gateway

by Ross Quinnell -

With the things mentioned in the script like the return URL, I would not worry too much about that as that is adjusted by quite easily by specifying a URL.


But however, I think this is being overcomplicated, than what it needs to be. As I mentioned before I can get it to work if I paste the script I showed earlier in the custom JS&css section in my chosen theme for Moodle.  However, the problem with that is where it is positioned in Moodle, in this case, it was being displayed at the bottom of the page. But the button shows and works as expected, just not in the right place.


So the only reason why I mentioned a block, is so that I could add this script within there so I can actually control where it is displayed and positioned on the site. But however, it does not work at all if I just paste the code in an HTML block.

In reply to Ross Quinnell

Re: Adding a payment gateway

by Garrett Boone -

Well at least we now know what you are trying to do.

Were you pasting the code while the text editor was in code "mode" or html-rendered mode?

In reply to Garrett Boone

Re: Adding a payment gateway

by Ross Quinnell -

This is true and I apologise if I did not explain properly.


So within the "HTML Block" I used the code option but does not appear to work.


However, it works if I add the code to the following section in Moodle.


Appearance > Themes > "My choosen theme" > Custom CSS & JS


Then paste the code in the Javascript section and only show on dashboard option checked.


But the issue, as I mentioned before adds the checkout button to the very bottom of the page, which looks very unprofessional.

In reply to Ross Quinnell

Re: Adding a payment gateway

by Garrett Boone -

What if you put the basic html button code in the html block and put the js in the custom settings? Maybe that will work.

If that doesn't work, we might need to figure out where you want the button, and "relocate" it after it loads with some custom javascript.

In reply to Garrett Boone

Re: Adding a payment gateway

by Garrett Boone -

For example, maybe we use the HTML block to create a <div> section that we relocate to...

In reply to Garrett Boone

Re: Adding a payment gateway

by Ross Quinnell -

Ok, so I kept the first line of the code in the HTML block.


And the rest in the custom JS section in the theme.


However, the site becomes unusable, such as the site administrator option never expands.

In reply to Ross Quinnell

Re: Adding a payment gateway

by Garrett Boone -

You should consider building a new block from scratch. I know it's a pain for a little button, but it will load it the way you want.