public function makePayment($gateway, $gatewaydata = array(), $successUrl = null, $cancelUrl = null)
    {
        //create payment
        $payment = $this->createPayment($gateway);
        if (!$payment) {
            //errors have been stored.
            return null;
        }

        $payment->setSuccessUrl($successUrl ? $successUrl : $this->getReturnUrl());

        // Explicitly set the cancel URL
        if ($cancelUrl) {
            $payment->setFailureUrl($cancelUrl);
        }

        // Create a payment service, by using the Service Factory. This will automatically choose an
        // AuthorizeService or PurchaseService, depending on Gateway configuration.
        // Set the user-facing success URL for redirects
        /**
         * @var ServiceFactory $factory
         */
        $factory = ServiceFactory::create();
        $service = $factory->getService($payment, ServiceFactory::INTENT_PAYMENT);

        // Initiate payment, get the result back
        try {
            $serviceResponse = $service->initiate($this->getGatewayData($gatewaydata));
        } catch (\SilverStripe\Omnipay\Exception\Exception $ex) {
            // error out when an exception occurs
            $this->error($ex->getMessage());
            return null;
        }

        // Check if the service response itself contains an error
        if ($serviceResponse->isError()) {
            if ($opResponse = $serviceResponse->getOmnipayResponse()) {
                $this->error($opResponse->getMessage());
            } else {
                $this->error('An unspecified payment error occurred. Please check the payment messages.');
            }
        }

        // For an OFFSITE payment, serviceResponse will now contain a redirect
        // For an ONSITE payment, ShopPayment::onCaptured will have been called, which will have called completePayment

        return $serviceResponse;
    }
public function makePayment($gateway, $gatewaydata = array(), $successUrl = null, $cancelUrl = null)
    {
        //create payment
        $payment = $this->createPayment($gateway);
        if (!$payment) {
            //errors have been stored.
            return null;
        }

        $payment->setSuccessUrl($successUrl ? $successUrl : $this->getReturnUrl());

        // Explicitly set the cancel URL
        if ($cancelUrl) {
            $payment->setFailureUrl($cancelUrl);
        }

        // Create a payment service, by using the Service Factory. This will automatically choose an
        // AuthorizeService or PurchaseService, depending on Gateway configuration.
        // Set the user-facing success URL for redirects
        /**
         * @var ServiceFactory $factory
         */
        $factory = ServiceFactory::create();
        $service = $factory->getService($payment, ServiceFactory::INTENT_PAYMENT);

        // Initiate payment, get the result back
        try {
            $serviceResponse = $service->initiate($this->getGatewayData($gatewaydata));
        } catch (\SilverStripe\Omnipay\Exception\Exception $ex) {
            // error out when an exception occurs
            $this->error($ex->getMessage());
            return null;
        }

        // Check if the service response itself contains an error
        if ($serviceResponse->isError()) {
            if ($opResponse = $serviceResponse->getOmnipayResponse()) {
                $this->error($opResponse->getMessage());
            } else {
                $this->error('An unspecified payment error occurred. Please check the payment messages.');
            }
        }

        // For an OFFSITE payment, serviceResponse will now contain a redirect
        // For an ONSITE payment, ShopPayment::onCaptured will have been called, which will have called completePayment

        return $serviceResponse;
    }
public function makePayment ( $ gateway , $ gatewaydata = array ( ) , $ successUrl = null , $ cancelUrl = null ) { //create payment $ payment = $ this -> createPayment ( $ gateway ) ; if ( ! $ payment ) { //errors have been stored. return null ; } $ payment -> setSuccessUrl ( $ successUrl ? $ successUrl : $ this -> getReturnUrl ( ) ) ; // Explicitly set the cancel URL if ( $ cancelUrl ) { $ payment -> setFailureUrl ( $ cancelUrl ) ; } // Create a payment service, by using the Service Factory. This will automatically choose an // AuthorizeService or PurchaseService, depending on Gateway configuration. // Set the user-facing success URL for redirects /**
         * @var ServiceFactory $factory
         */ $ factory = ServiceFactory :: create ( ) ; $ service = $ factory -> getService ( $ payment , ServiceFactory :: INTENT_PAYMENT ) ; // Initiate payment, get the result back try { $ serviceResponse = $ service -> initiate ( $ this -> getGatewayData ( $ gatewaydata ) ) ; } catch ( \ SilverStripe \ Omnipay \ Exception \ Exception $ ex ) { // error out when an exception occurs $ this -> error ( $ ex -> getMessage ( ) ) ; return null ; } // Check if the service response itself contains an error if ( $ serviceResponse -> isError ( ) ) { if ( $ opResponse = $ serviceResponse -> getOmnipayResponse ( ) ) { $ this -> error ( $ opResponse -> getMessage ( ) ) ; } else { $ this -> error ( 'An unspecified payment error occurred. Please check the payment messages.' ) ; } } // For an OFFSITE payment, serviceResponse will now contain a redirect // For an ONSITE payment, ShopPayment::onCaptured will have been called, which will have called completePayment return $ serviceResponse ; }
Create a payment model, and provide link to redirect to external gateway,
or redirect to order link.

@param string $gateway the gateway to use
@param array $gatewaydata the data that should be passed to the gateway
@param string $successUrl (optional) return URL for successful payments.
If left blank, the default return URL will be
used @see getReturnUrl
@param string $cancelUrl (optional) return URL for cancelled/failed payments

@return ServiceResponse|null
@throws \SilverStripe\Omnipay\Exception\InvalidConfigurationException
Create a payment model and provide link to redirect to external gateway or redirect to order link .