Jump to content

Restricting payment method for Digital Downloads


Brian T

Recommended Posts

I only offer Print_Order_Form and Paypal as payment options on my website.  When customers select digital downloads, I wish them to pay via paypal.

Despite spelling this out as clearly as I can on the website, I still get more people choosing Print_Order_Form as their payment method when they've selected a digital download.

 

Is there a way of them only being given the option of paying my paypal is they've chosen a digital download product?

 

Many thanks

Link to comment
Share on other sites

Hi Brian

There is no way to do this in core CubeCart and I would doubt it is a feature that many people would want although thise like you that do need it, it would be important.

I did look at writing a plugin before that would allow definition of a specific payment gateway either at a category or product level but it could also be done for digital / tangible products as well - it never went ahead but could be looked into again

Ian

Link to comment
Share on other sites

SemperFi came up with an intriguing start of a solution: scan the cart contents for any item that is digital, and if so, restrict the listing of the available gateways.

/classes/cubecart.class.php
Was:
 $gateways = $GLOBALS['db']->select('CubeCart_modules', false, $where, array('position' => 'ASC'));
 
Now:
 if ($this->_basket['digital_only']) {
   $where_digital_only = array('module' => 'gateway', 'folder' => 'PayPal', 'status' => '1');
   $gateways = $GLOBALS['db']->select('CubeCart_modules', false, $where_digital_only, array('position' => 'ASC'));
 } else {
   $gateways = $GLOBALS['db']->select('CubeCart_modules', false, $where, array('position' => 'ASC'));
 }

The above tests for a basket flag that CubeCart sets when there are only digital products, but does not take into account for when there is a mix and the desired outcome is still when any item in the mix is digital.
 

I'll experiment with this.

Link to comment
Share on other sites

My initial tests have shown that a code snippet can immediately direct a customer to a stated gateway (but not necessarily a plugin-type gateway) if the cart contents contains at least one digital product.

 

In admin, Manage Hooks, Code Snippets tab, click Add Snippet.

 

Enabled: Green Check

Unique ID: digital_gateway@cubecart  <==(32 characters max!)

Execution Order: 1

Description: Gives customer only one payment method if cart has a digital item in it

Trigger: class.cubecart.construct.gateway

Version: 1.0

Author: forums.cubecart.com/topic/49295-restricting-payment-method-for-digital-downloads/

PHP Code:

{php}
        $my_digital_gateway = "PayPal"; // must exactly match gateway module folder name!
 
        $this->_basket =& $GLOBALS['cart']->basket;
        $has_digital = false;
        foreach ($this->_basket['contents'] as $hash => $product){
            if ($product['digital']){ // has a digital product - no need to keep looking
                $has_digital = true;
                break;
            }
        }

        if (!$has_digital){
            if (isset($this->_basket['has_digital'])) unset($this->_basket['has_digital']); // digital item removed
        } else {
            $GLOBALS['cart']->set('has_digital', true);
        }

        if ($this->_basket['has_digital']){
            $_REQUEST['gateway'] = $my_digital_gateway;
        }
{/php}

The first line of code specifies the gateway to use.

 

Please test and let us know how it works for you.

 

Thanks goes to SemperFi!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...