Functions

Add a usergroup subscription.

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) : \AUTO_LINK

set y m d w

Parameters

$title

\SHORT_TEXT

The title

$description

\LONG_TEXT

The description

$cost

\SHORT_TEXT

The cost

$length

integer

The length

$length_units

\SHORT_TEXT

The units for the length

$group_id

\?GROUP

The usergroup that purchasing gains membership to (NULL: super members)

$uses_primary

\BINARY

Whether this is applied to primary usergroup membership

$enabled

\BINARY

Whether this is currently enabled

$mail_start

\?LONG_TEXT

The text of the e-mail to send out when a subscription is start (NULL: default)

$mail_end

\?LONG_TEXT

The text of the e-mail to send out when a subscription is ended (NULL: default)

$mail_uhoh

\?LONG_TEXT

The text of the e-mail to send out when a subscription cannot be renewed because the subproduct is gone (NULL: default)

Returns

\AUTO_LINKThe ID

Convert a country code to a currency code.

country_to_currency(\ID_TEXT $country) : \ID_TEXT

Parameters

$country

\ID_TEXT

The country code.

Returns

\ID_TEXTThe currency code.

Perform a currency conversion.

currency_convert(mixed $amount, \ID_TEXT $from_currency, \?ID_TEXT $to_currency, boolean $string) : \?mixed

Parameters

$amount

mixed

The starting amount (integer or float).

$from_currency

\ID_TEXT

The start currency code.

$to_currency

\?ID_TEXT

The end currency code (NULL: unknown, guess it).

$string

boolean

Whether to get as a string.

Returns

\?mixedThe new amount as float, or if $string then as a string (NULL: failed to do it).

Delete a usergroup subscription.

delete_usergroup_subscription(\AUTO_LINK $id, \LONG_TEXT $uhoh_mail) 

Parameters

$id

\AUTO_LINK

The ID

$uhoh_mail

\LONG_TEXT

The cancellation mail to send out

Get the symbol of the currency we're trading in.

ecommerce_get_currency_symbol() : \ID_TEXT

Returns

\ID_TEXTThe currency.

Check whether the system is in test mode (normally, not).

ecommerce_test_mode() : boolean

Returns

booleanThe answer.

Edit a usergroup subscription.

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) 

set y m d w

Parameters

$id

\AUTO_LINK

The ID

$title

\SHORT_TEXT

The title

$description

\LONG_TEXT

The description

$cost

\SHORT_TEXT

The cost

$length

integer

The length

$length_units

\SHORT_TEXT

The units for the length

$group_id

\?GROUP

The usergroup that purchasing gains membership to (NULL: super members)

$uses_primary

\BINARY

Whether this is applied to primary usergroup membership

$enabled

\BINARY

Whether this is currently enabled

$mail_start

\?LONG_TEXT

The text of the e-mail to send out when a subscription is start (NULL: default)

$mail_end

\?LONG_TEXT

The text of the e-mail to send out when a subscription is ended (NULL: default)

$mail_uhoh

\?LONG_TEXT

The text of the e-mail to send out when a subscription cannot be renewed because the subproduct is gone (NULL: default)

Find all products, except ones from hooks that might have too many to list (so don't rely on this for important backend tasks).

find_all_products(boolean $site_lang) : array

Parameters

$site_lang

boolean

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

Returns

arrayA list of maps of product details.

Find product.

find_product(\ID_TEXT $search, boolean $site_lang, boolean $search_titles_not_ids) : \?object

Parameters

$search

\ID_TEXT

The product name/product_id

$site_lang

boolean

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

$search_titles_not_ids

boolean

Whether $search refers to the product name rather than the product_id

Returns

\?objectThe product-class object (NULL: not found).

Find product info row.

find_product_row(\ID_TEXT $search, boolean $site_lang, boolean $search_titles_not_ids) : array

Parameters

$search

\ID_TEXT

The product name/product_id

$site_lang

boolean

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

$search_titles_not_ids

boolean

Whether $search refers to the product name rather than the product_id

Returns

arrayA pair: The product-class map, and the formal product name (both will be NULL if not found).

Get the currency map.

get_currency_map() : array

Returns

arrayThe currency map, currency code, to an array of country codes.

Find a transaction fee from a transaction amount.

get_transaction_fee(float $amount, \ID_TEXT $via) : float

Regular fees aren't taken into account.

Parameters

$amount

float

A transaction amount.

$via

\ID_TEXT

The service the payment went via.

Returns

floatThe fee

Find a transaction fee from a transaction amount.

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) : \tempcode

Regular fees aren't taken into account.

Parameters

$trans_id

\?ID_TEXT

The transaction ID (NULL: auto-generate)

$purchase_id

\ID_TEXT

The purchase ID

$item_name

\SHORT_TEXT

The item name

$amount

\SHORT_TEXT

The amount

$length

\?integer

The length (NULL: not a subscription)

$length_units

\ID_TEXT

The length units

Returns

\tempcodeThe form fields

Handle IPN's that have been confirmed as backed up by real money.

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) 

set SModified SCancelled Completed Pending Failed

Parameters

$purchase_id

\ID_TEXT

