Пример #1
0
 /** Save a base submission info and return new donation ID, so gateway can add it's specific data to the logs. */
 public function log_submission()
 {
     if (empty($_POST['leyka_campaign_id']) || (int) $_POST['leyka_campaign_id'] <= 0) {
         return false;
     }
     $campaign = new Leyka_Campaign((int) $_POST['leyka_campaign_id']);
     $pm_data = leyka_pf_get_payment_method_value();
     $donation_id = Leyka_Donation::add(apply_filters('leyka_new_donation_data', array('purpose_text' => $campaign->payment_title, 'gateway_id' => $pm_data['gateway_id'])));
     $campaign->increase_submits_counter();
     if (is_wp_error($donation_id)) {
         return false;
     } else {
         do_action('leyka_log_donation-' . $pm_data['gateway_id'], $donation_id);
         return $donation_id;
     }
 }
 public function _handle_service_calls($call_type = '')
 {
     // Test for gateway's IP:
     if (leyka_options()->opt('chronopay_ip') && !in_array($_SERVER['REMOTE_ADDR'], explode(',', leyka_options()->opt('chronopay_ip')))) {
         // Security fail
         $message = __("This message has been sent because a call to your ChronoPay function was made from an IP that did not match with the one in your Chronopay gateway setting. This could mean someone is trying to hack your payment website. The details of the call are below.", 'leyka') . "\n\r\n\r";
         $message .= "POST:\n\r" . print_r($_POST, true) . "\n\r\n\r";
         $message .= "GET:\n\r" . print_r($_GET, true) . "\n\r\n\r";
         $message .= "SERVER:\n\r" . print_r($_SERVER, true) . "\n\r\n\r";
         $message .= "IP:\n\r" . print_r($_SERVER['REMOTE_ADDR'], true) . "\n\r\n\r";
         $message .= "Chronopay IP setting value:\n\r" . print_r(leyka_options()->opt('chronopay_ip'), true) . "\n\r\n\r";
         wp_mail(get_option('admin_email'), __('Chronopay IP check failed!', 'leyka'), $message);
         status_header(200);
         die;
     }
     // Test for e-sign:
     $sharedsec = leyka_options()->opt('chronopay_shared_sec');
     $customer_id = isset($_POST['customer_id']) ? trim(stripslashes($_POST['customer_id'])) : '';
     $transaction_id = isset($_POST['transaction_id']) ? trim(stripslashes($_POST['transaction_id'])) : '';
     $transaction_type = isset($_POST['transaction_type']) ? trim(stripslashes($_POST['transaction_type'])) : '';
     $total = isset($_POST['total']) ? trim(stripslashes($_POST['total'])) : '';
     $sign = md5($sharedsec . $customer_id . $transaction_id . $transaction_type . $total);
     if (empty($_POST['sign']) || $sign != trim(stripslashes($_POST['sign']))) {
         // Security fail
         $message = __("This message has been sent because a call to your ChronoPay function was made by a server that did not have the correct security key.  This could mean someone is trying to hack your payment site.  The details of the call are below.", 'leyka') . "\n\r\n\r";
         $message .= "POST:\n\r" . print_r($_POST, true) . "\n\r\n\r";
         $message .= "GET:\n\r" . print_r($_GET, true) . "\n\r\n\r";
         $message .= "SERVER:\n\r" . print_r($_SERVER, true) . "\n\r\n\r";
         wp_mail(get_option('admin_email'), __('Chronopay security key check failed!', 'leyka'), $message);
         status_header(200);
         die;
     }
     $_POST['cs2'] = (int) $_POST['cs2'];
     $donation = new Leyka_Donation($_POST['cs2']);
     if (!$donation->id || !$donation->campaign_id) {
         $message = __("This message has been sent because a call to your ChronoPay callbacks URL was made with a donation ID parameter (POST['cs2']) that Leyka is unknown of. The details of the call are below.", 'leyka') . "\n\r\n\r";
         $message .= "POST:\n\r" . print_r($_POST, true) . "\n\r\n\r";
         $message .= "GET:\n\r" . print_r($_GET, true) . "\n\r\n\r";
         $message .= "SERVER:\n\r" . print_r($_SERVER, true) . "\n\r\n\r";
         $message .= "Donation ID:\n\r" . $_POST['cs2'] . "\n\r\n\r";
         wp_mail(get_option('admin_email'), __('Chronopay gives unknown donation ID parameter!', 'leyka'), $message);
         status_header(200);
         die;
     }
     if (strtolower($_POST['currency']) == 'rub') {
         $currency_string = 'rur';
     } else {
         $message = __("This message has been sent because a call to your ChronoPay callbacks URL was made with a currency parameter (POST['currency']) that Leyka is unknown of. The details of the call are below.", 'leyka') . "\n\r\n\r";
         $message .= "POST:\n\r" . print_r($_POST, true) . "\n\r\n\r";
         $message .= "GET:\n\r" . print_r($_GET, true) . "\n\r\n\r";
         $message .= "SERVER:\n\r" . print_r($_SERVER, true) . "\n\r\n\r";
         wp_mail(get_option('admin_email'), __('Chronopay gives unknown currency parameter!', 'leyka'), $message);
         status_header(200);
         die;
     }
     // Store donation data - rebill payment:
     if (apply_filters('leyka_chronopay_callback_is_recurring', leyka_options()->opt('chronopay_card_rebill_product_id_' . $currency_string) && $_POST['product_id'] == leyka_options()->opt('chronopay_card_rebill_product_id_' . $currency_string), $_POST['product_id'])) {
         if ($transaction_type == 'Purchase') {
             // Initial rebill payment
             if ($donation->status != 'funded') {
                 $donation->add_gateway_response($_POST);
                 $donation->status = 'funded';
                 $donation->type = 'rebill';
                 if (!$donation->donor_email && !empty($_POST['email'])) {
                     $donation->donor_email = $_POST['email'];
                 }
                 Leyka_Donation_Management::send_all_emails($donation->id);
                 // Save donor's customer_id parameter to link this donation to all others in this recurrent chain:
                 $donation->chronopay_customer_id = $customer_id;
             }
         } else {
             if ($transaction_type == 'Rebill') {
                 // Rebill payment
                 $donation_id = Leyka_Donation::add(array('status' => 'funded', 'payment_type' => 'rebill'));
                 $donation->add_gateway_response($_POST);
                 $init_recurrent_payment = $this->get_init_recurrent_donation($customer_id);
                 $donation->chronopay_customer_id = $customer_id;
                 $donation->payment_title = $init_recurrent_payment->title;
                 $donation->campaign_id = $init_recurrent_payment->campaign_id;
                 $donation->payment_method_id = $init_recurrent_payment->pm_id;
                 $donation->gateway_id = $init_recurrent_payment->gateway_id;
                 $donation->donor_name = $init_recurrent_payment->donor_name;
                 $donation->donor_email = $init_recurrent_payment->donor_email;
                 $donation->amount = $init_recurrent_payment->amount;
                 $donation->currency = $init_recurrent_payment->currency;
                 Leyka_Donation_Management::send_all_emails($donation_id);
             }
         }
     } else {
         if (leyka_options()->opt('chronopay_card_product_id_' . $currency_string) && $_POST['product_id'] == leyka_options()->opt('chronopay_card_product_id_' . $currency_string)) {
             if ($donation->status != 'funded') {
                 $donation->add_gateway_response($_POST);
                 $donation->status = 'funded';
                 if (!$donation->donor_email && !empty($_POST['email'])) {
                     $donation->donor_email = $_POST['email'];
                 }
                 Leyka_Donation_Management::send_all_emails($donation->id);
                 // Save donor's customer_id parameter.. just because we're scrupulous 0:)
                 $donation->chronopay_customer_id = $customer_id;
             }
         }
     }
     status_header(200);
     die;
 }
 /**
  * It is possible for CP to call a callback several times for one donation.
  * This donation must be created only once and then updated. It can be identified with CP transaction id.
  *
  * @param $cp_transaction_id integer
  * @return Leyka_Donation
  */
 public function get_donation_by_transaction_id($cp_transaction_id)
 {
     $donation = get_posts(array('posts_per_page' => 1, 'post_type' => Leyka_Donation_Management::$post_type, 'post_status' => 'any', 'meta_query' => array('RELATION' => 'AND', array('key' => '_cp_transaction_id', 'value' => $cp_transaction_id, 'compare' => '=')), 'orderby' => 'date', 'order' => 'ASC'));
     if (count($donation)) {
         $donation = new Leyka_Donation($donation[0]->ID);
     } else {
         $donation = new Leyka_Donation(Leyka_Donation::add(array('status' => 'submitted', 'transaction_id' => $cp_transaction_id)));
     }
     return $donation;
 }