LegacyDonationData.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\LegacyPaymentGateways\DataTransferObjects; |
| 4 | |
| 5 | use Give\PaymentGateways\DataTransferObjects\GatewayPaymentData; |
| 6 | |
| 7 | /** |
| 8 | * @since 2.19.0 |
| 9 | */ |
| 10 | class LegacyDonationData |
| 11 | { |
| 12 | /** @var GatewayPaymentData */ |
| 13 | protected $paymentData; |
| 14 | |
| 15 | /** @var string */ |
| 16 | protected $paymentMethodId; |
| 17 | |
| 18 | /** |
| 19 | * @since 2.19.0 |
| 20 | * @param GatewayPaymentData $paymentData |
| 21 | * @param $paymentMethodId |
| 22 | */ |
| 23 | public function __construct(GatewayPaymentData $paymentData, $paymentMethodId ) |
| 24 | { |
| 25 | $this->paymentData = $paymentData; |
| 26 | $this->paymentMethodId = $paymentMethodId; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @since 2.19.0 |
| 31 | * @return array |
| 32 | */ |
| 33 | public function toArray() |
| 34 | { |
| 35 | return [ |
| 36 | 'source_id' => $this->paymentMethodId, |
| 37 | 'donation_id' => $this->paymentData->donationId, |
| 38 | 'post_data' => [ |
| 39 | 'give-form-id' => give_get_payment_form_id( $this->paymentData->donationId ), |
| 40 | 'give-price-id' => $this->paymentData->priceId, |
| 41 | 'give-form-title' => give_get_donation_form_title( $this->paymentData->donationId ), |
| 42 | ], |
| 43 | 'user_info' => [ |
| 44 | 'first_name' => $this->paymentData->donorInfo->firstName, |
| 45 | 'last_name' => $this->paymentData->donorInfo->lastName, |
| 46 | 'user_email' => $this->paymentData->donorInfo->email, |
| 47 | ], |
| 48 | ]; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @since 2.19.0 |
| 53 | * @return array |
| 54 | */ |
| 55 | public function toArrayWithDescription() |
| 56 | { |
| 57 | return $this->toArray() + [ |
| 58 | 'description' => give_payment_gateway_donation_summary( $this->toArray(), false ) |
| 59 | ]; |
| 60 | } |
| 61 | } |
| 62 |