The ID of the purchase-type (meaning depends on item_name)

$item_name

\SHORT_TEXT

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)

$payment_status

\SHORT_TEXT

The status this transaction is telling of

$reason_code

\SHORT_TEXT

The code that gives reason to the status

$pending_reason

\SHORT_TEXT

The reason it is in pending status (if it is)

$memo

\SHORT_TEXT

A note attached to the transaction

$mc_gross

\SHORT_TEXT

The amount of money

$mc_currency

\SHORT_TEXT

The currency the amount is in

$txn_id

\SHORT_TEXT

The transaction ID

$parent_txn_id

\SHORT_TEXT

The ID of the parent transaction

$source

\ID_TEXT

The ID of a special source for the transaction

$period

string

The subscription period (blank: N/A)

Handle IPN's.

handle_transaction_script() : \ID_TEXT

Returns

\ID_TEXTThe ID of the purchase-type (meaning depends on item_name)

Standard code module initialisation function.

init__ecommerce() 

Convert an IP address to a currency code.

ip_to_currency(\?IP $ip) : \ID_TEXT

Parameters

$ip

\?IP

IP address (NULL: that of current member).

Returns

\ID_TEXTThe currency code.

Make a subscription cancellation button.

make_cancel_button(\AUTO_LINK $purchase_id, \ID_TEXT $via) : \?tempcode

Parameters

$purchase_id

\AUTO_LINK

The purchase ID.

$via

\ID_TEXT

The service the payment will go via via.

Returns

\?tempcodeThe button (NULL: no special cancellation -- just delete the subscription row to stop ocPortal regularly re-charging)

Make a shopping cart payment button.

make_cart_payment_button(\AUTO_LINK $order_id, \ID_TEXT $currency) : \tempcode

Parameters

$order_id

\AUTO_LINK

Order ID

$currency

\ID_TEXT

The currency to use.

Returns

\tempcodeThe button

Make a subscription (payment) button.

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

set d w m y

Parameters

$product

\ID_TEXT

The product codename.

$item_name

\SHORT_TEXT

The human-readable product title.

$purchase_id

\ID_TEXT

The purchase ID.

$amount

float

A transaction amount.

$length

integer

The subscription length in the units.

$length_units

\ID_TEXT

The length units.

$currency

\ID_TEXT

The currency to use.

$via

\?ID_TEXT

The service the payment will go via via (NULL: autodetect).

Returns

\tempcodeThe button

Make a transaction (payment) button.

make_transaction_button(\ID_TEXT $product, \SHORT_TEXT $item_name, \ID_TEXT $purchase_id, float $amount, \ID_TEXT $currency, \?ID_TEXT $via) : \tempcode

Parameters

$product

\ID_TEXT

The product codename.

$item_name

\SHORT_TEXT

The human-readable product title.

$purchase_id

\ID_TEXT

The purchase ID.

$amount

float

A transaction amount.

$currency

\ID_TEXT

The currency to use.

$via

\?ID_TEXT

The service the payment will go via via (NULL: autodetect).

Returns

\tempcodeThe button

Exit ocPortal and write to the error log file.

my_exit(string $error, boolean $dont_trigger) 

Parameters

$error

string

The message.

$dont_trigger

boolean

Dont trigger an error

Find whether local payment will be performed.

perform_local_payment() : boolean

Returns

booleanWhether local payment will be performed.

Send an invoice notification to a member.

send_invoice_mail(\MEMBER $member_id, \AUTO_LINK $id) 

Parameters

$member_id

\MEMBER

The member to send to.

$id

\AUTO_LINK

The invoice ID.

Constants

 

ECOMMERCE_PRODUCT_ALREADY_HAS

ECOMMERCE_PRODUCT_ALREADY_HAS 

 

ECOMMERCE_PRODUCT_AVAILABLE

ECOMMERCE_PRODUCT_AVAILABLE 

 

ECOMMERCE_PRODUCT_DISABLED

ECOMMERCE_PRODUCT_DISABLED 

 

ECOMMERCE_PRODUCT_INTERNAL_ERROR

ECOMMERCE_PRODUCT_INTERNAL_ERROR 

 

ECOMMERCE_PRODUCT_MISSING

ECOMMERCE_PRODUCT_MISSING 

 

ECOMMERCE_PRODUCT_NO_GUESTS

ECOMMERCE_PRODUCT_NO_GUESTS 

 

ECOMMERCE_PRODUCT_OUT_OF_STOCK

ECOMMERCE_PRODUCT_OUT_OF_STOCK 

 

ECOMMERCE_PRODUCT_PROHIBITED

ECOMMERCE_PRODUCT_PROHIBITED 

 

PRODUCT_CATALOGUE

PRODUCT_CATALOGUE 

 

PRODUCT_INVOICE

PRODUCT_INVOICE 

 

PRODUCT_ORDERS

PRODUCT_ORDERS 

 

PRODUCT_OTHER

PRODUCT_OTHER 

 

PRODUCT_PURCHASE_WIZARD

PRODUCT_PURCHASE_WIZARD 

 

PRODUCT_SUBSCRIPTION

PRODUCT_SUBSCRIPTION