PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.5
GiveWP – Donation Plugin and Fundraising Platform v4.15.5
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 2.3.2 2.30.0 All 255 releases
give / src / EventTickets / Actions / GenerateTicketsFromPurchaseData.php

GenerateTicketsFromPurchaseData.php in GiveWP – Donation Plugin and Fundraising Platform 4.15.5, at src/EventTickets/Actions/GenerateTicketsFromPurchaseData.php

52 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\EventTickets\Actions;
4
5 use Give\Donations\Models\Donation;
6 use Give\EventTickets\DataTransferObjects\TicketPurchaseData;
7 use Give\EventTickets\Models\EventTicket;
8 use Give\Framework\Support\ValueObjects\Money;
9
10 /**
11 * @since 3.6.0
12 */
13 class GenerateTicketsFromPurchaseData
14 {
15 /**
16 * @since 3.6.0
17 * @var Donation
18 */
19 protected $donation;
20
21 /**
22 * @since 3.6.0
23 */
24 public function __construct(Donation $donation)
25 {
26 $this->donation = $donation;
27 }
28
29 /**
30 * @since 4.6.0 Add support for currency conversion
31 * @since 3.20.0 Add "amount" to the array of props
32 * @since 3.6.0
33 */
34 public function __invoke(TicketPurchaseData $data)
35 {
36 for($i = 0; $i < $data->quantity; $i++) {
37 $amount = $data->ticketType->price;
38
39 if ($this->donation->amount->getCurrency() !== $data->ticketType->price->getCurrency()) {
40 $amount = new Money($data->ticketType->price->multiply($this->donation->exchangeRate)->getAmount(), $this->donation->amount->getCurrency());
41 }
42
43 EventTicket::create([
44 'eventId' => $data->ticketType->eventId,
45 'ticketTypeId' => $data->ticketType->id,
46 'donationId' => $this->donation->id,
47 'amount' => $amount,
48 ]);
49 }
50 }
51 }
52