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