public function updatePayment($shippingId = 0)
{
$paramsC = PhocacartUtils::getComponentParameters();
$change_remove_payment_method = $paramsC->get('change_remove_payment_method', 1);
$removeCoupon = 0;
if ((int) $shippingId > 0) {
// When we store shipping into database and immediately asking shipping id from database, we get empty result
// this is why we need to know shipping ID here
$currentShippingId = (int) $shippingId;
} else {
$currentShippingId = isset($this->shipping['id']) && $this->shipping['id'] > 0 ? (int) $this->shipping['id'] : 0;
}
$currentPaymentId = isset($this->payment['id']) && $this->payment['id'] > 0 ? (int) $this->payment['id'] : 0;
if ($this->pos && (int) $this->vendor->id > 0) {
$typeUser = 0;
} else {
if ((int) $this->user->id > 0) {
$typeUser = 0;
} else {
$typeUser = 1;
}
}
// $change_remove_payment_method is not a POS parameter
// In POS we don't remove shpping or payment a priori but we always validate it
if (!$this->pos && $change_remove_payment_method == 1) {
PhocacartPayment::removePayment($typeUser, $removeCoupon);
return;
}
if (!isset($this->total[0])) {
$this->total[0] = array();
}
$isValidPayment = false;
$paymentObject = new PhocacartPayment();
$paymentObject->setType($this->type);
if ($currentPaymentId > 0) {
$isValidPayment = $paymentObject->checkAndGetPaymentMethod((int) $currentPaymentId, $this->total[0], (int) $currentShippingId);
}
if (!$isValidPayment) {
PhocacartPayment::removePayment($typeUser, $removeCoupon);
}
}