View Single Post
  #1  
Old 05-31-2009, 09:23 PM
JamesGunner JamesGunner is offline
 
Join Date: Sep 2008
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Payment API custom modification

Hello,

Basically I made a custom profile field within vbulletin. My Game Servers update the data within the database once they earn something on the servers. I want them to be able to get a paid subscription with these points basically the z-points are the currency and the database is the API processor. Those points are saved within custom profile "field6".

Here is the code I have so far:

product_zpoints.xml

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="zpoints" active="1">
	<title>Z-Points</title>
	<description>Add Z-Points to the payment gateway</description>
	<version>0.0.2</version>
	<codes>
		<code version="1.0.0">
			<installcode><![CDATA[// Fill the settings array
// add the z-points record to the paymentapi table
$db->hide_errors();
$db->query_write("
	INSERT INTO " . TABLE_PREFIX . "paymentapi
	(title, currency, recurring, classname, active, settings)
	VALUES
	('Z-Points', 'z-points', 0, 'zpoints', 0, '" . $db->escape_string(serialize($settings)) . "')
");
$db->show_errors();]]></installcode>
			<uninstallcode><![CDATA[$db->hide_errors();
$db->query_write("DELETE FROM " . TABLE_PREFIX . "paymentapi WHERE title = 'Z-Points'");
$db->show_errors();]]></uninstallcode>
		</code>
	</codes>
	<templates>
		<template name="subscription_payment_zpoints" templatetype="template" date="0" username="JamesGunner" version="3.6.0">
			<![CDATA[
				<input type="hidden" name="amount" value="$cost">
				<input type="hidden" name="test_mode" value="$settings[test_mode]">
				<input type="hidden" name="product_name" value="$subinfo[title] Subscription">
				<input type="hidden" name="description" value="$subinfo[description]">
				<input type="hidden" name="unit_price" value="$cost">
				<input type="hidden" name="require_IPN" value="0">
				<input type="hidden" name="return_URL" value="$vboptions[bburl]/payment_gateway.php?method=zpoints">
			]]>
		</template>
	</templates>
	<plugins>	
		<plugin active="1" executionorder="5">
			<title><![CDATA[Z-Points - add 'order using']]></title>
			<hookname>paidsub_order_start</hookname>
			<phpcode><![CDATA[$vbphrase += array( 'zpoints' => 'Z-Points' );]]></phpcode>
		</plugin>
	</plugins>
	<phrases>
		<phrasetype name="GLOBAL" fieldname="global">
			<phrase name="setting_zpoints_test_mode_desc" date="1156824632" username="Hambil" version="1.0.0"><![CDATA[Enable Test Mode. Transactions in test mode are 'fake' and not charged to an account.]]></phrase>
			<phrase name="setting_zpoints_test_mode_title" date="1156824659" username="Hambil" version="1.0.0"><![CDATA[Test Mode]]></phrase>
			<phrase name="zpoints_order_instructions" date="1156875116" username="Hambil" version="1.0.0"><![CDATA[To pay for your subscription via Z-Points click the button below and follow the onscreen instructions.]]></phrase>
		</phrasetype>
		<phrasetype name="Error Messages" fieldname="error">
			<phrase name="zpoints_cancel"><![CDATA[[ZOW] Im sorry! You do not seem to have enough zpoints to get admin or an error occured!]]></phrase>
		</phrasetype>
	</phrases>
</product>
Which works perfectly fine and Z-points can also be activated as an Payment API.

Now I think my problem is the heart of the Payment API, the class file. I really think that I need help with this one.

This is what i got so far:

class_zpoints.php

PHP Code:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin                                   # ||    
|| # ---------------------------------------------------------------- # ||
|| # Copyright ?2000-2006 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/

if (!isset($GLOBALS['vbulletin']->db))
{
    exit;
}

/**
* Class that provides payment verification and form generation functions
*
* @package    vBulletin
* @version    $Revision: 1.6 $
* @date        $Date: 2006/05/11 21:21:00 $
*/
class vB_PaidSubscriptionMethod_zpoints extends vB_PaidSubscriptionMethod
{
    
/**
    * The currencies that are supported by this payment provider
    *
    * @var    array
    */
    
var $supported_currency = array('zpoints' => true);

    
/**
    * The variable indicating if this payment provider supports recurring transactions
    *
    * @var    bool
    */
    
var $supports_recurring false;

    
/**
    * The variable indicating that this payment provider gives immediate feedback that
    * should be displayed
    *
    * @var    bool
    */
    
var $display_feedback false;

    
/**
    * Perform verification of the payment, this is called from the payment gateway
    *
    * @return    bool    Whether the payment is valid
    */
    
function verify_payment()
    {      
        
$this->registry->input->clean_array_gpc('r', array(
            
'product_name'        => TYPE_STR,
            
'status'            => TYPE_STR,
            
'unit_price'        => TYPE_STR,
            
'transaction_id'    => TYPE_NUM,
            
'transaction_date'    => TYPE_STR,
            
'user_id'            => TYPE_STR
        
));
        
        
$this->product_name $this->registry->GPC['product_name'];
        
$this->status $this->registry->GPC['status'];
        
$this->unit_price $this->registry->GPC['unit_price'];
        
$this->transaction_id $this->registry->GPC['transaction_id'];
        
$this->transaction_date $this->registry->GPC['transaction_date'];
        
$this->user_id $this->registry->GPC['user_id'];
 
            
// lets check the values
            
if (!empty($this->paymentinfo))
            {
                
$zpoints $db->query_read("SELECT field6 FROM userfield WHERE userid = ".$this->user_id);
                
                if ((
$zpoints-$this->unit_price) => 0)
                {
                    
$zpointstotal $zpoints-$this->unit_price
                    
                    $db
->query_write("
                           UPDATE 'userfield'
                        SET `field6` = 
$zpointstotal
                        WHERE `userid` = "
.$this->user_id);
                    
                    
$this->type 1;
                    return 
true;
                }
                else
                {
                      
$this->error fetch_error('zpoints_cancel');
                }            
            }
        }
        return 
false;
    }

    
/**
    * Test that required settings are available, and if we can communicate with the server (if required)
    *
    * @return    bool    If the vBulletin has all the information required to accept payments
    */
    
function test()
    {
        return (!empty(
$this->settings['secret_code']) AND !empty($this->settings['email']));
        
//return true;
    
}

    
/**
    * Generates HTML for the subscription form page
    *
    * @param    string        Hash used to indicate the transaction within vBulletin
    * @param    string        The cost of this payment
    * @param    string        The currency of this payment
    * @param    array        Information regarding the subscription that is being purchased
    * @param    array        Information about the user who is purchasing this subscription
    * @param    array        Array containing specific data about the cost and time for the specific subscription period
    *
    * @return    array        Compiled form information
    */
    
function generate_form_html($cost$currency$subinfo$userinfo$timeinfo)
    {      
        
$currency strtoupper($currency);
        
        
// load settings into array so the template system can access them
        
$settings =& $this->settings;

        
$settings['email'] = htmlspecialchars_uni($settings['email']);
        
$settings['product_name'] = htmlspecialchars_uni($this->registry->subinfo['title']);
        
        eval(
'$form[\'hiddenfields\'] .= "' fetch_template('subscription_payment_zpoints') . '";');
        return 
$form;
    }
}

?>
Im not sure what I did wrong since I dont know much about php neither about vbulletin. I really need this Payment API so any help is really appreciated!

Thanks for the reply ahead...
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01136 seconds
  • Memory Usage 1,864KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete