Jump to content

integrating payment process in a user registration form


JeevanisM
 Share

Recommended Posts

Hello friends,

this is a simple problem, hope I will get an answer soon. I need to create a registration page for a website. The intention is to make sure only paid user can get into the members area. Well, I have done the user registration page, but how do I integrate the payment process into the registration form ? I mean only after successful payment, the registration should be completed.  Then the username and password will be emailed to the users email.

 

How to achieve this in Processwire ?



thank you

Link to comment
Share on other sites

It depends completely on the payment provider you choose, there are several modules available, but they all require some hands-on programming.  http://modules.processwire.com/search/?q=payment

Also often payment providers require a callback-endpoint at your site to process the result of a payment action. If all goes well, it will call this endpoint while the user is waiting for a bit during the payment process. After your system processes and acknowledges the payment (for instance it changes the status of the user to 'registered'), the payment provide will then forward the user back to your site. But.. it can also be the case that this callback happens minutes, hours or even days later in case of a hiccup with the banking system for instance. And, in case of a credit-card payment, it can in fact even change the state of a payment a month later — should the user formally dispute the charge. 

So, the flow of registration -> payment -> access is not as 1-2-3 as it may seem. You will need to consider all the possible outcomes of your registration process. You will be able to read more about the exact information your payment provider sends and expects in return in their documentation, as this varies wildly.

Another thing to consider is that you cannot depend on any $session variable during the callback function, as the payment provider has its own session. So you will probably have to pass the user-id to the payment provider while setting up the payment, which it in return should include during its callback to your server and which you can then use to look up the user. 

One other thing though, just in case you hadn't thought about this: you should never email users their passwords. With the exception of a single-use, time-constrained temporary password. For that purpose you can use the PasswordForceChange module.

Edited by eelkenet
Clarification
  • Like 3
  • Thanks 1
Link to comment
Share on other sites

I'd use LoginRegister module for registering the user, and then taking them to a form with FormBuilder that later basically just flags the user as paid (on a checkbox field for the user template) on a hook after payment. 

EDIT: Just re-read that you want the users to pay first before actually registering them, I'd still try to find a way to use FormBuilder to simplify the payment part and just use hooks to validate the form and create a user. 

  • Like 1
Link to comment
Share on other sites

21 hours ago, elabx said:

I'd use LoginRegister module for registering the user, and then taking them to a form with FormBuilder that later basically just flags the user as paid (on a checkbox field for the user template) on a hook after payment. 

EDIT: Just re-read that you want the users to pay first before actually registering them, I'd still try to find a way to use FormBuilder to simplify the payment part and just use hooks to validate the form and create a user. 

I talked to my client and he agreed to approach the very flow you have said. Now, can you explain me further on this part

Quote

later basically just flags the user as paid (on a checkbox field for the user template)

how to make that flag thing ? I have already installed the LoginRegister module

Link to comment
Share on other sites

12 minutes ago, JeevanisM said:

I talked to my client and he agreed to approach the very flow you have said. Now, can you explain me further on this part

 

Just to be clear, I was refering to FormBuilder's Stripe integration. So you'd have to consider that also. 

I have not used the payment feature with Stripe, so I couldn't tell you more details on how to implement this, but here is a pretty nice documentation page: https://processwire.com/store/form-builder/stripe/#hooks-reference. So a hook on chargeSuccess, chargeFail should help you implement what you want.

Or, another option I guess (maybe even more reliable?), could be using Stripe's webhooks

12 minutes ago, JeevanisM said:

how to make that flag thing ? I have already installed the LoginRegister module

Add a checkbox field to the user template, that's what I meant. 

Link to comment
Share on other sites

@elabx

my situation is slightly different. My work flow is as below

1. the registration page ( user case - Guest & unpaid )

2. user register now and success ( user case - registered & unpaid)

3. registered user can click the payment button ( for this I use PayTM , so the user will be taken to the payment page and after success I can put a custom Return URL )

4. in case of successful payment, I need to flag this registered user as the paid user. This part, how can I do in this ProcessWire way ? Is there any API to tinker the database to add such a custom flag ?

5. registered user clicks the payment button and proceed but failed the payment somehow, then the user remains as the unpaid one

Link to comment
Share on other sites

2 minutes ago, JeevanisM said:

4. in case of successful payment, I need to flag this registered user as the paid user. This part, how can I do in this ProcessWire way ? Is there any API to tinker the database to add such a custom flag ?

Take a look at what the payment gategay sends as a response in the return url and use that to check true a "Paid user" field in the user. 

$user->of(false);
$user->paid = true;
$user->save('paid');

Here I asume you already got $user with data you got on the return url. 

Link to comment
Share on other sites

1 minute ago, elabx said:

Take a look at what the payment gategay sends as a response in the return url and use that to check true a "Paid user" field in the user. 


$user->of(false);
$user->paid = true;
$user->save('paid');

Here I asume you already got $user with data you got on the return url. 

Wow. that will work.. thanks for that. I will return to you in case if I meet any issues.  You really helped me __/\__

Link to comment
Share on other sites

7 hours ago, JeevanisM said:

@elabx

4. in case of successful payment, I need to flag this registered user as the paid user. This part, how can I do in this ProcessWire way ? Is there any API to tinker the database to add such a custom flag ?

Add the "Paid" field to the user template: https://processwire.com/talk/topic/16400-is-it-possible-to-add-custom-user-properties-to-the-user/

Then you can update that field:

$user->setAndSave('paid', 'true');

You can use a FieldtypeCheckbox for that too, then the ON value is 1 and OFF value is 0

 

  • Like 1
Link to comment
Share on other sites

On 11/6/2019 at 8:41 PM, elabx said:

Take a look at what the payment gategay sends as a response in the return url and use that to check true a "Paid user" field in the user. 


$user->of(false);
$user->paid = true;
$user->save('paid');

Here I asume you already got $user with data you got on the return url. 

One more doubt I have.

I have added a custom field as Phone Number to the login/Register Module. Now once the registration is done, I am not able to output the $user->phone;

this display a null value. What would be the problem ?

Link to comment
Share on other sites

42 minutes ago, JeevanisM said:

One more doubt I have.

I have added a custom field as Phone Number to the login/Register Module. Now once the registration is done, I am not able to output the $user->phone;

this display a null value. What would be the problem ?

In what context are you trying to output it? Do you mean in a tempalte,  after "first login"? Could I see some code?

 
Link to comment
Share on other sites

@elabx

sorry if I confused you. so I have followed your suggestion.. I caught the Payment status and put the user paid status 1 for success payment. that part is done.

now, in the login/register module, I have added an extra field which is a phone number for the user to register.  Well, I have done this in a way that

1. first I installed a module for phone type

2. added a new field and selected the module phone type

3. added this field to the User template

4. added this phone field to the Login/Register configure option in order to show the Phone Number entry in Registration Form

Now, once the registration is done, I tried to output $user->phone, just as $user->email but $user->phone shows null  while $user->email shows correct user email.

So is there anything wrong I have done ?

Link to comment
Share on other sites

9 minutes ago, elabx said:

In what context are you trying to output it? Do you mean in a tempalte,  after "first login"? Could I see some code?

 

Basically, how can I store / save a phone number from the registration form ? Login/Register module supports only email and password fields for default. But I read some tutorials and tried this adding custom field to User template. But I am not able to output it

Link to comment
Share on other sites

5 hours ago, JeevanisM said:

1. first I installed a module for phone type

 

I think this might be the issue, LoginRegister supports starndard fields. At least says so in the description of the "Registration form fields" field, in the module's configuration. 

Link to comment
Share on other sites

10 hours ago, elabx said:

I think this might be the issue, LoginRegister supports starndard fields. At least says so in the description of the "Registration form fields" field, in the module's configuration. 

Oh ok, so I make a simple standard integer field type, it should work right? I will try

Link to comment
Share on other sites

Hello,

I have created a standard field type as userphone , then I added this field to the User template. I created a phone field type using Phone Field module. I added this field to the User template also.

image.thumb.png.f40f3d23d3f8849fdf15e13a06ef63b6.png

Now I used the below to create a test user

 $u = new User();
$u->of(false);
$u->name = "saarun";
$u->email = "saarunthomas@example.com";
$u->pass = "123456";
$u->Phone = 9446196667;
$u->userphone = 9446196667;
$u->headline = "hello there";
$u->paid=1;
$u->addRole("registered");
$u->save();
$u->of(true);

and I tried to out put as below

     $item = $users->get("saarun");
echo $item->email;
echo $item->Phone;
echo $item->paid;
echo $item->headline;
echo $item->userphone;

and I got the output a below.  Neither the userphone value nor the Phone value are output ... what am I doing here wrong  ? pls help

 

image.png.eee59c5c952dd521d71cb1dd8d23cd22.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...