public function _handle_service_calls($call_type = '') { if (empty($_POST['orderId'])) { $message = __("This message has been sent because a call to your RBK Money callback was made without orderId parameter given. The details of the call are below.", 'leyka') . "\n\r\n\r"; $message .= "THEIR_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'), __('RBK Money - orderId missing!', 'leyka'), $message); status_header(200); die; } $donation = new Leyka_Donation((int) stripslashes($_POST['orderId'])); if (!$donation) { status_header(200); die; } // Test for e-sign: if (leyka_options()->opt('rbk_use_hash')) { $sign = hash(leyka_options()->opt('rbk_hash_type'), implode('::', array(leyka_options()->opt('rbk_eshop_id'), $_POST['orderId'], $_POST['serviceName'], leyka_options()->opt('rbk_eshop_account'), $donation->amount, mb_strtoupper($donation->currency), $_POST['paymentStatus'], $_POST['userName'], $donation->donor_email, $_POST['paymentData'], leyka_options()->opt('rbk_secret_key')))); if (empty($_POST['hash']) || $sign != trim(mb_strtolower($_POST['hash']))) { $message = __("This message has been sent because a call to your RBK Money callback was called with wrong data hash. 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'), __('RBK Money hash check failed!', 'leyka'), $message); status_header(200); die; } } // Single payment: switch ($_POST['paymentStatus']) { case 4: $new_status = 'failed'; break; case 5: $new_status = 'funded'; break; default: $new_status = 'submitted'; } if ($donation->status != $new_status) { $donation->add_gateway_response($_POST); $donation->status = $new_status; if (!$donation->donor_email && !empty($_POST['userEmail'])) { $donation->donor_email = $_POST['userEmail']; } if (!$donation->donor_name && !empty($_POST['userName'])) { $donation->donor_name = $_POST['userName']; } Leyka_Donation_Management::send_all_emails($donation->id); } status_header(200); die; }
public function cancel_recurrents(Leyka_Donation $donation) { $ch = curl_init(); $product_id = leyka_options()->opt($donation->payment_method_id . '_product_id_' . $donation->currency); $hash = md5(leyka_options()->opt('chronopay_shared_sec') . '-7-' . $product_id); curl_setopt_array($ch, array(CURLOPT_URL => 'https://gate.chronopay.com/', CURLOPT_HEADER => 0, CURLOPT_POST => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 15, CURLOPT_POSTFIELDS => "<request>\r\r\n <Opcode>7</Opcode>\r\r\n <hash>{$hash}</hash>\r\r\n <Customer>{$donation->chronopay_customer_id}</Customer>\r\r\n <Product>{$product_id}</Product>\r\r\n </request>")); $result = curl_exec($ch); if ($result === false) { $errno = curl_errno($ch); $error = curl_error($ch); curl_close($ch); die(json_encode(array('status' => 0, 'message' => $error . " ({$errno})"))); } else { $donation->add_gateway_response($result); $p = xml_parser_create(); $response_xml = array(); xml_parse_into_struct($p, $result, $response_xml); xml_parser_free($p); $response_ok = false; $response_text = ''; $response_code = 0; foreach ($response_xml as $index => $tag) { if (strtolower($tag['tag']) == 'code' && $tag['type'] == 'complete') { $response_ok = $tag['value'] == '000'; if (!$response_ok) { $response_code = $tag['value']; $response_text = $response_xml[$index + 1]['value']; } break; } } curl_close($ch); if ($response_ok) { // Save the fact that recurrents has been cancelled: $init_recurrent_donation = $this->get_init_recurrent_donation($donation); $init_recurrent_donation->recurrents_cancelled = true; die(json_encode(array('status' => 1, 'message' => __('Recurrent donations cancelled.', 'leyka')))); } else { die(json_encode(array('status' => 0, 'message' => sprintf(__('Error on the gateway side: %s', 'leyka'), $response_text . " (code {$response_code})")))); } } }
/** 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 recurrent_cancel_metabox($donation) { /** @todo Uncomment this metabox in constructor when work on recurrents cancelling will begin. */ $donation = new Leyka_Donation($donation); if ($donation->payment_type != 'rebill' || !function_exists('curl_init')) { ?> <div id="hide-recurrent-metabox"></div> <?php return; } else { $init_recurrent_donation = Leyka_Donation::get_init_recurrent_donation($donation); if ($init_recurrent_donation->recurrents_cancelled) { ?> <div class=""> <?php print_r(__('Recurrent donations subscription was cancelled at %s', 'leyka'), date(get_option('date_format') . ', H:i', $init_recurrent_donation->recurrents_cancel_date)); ?> </div> <?php } } ?> <div class="recurrent-cancel" data-donation-id="<?php echo $donation->id; ?> " data-nonce="<?php echo wp_create_nonce('leyka_recurrent_cancel'); ?> " onclick="return confirm('<?php _e("You are about to cancel all future donations on this recurrent subscribe for this donor!\\n\\nDo you really want to do it?", "leyka"); ?> ');"><?php _e('Cancel recurrent donations of this donor', 'leyka'); ?> </div> <div id="ajax-processing" style="display: none;"> <img src="<?php echo LEYKA_PLUGIN_BASE_URL . '/img/ajax-loader-h.gif'; ?> " /> <?php _e('Recurrent cancelling in progress...', 'leyka'); ?> </div> <div id="ajax-response" style="display: none;"></div> <div id="recurrent-cancel-retry" style="display: none;"><?php _e('Try again', 'leyka'); ?> </div> <?php }
/** * 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; }
public function _handle_service_calls($call_type = '') { if (empty($_REQUEST['InvId'])) { $message = __("This message has been sent because a call to your Robokassa callback (Result URL) was made without InvId parameter given. The details of the call are below.", 'leyka') . "\n\r\n\r"; $message .= "THEIR_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'), __('Robokassa - InvId missing!', 'leyka'), $message); status_header(200); die; } $donation = new Leyka_Donation((int) $_REQUEST['InvId']); // Test for e-sign. Values from Robokassa must be used: $sign = strtoupper(md5("{$_REQUEST['OutSum']}:{$_REQUEST['InvId']}:" . leyka_options()->opt('robokassa_shop_password2') . ":Shp_item=1")); if (empty($_REQUEST['SignatureValue']) || strtoupper($_REQUEST['SignatureValue']) != $sign) { $message = __("This message has been sent because a call to your Robokassa callback was called with wrong digital signature. 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 .= "Signature from request:\n\r" . print_r($_REQUEST['SignatureValue'], true) . "\n\r\n\r"; $message .= "Signature calculated:\n\r" . print_r($sign, true) . "\n\r\n\r"; wp_mail(get_option('admin_email'), __('Robokassa digital signature check failed!', 'leyka'), $message); die; } // Single payment: if ($donation->status != 'funded') { $donation->add_gateway_response($_REQUEST); $donation->status = 'funded'; // $currency_letter = substr($_REQUEST['IncCurrLabel'], -1); $_REQUEST['IncCurrLabel'] = empty($_REQUEST['IncCurrLabel']) ? '' : substr_replace($_REQUEST['IncCurrLabel'], '', -1); if ($donation->pm_id != $_REQUEST['IncCurrLabel'] && array_key_exists($_REQUEST['IncCurrLabel'], $this->_payment_methods)) { $donation->pm_id = $_REQUEST['IncCurrLabel']; } Leyka_Donation_Management::send_all_emails($donation->id); die('OK' . $_REQUEST['InvId']); } else { die; } }
public function _handle_service_calls($call_type = '') { switch ($call_type) { case 'check_order': // Gateway test before the payment - to check if it's correct if ($_POST['action'] != 'checkOrder') { // Payment isn't correct, we're not allowing it $this->_callback_answer(1, 'co', __('Wrong service operation', 'leyka')); } $_POST['orderNumber'] = (int) $_POST['orderNumber']; // Donation ID if (!$_POST['orderNumber']) { $this->_callback_answer(1, 'co', __('Sorry, there is some tech error on our side. Your payment will be cancelled.', 'leyka'), __('OrderNumber is not set', 'leyka')); } $donation = new Leyka_Donation($_POST['orderNumber']); if ($donation->sum != $_POST['orderSumAmount']) { $this->_callback_answer(1, 'co', __('Sorry, there is some tech error on our side. Your payment will be cancelled.', 'leyka'), __('Donation sum is unmatched', 'leyka')); } $donation->add_gateway_response($_POST); // set_transient('leyka_yandex_test_cho', '<pre>'.print_r($_POST, true).'</pre>', 60*60*24); $this->_callback_answer(); // OK for yandex money payment break; // Not needed, just so my IDE can relax // Not needed, just so my IDE can relax case 'payment_aviso': if ($_POST['action'] != 'paymentAviso') { // Payment isn't correct, we're not allowing it $this->_callback_answer(1, 'pa', __('Wrong service operation', 'leyka')); } $_POST['orderNumber'] = (int) $_POST['orderNumber']; // Donation ID if (!$_POST['orderNumber']) { $this->_callback_answer(1, 'pa', __('Sorry, there is some tech error on our side. Your payment will be cancelled.', 'leyka'), __('OrderNumber is not set', 'leyka')); } $donation = new Leyka_Donation($_POST['orderNumber']); if ($donation->sum != $_POST['orderSumAmount']) { $this->_callback_answer(1, 'pa', __('Sorry, there is some tech error on our side. Your payment will be cancelled.', 'leyka'), __('Donation sum is unmatched', 'leyka')); } if ($donation->status != 'funded') { $donation->add_gateway_response($_POST); $donation->status = 'funded'; Leyka_Donation_Management::send_all_emails($donation->id); } do_action('leyka_yandex_payment_aviso_success', $donation); // set_transient('leyka_yandex_test_pa', '<pre>'.print_r($_POST, true).'</pre>', 60*60*24); $this->_callback_answer(0, 'pa'); // OK for yandex money payment break; // Not needed, just so my IDE can relax // Not needed, just so my IDE can relax default: } }