Ejemplo n.º 1
0
<?php

//define( 'SHORTINIT', true );
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/wp-load.php';
$payments_others = unserialize(get_option('carrental_available_payments_others'));
if (is_file(dirname(dirname(__FILE__)) . '/carrental-payments-mercadopago/mercadopago.php') && $payments_others && !empty($payments_others) && isset($payments_others['eway']) && $payments_others['eway']['enabled'] == 'yes') {
    require_once dirname(dirname(__FILE__)) . '/carrental-payments-mercadopago/mercadopago.php';
    $mp = new MP($payments_others['mercadopago']['client-id'], $payments_others['mercadopago']['client-secret']);
    $mp->sandbox_mode(false);
    try {
        $response = $mp->get_payment($_GET['id']);
        file_put_contents('mercadopago_ipn.log', print_r($response, true) . "\n\n-------------------------------------\n\n", FILE_APPEND);
    } catch (Exception $e) {
        file_put_contents('mercadopago_ipn.log', print_r($response, true) . "\n\n-------------------------------------\n\n", FILE_APPEND);
        file_put_contents('mercadopago_ipn.log', 'ERROR: ' . $e->getMessage() . "\n\n-------------------------------------\n\n", FILE_APPEND);
        exit;
    }
    //file_put_contents('mercadopago_ipn.log', print_r($response, true), FILE_APPEND . "\n\n-------------------------------------\n\n");
    if ($response) {
        if (isset($response['response']) && isset($response['response']['collection']) && isset($response['response']['collection']['status']) && $response['response']['collection']['status'] == 'approved') {
            // IPN response was "VERIFIED"
            list($payment_id, $lang) = explode('#', $response['response']['collection']['external_reference']);
            $wpdb->query($wpdb->prepare('UPDATE ' . CarRental::$db['booking'] . ' SET `paid_online` = ' . (double) $response['response']['collection']['total_paid_amount'] . ', `status` = 1 WHERE MD5(CONCAT(`id_order`, %s, `email`)) = %s', CarRental::$hash_salt, $payment_id));
            file_put_contents('mercadopago_ipn.log', '***VERIFIED*** - ' . $wpdb->prepare('UPDATE ' . CarRental::$db['booking'] . ' SET `paid_online` = ' . (double) $response['response']['collection']['total_paid_amount'] . ', `status` = 1 WHERE MD5(CONCAT(`id_order`, %s, `email`)) = %s', CarRental::$hash_salt, $payment_id), FILE_APPEND);
            // Send e-mail
            if (isset($lang) && !empty($lang)) {
                $emailBody = get_option('carrental_reservation_email_' . $lang);
                if ($emailBody == '') {
                    $emailBody = get_option('carrental_reservation_email_en_GB');
                }
                $emailSubject = get_option('carrental_reservation_email_subject_' . $lang);
Ejemplo n.º 2
0
 public function getPayment($payment_id)
 {
     $model = $this;
     $this->client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
     $this->client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
     $mp = new MP($this->client_id, $this->client_secret);
     return $mp->get_payment($payment_id);
 }