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 / Gateways / Stripe / Actions / AddExtraMetadataToPaymentIntent.php

AddExtraMetadataToPaymentIntent.php in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at src/PaymentGateways/Gateways/Stripe/Actions/AddExtraMetadataToPaymentIntent.php

38 lines 881 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\PaymentGateways\Gateways\Stripe\Actions;
4
5 use Give\Donations\Models\Donation;
6
7 /**
8 * Adds extra metadata to the transaction sent to Stripe.
9 *
10 * @since 4.16.7
11 */
12 class AddExtraMetadataToPaymentIntent
13 {
14 /**
15 * Stripe rejects metadata values longer than 500 characters.
16 */
17 const MAX_LENGTH = 500;
18
19 /**
20 * @since 4.16.7
21 */
22 public function __invoke(array $metadata, int $donationId): array
23 {
24 $donation = Donation::find($donationId);
25 $campaign = $donation ? $donation->campaign : null;
26
27 if (!$campaign || empty($campaign->title)) {
28 return $metadata;
29 }
30
31 $metadata['Campaign Name'] = mb_strlen($campaign->title) > self::MAX_LENGTH
32 ? mb_substr($campaign->title, 0, self::MAX_LENGTH - 3) . '...'
33 : $campaign->title;
34
35 return $metadata;
36 }
37 }
38