The myCRED_Payment_Gateway is a template class used by the BuyCred Add-on. It contains all the neccessery class methods along with a set of template functions. Note! You should never initiate this class directly! Instead make sure your custom hook extends it (see usage example bellow).


class My_Custom_Gateway extends myCRED_Payment_Gateway {
	function __construct( $gateway_prefs ) {
		parent::__construct( $args, $gateway_prefs );


  • $id (string)
    Gateway ID.
  • $core (object)
    myCRED Settings.
  • $prefs (array)
    This gateways preferences.
  • $current_user_id (int)
    The current users id (if logged in).
  • $response (string)
    Responses from the gateway or via the execution of the gateway. It can for example hold information when an error occurs.
  • $request (array)
    The purchase request being sent to the gateway to process.
  • $status (int|string)
    Payment status.
  • $errors (array)
    Holds (if any) error objects.


  1. myCRED_Payment_Gateway()Class constructor populating $current_user_id, $args, $prefs and $core.
  2. process()This method must be replaced by the child class and should manage requests from either form submissions resulting in contacting a payment gateway or by incoming notifications/verifications from a gateway.
  3. buy()This method must be replaced by the child class and should manage requests made to purchase creds. All purchase requests must nominate the gateway to avoid multiple gateway attempting to process the same purchase.
  4. returning()This method must be replaced by the child class if a purchase request were processed remotely.
  5. preferences()Outputs the gateways preferences. If not set, the default “This Gateway has no settings” is shown.
  6. sanitise_preferences( $data )Option to sanitize the gateways settings before they are saved in the database.
    • $data (array)
      The posted data.
  7. field_name( $data )Outputs this gateways field name.
    • $data (string|array)
      Either a string with the field id or an array if hook has multiple settings.
  8. field_id( $data )Outputs this gateways field id.
    • $data (string|array)
      Either a string with the field id or an array if hook has multiple settings.
  9. decode_log_entries( $entry, $object )This method decodes the log entry for purchases. When purchases are made, the buyers ID is saved under ref_id allowing us to use this users data as template tags.
    • $entry (type)
      The log entry.
    • $object (type)
      The log object.
  10. callback_url()Returns the callback URL for this gateway. Used by PayPal as the URL for the IPN callback. Can be used by any gateway that requires a callback URL.
  11. purchase_header( $title, $reload )Purchase page header.
  12. purchase_footer()The purchase page’s footer.
  13. form_with_redirect( $hidden_fields, $location, $logo_url, $custom_html, $sales_data )Generates a purchase form with the given hidden fields along with a gateway logo and optional custom html. Used by gateways with remote processors (i.e. PayPal or Skrill).
    • $hidden_fields (array)
      Required hidden form fields needed by the gateway.
    • $location (string)
      Form action URL.
    • $logo_url (string)
      Optional gateway logo URL.
    • $custom_html (string)
      Optional HTML to insert in page.
    • $sales_data (string|array)
      Optional sales data to include in page.
  14. get_to()Returns either the current user id or if gifting is enabled and used the id of the user this is gifted to.
  15. get_thankyou()Returns the “Thank You” page URL.
  16. get_cancelled()Returns the “Cancelled” page URL.
  17. get_entry( $_to, $_from )Returns the appropriate log entry template. If “Gifting” is enabled and the two values do not match the gift template is returned.
    • $_to (int)
      The user id of the recipient.
    • $_from (int)
      The user id of the purchaser.
  18. POST_to_data( $unset )Converts posted variables to local with the option to unset $_POST once done.
    • $unset (bool)
      Option to unser $_POST before returning the variables.
  19. transaction_id_is_unique( $transaction_id )Searches the log for a given transaction id. Returns false if id was found else true. Used to make sure purchases are unique.
    • $transaction_id (string|int) required
      The transaction id to look for.
  20. create_token()Returns a WP Nonce for the purchase. Uses wp_create_nonce().
  21. verify_token( $user_id, $nonce )Based on wp_verify_nonce() with the difference that a user id must be given. Returns true or false.
    • $user_id (type) required
      User id for the nonce in question.
    • $nonce (type) required
      The nonce.
  22. encode_sales_data( $data )Encodes the sales data. Uses the myCRED_Protect() class.
    • $data (string) required
      The data to be encoded.
  23. decode_sales_data( $data )Decodes the sales data. Uses the myCRED_Protect() class.
    • $data (string) required
      The data to be decoded.
  24. currencies_dropdown( $name )Generates a drop-down menu with accepted currencies. Uses the ‘mycred_dropdown_currencies’ filter.
    • $name (string) required
      The drop-down elements name.
  25. item_types_dropdown( $name )Generates a drop-down menu with available item types. Used by PayPal. Uses the ‘mycred_dropdown_item_types’ filter.
    • $name (string) required
  26. list_option_countries( $selected )Echos a list of html options for nations, highlighting the selected. Uses the ‘mycred_list_option_countries’ filter.
    • $selected (string)
      The selected countries two letter code.
  27. list_option_us_states( $selected, $non_us )Echos a list of html options for US states. If $non_us is set to true the “Outside US” option is appended.
    • $selected (string)
      The selected states two letter abbreviation.
    • $non_us (boolean)
      Option to add “Outside US”.
  28. list_option_months( $selected )Echos a list of html options for each month.
    • $selected (int) required
      The selected month number with leading zero.
  29. list_option_card_years( $selected, $number )Echos a list of html options for credit card expiry years.
    • $selected (type) required
      The selected years last two digits.
    • $number (type) required
      The number of years into the future to generate. Defaults to 16.