Back to PhocacartPayment class

Method checkAndGetPaymentMethods

public bool|array
checkAndGetPaymentMethods
(mixed $selectedPaymentId = 0, mixed $selected = 0, mixed $total = array(), mixed $shippingId = 0)
Check current payment method or all methods they meet criteria to be selected
Parameters
  • \number $selectedPaymentId
  • \number $selected
Returns
  • bool|array

Method checkAndGetPaymentMethods - Source code

/**
 * Check current payment method or all methods they meet criteria to be selected
 * @param number $selectedPaymentId
 * @param number $selected
 * @return boolean|array
 */
public function checkAndGetPaymentMethods($selectedPaymentId = 0, $selected = 0, $total = array(), $shippingId = 0)
{
    if (empty($total)) {
        $cart = new PhocacartCartRendercheckout();
        $cart->setType($this->type);
        $cart->setFullItems();
        $total = $cart->getTotal();
        $totalFinal = $total[0];
        $currentShippingId = $cart->getShippingId();
        //$currentPaymentId 		= $cart->getPaymentId();
    } else {
        $totalFinal = $total;
        $currentShippingId = $shippingId;
    }
    $user = PhocacartUser::getUser();
    $data = PhocacartUser::getUserData((int) $user->id);
    $fields = PhocacartFormUser::getFormXml('', '_phs', 1, 1, 0);
    $dataAddress = array();
    if (!empty($data)) {
        $dataAddress = PhocacartUser::getAddressDataOutput($data, $fields['array'], $user);
    } else {
        // Is this guest user
        $guest = PhocacartUserGuestuser::getGuestUser();
        if ($guest) {
            $data = PhocacartUserGuestuser::getUserAddressGuest();
            $dataAddress = PhocacartUser::getAddressDataOutput($data, $fields['array'], $user, 1);
        }
    }
    /*$country = 0;
    		if(isset($dataAddress['bcountry']) && (int)$dataAddress['bcountry']) {
    			$country = (int)$dataAddress['bcountry'];
    		}
    
    		$region = 0;
    		if(isset($dataAddress['bregion']) && (int)$dataAddress['bregion']) {
    			$region = (int)$dataAddress['bregion'];
    		}*/
    $country = $this->getUserCountryPayment($dataAddress);
    $region = $this->getUserRegionPayment($dataAddress);
    $paymentMethods = $this->getPossiblePaymentMethods($totalFinal['netto'], $totalFinal['brutto'], $country, $region, $currentShippingId, $selectedPaymentId, $selected);
    if (!empty($paymentMethods)) {
        return $paymentMethods;
    }
    return false;
}