ConfirmDonation.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Helpers\Frontend; |
| 4 | |
| 5 | use Give\Session\SessionDonation\DonationAccessor; |
| 6 | use Give\Helpers\Form\Utils as FormUtils; |
| 7 | |
| 8 | /** |
| 9 | * Class ConfirmDonation |
| 10 | * |
| 11 | * @package Give\Helpers\Frontend |
| 12 | */ |
| 13 | class ConfirmDonation { |
| 14 | /** |
| 15 | * Store posted data to donation session to access it in iframe if we are on payment confirmation page. |
| 16 | * This function will return true if data stored successfully in purchase session (session key name "give_purchase" ) otherwise false. |
| 17 | * |
| 18 | * Note: only for internal use. |
| 19 | * |
| 20 | * @return bool |
| 21 | * @since 2.7.0 |
| 22 | */ |
| 23 | public static function storePostedDataInDonationSession() { |
| 24 | $isShowingDonationReceipt = ! empty( $_REQUEST['giveDonationAction'] ) && 'showReceipt' === give_clean( $_REQUEST['giveDonationAction'] ); |
| 25 | |
| 26 | if ( $isShowingDonationReceipt ) { |
| 27 | $paymentGatewayId = ucfirst( give_clean( $_GET['payment-confirmation'] ) ); |
| 28 | |
| 29 | $session = new DonationAccessor(); |
| 30 | $session->store( "postDataFor{$paymentGatewayId}", array_map( 'give_clean', $_POST ) ); |
| 31 | |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Remove posted data from donation session just before rendering payment confirmation view because beyond this view this data is not useful. |
| 40 | * |
| 41 | * Note: Only for internal use. |
| 42 | * |
| 43 | * @since 2.7.0 |
| 44 | */ |
| 45 | public static function removePostedDataFromDonationSession() { |
| 46 | $paymentGatewayId = ucfirst( give_clean( $_GET['payment-confirmation'] ) ); |
| 47 | |
| 48 | $session = new DonationAccessor(); |
| 49 | $session->delete( "postDataFor{$paymentGatewayId}" ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Return whether or not we are viewing donation confirmation view or not. |
| 54 | * |
| 55 | * @since 2.7.0 |
| 56 | * @return bool |
| 57 | */ |
| 58 | public static function isConfirming() { |
| 59 | return FormUtils::isViewingFormReceipt() && isset( $_GET['payment-confirmation'] ); |
| 60 | } |
| 61 | } |
| 62 |