Skip to content

Commit

Permalink
remove custom field handles from pmt_row_desc, add validation and fil…
Browse files Browse the repository at this point in the history
…tering for pmt_userlanguage
  • Loading branch information
aschanMarcus committed Jan 18, 2019
1 parent 514c6cb commit 412aa43
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/models/PaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function rules()
$rules = parent::rules();
$rules[] = [['pmt_buyeremail', 'pmt_buyername', 'pmt_buyeraddress', 'pmt_buyerpostalcode', 'pmt_buyercity'], 'required'];
$rules[] = [['pmt_deliveryname', 'pmt_deliveryaddress', 'pmt_deliverypostalcode', 'pmt_deliverycity'], 'required'];
$rules[] = ['pmt_userlocale', 'filter', 'filter' => [$this, 'filterUserLocale']];

return $rules;
}
Expand All @@ -82,6 +83,24 @@ public function getAttributes($names = null, $except = [])
return $values;
}

/**
* Filter pmt_userlocale
* Return a default launguage string if value is not among allowed languages
*
* @param string $value
* @return string $value
*/
public function filterUserLocale($value)
{
$allowed = ['fi_FI', 'sv_FI', 'en_FI'];

if (in_array($value, $allowed)) {
return $value;
}

return 'en_FI';
}

/**
* Set attributes from PaymentForm
*
Expand Down Expand Up @@ -194,13 +213,11 @@ private function populatelineItems(array $lineItems)
*/
private function populatelineItem(LineItem $lineItem)
{
$product = $lineItem->snapshot['product'];

$row = [
'pmt_row_name' => $lineItem->description,
'pmt_row_desc' => $product['description'] ? $product['description'] : ' ',
'pmt_row_desc' => $lineItem->description,
'pmt_row_quantity' => $lineItem->qty,
'pmt_row_deliverydate' => $product['days']->one()->startDate->format('d.m.Y'),
'pmt_row_deliverydate' => date('d.m.Y'),
'pmt_row_price_net' => number_format($lineItem->price, 2, ',', ''),
'pmt_row_vat' => $this->getLineItemTax($lineItem),
'pmt_row_discountpercentage' => '0,00',
Expand Down

0 comments on commit 412aa43

Please sign in to comment.