public static function doPay($invest, &$errors = array()) { try { $project = Project::getMini($invest->project); $userData = User::getMini($invest->user); // Create request object $payRequest = new \ExecutePaymentRequest(); $payRequest->payKey = $invest->payment; $payRequest->requestEnvelope = 'SOAP'; // Create service wrapper object $ap = new \AdaptivePayments(); // invoke business method on service wrapper passing in appropriate request params $response = $ap->ExecutePayment($payRequest); // Check response if (strtoupper($ap->isSuccess) == 'FAILURE') { $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/invests', \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 . ' €'), 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'); unset($log); } break; } if (empty($errorId)) { $errors[] = 'NO es soapFault pero no es Success: <pre>' . print_r($ap, 1) . '</pre>'; @mail(\GOTEO_FAIL_MAIL, 'Error en implementacion Paypal API', 'ERROR en ' . __FUNCTION__ . ' No es un soap fault pero no es un success.<br /><pre>' . print_r($ap, 1) . '</pre>'); } else { $errors[] = "{$action} {$errorMsg} [{$errorId}]"; } return false; } // verificar el campo paymentExecStatus if ($response->paymentExecStatus == 'COMPLETED') { if ($invest->setStatus('3')) { return true; } else { $errors[] = "Obtenido estatus de ejecución {$response->paymentExecStatus} pero no se ha actualizado el registro de aporte id {$invest->id}."; @mail(\GOTEO_FAIL_MAIL, 'Error al actualizar registro aporte (setStatus)', 'ERROR en ' . __FUNCTION__ . ' Metodo paypal::setStatus ha fallado.<br /><pre>' . print_r($response, 1) . '</pre>'); return false; } } else { $errors[] = 'No se ha completado el pago encadenado, no se ha pagado al proyecto.'; @mail(\GOTEO_FAIL_MAIL, 'Error fatal en comunicacion Paypal API', 'ERROR en ' . __FUNCTION__ . ' aporte id ' . $invest->id . '. No payment exec status completed.<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; $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__ . '<br />No se ha podido inicializar la comunicación con Paypal.<br /><pre>' . print_r($fault, 1) . '</pre>'); return false; } }
session_start(); try { $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>
function ExecutePay($token) { $executePaymentRequest = new ExecutePaymentRequest(); $executePaymentRequest->payKey = $token; $executePaymentRequest->requestEnvelope = new RequestEnvelope(); $executePaymentRequest->requestEnvelope->errorLanguage = "en_US"; $ap = new AdaptivePayments(); $response = $ap->ExecutePayment($executePaymentRequest); if (strtoupper($ap->isSuccess) == 'FAILURE') { $FaultMsg = $ap->getLastError(); echo "Transaction ExecutePayment 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 { if ($response->paymentExecStatus == "COMPLETED") { if ($response->responseEnvelope->ack == "Success") { echo "Transaction ExecutePay Successful! \n"; } } } }