ocPortal Developer's Guide: eCommerce
» Return to Contents
sources/ecommerce.php
Global_functions_ecommerce.php
Function summary
|
void
|
init__ecommerce ()
|
|
boolean
|
ecommerce_test_mode ()
|
|
ID_TEXT
|
ecommerce_get_currency_symbol ()
|
|
tempcode
|
get_transaction_form_fields (?ID_TEXT trans_id, ID_TEXT purchase_id, SHORT_TEXT item_name, SHORT_TEXT amount, ?integer length, ID_TEXT length_units)
|
|
float
|
get_transaction_fee (float amount, ID_TEXT via)
|
|
tempcode
|
make_transaction_button (ID_TEXT product, SHORT_TEXT item_name, ID_TEXT purchase_id, float amount, ID_TEXT currency, ?ID_TEXT via)
|
|
tempcode
|
make_subscription_button (ID_TEXT product, SHORT_TEXT item_name, ID_TEXT purchase_id, float amount, integer length, ID_TEXT length_units, ID_TEXT currency, ?ID_TEXT via)
|
|
?tempcode
|
make_cancel_button (AUTO_LINK purchase_id, ID_TEXT via)
|
|
void
|
send_invoice_mail (MEMBER member_id, AUTO_LINK id)
|
|
array
|
find_all_products (boolean site_lang)
|
|
?object
|
find_product (ID_TEXT search, boolean site_lang, boolean search_titles_not_ids)
|
|
array
|
find_product_row (ID_TEXT search, boolean site_lang, boolean search_titles_not_ids)
|
|
boolean
|
perform_local_payment ()
|
|
ID_TEXT
|
handle_transaction_script ()
|
|
void
|
handle_confirmed_transaction (ID_TEXT purchase_id, SHORT_TEXT item_name, SHORT_TEXT payment_status, SHORT_TEXT reason_code, SHORT_TEXT pending_reason, SHORT_TEXT memo, SHORT_TEXT mc_gross, SHORT_TEXT mc_currency, SHORT_TEXT txn_id, SHORT_TEXT parent_txn_id, ID_TEXT source, string period)
|
|
void
|
my_exit (string error, boolean dont_trigger)
|
|
AUTO_LINK
|
add_usergroup_subscription (SHORT_TEXT title, LONG_TEXT description, SHORT_TEXT cost, integer length, SHORT_TEXT length_units, ?GROUP group_id, BINARY uses_primary, BINARY enabled, ?LONG_TEXT mail_start, ?LONG_TEXT mail_end, ?LONG_TEXT mail_uhoh)
|
|
void
|
edit_usergroup_subscription (AUTO_LINK id, SHORT_TEXT title, LONG_TEXT description, SHORT_TEXT cost, integer length, SHORT_TEXT length_units, ?GROUP group_id, BINARY uses_primary, BINARY enabled, ?LONG_TEXT mail_start, ?LONG_TEXT mail_end, ?LONG_TEXT mail_uhoh)
|
|
void
|
delete_usergroup_subscription (AUTO_LINK id, LONG_TEXT uhoh_mail)
|
|
tempcode
|
make_cart_payment_button (AUTO_LINK order_id, ID_TEXT currency)
|
void init__ecommerce()
Standard code module initialisation function.
Parameters…
(No return value)
function init__ecommerce()
{
if (!defined('PRODUCT_PURCHASE_WIZARD'))
{
define('PRODUCT_PURCHASE_WIZARD',0);
define('PRODUCT_INVOICE',1);
define('PRODUCT_SUBSCRIPTION',2);
define('PRODUCT_OTHER',2);
define('PRODUCT_CATALOGUE',3);
define('PRODUCT_ORDERS',4);
}
}
boolean ecommerce_test_mode()
Check whether the system is in test mode (normally, not).
Parameters…
Returns…
| Description |
The answer. |
| Type |
boolean |
function ecommerce_test_mode()
{
return get_option('ecommerce_test_mode')=='1';
}
ID_TEXT ecommerce_get_currency_symbol()
Get the symbol of the currency we're trading in.
Parameters…
Returns…
| Description |
The currency. |
| Type |
ID_TEXT |
function ecommerce_get_currency_symbol()
{
$currency=get_option('currency');
switch ($currency)
{
case 'USD':
$currency='$';
break;
case 'CAD':
$currency='$';
break;
case 'EUR':
$currency='€';
break;
case 'GBP':
$currency='£';
break;
case 'JPY':
$currency='¥';
break;
case 'AUD':
$currency='$';
break;
}
if ($GLOBALS['XSS_DETECT']) ocp_mark_as_escaped($currency);
return $currency;
}
tempcode get_transaction_form_fields(?ID_TEXT trans_id, ID_TEXT purchase_id, SHORT_TEXT item_name, SHORT_TEXT amount, ?integer length, ID_TEXT length_units)
Find a transaction fee from a transaction amount. Regular fees aren't taken into account.
Parameters…
| Name |
trans_id |
| Description |
The transaction ID (NULL: auto-generate) |
| Type |
?ID_TEXT |
| Name |
purchase_id |
| Description |
The purchase ID |
| Type |
ID_TEXT |
| Name |
item_name |
| Description |
The item name |
| Type |
SHORT_TEXT |
| Name |
amount |
| Description |
The amount |
| Type |
SHORT_TEXT |
| Name |
length |
| Description |
The length (NULL: not a subscription) |
| Type |
?integer |
| Name |
length_units |
| Description |
The length units |
| Type |
ID_TEXT |
Returns…
| Description |
The form fields |
| Type |
tempcode |
function get_transaction_form_fields($trans_id,$purchase_id,$item_name,$amount,$length,$length_units)
{
if (is_null($trans_id))
{
$via=get_option('payment_gateway');
require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via));
$object=object_factory('Hook_'.$via);
if (!method_exists($object,'do_transaction')) warn_exit(do_lang_tempcode('LOCAL_PAYMENT_NOT_SUPPORTED',escape_html($via)));
$trans_id=$object->generate_trans_id();
}
$GLOBALS['SITE_DB']->query_insert('trans_expecting',array(
'id'=>$trans_id,
'e_purchase_id'=>$purchase_id,
'e_item_name'=>$item_name,
'e_amount'=>$amount,
'e_member_id'=>get_member(),
'e_ip_address'=>get_ip_address(),
'e_session_id'=>get_session_id(),
'e_time'=>time(),
'e_length'=>$length,
'e_length_units'=>$length_units,
));
require_code('form_templates');
$fields=new ocp_tempcode();
$fields->attach(form_input_hidden('trans_id',$trans_id));
$fields->attach(form_input_line(do_lang_tempcode('CARDHOLDER_NAME'),do_lang_tempcode('DESCRIPTION_CARDHOLDER_NAME'),'name',ecommerce_test_mode()?$GLOBALS['FORUM_DRIVER']->get_username(get_member()):get_ocp_cpf('TODO'),true));
$fields->attach(form_input_list(do_lang_tempcode('CARD_TYPE'),'','card_type',$object->nice_get_card_types(ecommerce_test_mode()?'Visa':get_ocp_cpf('payment_type'))));
$fields->attach(form_input_line(do_lang_tempcode('CARD_NUMBER'),do_lang_tempcode('DESCRIPTION_CARD_NUMBER'),'card_number',ecommerce_test_mode()?'4444333322221111':get_ocp_cpf('payment_card_number'),true));
$fields->attach(form_input_line(do_lang_tempcode('CARD_START_DATE'),do_lang_tempcode('DESCRIPTION_CARD_START_DATE'),'start_date',ecommerce_test_mode()?date('m/y',utctime_to_usertime(time()-60*60*24*365)):get_ocp_cpf('payment_card_start_date'),true));
$fields->attach(form_input_line(do_lang_tempcode('CARD_EXPIRY_DATE'),do_lang_tempcode('DESCRIPTION_CARD_EXPIRY_DATE'),'expiry_date',ecommerce_test_mode()?date('m/y',utctime_to_usertime(time()+60*60*24*365)):get_ocp_cpf('payment_card_expiry_date'),true));
$fields->attach(form_input_integer(do_lang_tempcode('CARD_ISSUE_NUMBER'),do_lang_tempcode('DESCRIPTION_CARD_ISSUE_NUMBER'),'issue_number',intval(get_ocp_cpf('payment_card_issue_number')),false));
$fields->attach(form_input_line(do_lang_tempcode('CARD_CV2'),do_lang_tempcode('DESCRIPTION_CARD_CV2'),'cv2',ecommerce_test_mode()?'123':get_ocp_cpf('payment_card_cv2'),true));
//Shipping address fields
$fields->attach(form_input_line(do_lang_tempcode('SPECIAL_CPF__ocp_firstname'),'','first_name',get_ocp_cpf('firstname'),true));
$fields->attach(form_input_line(do_lang_tempcode('SPECIAL_CPF__ocp_lastname'),'','last_name',get_ocp_cpf('last_name'),true));
$fields->attach(form_input_line(do_lang_tempcode('SPECIAL_CPF__ocp_building_name_or_number'),'','address1',get_ocp_cpf('building_name_or_number'),true));
$fields->attach(form_input_line(do_lang_tempcode('SPECIAL_CPF__ocp_city'),'','city',get_ocp_cpf('city'),true));
$fields->attach(form_input_line(do_lang_tempcode('SPECIAL_CPF__ocp_state'),'','zip',get_ocp_cpf('state'),true));
$fields->attach(form_input_line(do_lang_tempcode('SPECIAL_CPF__ocp_post_code'),'','zip',get_ocp_cpf('post_code'),true));
$fields->attach(form_input_line(do_lang_tempcode('SPECIAL_CPF__ocp_country'),'','country',get_ocp_cpf('country'),true));
//Set purchase id as hidden form field to get back after transaction
$fields->attach(form_input_hidden('customfld1',$purchase_id));
return $fields;
}
float get_transaction_fee(float amount, ID_TEXT via)
Find a transaction fee from a transaction amount. Regular fees aren't taken into account.
Parameters…
| Name |
amount |
| Description |
A transaction amount. |
| Type |
float |
| Name |
via |
| Description |
The service the payment went via. |
| Type |
ID_TEXT |
Returns…
| Description |
The fee |
| Type |
float |
function get_transaction_fee($amount,$via)
{
if ($via=='') return 0.0;
if ($via=='manual') return 0.0;
if ((file_exists(get_file_base().'/sources/hooks/systems/ecommerce_via/'.$via)) || (file_exists(get_file_base().'/sources_custom/hooks/systems/ecommerce_via/'.$via)))
{
require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via));
$object=object_factory('Hook_'.$via);
return $object->get_transaction_fee($amount);
}
return 0.0;
}
tempcode make_transaction_button(ID_TEXT product, SHORT_TEXT item_name, ID_TEXT purchase_id, float amount, ID_TEXT currency, ?ID_TEXT via)
Make a transaction (payment) button.
Parameters…
| Name |
product |
| Description |
The product codename. |
| Type |
ID_TEXT |
| Name |
item_name |
| Description |
The human-readable product title. |
| Type |
SHORT_TEXT |
| Name |
purchase_id |
| Description |
The purchase ID. |
| Type |
ID_TEXT |
| Name |
amount |
| Description |
A transaction amount. |
| Type |
float |
| Name |
currency |
| Description |
The currency to use. |
| Type |
ID_TEXT |
| Name |
via |
| Description |
The service the payment will go via via (NULL: autodetect). |
| Default value |
|
| Type |
?ID_TEXT |
Returns…
| Description |
The button |
| Type |
tempcode |
function make_transaction_button($product,$item_name,$purchase_id,$amount,$currency,$via=NULL)
{
if (is_null($via)) $via=get_option('payment_gateway');
require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via));
$object=object_factory('Hook_'.$via);
return $object->make_transaction_button($product,$item_name,$purchase_id,$amount,$currency);
}
tempcode make_subscription_button(ID_TEXT product, SHORT_TEXT item_name, ID_TEXT purchase_id, float amount, integer length, ID_TEXT length_units, ID_TEXT currency, ?ID_TEXT via)
Make a subscription (payment) button.
Parameters…
| Name |
product |
| Description |
The product codename. |
| Type |
ID_TEXT |
| Name |
item_name |
| Description |
The human-readable product title. |
| Type |
SHORT_TEXT |
| Name |
purchase_id |
| Description |
The purchase ID. |
| Type |
ID_TEXT |
| Name |
amount |
| Description |
A transaction amount. |
| Type |
float |
| Name |
length |
| Description |
The subscription length in the units. |
| Type |
integer |
| Name |
length_units |
| Description |
The length units. |
| Type |
ID_TEXT |
| Values restricted to |
d w m y |
| Name |
currency |
| Description |
The currency to use. |
| Type |
ID_TEXT |
| Name |
via |
| Description |
The service the payment will go via via (NULL: autodetect). |
| Default value |
|
| Type |
?ID_TEXT |
Returns…
| Description |
The button |
| Type |
tempcode |
function make_subscription_button($product,$item_name,$purchase_id,$amount,$length,$length_units,$currency,$via=NULL)
{
if (is_null($via)) $via=get_option('payment_gateway');
require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via));
$object=object_factory('Hook_'.$via);
return $object->make_subscription_button($product,$item_name,$purchase_id,$amount,$length,$length_units,$currency);
}
?tempcode make_cancel_button(AUTO_LINK purchase_id, ID_TEXT via)
Make a subscription cancellation button.
Parameters…
| Name |
purchase_id |
| Description |
The purchase ID. |
| Type |
AUTO_LINK |
| Name |
via |
| Description |
The service the payment will go via via. |
| Type |
ID_TEXT |
Returns…
| Description |
The button (NULL: no special cancellation -- just delete the subscription row to stop ocPortal regularly re-charging) |
| Type |
?tempcode |
function make_cancel_button($purchase_id,$via)
{
if ($via=='') return NULL;
if ($via=='manual') return NULL;
require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via));
$object=object_factory('Hook_'.$via);
if (!method_exists($object,'make_cancel_button')) return NULL;
return $object->make_cancel_button($purchase_id);
}
void send_invoice_mail(MEMBER member_id, AUTO_LINK id)
Send an invoice notification to a member.
Parameters…
| Name |
member_id |
| Description |
The member to send to. |
| Type |
MEMBER |
| Name |
id |
| Description |
The invoice ID. |
| Type |
AUTO_LINK |
(No return value)
function send_invoice_mail($member_id,$id)
{
// Send out mail
require_code('notifications');
$_url=build_url(array('page'=>'invoices','type'=>'misc'),get_module_zone('invoices'),NULL,false,false,true);
$url=$_url->evaluate();
dispatch_notification('invoice',NULL,do_lang('INVOICE_SUBJECT',strval($id),NULL,NULL,get_lang($member_id)),do_lang('INVOICE_MESSAGE',$url,get_site_name(),NULL,get_lang($member_id)),array($member_id));
}
array find_all_products(boolean site_lang)
Find all products, except ones from hooks that might have too many to list (so don't rely on this for important backend tasks).
Parameters…
| Name |
site_lang |
| Description |
Whether to make sure the language for item_name is the site default language (crucial for when we read/go to third-party sales systems and use the item_name as a key). |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
A list of maps of product details. |
| Type |
array |
function find_all_products($site_lang=false)
{
$_hooks=find_all_hooks('systems','ecommerce');
$products=array();
foreach (array_keys($_hooks) as $hook)
{
require_code('hooks/systems/ecommerce/'.filter_naughty_harsh($hook));
$object=object_factory('Hook_'.filter_naughty_harsh($hook),true);
if (is_null($object)) continue;
$_products=$object->get_products($site_lang);
foreach ($_products as $product=>$details)
{
if (!array_key_exists(4,$details))
{
$details[4]=do_lang('CUSTOM_PRODUCT_'.$product,NULL,NULL,NULL,$site_lang?get_site_default_lang():NULL);
}
$details[]=$object;
$products[$product]=$details;
}
}
return $products;
}
?object find_product(ID_TEXT search, boolean site_lang, boolean search_titles_not_ids)
Find product.
Parameters…
| Name |
search |
| Description |
The product name/product_id |
| Type |
ID_TEXT |
| Name |
site_lang |
| Description |
Whether to make sure the language for item_name is the site default language (crucial for when we read/go to third-party sales systems and use the item_name as a key). |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
search_titles_not_ids |
| Description |
Whether $search refers to the product name rather than the product_id |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The product-class object (NULL: not found). |
| Type |
?object |
function find_product($search,$site_lang=false,$search_titles_not_ids=false)
{
$_hooks=find_all_hooks('systems','ecommerce');
foreach (array_keys($_hooks) as $hook)
{
require_code('hooks/systems/ecommerce/'.filter_naughty_harsh($hook));
$object=object_factory('Hook_'.filter_naughty_harsh($hook),true);
if (is_null($object)) continue;
$_products=$object->get_products($site_lang,$search,$search_titles_not_ids);
$product=mixed();
foreach ($_products as $product=>$product_row)
{
if (is_integer($product)) $product=strval($product);
if ($search_titles_not_ids)
{
if (($product_row[4]==$search) || ('_'.$product==$search)) return $object;
} else
{
if ($product==$search) return $object;
}
}
}
return NULL;
}
array find_product_row(ID_TEXT search, boolean site_lang, boolean search_titles_not_ids)
Find product info row.
Parameters…
| Name |
search |
| Description |
The product name/product_id |
| Type |
ID_TEXT |
| Name |
site_lang |
| Description |
Whether to make sure the language for item_name is the site default language (crucial for when we read/go to third-party sales systems and use the item_name as a key). |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
search_titles_not_ids |
| Description |
Whether $search refers to the product name rather than the product_id |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
A pair: The product-class map, and the formal product name (both will be NULL if not found). |
| Type |
array |
function find_product_row($search,$site_lang=false,$search_titles_not_ids=false)
{
$_hooks=find_all_hooks('systems','ecommerce');
foreach (array_keys($_hooks) as $hook)
{
require_code('hooks/systems/ecommerce/'.filter_naughty_harsh($hook));
$object=object_factory('Hook_'.filter_naughty_harsh($hook),true);
if (is_null($object)) continue;
$_products=$object->get_products($site_lang,$search,$search_titles_not_ids);
$product=mixed();
foreach ($_products as $product=>$product_row)
{
if (is_integer($product)) $product=strval($product);
if ($search_titles_not_ids)
{
if (($product_row[4]==$search) || ('_'.$product==$search))
{
return array($product_row,$product);
}
} else
{
if ($product==$search) return array($product_row,$product);
}
}
}
return array(NULL,NULL);
}
boolean perform_local_payment()
Find whether local payment will be performed.
Parameters…
Returns…
| Description |
Whether local payment will be performed. |
| Type |
boolean |
function perform_local_payment()
{
$via=get_option('payment_gateway');
require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via));
$object=object_factory('Hook_'.$via);
return ((get_option('use_local_payment')=='1') && (method_exists($object,'do_transaction')));
}
ID_TEXT handle_transaction_script()
Handle IPN's.
Parameters…
Returns…
| Description |
The ID of the purchase-type (meaning depends on item_name) |
| Type |
ID_TEXT |
function handle_transaction_script()
{
require_lang('ecommerce');
$via=get_param('from',get_option('payment_gateway'));
require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via));
$object=object_factory('Hook_'.$via);
ob_start();
$test=false;
if (!$test)
{
list($purchase_id,$item_name,$payment_status,$reason_code,$pending_reason,$memo,$mc_gross,$mc_currency,$txn_id,$parent_txn_id)=$object->handle_transaction();
} else
{
$purchase_id='15';
$item_name=do_lang('CUSTOM_PRODUCT_OTHER');
$payment_status='Completed';
$reason_code='';
$pending_reason='bar';
$memo='foo';
$mc_gross='0.01';
$mc_currency=get_option('currency');
$txn_id='0';
$parent_txn_id='0';
}
handle_confirmed_transaction($purchase_id,$item_name,$payment_status,$reason_code,$pending_reason,$memo,$mc_gross,$mc_currency,$txn_id,$parent_txn_id,$via,post_param('period3',''));
return $purchase_id;
//my_exit(do_lang('SUCCESS'));
}
void handle_confirmed_transaction(ID_TEXT purchase_id, SHORT_TEXT item_name, SHORT_TEXT payment_status, SHORT_TEXT reason_code, SHORT_TEXT pending_reason, SHORT_TEXT memo, SHORT_TEXT mc_gross, SHORT_TEXT mc_currency, SHORT_TEXT txn_id, SHORT_TEXT parent_txn_id, ID_TEXT source, string period)
Handle IPN's that have been confirmed as backed up by real money.
Parameters…
| Name |
purchase_id |
| Description |
The ID of the purchase-type (meaning depends on item_name) |
| Type |
ID_TEXT |
| Name |
item_name |
| Description |
The item being purchased (aka the product) (blank: subscription, so we need to look it up). One might wonder why we use $item_name instead of $product. This is because we pass human-readable-names (hopefully unique!!!) through payment gateways because they are visually shown to the user. (blank: it's a subscription, so look up via a key map across the subscriptions table) |
| Type |
SHORT_TEXT |
| Name |
payment_status |
| Description |
The status this transaction is telling of |
| Type |
SHORT_TEXT |
| Values restricted to |
SModified SCancelled Completed Pending Failed |
| Name |
reason_code |
| Description |
The code that gives reason to the status |
| Type |
SHORT_TEXT |
| Name |
pending_reason |
| Description |
The reason it is in pending status (if it is) |
| Type |
SHORT_TEXT |
| Name |
memo |
| Description |
A note attached to the transaction |
| Type |
SHORT_TEXT |
| Name |
mc_gross |
| Description |
The amount of money |
| Type |
SHORT_TEXT |
| Name |
mc_currency |
| Description |
The currency the amount is in |
| Type |
SHORT_TEXT |
| Name |
txn_id |
| Description |
The transaction ID |
| Type |
SHORT_TEXT |
| Name |
parent_txn_id |
| Description |
The ID of the parent transaction |
| Type |
SHORT_TEXT |
| Name |
source |
| Description |
The ID of a special source for the transaction |
| Default value |
|
| Type |
ID_TEXT |
| Name |
period |
| Description |
The subscription period (blank: N/A) |
| Default value |
|
| Type |
string |
(No return value)
function handle_confirmed_transaction($purchase_id,$item_name,$payment_status,$reason_code,$pending_reason,$memo,$mc_gross,$mc_currency,$txn_id,$parent_txn_id,$source='',$period='')
{
/*#####################################################################################*/
//Temporary setting - force payment setting to "completed" for test mode transactions
if(get_option('ecommerce_test_mode')=="1")
$payment_status = 'Completed';
/*#####################################################################################*/
// Try and locate the product
if (($item_name=='')/* && ($payment_status[0]=='S')*/) // Subscription
{
$product=$GLOBALS['SITE_DB']->query_value_null_ok('subscriptions','s_type_code',array('id'=>intval($purchase_id))); // Note that s_type_code is not numeric, it is a $product
if (is_null($product)) warn_exit(do_lang_tempcode('NO_SUCH_SUBSCRIPTION',strval($purchase_id)));
$item_name='_'.$product;
// Check what we sold
list($found,)=find_product_row($product,true,false);
if (!is_null($found))
{
$item_name=$found[4];
}
} else
{
// Check what we sold
list($found,$product)=find_product_row($item_name,true,true);
}
if (is_null($found)) my_exit(do_lang('PRODUCT_NO_SUCH').' - '.$item_name);
// Check price
if (($mc_gross!=$found[1]) && ($found[1]!='?'))
{
if ($payment_status=='SModified')
$GLOBALS['SITE_DB']->query_update('subscriptions',array('s_state'=>'new'),array('id'=>intval($purchase_id)),'',1);
if (($payment_status!='SCancelled') && (substr($txn_id,0,6)!='manual')) my_exit(do_lang('PURCHASE_WRONG_PRICE',$item_name));
}
if ($period!='')
{
$length=array_key_exists('length',$found[3])?strval($found[3]['length']):'1';
$length_units=array_key_exists('length_units',$found[3])?$found[3]['length_units']:'m';
if (strtolower($period)!=strtolower($length.' '.$length_units)) my_exit(do_lang('IPN_SUB_PERIOD_WRONG'));
}
// Store
$GLOBALS['SITE_DB']->query_insert('transactions',array('id'=>$txn_id,'t_memo'=>$memo,'purchase_id'=>$purchase_id,'status'=>$payment_status,'pending_reason'=>$pending_reason,'reason'=>$reason_code,'amount'=>$mc_gross,'t_currency'=>$mc_currency,'linked'=>$parent_txn_id,'t_time'=>time(),'item'=>$product,'t_via'=>$source));
$found['txn_id'] = $txn_id;
// Check currency
if ($mc_currency!=get_option('currency'))
{
if ($payment_status=='SModified')
$GLOBALS['SITE_DB']->query_update('subscriptions',array('s_state'=>'new'),array('id'=>intval($purchase_id)),'',1);
if (($payment_status!='SCancelled') && (substr($txn_id,0,6)!='manual')) my_exit(do_lang('PURCHASE_WRONG_CURRENCY'));
}
// Pending
if (($payment_status=='Pending') && ($found[0]==PRODUCT_INVOICE)) // Invoices have special support for tracking the order status
{
$GLOBALS['SITE_DB']->query_update('invoices',array('i_state'=>'pending'),array('id'=>intval($purchase_id)),'',1);
}
elseif (($payment_status=='Pending') && ($found[0]==PRODUCT_SUBSCRIPTION)) // Subscriptions have special support for tracking the order status
{
$GLOBALS['SITE_DB']->query_update('subscriptions',array('s_state'=>'pending'),array('id'=>intval($purchase_id)),'',1);
if ($found[2]!='') call_user_func_array($found[2],array($purchase_id,$found,$product,true)); // Run cancel code
}
elseif (($payment_status=='Pending') && ($item_name==do_lang('CART_ORDER',$purchase_id))) // Cart orders have special support for tracking the order status
{
$found['ORDER_STATUS']='ORDER_STATUS_awaiting_payment';
if ($found[2]!='') call_user_func_array($found[2],array($purchase_id,$found,$product,true)); // Set order status
}
// Subscription: Cancelled
elseif (($payment_status=='SCancelled') && ($found[0]==PRODUCT_SUBSCRIPTION))
{
$GLOBALS['SITE_DB']->query_update('subscriptions',array('s_auto_fund_source'=>$source,'s_auto_fund_key'=>$txn_id,'s_state'=>'cancelled'),array('id'=>intval($purchase_id)),'',1);
}
// Subscription: Made active
elseif ($found[0]==PRODUCT_SUBSCRIPTION)
{
$GLOBALS['SITE_DB']->query_update('subscriptions',array('s_auto_fund_source'=>$source,'s_auto_fund_key'=>$txn_id,'s_state'=>'active'),array('id'=>intval($purchase_id)),'',1);
}
// Check completed: if not, proceed no further
elseif (($payment_status!='Completed') && ($payment_status!='SCancelled') && (get_option('ecommerce_test_mode')!='1'))
my_exit(do_lang('TRANSACTION_NOT_COMPLETE',$product.':'.strval($purchase_id),$payment_status),true);
// Invoice: Check price
if ($found[0]==PRODUCT_INVOICE)
{
$price=$GLOBALS['SITE_DB']->query_value('invoices','i_amount',array('id'=>intval($purchase_id)));
if ($price!=$mc_gross)
{
if (substr($txn_id,0,6)!='manual')
my_exit(do_lang('PURCHASE_WRONG_PRICE',$item_name));
}
}
/* At this point we know our order (or subscription cancellation) is good */
// Dispatch
if ($payment_status=='Completed')
{
//Find product hooks of this order to check dispatch type
$object = find_product($product,true);
if(is_object($object) && !method_exists($object,'get_product_dispatch_type'))
{ //If hook does not have dispatch method setting take dispatch method as automatic
$found['ORDER_STATUS'] = 'ORDER_STATUS_dispatched';
}
elseif(is_object($object) && $object->get_product_dispatch_type($purchase_id)=='automatic')
{
$found['ORDER_STATUS'] = 'ORDER_STATUS_dispatched';
}
else
{
$found['ORDER_STATUS'] = 'ORDER_STATUS_payment_received';
}
if ($found[2]!='') call_user_func_array($found[2],array($purchase_id,$found,$product));
}
// Invoice handling
if ($found[0]==PRODUCT_INVOICE)
{
$GLOBALS['SITE_DB']->query_update('invoices',array('i_state'=>'paid'),array('id'=>intval($purchase_id)),'',1);
}
// Subscription: Delete if cancelled
if (($payment_status=='SCancelled') && ($found[0]==PRODUCT_SUBSCRIPTION))
{
$GLOBALS['SITE_DB']->query_delete('subscriptions',array('id'=>intval($purchase_id)),'',1);
}
}
void my_exit(string error, boolean dont_trigger)
Exit ocPortal and write to the error log file.
Parameters…
| Name |
error |
| Description |
The message. |
| Type |
string |
| Name |
dont_trigger |
| Description |
Dont trigger an error |
| Default value |
boolean-false |
| Type |
boolean |
(No return value)
function my_exit($error,$dont_trigger=false)
{
echo $error."\n";
if (!$dont_trigger) trigger_error($error,E_USER_NOTICE);
exit();
}
AUTO_LINK add_usergroup_subscription(SHORT_TEXT title, LONG_TEXT description, SHORT_TEXT cost, integer length, SHORT_TEXT length_units, ?GROUP group_id, BINARY uses_primary, BINARY enabled, ?LONG_TEXT mail_start, ?LONG_TEXT mail_end, ?LONG_TEXT mail_uhoh)
Add a usergroup subscription.
Parameters…
| Name |
title |
| Description |
The title |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
The description |
| Type |
LONG_TEXT |
| Name |
cost |
| Description |
The cost |
| Type |
SHORT_TEXT |
| Name |
length |
| Description |
The length |
| Type |
integer |
| Name |
length_units |
| Description |
The units for the length |
| Type |
SHORT_TEXT |
| Values restricted to |
y m d w |
| Name |
group_id |
| Description |
The usergroup that purchasing gains membership to (NULL: super members) |
| Type |
?GROUP |
| Name |
uses_primary |
| Description |
Whether this is applied to primary usergroup membership |
| Type |
BINARY |
| Name |
enabled |
| Description |
Whether this is currently enabled |
| Type |
BINARY |
| Name |
mail_start |
| Description |
The text of the e-mail to send out when a subscription is start (NULL: default) |
| Type |
?LONG_TEXT |
| Name |
mail_end |
| Description |
The text of the e-mail to send out when a subscription is ended (NULL: default) |
| Type |
?LONG_TEXT |
| Name |
mail_uhoh |
| Description |
The text of the e-mail to send out when a subscription cannot be renewed because the subproduct is gone (NULL: default) |
| Type |
?LONG_TEXT |
Returns…
| Description |
The ID |
| Type |
AUTO_LINK |
function add_usergroup_subscription($title,$description,$cost,$length,$length_units,$group_id,$uses_primary,$enabled,$mail_start,$mail_end,$mail_uhoh)
{
$dbs_bak=$GLOBALS['NO_DB_SCOPE_CHECK'];
$GLOBALS['NO_DB_SCOPE_CHECK']=true;
$id=$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']->query_insert('f_usergroup_subs',array(
's_title'=>insert_lang($title,2,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
's_description'=>insert_lang($description,2,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
's_cost'=>$cost,
's_length'=>$length,
's_length_units'=>$length_units,
's_group_id'=>$group_id,
's_uses_primary'=>$uses_primary,
's_enabled'=>$enabled,
's_mail_start'=>insert_lang($mail_start,2,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
's_mail_end'=>insert_lang($mail_end,2,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
's_mail_uhoh'=>insert_lang($mail_uhoh,2,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
),true);
log_it('ADD_USERGROUP_SUBSCRIPTION',strval($id),$title);
$GLOBALS['NO_DB_SCOPE_CHECK']=$dbs_bak;
return $id;
}
void edit_usergroup_subscription(AUTO_LINK id, SHORT_TEXT title, LONG_TEXT description, SHORT_TEXT cost, integer length, SHORT_TEXT length_units, ?GROUP group_id, BINARY uses_primary, BINARY enabled, ?LONG_TEXT mail_start, ?LONG_TEXT mail_end, ?LONG_TEXT mail_uhoh)
Edit a usergroup subscription.
Parameters…
| Name |
id |
| Description |
The ID |
| Type |
AUTO_LINK |
| Name |
title |
| Description |
The title |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
The description |
| Type |
LONG_TEXT |
| Name |
cost |
| Description |
The cost |
| Type |
SHORT_TEXT |
| Name |
length |
| Description |
The length |
| Type |
integer |
| Name |
length_units |
| Description |
The units for the length |
| Type |
SHORT_TEXT |
| Values restricted to |
y m d w |
| Name |
group_id |
| Description |
The usergroup that purchasing gains membership to (NULL: super members) |
| Type |
?GROUP |
| Name |
uses_primary |
| Description |
Whether this is applied to primary usergroup membership |
| Type |
BINARY |
| Name |
enabled |
| Description |
Whether this is currently enabled |
| Type |
BINARY |
| Name |
mail_start |
| Description |
The text of the e-mail to send out when a subscription is start (NULL: default) |
| Type |
?LONG_TEXT |
| Name |
mail_end |
| Description |
The text of the e-mail to send out when a subscription is ended (NULL: default) |
| Type |
?LONG_TEXT |
| Name |
mail_uhoh |
| Description |
The text of the e-mail to send out when a subscription cannot be renewed because the subproduct is gone (NULL: default) |
| Type |
?LONG_TEXT |
(No return value)
function edit_usergroup_subscription($id,$title,$description,$cost,$length,$length_units,$group_id,$uses_primary,$enabled,$mail_start,$mail_end,$mail_uhoh)
{
$dbs_bak=$GLOBALS['NO_DB_SCOPE_CHECK'];
$GLOBALS['NO_DB_SCOPE_CHECK']=true;
$rows=$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']->query_select('f_usergroup_subs',array('*'),array('id'=>$id),'',1);
if (!array_key_exists(0,$rows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$myrow=$rows[0];
// If usergroup has changed, do a move
if ($myrow['s_group_id']!=$group_id)
{
require_code('ocf_groups_action');
require_code('ocf_groups_action2');
$product='USERGROUP'.strval($id);
$subscriptions=$GLOBALS['SITE_DB']->query_select('subscriptions',array('*'),array('s_type_code'=>$product));
foreach ($subscriptions as $sub)
{
$member_id=$sub['s_member_id'];
if ((get_value('unofficial_ecommerce')=='1') && (get_forum_type()!='ocf'))
{
$GLOBALS['FORUM_DB']->remove_member_from_group($member_id,$group_id);
$GLOBALS['FORUM_DB']->add_member_to_group($member_id,$group_id);
} else
{
$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']->query_delete('f_group_members',array('gm_group_id'=>$group_id,'gm_member_id'=>$member_id),'',1);
ocf_add_member_to_group($member_id,$group_id);
}
}
}
$_title=$myrow['s_title'];
$_description=$myrow['s_description'];
$_mail_start=$myrow['s_mail_start'];
$_mail_end=$myrow['s_mail_end'];
$_mail_uhoh=$myrow['s_mail_uhoh'];
$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']->query_update('f_usergroup_subs',array(
's_title'=>lang_remap($_title,$title,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
's_description'=>lang_remap($_description,$description,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
's_cost'=>$cost,
's_length'=>$length,
's_length_units'=>$length_units,
's_group_id'=>$group_id,
's_uses_primary'=>$uses_primary,
's_enabled'=>$enabled,
's_mail_start'=>lang_remap($_mail_start,$mail_start,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
's_mail_end'=>lang_remap($_mail_end,$mail_end,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
's_mail_uhoh'=>lang_remap($_mail_uhoh,$mail_uhoh,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']),
),array('id'=>$id),'',1);
log_it('EDIT_USERGROUP_SUBSCRIPTION',strval($id),$title);
$GLOBALS['NO_DB_SCOPE_CHECK']=$dbs_bak;
}
void delete_usergroup_subscription(AUTO_LINK id, LONG_TEXT uhoh_mail)
Delete a usergroup subscription.
Parameters…
| Name |
id |
| Description |
The ID |
| Type |
AUTO_LINK |
| Name |
uhoh_mail |
| Description |
The cancellation mail to send out |
| Type |
LONG_TEXT |
(No return value)
function delete_usergroup_subscription($id,$uhoh_mail)
{
$dbs_bak=$GLOBALS['NO_DB_SCOPE_CHECK'];
$GLOBALS['NO_DB_SCOPE_CHECK']=true;
$rows=$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']->query_select('f_usergroup_subs',array('*'),array('id'=>$id),'',1);
if (!array_key_exists(0,$rows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$myrow=$rows[0];
$new_group=$myrow['s_group_id'];
// Remove benefits
$product='USERGROUP'.strval($id);
$subscriptions=$GLOBALS['SITE_DB']->query_select('subscriptions',array('*'),array('s_type_code'=>$product));
$to_members=array();
foreach ($subscriptions as $sub)
{
$member_id=$sub['s_member_id'];
if ((get_value('unofficial_ecommerce')=='1') && (get_forum_type()!='ocf'))
{
$GLOBALS['FORUM_DB']->remove_member_from_group($member_id,$new_group);
} else
{
$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']->query_delete('f_group_members',array('gm_group_id'=>$new_group,'gm_member_id'=>$member_id),'',1);
}
$to_members[]=$member_id;
}
if ($uhoh_mail!='')
{
require_code('notifications');
dispatch_notification('paid_subscription_ended',NULL,do_lang('PAID_SUBSCRIPTION_ENDED',NULL,NULL,NULL,get_site_default_lang()),$uhoh_mail,$to_members);
}
$_title=$myrow['s_title'];
$_description=$myrow['s_description'];
$title=get_translated_text($_title,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']);
$_mail_start=$myrow['s_mail_start'];
$_mail_end=$myrow['s_mail_end'];
$_mail_uhoh=$myrow['s_mail_uhoh'];
$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']->query_delete('f_usergroup_subs',array('id'=>$id),'',1);
delete_lang($_title,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']);
delete_lang($_description,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']);
delete_lang($_mail_start,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']);
delete_lang($_mail_end,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']);
delete_lang($_mail_uhoh,$GLOBALS[(get_forum_type()=='ocf')?'FORUM_DB':'SITE_DB']);
log_it('DELETE_USERGROUP_SUBSCRIPTION',strval($id),$title);
$GLOBALS['NO_DB_SCOPE_CHECK']=$dbs_bak;
}
tempcode make_cart_payment_button(AUTO_LINK order_id, ID_TEXT currency)
Make a shopping cart payment button.
Parameters…
| Name |
order_id |
| Description |
Order Id |
| Type |
AUTO_LINK |
| Name |
currency |
| Description |
The currency to use. |
| Type |
ID_TEXT |
Returns…
| Description |
The button |
| Type |
tempcode |
function make_cart_payment_button($order_id,$currency)
{
$_items=$GLOBALS['SITE_DB']->query_select('shopping_order_details',array('p_name','p_price','p_quantity'),array('order_id'=>$order_id));
$items=array();
foreach ($_items as $item)
{
$items[]=array(
'PRODUCT_NAME'=>$item['p_name'],
'PRICE'=>float_to_raw_string($item['p_price']),
'QUANTITY'=>strval($item['p_quantity']),
);
}
$via=get_option('payment_gateway');
require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via));
$object=object_factory('Hook_'.$via);
if (!method_exists($object,'make_cart_transaction_button'))
{
$amount = $GLOBALS['SITE_DB']->query_value('shopping_order','tot_price',array('id'=>$order_id));
return $object->make_transaction_button($order_id,do_lang('CART_ORDER',$order_id),$order_id,$amount,$currency);
}
return $object->make_cart_transaction_button($items,$currency,$order_id);
}
0 reviews: Unrated (average)
There have been no comments yet