public function validatePayment(AnCommandContext $context)
    {
        $data = $context->data;
        $package = $this->getItem();

        if ($data->token) {

            $country = null;
            $identifier = 'com:subscriptions.controller.subscription';
            $method = $this->getService($identifier)->getGateway()->getExpressPaymentMethod($data->token, $country);
            $this->order->setPaymentMethod($method);
            $this->order->country = $country;

        } else {

            $url = route('option=com_subscriptions&view=signup&layout=payment&id='.$package->id);
            $error = false;

            //validate creditcard
            if (!$this->creditcard->is_valid()) {
                $error = true;
                $this->storeValue('credit_card_error', AnTranslator::_('COM-SUBSCRIPTIONS-CREDITCARD-INVALID'));
            }

            //validate contact
            $contact = $this->contact;

            if (! (
                  $contact->address &&
                  $contact->city &&
                  $contact->country &&
                  $contact->state &&
                  $contact->zip
            )) {
                $this->storeValue('address_error', AnTranslator::_('COM-SUBSCRIPTIONS-BILLING-INVALID'));
            }

            if ($error) {
                $context->response->setRedirect($url);
                return false;
            }

            $this->order->country = $contact->country;

            return true;
        }
    }
public function validatePayment(AnCommandContext $context)
    {
        $data = $context->data;
        $package = $this->getItem();

        if ($data->token) {

            $country = null;
            $identifier = 'com:subscriptions.controller.subscription';
            $method = $this->getService($identifier)->getGateway()->getExpressPaymentMethod($data->token, $country);
            $this->order->setPaymentMethod($method);
            $this->order->country = $country;

        } else {

            $url = route('option=com_subscriptions&view=signup&layout=payment&id='.$package->id);
            $error = false;

            //validate creditcard
            if (!$this->creditcard->is_valid()) {
                $error = true;
                $this->storeValue('credit_card_error', AnTranslator::_('COM-SUBSCRIPTIONS-CREDITCARD-INVALID'));
            }

            //validate contact
            $contact = $this->contact;

            if (! (
                  $contact->address &&
                  $contact->city &&
                  $contact->country &&
                  $contact->state &&
                  $contact->zip
            )) {
                $this->storeValue('address_error', AnTranslator::_('COM-SUBSCRIPTIONS-BILLING-INVALID'));
            }

            if ($error) {
                $context->response->setRedirect($url);
                return false;
            }

            $this->order->country = $contact->country;

            return true;
        }
    }
public function validatePayment ( AnCommandContext $ context ) { $ data = $ context -> data ; $ package = $ this -> getItem ( ) ; if ( $ data -> token ) { $ country = null ; $ identifier = 'com:subscriptions.controller.subscription' ; $ method = $ this -> getService ( $ identifier ) -> getGateway ( ) -> getExpressPaymentMethod ( $ data -> token , $ country ) ; $ this -> order -> setPaymentMethod ( $ method ) ; $ this -> order -> country = $ country ; } else { $ url = route ( 'option=com_subscriptions&view=signup&layout=payment&id=' . $ package -> id ) ; $ error = false ; //validate creditcard if ( ! $ this -> creditcard -> is_valid ( ) ) { $ error = true ; $ this -> storeValue ( 'credit_card_error' , AnTranslator :: _ ( 'COM-SUBSCRIPTIONS-CREDITCARD-INVALID' ) ) ; } //validate contact $ contact = $ this -> contact ; if ( ! ( $ contact -> address && $ contact -> city && $ contact -> country && $ contact -> state && $ contact -> zip ) ) { $ this -> storeValue ( 'address_error' , AnTranslator :: _ ( 'COM-SUBSCRIPTIONS-BILLING-INVALID' ) ) ; } if ( $ error ) { $ context -> response -> setRedirect ( $ url ) ; return false ; } $ this -> order -> country = $ contact -> country ; return true ; } }
Validates before confirm and process.

@param AnCommandContext $context

@return bool
Validates before confirm and process .