Custom Payment Methods

Would need to have Custom Payment Methods.
Other types of payments that don't require credit card processing such as Money Orders, Bank Deposits and Cash on Delivery (COD). Also a custom payment method name would be great.

  • Theokie

    @keithjameslock Here goes,

    just paste it in wp-content/plugins/marketpress/marketpress-includes/plugins-gateway/testmode.php

    or download Here

    <br />
    <?php<br />
    class MP_Gateway_Cash extends MP_Gateway_API {<br />
        //private gateway slug. Lowercase alpha (a-z) and dashes (-) only please!<br />
        var $plugin_name = 'cash';</p>
    <p>    //name of your gateway, for the admin side.<br />
        var $admin_name = 'Cash/EFT';</p>
    <p>    //public name of your gateway, for lists and such.<br />
        var $public_name = 'Cash/EFT';</p>
    <p>    //url for an image for your checkout method. Displayed on method form<br />
        var $method_img_url = '';</p>
    <p>    //url for an submit button image for your checkout method. Displayed on checkout form if set<br />
        var $method_button_img_url = '';</p>
    <p>    //whether or not ssl is needed for checkout page<br />
        var $force_ssl = false;</p>
    <p>    //always contains the url to send payment notifications to if needed by your gateway. Populated by the parent class<br />
        var $ipn_url;</p>
    <p>    /****** Below are the public methods you may overwrite via a plugin ******/</p>
    <p>    /**<br />
         * Runs when your class is instantiated. Use to setup your plugin instead of __construct()<br />
         */<br />
        function on_creation() {<br />
    		global $mp;<br />
    		$settings = get_option('mp_settings');</p>
    <p>		//set names here to be able to translate<br />
    		$this->admin_name = __('Tet', 'mp');<br />
    		$this->public_name = __('Test', 'mp');<br />
        }</p>
    <p>    /**<br />
         * Echo fields you need to add to the payment screen, like your credit card info fields<br />
         *<br />
         * @param array $shipping_info. Contains shipping info and email in case you need it<br />
         */<br />
        function payment_form($cart, $shipping_info) {<br />
            global $mp;<br />
            $settings = get_option('mp_settings');<br />
            echo nl2br($settings['gateways']['cash']['details']);<br />
        }</p>
    <p>    /**<br />
         * Use this to process any fields you added. Use the $_POST global,<br />
         *  and be sure to save it to both the $_SESSION and usermeta if logged in.<br />
         *  DO NOT save credit card details to usermeta as it's not PCI compliant.<br />
         *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors<br />
         *  it will redirect to the next step.<br />
         *<br />
         * @param array $shipping_info. Contains shipping info and email in case you need it<br />
         */<br />
    		function process_payment_form($cart, $shipping_info) {<br />
    			global $mp;<br />
        }</p>
    <p>    /**<br />
         * Echo the chosen payment details here for final confirmation. You probably don't need<br />
         *  to post anything in the form as it should be in your $_SESSION var already.<br />
         *<br />
         * @param array $shipping_info. Contains shipping info and email in case you need it<br />
         */<br />
    		function confirm_payment_form($cart, $shipping_info) {<br />
    	  global $mp;</p>
    <p>    }</p>
    <p>    /**<br />
         * Use this to do the final payment. Create the order then process the payment. If<br />
         *  you know the payment is successful right away go ahead and change the order status<br />
         *  as well.<br />
         *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors<br />
         *  it will redirect to the next step.<br />
         *<br />
         * @param array $shipping_info. Contains shipping info and email in case you need it<br />
         */<br />
    	function process_payment($cart, $shipping_info) {<br />
        global $mp;</p>
    <p>    $timestamp = time();<br />
        $settings = get_option('mp_settings');<br />
          $totals = array();<br />
          foreach ($cart as $product_id => $data) {<br />
            $totals[] = $data['price'] * $data['quantity'];<br />
          }<br />
          $total = array_sum($totals);</p>
    <p>	  if ( $coupon = $mp->coupon_value($mp->get_coupon_code(), $total) ) {<br />
          $total = $coupon['new_total'];<br />
        }</p>
    <p>    //shipping line<br />
        if ( ($shipping_price = $mp->shipping_price()) !== false ) {<br />
          $total = $total + $shipping_price;<br />
        }</p>
    <p>    //tax line<br />
        if ( ($tax_price = $mp->tax_price()) !== false ) {<br />
          $total = $total + $tax_price;<br />
        }</p>
    <p>	$order_id = $mp->generate_order_id();</p>
    <p>      $payment_info['gateway_public_name'] = $this->public_name;<br />
          $payment_info['gateway_private_name'] = $this->admin_name;<br />
          $payment_info['status'][$timestamp] = "received";<br />
          $payment_info['total'] = $total;<br />
          $payment_info['currency'] = "ZAR";<br />
    	  $payment_info['method'] = "EFT / Cash";<br />
    	  $payment_info['transaction_id'] = $order_id;<br />
        //succesful payment, create our order now<br />
        $result = $mp->create_order($_SESSION['mp_order'], $cart, $shipping_info, $payment_info, false);</p>
    <p>    }</p>
    <p>    /**<br />
         * Runs before page load incase you need to run any scripts before loading the success message page<br />
         */<br />
    		function order_confirmation($order) {</p>
    <p>    }</p>
    <p>		/**<br />
         * Filters the order confirmation email message body. You may want to append something to<br />
         *  the message. Optional<br />
         *<br />
         * Don't forget to return!<br />
         */<br />
    		function order_confirmation_email($msg) {<br />
          return $msg;<br />
        }</p>
    <p>    /**<br />
         * Echo any html you want to show on the confirmation screen after checkout. This<br />
         *  should be a payment details box and message.<br />
         */<br />
    		function order_confirmation_msg($order) {<br />
              global $mp;<br />
          echo '<p>' . sprintf(__('Your Order for %s has been received. Here is the latest status:', 'mp'), $mp->format_currency($order->mp_payment_info['currency'], $order->mp_payment_info['total'])) . '</p>';<br />
          }</p>
    <p>		/**<br />
         * Echo a settings meta box with whatever settings you need for you gateway.<br />
         *  Form field names should be prefixed with mp[gateways][plugin_name], like "mp[gateways][plugin_name][mysetting]".<br />
         *  You can access saved settings via $settings array.<br />
         */<br />
    		function gateway_settings_box($settings) {<br />
        global $mp;<br />
        $settings = get_option('mp_settings');</p>
    <p>    ?><br />
           <div id="mp_2checkout" class="postbox"><br />
              <h3 class='handle'><span><?php _e('Cash/EFT Settings', 'mp'); ?></span></h3><br />
            <div class="inside"><br />
            <span class="description"><?php _e('Get paid by EFT or Cash.', 'mp') ?></span><br />
            <table class="form-table"><br />
            <tr><br />
                <th scope="row"></th><br />
                <td><br />
                  <p><br />
                      <label><?php _e('Banking Details for EFT', 'mp') ?><br />
                      <textarea name="mp[gateways][cash][details]" cols=40 rows=6><?php echo esc_attr($settings['gateways']['cash']['details']); ?></TEXTAREA><br />
                      </label><br />
                  </p><br />
                </td><br />
            </tr><br />
          </table><br />
        </div><br />
        <?php<br />
        }</p>
    <p>    /**<br />
         * Filters posted data from your settings form. Do anything you need to the $settings['gateways']['plugin_name']<br />
         *  array. Don't forget to return!<br />
         */<br />
    		function process_gateway_settings($settings) {</p>
    <p>      return $settings;<br />
        }</p>
    <p>		/**<br />
         * Use to handle any payment returns to the ipn_url. Do not display anything here. If you encounter errors<br />
         *  return the proper headers. Exits after.<br />
         */<br />
    		function process_ipn_return() {</p>
    <p>    }<br />
    }</p>
    <p>mp_register_gateway_plugin( 'MP_Gateway_Cash', 'Cash', __('Cash / EFT', 'mp') );</p>
    <p>?><br />

    Now I dont back this code 100% :wink: but it works for me so far...

    Let me know if it works please!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.