vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Payment API custom modification (https://vborg.vbsupport.ru/showthread.php?t=215018)

JamesGunner 05-31-2009 09:23 PM

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...

JamesGunner 06-03-2009 03:21 PM

nobody can help me?

imported_silkroad 07-10-2009 07:32 PM

Hi James,

Do you have this working yet?

Question, in this install code:

Quote:

<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>
Where do you input the settings into the database?

JamesGunner 07-10-2009 07:46 PM

hey thanks for you trying to help. We already implemented this after a long time of trying and trying. We ended up making our own currency and whatnot but it seems to work now.

imported_silkroad 07-10-2009 08:47 PM

Hi James,

I am working on a similar problem. Can you post your final code?

Thanks!

jskoh 09-27-2009 06:29 PM

anybody have successfully add a local currency?

imported_silkroad 09-27-2009 06:38 PM

Yes, but it is a lot of template work.


All times are GMT. The time now is 02:31 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02764 seconds
  • Memory Usage 1,789KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete