Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
[How-To] Extending the vBulletin Payment Gateway
hambil
Join Date: Jun 2004
Posts: 1,719

Seattle
by hambil hambil is offline 31 Aug 2006
Rating: (1 vote - 5.00 average)

Overview

This tutorial shows you how to add a new payment method to the vBulletin Payment Gateway. It uses my pgStormPay hack as the example.

Step 1: The database

The first thing you need to understand is the paymentapi table in the database.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Title
The title of the payment method, in our case “StormPay”.

Currency
Comma delimited list of currency types this payment method can accept. StormPay only accepts us dollars, so in our case it’s just “usd”.

Recurring
Whether or not this payment method can handle recurring payments (monthly, yearly, etc…).

Classname
The name of the class in yourforum/includes/paymentapi that contains the functions needed to use this payment method. This field name is a little deceptive, because it you look in yourforum/payment_gateway.php you see the following:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So what this field really represents is the unique part of the filename and the classname. class_classname.php and vB_PaidSubscriptionMethod_classname. Or in our case: class_stormpay.php and vB_PaidSubscriptionMethod_stormpay. So you can see the value of this field for us should be just “stormpay”.

Active
Is this payment method active? In general you should set this to 0 initially and let the admin activate your payment method from the admincp.

Settings
This is a critical part of the payment method, and needs some explaining. It represents the information the admin must fill in for this payment method to work. It will be different for each payment method. It is an array of arrays, with each inner array representing a field to be filled out. The structure of the inner array is similar to a html input element. It has a type, a value, and how to validate the value. For StormPay, we create four fields, as shown bellow.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Putting it into the database
Once you know the values you want for your payment method, you can write them into the database in your install section of your product xml file.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Step 2: The template

Next you’ll need to create a template for your payment form. This is the form that is filled out automatically by vBulletin before it submits data to your payment method. In the case of StormPay, we are going to use a simple single item payment, as specified in their integration api: http://www.stormpay.com/stormpay/user/manual.php

Note: I use unit_price instead of amount. It works the same, and seems to clear up some minor bugs.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

In the case of StormPay we are telling it we require IPN (Immediate Payment Notification). StormPay will post back to the ‘return_URL’, which we set to the payment_gateway.php file and tell it the method is stormpay. No code changes need to be made to the payment_gateway.php as it just uses the method to create an instance of the class we will look at later in this tutorial. Notice we are using some of the settings we created when we added our payment method to the database.

To create this template, vBulletin expects it to have the name subscription_payment_classname. So in our case the template section of the product xml would look like this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Step 3: The plugin
This is not the only way to accomplish this step, but it is the way I have chosen. You need to add the StormPay phrase to the vbphrases array, so it can appear on the “Order Using” button. Since these are service names, and not translated, vBulletin hard codes them in yourforum/payment.php. However, it does provide a hook (paidsub_order_start).

The hook code we need is very simple:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The plugins section of your product xml would look like this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Step 4: The phrases


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The phrases section of your product xml would look like this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Step 5: The payment method class

This is the final part, and the real meat of the payment method. It ties everything else together. It extends the vBulletin class vB_PaidSubscriptionMethod, and the easiest thing is probably to copy one of the existing classes and modify it.

It has three functions you need to deal with:

verify_payment() function
This function will depend on what the payment method you are using sends back to the payment_gateway.php file. In general you’ll want to get the variables from the submitted request, check them for successful payment, and return true or false to the payment_gateway.php file. Here is a look at the verify_payment() function for StormPay:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Note: $this->type defaults to 0, and if the payment is successful you must set it to 1, as well as returning true. A type of 2 is a delete, and handled by vBulletin so you don’t need to worry about it.

test() function
This function is used by the Test Communications link under the Paid Subscriptions menu in the admincp. In general it is just a validation of the specific data (settings) needed by the payment method. In our case, we need a valid email and a ‘secret code’. So, or method looks like this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

generate_form_html() function
This function generates the form that is sent to your payment method, using the template you created earlier. Several variables get passed into the method, and you can also retrieve any values you put into settings. Here is a look at the StormPay function.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Feedback
One final thing to be aware of is that in order to display feedback from your payment method payment_gateway.php requires the value “display_feedback” be set to true. It defaults to false in the vBulletin class you extend. So, you must force it true:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

That’s all!
That’s it folks! Check out the pgStormPay hack if you still need more details.

Last edited by hambil; 31 Aug 2006 at 03:52..
Views: 18140
Reply With Quote
Comments
  #2  
Old 01 Sep 2006, 01:49
MajorFm.com MajorFm.com is offline
 
Join Date: Dec 2004
Can someone do one for me for verotel with re-occuring billing... i can pay for this mod...
Reply With Quote
  #3  
Old 16 Mar 2007, 18:35
rungss rungss is offline
 
Join Date: Jan 2007
I am extending the Payment Gateway

What is username Hambil here?

I'll need to change it right??
Reply With Quote
  #4  
Old 16 Mar 2007, 18:54
hambil's Avatar
hambil hambil is offline
 
Join Date: Jun 2004
Real name: Hambil
I'm sorry, I don't understand what you are asking me...
__________________
Reply With Quote
  #5  
Old 16 Mar 2007, 19:30
rungss rungss is offline
 
Join Date: Jan 2007
in a lot of places in your code your username is mentioned

like in

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

