示例#1
0
    <input type="hidden" name="notify_url" value="<?php 
        echo str_replace('payment.php', 'ipn_paypal.php', ACTUAL_URL);
        ?>
">
    <input type="hidden" name="return" value="<?php 
        echo str_replace('payment.php', 'login.php', ACTUAL_URL);
        ?>
">
    <input type="hidden" name="cancel_return" value="<?php 
        echo str_replace('payment.php', 'login.php', ACTUAL_URL);
        ?>
">
    <input type="image" src="https://www.paypalobjects.com/webstatic/mktg/logo-center/logotipo_paypal_pagos.png" border="0" name="submit" alt="Pagar">
    </form><?php 
    } else {
        $mp = new MercadoPagoVE(MERCADOPAGO_KEY, MERCADOPAGO_SECRET);
        if (MERCADOPAGO_SANDBOX) {
            $mp->sandbox_mode(true);
        }
        $preference_data = array('items' => array(array('id' => $_GET['id_plan'], 'title' => $plan_db['nombre'], 'quantity' => 1, 'currency_id' => $plan_db['currency'], 'unit_price' => (double) $plan_db['amount'])), 'back_urls' => array('success' => str_replace('payment.php', 'login.php', ACTUAL_URL), 'failure' => str_replace('payment.php', 'login.php', ACTUAL_URL), 'pending' => str_replace('payment.php', 'login.php', ACTUAL_URL)), 'external_reference' => $_GET['id_plan'] . '-' . $user->id . ($service ? '-' . $service['id_service'] : ''), 'payer' => array('email' => $user->mail, 'name' => $user->name));
        $preference_data['payment_methods']['excluded_payment_types'][] = array('id' => 'bank_transfer');
        $preference_data['payment_methods']['excluded_payment_types'][] = array('id' => 'atm');
        $preference_data['payment_methods']['excluded_payment_types'][] = array('id' => 'ticket');
        try {
            $preference = $mp->create_preference($preference_data);
        } catch (Exception $error) {
            echo 'Error conectando a MercadoPago: ' . print_r($error, true) . print_r($preference_data, true);
        }
        if (MERCADOPAGO_SANDBOX) {
            $init_point = $preference['response']['sandbox_init_point'];
        } else {
示例#2
0
function validateMercadoPago($mp_op_id = false)
{
    if (!$mp_op_id) {
        return false;
    }
    $mp = new MercadoPagoVE(MERCADOPAGO_KEY, MERCADOPAGO_SECRET);
    if (MERCADOPAGO_SANDBOX) {
        $mp->sandbox_mode(true);
    }
    try {
        $payment_info = $mp->get_payment_info($mp_op_id);
    } catch (Exception $e) {
        return false;
    }
    if (isset($payment_info['response']) && isset($payment_info['response']['collection'])) {
        $payment_info = $payment_info['response']['collection'];
    }
    if (!isset($payment_info['status']) || !isset($payment_info['order_id'])) {
        return false;
    }
    $ret = array();
    switch ($payment_info['status']) {
        case 'approved':
            $status_act = 'Completed';
            break;
        case 'refunded':
        case 'cancelled':
        case 'rejected':
            $status_act = 'Rejected';
            break;
        default:
            $status_act = 'Pending';
            break;
    }
    $ret['price'] = $payment_info['total_paid_amount'];
    $ret['currency'] = $payment_info['currency_id'];
    $ret['status'] = $status_act;
    $ret['order_id'] = $payment_info['order_id'];
    $ret['message'] = json_encode($payment_info) . '\\n';
    return $ret;
}