Exemplo n.º 1
0
 public static function cancelPreapproval($invest, &$errors = array(), $fail = false)
 {
     try {
         if (empty($invest->preapproval)) {
             $invest->cancel($fail);
             return true;
         }
         $CPRequest = new \CancelPreapprovalRequest();
         $CPRequest->requestEnvelope = new \RequestEnvelope();
         $CPRequest->requestEnvelope->errorLanguage = "es_ES";
         $CPRequest->preapprovalKey = $invest->preapproval;
         $ap = new \AdaptivePayments();
         $response = $ap->CancelPreapproval($CPRequest);
         if (strtoupper($ap->isSuccess) == 'FAILURE') {
             Invest::setDetail($invest->id, 'paypal-cancel-fail', 'Ha fallado al cancelar el preapproval. Proceso libary/paypal::cancelPreapproval');
             $errors[] = 'Preapproval cancel failed.' . $ap->getLastError();
             @mail(\GOTEO_FAIL_MAIL, 'Fallo al cancelar preapproval Paypal API', 'ERROR en ' . __FUNCTION__ . '<br /><pre>' . print_r($ap->getLastError(), 1) . '</pre>');
             return false;
         } else {
             Invest::setDetail($invest->id, 'paypal-cancel', 'El Preapproval se ha cancelado y con ello el aporte. Proceso libary/paypal::cancelPreapproval');
             $invest->cancel($fail);
             return true;
         }
     } catch (Exception $ex) {
         $fault = new \FaultMessage();
         $errorData = new \ErrorData();
         $errorData->errorId = $ex->getFile();
         $errorData->message = $ex->getMessage();
         $fault->error = $errorData;
         Invest::setDetail($invest->id, 'paypal-cancel-fail', 'Ha fallado al cancelar el preapproval. Proceso libary/paypal::cancelPreapproval');
         $errors[] = 'Error fatal en la comunicación con Paypal, se ha reportado la incidencia. Disculpe las molestias.';
         @mail(\GOTEO_FAIL_MAIL, 'Error fatal en comunicacion Paypal API', 'ERROR en ' . __FUNCTION__ . '<br /><pre>' . print_r($fault, 1) . '</pre>');
         return false;
     }
 }
    $serverName = $_SERVER['SERVER_NAME'];
    $serverPort = $_SERVER['SERVER_PORT'];
    $url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
    /* The returnURL is the location where buyers return when a
    	 payment has been succesfully authorized.
    	 The cancelURL is the location buyers are sent to when they hit the
    	 cancel button during authorization of payment during the PayPal flow                 */
    $payKey = $_REQUEST["payKey"];
    $executePaymentRequest = new ExecutePaymentRequest();
    $executePaymentRequest->payKey = $payKey;
    $executePaymentRequest->requestEnvelope = new RequestEnvelope();
    $executePaymentRequest->requestEnvelope->errorLanguage = "en_US";
    $ap = new AdaptivePayments();
    $response = $ap->ExecutePayment($executePaymentRequest);
    if (strtoupper($ap->isSuccess) == 'FAILURE') {
        $_SESSION['FAULTMSG'] = $ap->getLastError();
        $location = "APIError.php";
        header("Location: {$location}");
    } else {
        if ($response->paymentExecStatus == "COMPLETED") {
            if ($response->responseEnvelope->ack == "Success") {
                ?>
<html>
<head>

<title>PayPal Platform SDK - Execute Payment Options</title>
<link href="sdk.css" rel="stylesheet" type="text/css">
</head>
<body alink=#0000FF vlink=#0000FF>

Exemplo n.º 3
0
function refund_order()
{
    global $wpdb;
    if (isset($_POST['btnRefundSubmit'])) {
        session_start();
        try {
            $currencyCode = $_REQUEST["currencyCode"];
            $payKey = $_REQUEST["payKey"];
            $email = $_REQUEST["receiveremail"];
            $amount = $_REQUEST["amount"];
            /* Make the call to PayPal to get the Pay token
               If the API call succeded, then redirect the buyer to PayPal
               to begin to authorize payment.  If an error occured, show the
               resulting errors
               */
            $refundRequest = new RefundRequest();
            $refundRequest->currencyCode = $currencyCode;
            $refundRequest->payKey = $payKey;
            $refundRequest->requestEnvelope = new RequestEnvelope();
            $refundRequest->requestEnvelope->errorLanguage = "en_US";
            $refundRequest->receiverList = new ReceiverList();
            $receiver1 = new Receiver();
            $receiver1->email = $email;
            $receiver1->amount = $amount;
            $refundRequest->receiverList->receiver = $receiver1;
            $ap = new AdaptivePayments();
            $response = $ap->Refund($refundRequest);
            if (strtoupper($ap->isSuccess) == 'FAILURE') {
                $_SESSION['FAULTMSG'] = $ap->getLastError();
                $location = "APIError.php";
                header("Location: {$location}");
            }
        } catch (Exception $ex) {
            $fault = new FaultMessage();
            $errorData = new ErrorData();
            $errorData->errorId = $ex->getFile();
            $errorData->message = $ex->getMessage();
            $fault->error = $errorData;
            $_SESSION['FAULTMSG'] = $fault;
            $location = "APIError.php";
            //header("Location: $location");
        }
    }
    //end if
    $order_pay_info = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "ign_pay_info WHERE id = '" . $_GET['orderid'] . "'");
    $product_data = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "ign_products WHERE product_id = '" . $order_pay_info->product_id . "'");
    $paypal_settings = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "ign_pay_settings WHERE product_id = '" . $order_pay_info->product_id . "'");
    require 'languages/text_variables.php';
    echo '<div class="wrap">
			' . admin_menu_html();
    include_once 'templates/admin/_orderRefund.php';
    echo '</div>';
}
Exemplo n.º 4
0
 /**
  * Gets PayPal preapproval needed for the challenge
  */
 function get_preapproval_key(Challenge $challenge)
 {
     $amount = "50.00";
     // FIXME: calculate maximum amount that challenger may need to pay out (donation + challenge)
     error_reporting(E_ALL & ~E_STRICT);
     $token = '';
     $startDate = date('Y-m-d');
     $endDate = date('Y-m-d', time() + 3600 * 24 * 30 * 6);
     // FIXME: use real months
     $preapprovalRequest = new PreapprovalRequest();
     $preapprovalRequest->memo = "To be paid to charity if challenge is met";
     $preapprovalRequest->cancelUrl = $this->abs_url('cancel') . '?preapprovalKey=${preapprovalKey}';
     $preapprovalRequest->returnUrl = $this->abs_url('ok') . '?preapprovalKey=${preapprovalKey}';
     $preapprovalRequest->clientDetails = $this->clientDetails();
     $preapprovalRequest->currencyCode = self::CURRENCY;
     $preapprovalRequest->startingDate = $startDate;
     $preapprovalRequest->endingDate = $endDate;
     //		$preapprovalRequest->maxNumberOfPayments = "10" ;
     $preapprovalRequest->maxTotalAmountOfAllPayments = $amount;
     $preapprovalRequest->requestEnvelope = new RequestEnvelope();
     $preapprovalRequest->requestEnvelope->errorLanguage = "en_US";
     //default it is en_US, which is the only language currently supported
     $ap = new AdaptivePayments();
     $response = $ap->Preapproval($preapprovalRequest);
     if (strtoupper($ap->isSuccess) == 'FAILURE') {
         $FaultMsg = $ap->getLastError();
         $error = is_array($FaultMsg->error) ? $FaultMsg->error[0] : $FaultMsg->error;
         throw new Exception("Transaction Preapproval Failed: error Id: " . $error->errorId . ", error message: " . $error->message);
     } else {
         error_reporting(E_ALL | E_STRICT);
         return $response->preapprovalKey;
     }
 }