what is it the username of the administrator of the forum or the username of the person who is updating the plugin or what??
Reply With Quote
  #6  
Old 16 Mar 2007, 19:37
rungss rungss is offline
 
Join Date: Jan 2007
After installing my payment gateway extenssion I am geting two submit button instead of one..

see the image attached.

any idea why it can happen..
Attached Images
File Type: gif payment-gateway-error.gif (6.5 KB, 324 views)
Reply With Quote
  #7  
Old 16 Mar 2007, 20:22
rungss rungss is offline
 
Join Date: Jan 2007
Originally Posted by rungss View Post
After installing my payment gateway extenssion I am geting two submit button instead of one..

see the image attached.

any idea why it can happen..
this issue is solved...
Reply With Quote
  #8  
Old 17 Mar 2007, 04:18
hambil's Avatar
hambil hambil is offline
 
Join Date: Jun 2004
Real name: Hambil
Originally Posted by rungss View Post
in a lot of places in your code your username is mentioned

like in

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

what is it the username of the administrator of the forum or the username of the person who is updating the plugin or what??
In the case you show it's a standard part of the product.xml - it's the name of the author of the template. It will show up if you look at the templates change history.
__________________
Reply With Quote
  #9  
Old 19 Mar 2007, 05:58
rungss rungss is offline
 
Join Date: Jan 2007
Originally Posted by hambil View Post
In the case you show it's a standard part of the product.xml - it's the name of the author of the template. It will show up if you look at the templates change history.
ok Thanks got it,

It can be used for logging purpose but not completely coz it can't be associated with a user in the user table of the party who is installing the hack. because the developer need not be a member in the forum of the party installing it.

right??
Reply With Quote
  #10  
Old 19 Mar 2007, 06:09
hambil's Avatar
hambil hambil is offline
 
Join Date: Jun 2004
Real name: Hambil
Right, which really doesn' t have anything to do with this hack, it's the same for all hacks. It's just the name of the author of the template.
__________________
Reply With Quote
  #11  
Old 19 Mar 2007, 08:03
rungss rungss is offline
 
Join Date: Jan 2007
Originally Posted by hambil View Post
it's the same for all hacks
of course, of course..
I was just pointing it out in general.
This thread is not just about this Hack.

It's about learning how to develop a new plugin isn't it.

Thanks a lot for this thread.

I was able to develop my first vB plugin as per the specification because of this thread.
Reply With Quote
  #12  
Old 22 Apr 2007, 20:36
Champster Champster is offline
 
Join Date: Mar 2006
Can this be used to modify an existing payment apt, ccbill specifically?

I need to modify vb CCBill Form Character Code where the form accepts more than just one form code.
Reply With Quote
  #13  
Old 20 Feb 2008, 21:32
nanaimobar nanaimobar is offline
 
Join Date: Nov 2005
Work for 3.6.7?

Does your tutorial work for 3.6.7?


Whoops!! I mean 3.7

Last edited by nanaimobar; 20 Feb 2008 at 21:51. Reason: Correct dumb mistake in version; meant 3.7
Reply With Quote
  #14  
Old 22 Jun 2008, 21:08
Mum Mum is offline
 
Join Date: Jun 2006
Real name: Kirsty
I am trying to write a payment api at the moment, and was querying 'Settings
This is a critical part of the payment method, and needs some explaining. It represents the information the admin must fill in for this payment method to work. It will be different for each payment method. It is an array of arrays, with each inner array representing a field to be filled out. The structure of the inner array is similar to a html input element. It has a type, a value, and how to validate the value. For StormPay, we create four fields, as shown bellow.'

how can i work out what my processor (paymex) requires?

--------------- Added 22 Jun 2008 at 22:48 ---------------

I foudn these, but not sure which relates to what http://www.paymex.co.nz/kb.aspx?id=34 hoping that someone can help me, i can pay a small amount.
__________________
Mummybrain.com We're virtually family

Last edited by Mum; 22 Jun 2008 at 22:48. Reason: Auto-Merged DoublePost
Reply With Quote
  #15  
Old 03 Nov 2008, 06:48
imedic's Avatar
imedic imedic is offline
 
Join Date: Mar 2008
I am looking for a modification of payment api that permit manual payment approved by admin. User pays in various ways, send me confirmation of payment and I validate manually his subscription.

I have a small professional community so total number cannot go above 10k users and some of them are not familiar with electronic payment. They will send money by post, direct payment in bank account (or even pay me cash when we meet ) and I want to take advantage of the subscription system build in VB (reminders for end of subscription, period subscripted) so I don't need to make a separate group and write down each username , and period of subscription.

My alternative for the moment is to make a group user request to join and I approve after receiving the confirmation of payment. This way I need to keep manual track of each user time of subscription ending and name.

I have no coding knowledge but willing to learn or appreciate a helping hand.
Maybe I am lucky and there is a setting I don't know in vb allowing me to do this !

PS I will like to have this additional to electronic payment (for users able to pay this way)
after I manage to integrate my local card processor using this tutorial I am thankful for

Edit:
Found by accident a possible solution. In Subscription management make a valid payed subscription (even if no bank set) and manually add users from drop down menu in Subscription manager page from Admin CP. Hope is useful for some.

Last edited by imedic; 03 Nov 2008 at 07:55.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 20:32.

Layout Options | Width: Wide Color: