Forum

Thread tagged as: Shop

Gateway documentation

Is there any documentation on adding omnipay gateways to perch shop?

Benjamin Verkleij

Benjamin Verkleij 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

There's not as yet - but's it's fairly basic.

Define and include a new gateway class that extends PerchShopGateway_default. For an example gateway called "Mango" you'd use:

class PerchShopGateway_mango extends PerchShopGateway_default
{
    protected $slug = 'mango';
    public $omnipay_name = 'Mango';
}

You'd then add any of the methods from PerchShopGateway_default that you need to customise. A good example might be the WorldPay implementation.

class PerchShopGateway_worldpay extends PerchShopGateway_default
{
    protected $slug = 'worldpay';
    public $omnipay_name = 'WorldPay';

    public function set_credentials(&$Omnipay, $config)
    {
        if ($config['test_mode']) {
            $Omnipay->setInstallationId($config['test']['installationId']);
            $Omnipay->setAccountId($config['test']['accountId']);
            $Omnipay->setSecretWord($config['test']['secretWord']);
            $Omnipay->setCallbackPassword($config['test']['callbackPassword']);
            $Omnipay->setTestMode(true);
        }else{
            $Omnipay->setInstallationId($config['live']['installationId']);
            $Omnipay->setAccountId($config['live']['accountId']);
            $Omnipay->setSecretWord($config['live']['secretWord']);
            $Omnipay->setCallbackPassword($config['live']['callbackPassword']);
            $Omnipay->setTestMode(false);
        }
    }

    public function get_order_from_env($Orders, $get, $post)
    {
        if (isset($post['cartId'])) {
            $Order = $Orders->find($post['cartId']);
            if ($Order) {
                PerchShop_Session::set('shop_order_id', $Order->id());
                return $Order;
            }   
        }
        return false;
    }

    public function callback_looks_valid($get, $post)
    {
        if (isset($post['cartId']) && isset($post['transStatus']) && $post['transStatus'] == 'Y') {
            return true;
        }
        return false;
    }

    public function action_payment_callback($Order, $args, $gateway_opts)
    {
        $result = $this->complete_payment($Order, $args);
    }
}

Thanks,

I'm looking at implementing an official omnipay gateway, is there a prefered path in perch where gateway packages should be placed, in our case omnipay/multisafepay.

There's perch/addons/apps/perch_shop/gateways but all omnipay packages a listed in perch/addons/apps/perch_shop/lib/vendor/omnipay

Drew McLellan

Drew McLellan 2638 points
Perch Support

You shouldn't make any changes inside apps/perch_shop. The better route would be to implement your code (including any dependancies) as their own app.