Я пытаюсь использовать PHP SDK PayPal с их API-интерфейсом Adaptive Payments для создания серверного сценария для автоматизации платежей партнеров нашего веб-сайта.Я установил следующие константы в соответствующие значения, которые мне дал PayPal:
define('API_AUTHENTICATION_MODE','3token');
define('API_USERNAME', 'xxx');
define('API_PASSWORD', 'xxx');
define('API_SIGNATURE', 'xxx');
define('PAYPAL_REDIRECT_URL', 'https://www.paypal.com/webscr&cmd=_ap-payment&paykey=');
define('DEVELOPER_PORTAL', 'https://developer.paypal.com');
define('DEVICE_ID', 'PayPal_Platform_PHP_SDK');
define('APPLICATION_ID', 'xxx'); //(Using correct APP ID given by paypal after registering application
Где 'xxx' равняется правильным значениям.
Есть что-то, что я пропускаю?Каждый раз, когда я пытаюсь отправить платеж с помощью нашего аккаунта, я получаю сообщение об ошибке 520003.
Это моя функция, которая пытается отправлять платежи:
function ImplicitPayment() {
global $Accounts1;
global $Accounts;
global $Affiliates;
global $fault;
global $mAmount;
global $mCompanyName;
global $mEditAffiliate_ID;
global $mEmailAffiliate;
global $mLocalFlag;
global $mPayPalEmailAccount;
global $mToday;
global $mPayPalTestEmail;
global $mLocalFlag;
if (!isset($Affiliates)) {
$Affiliates = new DB('affiliates');
}
$Affiliates->select('SELECT * FROM affiliates
LEFT JOIN accounts
ON accounts.EMAIL_NO = affiliates.EMAIL_NO
WHERE affiliates.AFFILIATE = %d
AND affiliates.ACTIVE = 1
AND affiliates.SHUTOFF != 1
AND affiliates.DELETED != 1
AND accounts.ACTIVE = 1
AND accounts.SHUTOFF != 1;', $mEditAffiliate_ID);
$Affiliates->getNext();
if (FALSE) {
if (date('d') < 10) {
//make commission payment late (at beginning of month 2)
$mAmount = $Affiliates->d->COMM_DUE - $Affiliates->d->COMM - $Affiliates->d->COMM1;
} else {
$mAmount = $Affiliates->d->COMM_DUE - $Affiliates->d->COMM;
}
}
$mAmount = $_REQUEST['mAmount'];
$mEmailAffiliate = $Affiliates->d->EMAIL;
include_once(SCRIPTPATH . '/admin/paypal_adaptive_payments/AdaptivePayments.php');
include_once(SCRIPTPATH . '/admin/paypal_adaptive_payments/web_constants.php');
try {
/* The servername and serverport tells PayPal where the buyer
should be directed back to after authorizing payment.
In this case, its the local webserver that is running this script
Using the servername and serverport, the return URL is the first
portion of the URL that buyers will return to after authorizing payment */
$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 */
$returnURL = 'http://www.realadventures.com/'; //$_SERVER["DOCUMENT_ROOT"] . $_SERVER['PHP_SELF'];
$cancelURL = 'http://www.realadventures.com/'; //$_SERVER["DOCUMENT_ROOT"] . $_SERVER['PHP_SELF'];
$currencyCode = 'USD';
$email = $mPayPalEmailAccount; //$_REQUEST["email"];
$preapprovalKey = ""; // No preapprovalKey for an implicit use case
$requested = '';
$receiverEmail = '';
$count = 1; //count($_POST['receiveremail']);
$payRequest = new PayRequest();
$payRequest->actionType = "PAY";
$payRequest->cancelUrl = $cancelURL;
$payRequest->returnUrl = $returnURL;
$payRequest->clientDetails = new ClientDetailsType();
$payRequest->clientDetails->applicationId = APPLICATION_ID;
$payRequest->clientDetails->deviceId = DEVICE_ID;
$payRequest->clientDetails->ipAddress = "127.0.0.1";
$payRequest->currencyCode = $currencyCode;
$payRequest->senderEmail = $email;
$payRequest->requestEnvelope = new RequestEnvelope();
$payRequest->requestEnvelope->errorLanguage = "en_US";
if ($preapprovalKey != "") {
$payRequest->preapprovalKey = $preapprovalKey;
}
$receiver1 = new receiver();
$receiver1->email = $mEmailAffiliate; //$_POST['receiveremail'][0];
$receiver1->amount = $mAmount;
$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);
if (strtoupper($ap->isSuccess) == 'FAILURE') {
$_SESSION['FAULTMSG'] = $ap->getLastError();
DisplayErrors();
//$location = "APIError.php";
//header("Location: $location");
} else {
$_SESSION['payKey'] = $response->payKey;
if ($response->paymentExecStatus == "COMPLETED") {
//DisplayDetails();
//$location = "PaymentDetails.php";
//header("Location: $location");
} else {
$token = $response->payKey;
$payPalURL = PAYPAL_REDIRECT_URL.'_ap-payment&paykey='.$token;
DisplayErrors();
//header("Location: ".$payPalURL);
}
}
} catch(Exception $ex) {
$fault = new FaultMessage();
$errorData = new ErrorData();
$errorData->errorId = $ex->getFile() ;
$errorData->message = $ex->getMessage();
$fault->error = $errorData;
$_SESSION['FAULTMSG']=$fault;
DisplayErrors();
//$location = SCRIPTPATH . "/admin/APIError.php";
//header("Location: $location");
}
}
РЕДАКТИРОВАТЬ: Кроме того, $ mPayPalEmailAccount имеет значението же значение, что и API_USERNAME