function payment($paymentDetails = array(array('paypalemail' => '*****@*****.**', 'amount' => 10.0)))
 {
     $payRequest = new PayRequest();
     $payRequest->actionType = "PAY";
     $returnURL = RETURN_URL;
     $cancelURL = CENCEL_URL;
     $payRequest->cancelUrl = $cancelURL;
     $payRequest->returnUrl = $returnURL;
     $payRequest->clientDetails = new ClientDetailsType();
     $payRequest->clientDetails->applicationId = API_APPLICATIONID;
     $payRequest->clientDetails->deviceId = '127001';
     $payRequest->clientDetails->ipAddress = $_SERVER['REMOTE_ADDR'];
     $payRequest->currencyCode = 'USD';
     $payRequest->senderEmail = PAYPAL_SENDER_EMAIL;
     $payRequest->requestEnvelope = new RequestEnvelope();
     $payRequest->requestEnvelope->errorLanguage = 'en_US';
     $receiverList = array();
     $i = 0;
     foreach ($paymentDetails as $paymentDetail) {
         $receiverList[$i] = new receiver();
         $receiverList[$i]->email = $paymentDetail['paypalemail'];
         $receiverList[$i]->amount = $paymentDetail['amount'];
         $i++;
     }
     $payRequest->receiverList = $receiverList;
     // Create service wrapper object
     $ap = new AdaptivePayments();
     // invoke business method on service wrapper passing in appropriate request params
     $response = $ap->Pay($payRequest);
     $adaptiveResponce['ap'] = $ap;
     $adaptiveResponce['response'] = $response;
     //$response1 = $ap->ExecutePayment($adaptiveResponce['response'],true);
     return $adaptiveResponce;
 }
Esempio n. 2
0
 public static function pay($invest, &$errors = array())
 {
     if ($invest->status == 1) {
         $errors[] = 'Este aporte ya está cobrado!';
         @mail(\GOTEO_FAIL_MAIL, 'Dobleejecución de preapproval', 'Se intentaba ejecutar un aporte en estado Cobrado. <br /><pre>' . print_r($invest, 1) . '</pre>');
         return false;
     }
     try {
         $project = Project::getMini($invest->project);
         $userData = User::getMini($invest->user);
         // al productor le pasamos el importe del cargo menos el 8% que se queda goteo
         $amountPay = $invest->amount - $invest->amount * 0.08;
         // Create request object
         $payRequest = new \PayRequest();
         $payRequest->memo = "Cargo del aporte de {$invest->amount} EUR del usuario '{$userData->name}' al proyecto '{$project->name}'";
         $payRequest->cancelUrl = SITE_URL . '/invest/charge/fail/' . $invest->id;
         $payRequest->returnUrl = SITE_URL . '/invest/charge/success/' . $invest->id;
         $payRequest->clientDetails = new \ClientDetailsType();
         $payRequest->clientDetails->customerId = $invest->user;
         $payRequest->clientDetails->applicationId = PAYPAL_APPLICATION_ID;
         $payRequest->clientDetails->deviceId = PAYPAL_DEVICE_ID;
         $payRequest->clientDetails->ipAddress = PAYPAL_IP_ADDRESS;
         $payRequest->currencyCode = 'EUR';
         $payRequest->preapprovalKey = $invest->preapproval;
         $payRequest->actionType = 'PAY_PRIMARY';
         $payRequest->feesPayer = 'EACHRECEIVER';
         $payRequest->reverseAllParallelPaymentsOnError = true;
         //                $payRequest->trackingId = $invest->id;
         // SENDER no vale para chained payments   (PRIMARYRECEIVER, EACHRECEIVER, SECONDARYONLY)
         $payRequest->requestEnvelope = new \RequestEnvelope();
         $payRequest->requestEnvelope->errorLanguage = 'es_ES';
         // Primary receiver, Goteo Business Account
         $receiverP = new \receiver();
         $receiverP->email = PAYPAL_BUSINESS_ACCOUNT;
         // tocar en config para poner en real
         $receiverP->amount = $invest->amount;
         $receiverP->primary = true;
         // Receiver, Projects PayPal Account
         $receiver = new \receiver();
         $receiver->email = \trim($invest->account);
         $receiver->amount = $amountPay;
         $receiver->primary = false;
         $payRequest->receiverList = array($receiverP, $receiver);
         // Create service wrapper object
         $ap = new \AdaptivePayments();
         // invoke business method on service wrapper passing in appropriate request params
         $response = $ap->Pay($payRequest);
         // Check response
         if (strtoupper($ap->isSuccess) == 'FAILURE') {
             $error_txt = '';
             $soapFault = $ap->getLastError();
             if (is_array($soapFault->error)) {
                 $errorId = $soapFault->error[0]->errorId;
                 $errorMsg = $soapFault->error[0]->message;
             } else {
                 $errorId = $soapFault->error->errorId;
                 $errorMsg = $soapFault->error->message;
             }
             if (is_array($soapFault->payErrorList->payError)) {
                 $errorId = $soapFault->payErrorList->payError[0]->error->errorId;
                 $errorMsg = $soapFault->payErrorList->payError[0]->error->message;
             }
             // tratamiento de errores
             switch ($errorId) {
                 case '569013':
                     // preapproval cancelado por el usuario desde panel paypal
                 // preapproval cancelado por el usuario desde panel paypal
                 case '539012':
                     // preapproval no se llegó a autorizar
                     if ($invest->cancel()) {
                         $action = 'Aporte cancelado';
                         // Evento Feed
                         $log = new Feed();
                         $log->setTarget($project->id);
                         $log->populate('Aporte cancelado por preaproval cancelado por el usuario paypal', '/admin/accounts', \vsprintf('Se ha <span class="red">Cancelado</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s por preapproval cancelado', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                         $log->doAdmin('system');
                         $error_txt = $log->title;
                         unset($log);
                     }
                     break;
                 case '569042':
                     // cuenta del proyecto no confirmada en paypal
                     // Evento Feed
                     $log = new Feed();
                     $log->setTarget($project->id);
                     $log->populate('Cuenta del proyecto no confirmada en PayPal', '/admin/accounts', \vsprintf('Ha <span class="red">fallado al ejecutar</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s porque la cuenta del proyecto <span class="red">no está confirmada</span> en PayPal', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                     $log->doAdmin('system');
                     $error_txt = $log->title;
                     unset($log);
                     break;
                 case '580022':
                     // uno de los mails enviados no es valido
                 // uno de los mails enviados no es valido
                 case '589039':
                     // el mail del preaproval no está registrada en paypal
                     // Evento Feed
                     $log = new Feed();
                     $log->setTarget($project->id);
                     $log->populate('El mail del preaproval no esta registrado en PayPal', '/admin/accounts', \vsprintf('Ha <span class="red">fallado al ejecutar</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s porque el mail del preaproval <span class="red">no está registrado</span> en PayPal', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                     $log->doAdmin('system');
                     $error_txt = $log->title;
                     unset($log);
                     break;
                 case '520009':
                     // la cuenta esta restringida por paypal
                     // Evento Feed
                     $log = new Feed();
                     $log->setTarget($project->id);
                     $log->populate('La cuenta esta restringida por PayPal', '/admin/accounts', \vsprintf('Ha <span class="red">fallado al ejecutar</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s porque la cuenta <span class="red">está restringida</span> por PayPal', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                     $log->doAdmin('system');
                     $error_txt = $log->title;
                     unset($log);
                     break;
                 case '579033':
                     // misma cuenta que el proyecto
                     // Evento Feed
                     $log = new Feed();
                     $log->setTarget($project->id);
                     $log->populate('Se ha usado la misma cuenta que del proyecto', '/admin/accounts', \vsprintf('Ha <span class="red">fallado al ejecutar</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s porque la cuenta <span class="red">es la misma</span> que la del proyecto', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                     $log->doAdmin('system');
                     $error_txt = $log->title;
                     unset($log);
                     break;
                 case '579024':
                     // fuera de fechas
                     // Evento Feed
                     $log = new Feed();
                     $log->setTarget($project->id);
                     $log->populate('Está fuera del rango de fechas', '/admin/accounts', \vsprintf('Ha <span class="red">fallado al ejecutar</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s porque estamos <span class="red">fuera del rango de fechas</span> del preapproval', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                     $log->doAdmin('system');
                     $error_txt = $log->title;
                     unset($log);
                     break;
                 case '579031':
                     // The total amount of all payments exceeds the maximum total amount for all payments
                     // Evento Feed
                     $log = new Feed();
                     $log->setTarget($project->id);
                     $log->populate('Problema con los importes', '/admin/accounts', \vsprintf('Ha <span class="red">fallado al ejecutar</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s porque ha habido <span class="red">algun problema con los importes</span>', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                     $log->doAdmin('system');
                     $error_txt = $log->title;
                     unset($log);
                     break;
                 case '520002':
                     // Internal error
                     // Evento Feed
                     $log = new Feed();
                     $log->setTarget($project->id);
                     $log->populate('Error interno de PayPal', '/admin/accounts', \vsprintf('Ha <span class="red">fallado al ejecutar</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s porque ha habido <span class="red">un error interno en PayPal</span>', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                     $log->doAdmin('system');
                     $error_txt = $log->title;
                     unset($log);
                     break;
                 default:
                     if (empty($errorId)) {
                         @mail(\GOTEO_FAIL_MAIL, 'Error fatal en comunicacion Paypal API', 'ERROR en ' . __FUNCTION__ . ' No es un soap fault pero no es un success.<br /><pre>' . print_r($ap, 1) . '</pre>');
                         $log = new Feed();
                         $log->setTarget($project->id);
                         $log->populate('Error interno de PayPal', '/admin/accounts', \vsprintf('Ha <span class="red">fallado al ejecutar</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s <span class="red">NO es soapFault pero no es Success</span>, se ha reportado el error.', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                         $log->doAdmin('system');
                         $error_txt = $log->title;
                         unset($log);
                     } else {
                         $log = new Feed();
                         $log->setTarget($project->id);
                         $log->populate('Error interno de PayPal', '/admin/accounts', \vsprintf('Ha <span class="red">fallado al ejecutar</span> el aporte de %s de %s (id: %s) al proyecto %s del dia %s <span class="red">' . $action . ' ' . $errorMsg . ' [' . $errorId . ']</span>', array(Feed::item('user', $userData->name, $userData->id), Feed::item('money', $invest->amount . ' &euro;'), Feed::item('system', $invest->id), Feed::item('project', $project->name, $project->id), Feed::item('system', date('d/m/Y', strtotime($invest->invested))))));
                         $log->doAdmin('system');
                         $error_txt = $log->title;
                         unset($log);
                     }
                     break;
             }
             if (empty($errorId)) {
                 $errors[] = 'NO es soapFault pero no es Success: <pre>' . print_r($ap, 1) . '</pre>';
             } elseif (!empty($error_txt)) {
                 $errors[] = $error_txt;
             } else {
                 $errors[] = "{$action} {$errorMsg} [{$errorId}]";
             }
             Invest::setIssue($invest->id);
             return false;
         }
         $token = $response->payKey;
         if (!empty($token)) {
             if ($invest->setPayment($token)) {
                 if ($response->paymentExecStatus != 'INCOMPLETE') {
                     Invest::setIssue($invest->id);
                     $errors[] = "Error de Fuente de crédito.";
                     return false;
                 }
                 $invest->setStatus(1);
                 return true;
             } else {
                 Invest::setIssue($invest->id);
                 $errors[] = "Obtenido payKey: {$token} pero no se ha grabado correctamente (paypal::setPayment) en el registro id: {$invest->id}.";
                 @mail(\GOTEO_FAIL_MAIL, 'Error al actualizar registro aporte (setPayment)', 'ERROR en ' . __FUNCTION__ . ' Metodo paypal::setPayment ha fallado.<br /><pre>' . print_r($response, 1) . '</pre>');
                 return false;
             }
         } else {
             Invest::setIssue($invest->id);
             $errors[] = 'No ha obtenido Payment Key.';
             @mail(\GOTEO_FAIL_MAIL, 'Error en implementacion Paypal API (no payKey)', 'ERROR en ' . __FUNCTION__ . ' No payment key obtained.<br /><pre>' . print_r($response, 1) . '</pre>');
             return false;
         }
     } catch (Exception $e) {
         $fault = new \FaultMessage();
         $errorData = new \ErrorData();
         $errorData->errorId = $ex->getFile();
         $errorData->message = $ex->getMessage();
         $fault->error = $errorData;
         Invest::setIssue($invest->id);
         $errors[] = 'No se ha podido inicializar la comunicación con Paypal, se ha reportado la incidencia.';
         @mail(\GOTEO_FAIL_MAIL, 'Error fatal en comunicacion Paypal API', 'ERROR en ' . __FUNCTION__ . ' Exception<br /><pre>' . print_r($fault, 1) . '</pre>');
         return false;
     }
 }
Esempio n. 3
0
     $payRequest->preapprovalKey = $preapprovalKey;
 }
 $receiver1 = new receiver();
 $receiver1->email = $_POST['receiveremail'][0];
 $receiver1->amount = $_REQUEST['amount'][0];
 $receiver2 = new receiver();
 $receiver2->email = $_POST['receiveremail'][1];
 $receiver2->amount = $_REQUEST['amount'][1];
 $payRequest->receiverList = array($receiver1, $receiver2);
 /* 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);
 if (strtoupper($ap->isSuccess) == 'FAILURE') {
     $_SESSION['FAULTMSG'] = $ap->getLastError();
     $location = "APIError.php";
     header("Location: {$location}");
 } else {
     $_SESSION['payKey'] = $response->payKey;
     if ($response->paymentExecStatus == "CREATED") {
         if (isset($_GET['cs'])) {
             $_SESSION['payKey'] = '';
         }
         try {
             if (isset($_REQUEST["payKey"])) {
                 $payKey = $_REQUEST["payKey"];
             }
             if (empty($payKey)) {
Esempio n. 4
0
 /**
  * Takes initial donation via MissionFish from preapproved payment
  */
 function get_donation_payment(Challenge $challenge)
 {
     error_reporting(E_ALL & ~E_STRICT);
     $payRequest = new PayRequest();
     $payRequest->actionType = "PAY";
     $payRequest->cancelUrl = $this->abs_url('cancel');
     $payRequest->returnUrl = $this->abs_url('ok');
     $payRequest->clientDetails = $this->clientDetails();
     $payRequest->currencyCode = self::CURRENCY;
     $payRequest->requestEnvelope = new RequestEnvelope();
     $payRequest->requestEnvelope->errorLanguage = "en_US";
     $payRequest->memo = "Starting donation to charity";
     $payRequest->preapprovalKey = $challenge->paypal_preapproval_key;
     $receiver = new Receiver();
     $receiver->amount = $this->amountFromPence($challenge->base_donation_pence);
     $receiver->email = self::MISSION_FISH_EMAIL;
     $receiver->invoiceId = $challenge->charity->missionfish_invoice_id();
     $payRequest->receiverList = array($receiver);
     $ap = new AdaptivePayments();
     $response = $ap->Pay($payRequest);
     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 projectPurchaseAdaptive()
{
    if (isset($_POST)) {
        //exit;
    }
    if (isset($_POST['submitPaymentAdaptive'])) {
        // Store all the required variables in SESSION to get them later
        session_start();
        $project_id = $_POST['project_id'];
        $project = new ID_Project($project_id);
        $payment_variables = array("fname" => isset($_POST['first_name']) ? $_POST['first_name'] : '', "lname" => isset($_POST['last_name']) ? $_POST['last_name'] : '', "email" => isset($_POST['email']) ? $_POST['email'] : '', "address" => isset($_POST['address']) ? $_POST['address'] : '', "country" => isset($_POST['country']) ? $_POST['country'] : '', "state" => isset($_POST['state']) ? $_POST['state'] : '', "city" => isset($_POST['city']) ? $_POST['city'] : '', "zip" => isset($_POST['zip']) ? $_POST['zip'] : '', "product_id" => isset($_POST['project_id']) ? absint($_POST['project_id']) : '', "level" => isset($_POST['level']) ? absint($_POST['level']) : '', "prod_price" => isset($_POST['price']) ? str_replace(',', '', $_POST['price']) : '');
        $_SESSION['ig_payment_variables'] = http_build_query($payment_variables);
        //print_r($payment_variables);
        //echo $_SESSION['ig_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 = $project->get_project_settings();
        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/');
            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_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';
        //print_r($adaptive_pay_settings);
        // Setting the necessary variables for the payment
        $returnURL = site_url() . "/?payment_success=1&product_id=" . $_POST['project_id'];
        $cancelURL = site_url() . "/?payment_cancel=1";
        $notifyURL = esc_url(site_url()) . "/?ipn_handler=1&" . $_SESSION['ig_payment_variables'];
        $currencyCode = $prod_settings->currency_code;
        $email = esc_attr($_POST['email']);
        $preapprovalKey = "";
        $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 = $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 = esc_attr(str_replace(',', '', $_POST['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();
        //print_r($ap);
        $response = $ap->Pay($payRequest);
        //echo "end of line<br/>";
        if (strtoupper($ap->isSuccess) == 'FAILURE') {
            //echo "inside failure<br/>";
            $fault = $ap->getLastError();
            if (isset($fault)) {
                $errors = $fault->error;
            }
            if (count($errors) > 1) {
                $errors_content = array();
                foreach ($errors as $error) {
                    $errors_content[] = $error->message;
                }
            } else {
                $errors_content = $errors->message;
            }
            // 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 />';
            				}
            			}*/
            if ($_POST['price'] > 0) {
                $_SESSION['paypal_errors_content'] = $errors_content;
            } else {
                $_SESSION['paypal_errors_content'] = "Please enter an amount greater than 0.00";
            }
        } else {
            //echo "inside non-fail<br/>";
            $_SESSION['payKey'] = $response->payKey;
            if ($response->paymentExecStatus == "COMPLETED") {
                //$location = "PaymentDetails.php";
                $success_url = site_url() . "/?payment_success=1&product_id=" . $_POST['project_id'];
                echo '<script type="text/javascript">window.location="' . $success_url . '";</script>';
            } else {
                $token = $response->payKey;
                $payPalURL = PAYPAL_REDIRECT_URL . '_ap-payment&paykey=' . $token;
                echo '<script type="text/javascript">window.location="' . $payPalURL . '";</script>';
                //header("Location: ".$payPalURL);
            }
        }
    }
}
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;
}
function CreatePay()
{
    $token = '';
    // CreatePay
    $payRequest = new PayRequest();
    $payRequest->actionType = "CREATE";
    $returnURL = 'http://www.paypal.com';
    $cancelURL = 'http://www.paypal.com';
    $payRequest->cancelUrl = $cancelURL;
    $payRequest->returnUrl = $returnURL;
    $payRequest->clientDetails = new ClientDetailsType();
    $payRequest->clientDetails->applicationId = 'APP-80W284485P519543T';
    $payRequest->clientDetails->deviceId = 'PayPal_PHP_SDK';
    $payRequest->clientDetails->ipAddress = '127.0.0.1';
    $payRequest->currencyCode = 'USD';
    $payRequest->senderEmail = '*****@*****.**';
    $payRequest->requestEnvelope = new RequestEnvelope();
    $payRequest->requestEnvelope->errorLanguage = 'en_US';
    $receiver1 = new receiver();
    $receiver1->email = '*****@*****.**';
    $receiver1->amount = '1.00';
    $receiver2 = new receiver();
    $receiver2->email = '*****@*****.**';
    $receiver2->amount = '1.0';
    $payRequest->receiverList = array($receiver1, $receiver2);
    /* 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);
    if (strtoupper($ap->isSuccess) == 'FAILURE') {
        $FaultMsg = $ap->getLastError();
        echo "Transaction CreatePay 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 {
        $token = $response->payKey;
        echo "Transaction CreatePay Successful! PayKey is {$token} \n";
    }
    return $token;
}
Esempio n. 8
0
 function payment($paymentDetails = array(array('email' => '*****@*****.**', 'amount' => 10.0)))
 {
     $payRequest = new PayRequest();
     $payRequest->actionType = "PAY";
     $returnURL = RETURN_URL;
     $cancelURL = CENCEL_URL;
     $payRequest->cancelUrl = $cancelURL;
     $payRequest->returnUrl = $returnURL;
     $payRequest->clientDetails = new ClientDetailsType();
     $payRequest->clientDetails->applicationId = 'APP-80W284485P519543T';
     $payRequest->clientDetails->deviceId = '127001';
     $payRequest->clientDetails->ipAddress = '127.0.0.1';
     $payRequest->currencyCode = 'USD';
     $payRequest->senderEmail = '*****@*****.**';
     $payRequest->requestEnvelope = new RequestEnvelope();
     $payRequest->requestEnvelope->errorLanguage = 'en_US';
     /*$receiver1 = new receiver();
     		$receiver1->email = '*****@*****.**';
     		$receiver1->amount = '1.00';*/
     /*$receiver2 = new receiver();
     		$receiver2->email = '*****@*****.**';
     		$receiver2->amount = '1.00';*/
     $receiverList = array();
     $i = 0;
     foreach ($paymentDetails as $paymentDetail) {
         $receiverList[$i] = new receiver();
         $receiverList[$i]->email = $paymentDetail['email'];
         $receiverList[$i]->amount = $paymentDetail['amount'];
         $i++;
     }
     //$payRequest->receiverList = //array($receiver1, $receiver2);
     $payRequest->receiverList = $receiverList;
     // Create service wrapper object
     $ap = new AdaptivePayments();
     // invoke business method on service wrapper passing in appropriate request params
     $response = $ap->Pay($payRequest);
     $adaptiveResponce['ap'] = $ap;
     $adaptiveResponce['response'] = $response;
     return $adaptiveResponce;
 }