DeprecateOldTemplateHook.php
4 years ago
HookCommandInterface.php
5 years ago
SetupFieldConfirmation.php
4 years ago
SetupFieldEmailTag.php
4 years ago
SetupFieldPersistance.php
4 years ago
SetupFieldReceipt.php
4 years ago
SetupFieldValidation.php
4 years ago
SetupNewTemplateHook.php
4 years ago
SetupFieldReceipt.php
104 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Form\LegacyConsumer\Commands; |
| 4 | |
| 5 | use Give\Receipt\DonationReceipt; |
| 6 | use Give\Framework\FieldsAPI\Field; |
| 7 | use Give\Framework\FieldsAPI\Group; |
| 8 | |
| 9 | /** |
| 10 | * @since 2.10.2 |
| 11 | */ |
| 12 | class SetupFieldReceipt { |
| 13 | |
| 14 | /** |
| 15 | * @since 2.10.2 |
| 16 | * |
| 17 | * @param DonationReceipt $receipt |
| 18 | */ |
| 19 | public function __construct( DonationReceipt $receipt ) { |
| 20 | $this->receipt = $receipt; |
| 21 | } |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * @since 2.10.2 |
| 26 | * |
| 27 | * @param string $hook |
| 28 | * |
| 29 | * @return void |
| 30 | */ |
| 31 | public function __invoke( $hook ) { |
| 32 | |
| 33 | $formID = give_get_payment_meta( $this->receipt->donationId, '_give_payment_form_id' ); |
| 34 | |
| 35 | $collection = Group::make( $hook ); |
| 36 | do_action( "give_fields_{$hook}", $collection, $formID ); |
| 37 | |
| 38 | $collection->walkFields( [ $this, 'apply' ] ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @since 2.10.2 |
| 43 | * |
| 44 | * @param Field $field |
| 45 | * |
| 46 | * @return void |
| 47 | */ |
| 48 | public function apply( Field $field ) { |
| 49 | |
| 50 | if ( ! $field->shouldShowInReceipt() ) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | if ( $field->shouldStoreAsDonorMeta() ) { |
| 55 | $this->addDonorLineItem( $field ); |
| 56 | } else { |
| 57 | $this->addAdditionalLineItems( $field ); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @since 2.10.2 |
| 63 | * |
| 64 | * @param Field $field |
| 65 | * |
| 66 | * @return void |
| 67 | */ |
| 68 | protected function addDonorLineItem( Field $field ) { |
| 69 | $donorID = give_get_payment_meta( $this->receipt->donationId, '_give_payment_donor_id' ); |
| 70 | if ( $value = Give()->donor_meta->get_meta( $donorID, $field->getName(), true ) ) { |
| 71 | $this->receipt |
| 72 | ->getSections()[ DonationReceipt::DONORSECTIONID ] |
| 73 | ->addLineItem( |
| 74 | [ |
| 75 | 'id' => $field->getName(), |
| 76 | 'label' => $field->getLabel(), |
| 77 | 'value' => $value, |
| 78 | ] |
| 79 | ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @since 2.10.2 |
| 85 | * |
| 86 | * @param Field $field |
| 87 | * |
| 88 | * @return void |
| 89 | */ |
| 90 | protected function addAdditionalLineItems( Field $field ) { |
| 91 | if ( $value = give_get_payment_meta( $this->receipt->donationId, $field->getName() ) ) { |
| 92 | $this->receipt |
| 93 | ->getSections()[ DonationReceipt::ADDITIONALINFORMATIONSECTIONID ] |
| 94 | ->addLineItem( |
| 95 | [ |
| 96 | 'id' => $field->getName(), |
| 97 | 'label' => $field->getLabel(), |
| 98 | 'value' => $value, |
| 99 | ] |
| 100 | ); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 |