HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


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)


Return to the function index for this class Expand: View the source code to this function

boolean ecommerce_test_mode()

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

Parameters…

Returns…

Description The answer.
Type boolean

Return to the function index for this class Expand: View the source code to this function

ID_TEXT ecommerce_get_currency_symbol()

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

Parameters…

Returns…

Description The currency.
Type ID_TEXT

Return to the function index for this class Expand: View the source code to this function

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

Return to the function index for this class Expand: View the source code to this function

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

Return to the function index for this class Expand: View the source code to this function

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

Return to the function index for this class Expand: View the source code to this function

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

Return to the function index for this class Expand: View the source code to this function

?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

Return to the function index for this class Expand: View the source code to this function

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)


Return to the function index for this class Expand: View the source code to this function

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

Return to the function index for this class Expand: View the source code to this function

?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

Return to the function index for this class Expand: View the source code to this function

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

Return to the function index for this class Expand: View the source code to this function

boolean perform_local_payment()

Find whether local payment will be performed.

Parameters…

Returns…

Description Whether local payment will be performed.
Type boolean

Return to the function index for this class Expand: View the source code to this function

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

Return to the function index for this class Expand: View the source code to this function

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)


Return to the function index for this class Expand: View the source code to this function

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)


Return to the function index for this class Expand: View the source code to this function

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

Return to the function index for this class Expand: View the source code to this function

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)


Return to the function index for this class Expand: View the source code to this function

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)


Return to the function index for this class Expand: View the source code to this function

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

Return to the function index for this class Expand: View the source code to this function