Example #1
0
require get_template_directory() . '/paypal/paypalapi.php';
if (isset($_GET['func']) && $_GET['func'] == 'confirm' && isset($_GET['token']) && isset($_GET['PayerID'])) {
    WPCAds_PayPalAPI::ConfirmExpressCheckout();
    if (isset($_SESSION['RETURN_URL'])) {
        $url = $_SESSION['RETURN_URL'];
        unset($_SESSION['RETURN_URL']);
        header('Location: ' . $url);
        exit;
    }
    if (is_numeric(get_option('paypal_success_page')) && get_option('paypal_success_page') > 0) {
        header('Location: ' . get_permalink(get_option('paypal_success_page')));
    } else {
        header('Location: ' . home_url());
    }
    exit;
}
if (!count($_POST)) {
    trigger_error('Payment error code: #00001', E_USER_ERROR);
}
$allowed_func = array('start');
if (count($_POST) && (!isset($_POST['func']) || !in_array($_POST['func'], $allowed_func))) {
    trigger_error('Payment error code: #00002', E_USER_ERROR);
}
if (count($_POST) && (!isset($_POST['AMT']) || !is_numeric($_POST['AMT']) || $_POST['AMT'] < 0)) {
    trigger_error('Payment error code: #00003', E_USER_ERROR);
}
switch ($_POST['func']) {
    case 'start':
        WPCAds_PayPalAPI::StartExpressCheckout();
        break;
}
Example #2
0
 /**
  * Close transaction
  */
 function DoExpressCheckout($result)
 {
     global $redux_demo;
     $paypal_api_environment = $redux_demo['paypal_api_environment'];
     $paypal_success = $redux_demo['paypal_success'];
     $paypal_fail = $redux_demo['paypal_fail'];
     $paypal_api_username = $redux_demo['paypal_api_username'];
     $paypal_api_password = $redux_demo['paypal_api_password'];
     $paypal_api_signature = $redux_demo['paypal_api_signature'];
     // FIELDS
     $fields = array('USER' => urlencode($paypal_api_username), 'PWD' => urlencode($paypal_api_password), 'SIGNATURE' => urlencode($paypal_api_signature), 'VERSION' => urlencode('72.0'), 'PAYMENTREQUEST_0_PAYMENTACTION' => urlencode('Sale'), 'PAYERID' => urlencode($result['PAYERID']), 'TOKEN' => urlencode($result['TOKEN']), 'PAYMENTREQUEST_0_AMT' => urlencode($result['AMT']), 'METHOD' => urlencode('DoExpressCheckoutPayment'));
     $fields_string = '';
     foreach ($fields as $key => $value) {
         $fields_string .= $key . '=' . $value . '&';
     }
     rtrim($fields_string, '&');
     // CURL
     $ch = curl_init();
     if ($paypal_api_environment == '1') {
         curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
     } elseif ($paypal_api_environment == '2') {
         curl_setopt($ch, CURLOPT_URL, 'https://api-3t.paypal.com/nvp');
     }
     curl_setopt($ch, CURLOPT_POST, count($fields));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     //execute post
     $result = curl_exec($ch);
     //close connection
     curl_close($ch);
     parse_str($result, $result);
     if ($result['ACK'] == 'Success') {
         WPCAds_PayPalAPI::UpdatePayment($result, 'success');
     } else {
         WPCAds_PayPalAPI::UpdatePayment($result, 'failed');
     }
 }