function adaptivePreapproval()
{
    if (isset($_POST['btnSubmitPreapproval'])) {
        global $wpdb;
        $tz = get_option('timezone_string');
        if (empty($tz)) {
            $tz = 'UTC';
        }
        date_default_timezone_set($tz);
        //print_r($_POST);
        session_start();
        $payment_variables = array("fname" => $_POST['first_name'], "lname" => $_POST['last_name'], "email" => $_POST['email'], "address" => $_POST['address'], "country" => $_POST['country'], "state" => $_POST['state'], "city" => $_POST['city'], "zip" => $_POST['zip'], "product_id" => absint($_POST['project_id']), "level" => absint($_POST['level']), "prod_price" => str_replace(',', '', $_POST['price']));
        $preapproval_key = "";
        $project = new ID_Project($variables['product_id']);
        $post_id = $project->get_project_postid();
        $product_name = get_the_title($post_id);
        $_SESSION['ig_payment_variables'] = http_build_query($payment_variables);
        // Getting the Adaptive payment settings
        $adaptive_pay_settings = getAdaptivePayPalSettings();
        require_once 'paypal/lib/AdaptivePayments.php';
        // GETTING product default settings
        $default_prod_settings = getProductDefaultSettings();
        // Getting product settings and if they are not present, set the default settings as product settings
        $prod_settings = getProductSettings(absint(esc_attr($_POST['project_id'])));
        if (empty($prod_settings)) {
            $prod_settings = $default_prod_settings;
        }
        # Endpoint: this is the server URL which you have to connect for submitting your API request.
        //Chanege to https://svcs.paypal.com/  to go live */
        if ($adaptive_pay_settings->paypal_mode == "sandbox") {
            define('API_BASE_ENDPOINT', 'https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval/');
            define('PAYPAL_REDIRECT_URL', 'https://www.sandbox.paypal.com/webscr&cmd=_ap-preapproval&preapprovalkey=' . $preapproval_key);
            $app_id = "APP-80W284485P519543T";
        } else {
            define('API_BASE_ENDPOINT', 'https://svcs.paypal.com/AdaptivePayments/Preapproval/');
            define('PAYPAL_REDIRECT_URL', 'https://www.paypal.com/webscr&cmd=_ap-preapproval&preapprovalkey=' . $preapproval_key);
            $app_id = $adaptive_pay_settings->app_id;
        }
        /***** 3token API credentials *****************/
        define('API_AUTHENTICATION_MODE', '3token');
        define('API_USERNAME', $adaptive_pay_settings->api_username);
        define('API_PASSWORD', $adaptive_pay_settings->api_password);
        define('API_SIGNATURE', $adaptive_pay_settings->api_signature);
        define('X_PAYPAL_APPLICATION_ID', $app_id);
        require_once 'paypal/lib/Config/paypal_sdk_clientproperties.php';
        $returnURL = site_url() . "/?payment_success=1&product_id=" . absint(esc_attr($_POST['project_id']));
        $cancelURL = site_url() . "/?payment_cancel=1";
        $notifyURL = esc_url(site_url()) . "/?ipn_handler=1&type=paypal_preauth&" . $_SESSION['ig_payment_variables'];
        $currencyCode = $prod_settings->currency_code;
        $senderEmail = esc_attr($_POST['email']);
        $preauth = new PreapprovalRequest();
        $preauth->cancelUrl = $cancelURL;
        $preauth->ipnNotificationUrl = $notifyURL;
        $preauth->returnUrl = $returnURL;
        $preauth->currencyCode = $currencyCode;
        $preauth->maxNumberOfPayments = "1";
        $preauth->maxNumberofPaymentsPerPeriod = 1;
        $preauth->endingDate = date("Y-m-d\\Z", strtotime("+ 364 day"));
        $preauth->startingDate = date('Y-m-d\\Z');
        $preauth->maxTotalAmountOfAllPayments = esc_attr(str_replace(',', '', $_POST['price']));
        $preauth->memo = $product_name . ' pledge of ' . number_format($_POST['price'], 2, '.', ',') . ' ' . $currencyCode;
        $preauth->clientDetails = new ClientDetailsType();
        $preauth->clientDetails->applicationId = $app_id;
        //$preauth->clientDetails->deviceId = DEVICE_ID;
        //$preauth->clientDetails->ipAddress = "127.0.0.1";
        //$preapprovalRequest->maxNumberOfPayments = $maxNumberOfPayments;
        //$preapprovalRequest->maxTotalAmountOfAllPayments = $maxTotalAmountOfAllPayments;
        $preauth->requestEnvelope = new RequestEnvelope();
        $preauth->requestEnvelope->errorLanguage = "en_US";
        $preauth->senderEmail = $senderEmail;
        $ap = new AdaptivePayments();
        $response = $ap->Preapproval($preauth);
        //print_r($preauth);
        //print_r($response);
        //print_r($ap);
        if (strtoupper($ap->isSuccess) == 'FAILURE') {
            $fault = $ap->getLastError();
            // For error handling
            if (is_array($fault->error)) {
                $errors_content = '<table width =\\"450px\\" align=\\"center\\">';
                foreach ($fault->error as $err) {
                    $errors_content .= '<tr>';
                    $errors_content .= '<td>';
                    $errors_content .= 'Error ID: ' . $err->errorId . '<br />';
                    $errors_content .= 'Domain: ' . $err->domain . '<br />';
                    $errors_content .= 'Severity: ' . $err->severity . '<br />';
                    $errors_content .= 'Category: ' . $err->category . '<br />';
                    $errors_content .= 'Message: ' . $err->message . '<br />';
                    if (empty($err->parameter)) {
                        $errors_content .= '<br />';
                    } else {
                        $errors_content .= 'Parameter: ' . $err->parameter . '<br /><br />';
                    }
                    $errors_content .= '</td>';
                    $errors_content .= '</tr>';
                }
                $errors_content .= '</table>';
            } else {
                $errors_content = 'Error ID: ' . $fault->error->errorId . '<br />';
                $errors_content .= 'Domain: ' . $fault->error->domain . '<br />';
                $errors_content .= 'Severity: ' . $fault->error->severity . '<br />';
                $errors_content .= 'Category: ' . $fault->error->category . '<br />';
                $errors_content .= 'Message: ' . $fault->error->message . '<br />';
                if (empty($fault->error->parameter)) {
                    $errors_content .= '</br>';
                } else {
                    $errors_content .= 'Parameter: ' . $fault->error->parameter . '<br /><br />';
                }
            }
            $_SESSION['paypal_errors_content'] = $errors_content;
        } else {
            // Redirect to paypal.com here
            $_SESSION['preapprovalKey'] = $response->preapprovalKey;
            $token = $response->preapprovalKey;
            $payPalURL = PAYPAL_REDIRECT_URL . '_ap-preapproval&preapprovalkey=' . $token;
            echo '<script type="text/javascript">window.location="' . $payPalURL . '";</script>';
        }
    }
}
function idpp_process_handler()
{
    global $wpdb;
    $product_id = $_POST['Project'];
    $sql = $wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'ign_pay_info WHERE product_id = %s AND status=%s', $product_id, 'W');
    //echo $sql;
    $res = $wpdb->get_results($sql);
    //print_r($res);
    $adaptive_pay_settings = getAdaptivePayPalSettings();
    // GETTING product default settings
    $default_prod_settings = getProductDefaultSettings();
    // Getting product settings and if they are not present, set the default settings as product settings
    $prod_settings = getProductSettings($product_id);
    if (empty($prod_settings)) {
        $prod_settings = $default_prod_settings;
    }
    require_once 'paypal/lib/AdaptivePayments.php';
    # Endpoint: this is the server URL which you have to connect for submitting your API request.
    //Chanege to https://svcs.paypal.com/  to go live */
    if ($adaptive_pay_settings->paypal_mode == "sandbox") {
        define('API_BASE_ENDPOINT', 'https://svcs.sandbox.paypal.com/');
        define('PAYPAL_REDIRECT_URL', 'https://www.sandbox.paypal.com/webscr&cmd=');
        $app_id = "APP-80W284485P519543T";
    } else {
        define('API_BASE_ENDPOINT', 'https://svcs.paypal.com/');
        define('PAYPAL_REDIRECT_URL', 'https://www.paypal.com/webscr&cmd=');
        $app_id = $adaptive_pay_setings->app_id;
    }
    /***** 3token API credentials *****************/
    define('API_AUTHENTICATION_MODE', '3token');
    define('API_USERNAME', $adaptive_pay_settings->api_username);
    define('API_PASSWORD', $adaptive_pay_settings->api_password);
    define('API_SIGNATURE', $adaptive_pay_settings->api_signature);
    require_once 'paypal/lib/Config/paypal_sdk_clientproperties.php';
    $no_success = array();
    $no_failures = array();
    foreach ($res as $payment) {
        if ($payment->preapproval_key !== '') {
            // Setting the necessary variables for the payment
            $returnURL = site_url('/');
            $cancelURL = site_url('/');
            $notifyURL = site_url('/') . '?ipn_handler=1';
            $currencyCode = $prod_settings->currency_code;
            $email = $payment->email;
            $preapprovalKey = $payment->preapproval_key;
            $requested = '';
            $payRequest = new PayRequest();
            $payRequest->actionType = "PAY";
            $payRequest->cancelUrl = $cancelURL;
            $payRequest->returnUrl = $returnURL;
            $payRequest->ipnNotificationUrl = $notifyURL;
            $payRequest->clientDetails = new ClientDetailsType();
            $payRequest->clientDetails->applicationId = $app_id;
            //"APP-1JE4291016473214C";
            //$payRequest->clientDetails->deviceId = DEVICE_ID;
            $payRequest->clientDetails->ipAddress = $_SERVER['REMOTE_ADDR'];
            $payRequest->currencyCode = $currencyCode;
            $payRequest->senderEmail = html_entity_decode($email);
            $payRequest->requestEnvelope = new RequestEnvelope();
            $payRequest->requestEnvelope->errorLanguage = "en_US";
            //$payRequest->preapprovalKey = "PA-16707604HP296522Y";
            //print_r($payRequest);
            if ($preapprovalKey !== "") {
                $payRequest->preapprovalKey = $preapprovalKey;
                //echo $preapprovalKey."keyhere";
            }
            $receiver1 = new receiver();
            $receiver1->email = $adaptive_pay_settings->paypal_email;
            $receiver1->amount = $payment->prod_price;
            $payRequest->receiverList = new ReceiverList();
            $payRequest->receiverList = array($receiver1);
            /* 	Make the call to PayPal to get the Pay token
             *	If the API call succeded, then redirect the buyer to PayPal
             *	to begin to authorize payment.  If an error occured, show the
             *	resulting errors
             */
            $ap = new AdaptivePayments();
            $response = $ap->Pay($payRequest);
            //echo "end of line<br/>";
            if (strtoupper($ap->isSuccess) == 'SUCCESS') {
                $no_success[] = 'success';
            } else {
                if (strtoupper($ap->isSuccess) == 'FAILURE') {
                    $no_failures[] = 'failure';
                    //echo "inside failure<br/>";
                    $fault = $ap->getLastError();
                    $errors_content = $fault->error->message;
                    //echo $errors_content;
                    // For error handling
                    /*if (is_object($fault->error))
                    				{ 
                    
                    					//$errors_content = '<table width =\"450px\" align=\"center\">';
                    					$errors_content;
                    					$errors_content = '';
                    					foreach($fault->error as $err) {
                    
                    						//$errors_content .= '<tr>';
                    						//$errors_content .= '<td>';
                    						//$errors_content .= 'Error ID: ' . $err->errorId . '<br />';
                    						//$errors_content .= 'Domain: ' . $err->domain . '<br />';
                    						//$errors_content .= 'Severity: ' . $err->severity . '<br />';
                    						//$errors_content .= 'Category: ' . $err->category . '<br />';
                    						$errors_content .= $err . "<br />";
                    
                    						if(empty($err->parameter)) {
                    							//$errors_content .= '<br />';
                    						}
                    						else {
                    							//$errors_content .= 'Parameter: ' . $err->parameter . '<br /><br />';
                    						}
                    							
                    						//$errors_content .= '</td>';
                    						//$errors_content .= '</tr>';
                    					}
                    					//$errors_content .= '</table>';
                    				}
                    				else
                    				{
                    
                    					$errors_content = "";
                    					//$errors_content .= 'Error ID: ' . $fault->error->errorId . '<br />';
                    					//$errors_content .= 'Domain: ' . $fault->error->domain . '<br />';
                    					//$errors_content .= 'Severity: ' . $fault->error->severity . '<br />';
                    					//$errors_content .= 'Category: ' . $fault->error->category . '<br />';
                    					$errors_content .= $fault->error->message . '<br />';
                    					if(empty($fault->error->parameter)) {
                    						//$errors_content .= '</br>';
                    					}
                    					else {
                    						//$errors_content .= 'Parameter: ' . $fault->error->parameter . '<br /><br />';
                    					}
                    				}*/
                }
            }
        }
    }
    $response_array['counts'] = array('success' => count($no_success), 'failures' => count($no_failures));
    print_r(json_encode($response_array));
    exit;
}
Exemplo n.º 7
0
function ConvertCurrency()
{
    $CCRequest = new ConvertCurrencyRequest();
    $list = array();
    $baseamount = array('1.00', '100.00');
    $fromcode = array('GBP', 'EUR');
    $tocode = array('USD', 'CAD', 'JPY');
    for ($i = 0; $i < count($baseamount); $i++) {
        $ccType = new currency();
        $ccType->amount = $baseamount[$i];
        $ccType->code = $fromcode[$i];
        $list[$i] = $ccType;
    }
    $clist = array();
    for ($i = 0; $i < count($tocode); $i++) {
        $clist[$i] = array('currencyCode' => $tocode[$i]);
    }
    $CCRequest->baseAmountList = $list;
    $CCRequest->convertToCurrencyList = $clist;
    $CCRequest->requestEnvelope = new RequestEnvelope();
    $CCRequest->requestEnvelope->errorLanguage = "en_US";
    $ap = new AdaptivePayments();
    $response = $ap->ConvertCurrency($CCRequest);
    if (strtoupper($ap->isSuccess) == 'FAILURE') {
        $FaultMsg = $ap->getLastError();
        echo "Transaction ConvertCurrency Failed: error Id: ";
        if (is_array($FaultMsg->error)) {
            echo $FaultMsg->error[0]->errorId . ", error message: " . $FaultMsg->error[0]->message;
        } else {
            echo $FaultMsg->error->errorId . ", error message: " . $FaultMsg->error->message;
        }
    } else {
        echo "ConvertCurrency Transaction Successful! \n";
    }
}