PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
give / src / PaymentGateways / Stripe / Traits / HasStripeStatementDescriptorText.php

HasStripeStatementDescriptorText.php in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at src/PaymentGateways/Stripe/Traits/HasStripeStatementDescriptorText.php

68 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\PaymentGateways\Stripe\Traits;
4
5 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
6
7 /**
8 * @since 2.19.0
9 */
10 trait HasStripeStatementDescriptorText
11 {
12 /**
13 * Return filtered stripe statement descriptor text.
14 * Check Stripe statement descriptor requirements: https://stripe.com/docs/statement-descriptors#requirements
15 *
16 * @since 2.19.0
17 *
18 * @param string $statementDescriptor
19 */
20 protected function validateStatementDescriptor($statementDescriptor)
21 {
22 $maxLength = 22;
23 $minLength = 5;
24 $unsupportedCharacters = ['<', '>', '"', '\\', '\'', '*']; // Stripe reserve keywords.
25
26 if ($minLength > strlen($statementDescriptor) || $maxLength < strlen($statementDescriptor)) {
27 throw new InvalidArgumentException(
28 esc_html__('Stripe statement descriptor text should contain between 5 - 22 letters, inclusive.', 'give')
29 );
30 }
31
32 if (is_numeric($statementDescriptor)) {
33 throw new InvalidArgumentException(
34 esc_html__('Stripe statement descriptor text should contain at least one letter.', 'give')
35 );
36 }
37
38 if (array_intersect($unsupportedCharacters, str_split($statementDescriptor))) {
39 throw new InvalidArgumentException(
40 __(
41 'Stripe statement descriptor text should not contain any of the special characters <code>< > \ \' " *</code>.',
42 'give'
43 )
44 );
45 }
46 }
47
48 /**
49 * Return filtered statement descriptor.
50 * This function should be used to filter statement description
51 * which was storing in stripe_statement_descriptor give setting prior to Giver 2.19.
52 *
53 * @since 2.19.1
54 * @deprecated
55 *
56 * @param string $text
57 *
58 * @return false|string
59 */
60 protected function filterOldStatementDescriptor($text)
61 {
62 $statementDescriptor = trim($text);
63 $unsupportedCharacters = ['<', '>', '"', '\''];
64 $statementDescriptor = str_replace($unsupportedCharacters, '', $statementDescriptor);
65 return substr($statementDescriptor, 0, 22);
66 }
67 }
68