<?php

/**
 * Display the PayPal sandbox test form.
 *
 * @author  Studio 164a
 * @package Charitable/Admin Views/Settings
 * @since   1.4.3
 */
$submit_url = add_query_arg(array('charitable_action' => 'do_paypal_sandbox_test'), admin_url('admin.php'));
$return_url = add_query_arg(array('charitable_action' => 'paypal_sandbox_test_return'), admin_url('admin.php'));
$notify_url = charitable_get_ipn_url('paypal_sandbox_test');
$result = get_option('charitable_paypal_sandbox_test', false);
$mode = 'donations' == charitable_get_option(array('gateways_paypal', 'transaction_mode'), 'standard') ? '_donations' : '_xclick';
?>
<div id="paypal-sandbox-test">
<?php 
if (isset($_GET['sandbox_test']) && !$result) {
    ?>

	<div class="notice notice-warning charitable-notice" data-notice="paypal-sandbox-test">
		<p><?php 
    _e('We haven\'t received a notification from PayPal yet. Refresh this page in a few minutes. We will also send you an email to notify you when we receive the notification from PayPal.', 'charitable');
    ?>
</p>
	</div>

<?php 
} elseif ($result && get_transient('charitable_paypal-sandbox-test_notice')) {
    if (!wp_script_is('charitable-admin-notice')) {
        wp_enqueue_script('charitable-admin-notice');
 /**
  * Process the donation with PayPal.
  *
  * @param   boolean|array $return
  * @param   int $donation_id
  * @param   Charitable_Donation_Processor $processor
  * @return  array
  * @access  public
  * @static
  * @since   1.0.0
  */
 public static function process_donation($return, $donation_id, $processor)
 {
     $gateway = new Charitable_Gateway_Paypal();
     $user_data = $processor->get_donation_data_value('user');
     $donation = charitable_get_donation($donation_id);
     $transaction_mode = $gateway->get_value('transaction_mode');
     $paypal_args = apply_filters('charitable_paypal_redirect_args', array('business' => $gateway->get_value('paypal_email'), 'email' => isset($user_data['email']) ? $user_data['email'] : '', 'first_name' => isset($user_data['first_name']) ? $user_data['first_name'] : '', 'last_name' => isset($user_data['last_name']) ? $user_data['last_name'] : '', 'address1' => isset($user_data['address']) ? $user_data['address'] : '', 'address2' => isset($user_data['address_2']) ? $user_data['address_2'] : '', 'city' => isset($user_data['city']) ? $user_data['city'] : '', 'country' => isset($user_data['country']) ? $user_data['country'] : '', 'zip' => isset($user_data['postcode']) ? $user_data['postcode'] : '', 'invoice' => $processor->get_donation_data_value('donation_key'), 'amount' => $donation->get_total_donation_amount(true), 'item_name' => html_entity_decode($donation->get_campaigns_donated_to(), ENT_COMPAT, 'UTF-8'), 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => charitable_get_currency(), 'charset' => get_bloginfo('charset'), 'custom' => $donation_id, 'rm' => '2', 'return' => charitable_get_permalink('donation_receipt_page', array('donation_id' => $donation_id)), 'cancel_return' => charitable_get_permalink('donation_cancel_page', array('donation_id' => $donation_id)), 'notify_url' => charitable_get_ipn_url(Charitable_Gateway_Paypal::ID), 'cbt' => get_bloginfo('name'), 'bn' => 'Charitable_SP', 'cmd' => 'donations' == $transaction_mode ? '_donations' : '_xclick'), $donation_id, $processor);
     /* Set up the PayPal redirect URL. */
     $paypal_redirect = trailingslashit($gateway->get_redirect_url()) . '?';
     $paypal_redirect .= http_build_query($paypal_args);
     $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
     /* Redirect to PayPal */
     return array('redirect' => $paypal_redirect, 'safe' => false);
 }
 /**
  * Return the IPN url.
  *
  * IPNs in Charitable are structured in this way: charitable-listener=gateway
  *
  * @deprecated
  *
  * @param   string $gateway
  * @return  string
  * @access  public
  * @since   1.0.0
  */
 public function get_ipn_url($gateway)
 {
     charitable_get_deprecated()->deprecated_function(__METHOD__, '1.4.0', 'charitable_get_ipn_url()');
     return charitable_get_ipn_url($gateway);
 }