PluginProbe
seQura / 2.0.9
seQura v2.0.9
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / vendor / sequra / php-client / src / Helper.php

Helper.php in seQura 2.0.9, at vendor/sequra/php-client/src/Helper.php

73 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Copyright © 2017 SeQura Engineering. All rights reserved.
4 */
5
6
7 namespace Sequra\PhpClient;
8
9 class Helper
10 {
11 const ISO8601_PATTERN = '^((\d{4})-([0-1]\d)-([0-3]\d))+$|P(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$';
12
13 public static function isConsistentCart($cart)
14 {
15 $totals = self::totals($cart);
16 return $cart['order_total_with_tax'] == $totals['with_tax'];
17 }
18
19 public static function totals($cart)
20 {
21 $total_with_tax = 0;
22 foreach ($cart['items'] as $item) {
23 $total_with_tax += $item['total_with_tax'];
24 }
25
26 return array('with_tax' => $total_with_tax);
27 }
28
29 public static function removeNulls($data)
30 {
31 foreach ($data as $key => $value) {
32 if (is_null($value)) {
33 unset($data[$key]);
34 } else {
35 if (is_array($value)) {
36 $data[$key] = self::removeNulls($value);
37 }
38 }
39 }
40
41 return $data;
42 }
43
44 public static function removeHtmlEntities($data)
45 {
46 foreach ($data as $key => $value) {
47 if (is_string($value)) {
48 $data[$key] = html_entity_decode($value, ENT_COMPAT | ENT_HTML401, 'UTF-8');
49 } else {
50 if (is_array($value)) {
51 $data[$key] = self::removeHtmlEntities($value);
52 }
53 }
54 }
55 return $data;
56 }
57
58 public static function notNull($value1, $value2)
59 {
60 return is_null($value1) ? $value2 : $value1;
61 }
62
63 public static function sign($value, $pass)
64 {
65 $signature = hash_hmac('sha256', $value, $pass);
66 if ($signature) {
67 return $signature;
68 }
69
70 return sha1($value . $pass);
71 }
72 }
73