Exemplo n.º 1
0
function checkoutWithPaypal($total, $cart)
{
    try {
        $paypal = new PayPal(true);
    } catch (Exception $e) {
        Logger::i()->writeLog("Caught Exception: " . $e->getMessage(), 'dev');
        die;
    }
    $params = array('RETURNURL' => createURLForScript("process.php"), 'CANCELURL' => createURLForScript("cancel.php"), 'PAYMENTREQUEST_0_AMT' => floatval(number_format(floatval($total), 2)), 'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR');
    $params['SOLUTIONTYPE'] = "Sole";
    $params['LANDINGPAGE'] = "Billing";
    $k = 0;
    foreach ($cart as $key => $value) {
        $info = (array) $value;
        $params['L_PAYMENTREQUEST_0_NAME' . $k] = $info["name"];
        $params['L_PAYMENTREQUEST_0_DESCR' . $k] = $info["description"];
        $params['L_PAYMENTREQUEST_0_AMT' . $k] = floatval(number_format(floatval($info['price']), 2));
        $params['L_PAYMENTREQUEST_0_QTY' . $k] = intval($info['quantity']);
        $k++;
    }
    $response = $paypal->doRequest("SetExpressCheckout", $params);
    if ($response) {
        Logger::i()->writeLog("Starting PayPal checkout");
        return $paypal->generateURL($response['TOKEN']);
    } else {
        Logger::i()->writeLog("Could not get token, error = " . $paypal->error, 'dev');
        die(Submission::createResult("Can not checkout at the moment. Please try again later."));
    }
}
Exemplo n.º 2
0
    $message .= "- Your " . Settings::i()->title . " Team";
    return $message;
}
if (isset($_GET['token'])) {
    Logger::i()->writeLog("Processing PayPal Payment");
    if (!SessionManager::i()->isLoggedIn()) {
        Logger::i()->writeLog("User not logged in", 'dev');
        die;
    }
    try {
        $paypal = new PayPal(true);
    } catch (Exception $e) {
        Logger::i()->writeLog("Caught Exception: " . $e->getMessage(), 'dev');
        die;
    }
    $response = $paypal->doRequest("GetExpressCheckoutDetails", array("TOKEN" => $_GET['token']));
    $first_name = $response['FIRSTNAME'];
    if (!$response) {
        Logger::i()->writeLog("Could not get express checkout details, error = " . $paypal->error, 'dev');
        header("Location: index.php");
        die;
    }
    $response = $paypal->doRequest("DoExpressCheckoutPayment", array("TOKEN" => $response['TOKEN'], "PAYERID" => $response['PAYERID'], "PAYMENTACTION" => "Sale", "PAYMENTREQUEST_0_AMT" => $response['PAYMENTREQUEST_0_AMT'], "PAYMENTREQUEST_0_CURRENCYCODE" => $response['PAYMENTREQUEST_0_CURRENCYCODE']));
    if ($response) {
        if ($response['PAYMENTINFO_0_PAYMENTSTATUS'] == "Completed" && $response['ACK'] == "Success" && $response['PAYMENTINFO_0_ACK'] == "Success") {
            //did pay
            $userid = intval($_SESSION['userid']);
            if (isset($_SESSION['shopping-cart'])) {
                $token = base64_encode(DbManager::i()->escapeString($_GET['token']));
                $payerid = base64_encode(DbManager::i()->escapeString($_GET['PayerID']));
                $cart = DbManager::i()->escapeString($_SESSION['shopping-cart']);