Question

ORIGINAL QUESTION

Using the functions in paypalplatform.php, I have the following code which works fine:

$resArray = CallPaymentDetails( ... );
// $resArray = CallPay ( ... );

The following also works fine:

// $resArray = CallPaymentDetails( ... );
$resArray = CallPay ( ... );

But this does not work:

$resArray = CallPaymentDetails( ... );
$resArray = CallPay ( ... );

The error happens on the second line, i.e. $resArray = CallPay ( ... ); and the error message is:

'error(0).message' => string 'The trackingId some_string_here is invalid'

I can't see anything wrong with the trackingId and I can't seem to work out why CallPay works if CallPaymentDetails is not used before it.

After some debugging, I can see that the following line from paypalplatform.php is the line which captures the error message:

$response = curl_exec($ch);

but I can't step through that line to see why it's causing an error. Anyone know that's going on?


UPDATE - FULL CODE

<?php
    error_reporting( E_ALL | E_STRICT );
    ini_set('display_errors', 1);

    require_once ("paypalplatform.php");

    $payKey = "existing payKey goes here";
    $transactionId = "";
    $trackingId = "";

    // if( user has already tried paying where the payment failed, get old $payKey and use in CallPaymentDetails() ) = true {
        $resArray = CallPaymentDetails( $payKey, $transactionId, $trackingId );
    // }

    var_dump($resArray);

    unset($resArray);

    $actionType = "PAY";
    $cancelUrl = "http://" . $_SERVER["SERVER_ADDR"] . "/cancel.php";
    $returnUrl = "http://" . $_SERVER["SERVER_ADDR"] . "/success.php";
    $currencyCode = "GBP";
    $receiverEmailArray = array( 'company email goes here' );
    $receiverAmountArray = array( '2' );
    $receiverPrimaryArray = array();
    $senderEmail = "";
    $feesPayer = "";
    $ipnNotificationUrl = "";
    $memo = "";
    $pin = "";
    $preapprovalKey = "";
    $reverseAllParallelPaymentsOnError = "";
    $trackingId = generateTrackingID();
    $receiverInvoiceIdArray = array( $trackingId );

    $resArray = CallPay ( $actionType, $cancelUrl, $returnUrl, $currencyCode, 
        $receiverEmailArray, $receiverAmountArray, $receiverPrimaryArray,
        $receiverInvoiceIdArray, $feesPayer, $ipnNotificationUrl, $memo, 
        $pin, $preapprovalKey, $reverseAllParallelPaymentsOnError, 
        $senderEmail, $trackingId );

    var_dump($resArray);
?>

The $payKey variable right at the top needs to be entered in and $receiverEmailArray also needs to be entered in.

Was it helpful?

Solution

The problem is within paypalplatform.php

In the hashcall function, $API_Endpoint is declared as global and then $methodname is appended to it. $methodname is the operation that hashcall is instructed to carry out. Because $API_Endpoint is being appended to directly (as it is then global), any subsequent calls to hashcall will use the modified $API_Endpoint.

On the first call to hashcall from CallPaymentDetails $API_Endpoint is: https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails

On the second call to hashcall from CallPay $API_Endpoint is: https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails/Pay

It is this that is causing the unexpected results.

Edit paypalplatform.php to remove the line stated and modify the line stated:

function hash_call($methodName, $nvpStr){
global $API_Endpoint, $API_UserName, $API_Password, $API_Signature, $API_AppID;
global $USE_PROXY, $PROXY_HOST, $PROXY_PORT;

$API_Endpoint .= "/" . $methodName; //REMOVE THIS LINE

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$API_Endpoint); //MODIFY THIS LINE

So that the beginning of hashcall is as follows:

function hash_call($methodName,$nvpStr){
global $API_Endpoint,$API_UserName,$API_Password,$API_Signature,$API_AppID;
global $USE_PROXY,$PROXY_HOST,$PROXY_PORT;

$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"$API_Endpoint/$methodName");

OTHER TIPS

I think it's not working because it's missing parameters.

  'error(0).parameter(0)' => string 'some_string_here' (length=9)

EDIT: There also seems to be something wrong with the function when it's doing the first database call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top