Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:16:34+00:00 2026-06-09T13:16:34+00:00

class ExpressCheckout { static function PPHttpPost($methodName_, $nvpStr_) { require_once(DataClass.php); $API_Data = Data::GetPayPalData(); // Set

  • 0
class ExpressCheckout {

static function PPHttpPost($methodName_, $nvpStr_) {
    require_once("DataClass.php");
    $API_Data = Data::GetPayPalData();

    // Set up your API credentials, PayPal end point, and API version.
    $environment = $API_Data['enviro'];
    $API_UserName = urlencode($API_Data['user']);
    $API_Password = urlencode($API_Data['pass']);
    $API_Signature = urlencode($API_Data['sig']);
    $API_Endpoint = "https://api-3t.paypal.com/nvp";
    if("sandbox" === $environment || "beta-sandbox" === $environment) {
        $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
    }
    $version = urlencode('72.0');

    // Set the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    // Turn off the server and peer verification (TrustManager Concept).
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);

    // Set the API operation, version, and API signature in the request.
    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

    // Set the request as a POST FIELD for curl.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

    // Get response from the server.
    $httpResponse = curl_exec($ch);

    if(!$httpResponse) {
        exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
    }

    // Extract the response details.
    $httpResponseAr = explode("&", $httpResponse);

    $httpParsedResponseAr = array();
    foreach ($httpResponseAr as $i => $value) {
        $tmpAr = explode("=", $value);
        if(sizeof($tmpAr) > 1) {
            $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
        }
    }

    if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
        exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
    }

    return $httpParsedResponseAr;
}

static function send() {

require_once("DataClass.php");
$API_Data = Data::GetPayPalData();
// Set request-specific fields.
$paymentAmount = urlencode($API_Data['pay']);
$currencyID = urlencode($API_Data['currency']);         // or other currency code ('USD', 'EUR', 'JPY', 'CAD', 'AUD')
$paymentType = urlencode($API_Data['type']);            // or 'Sale' or 'Order'

$returnURL = urlencode($API_Data['return']);
$cancelURL = urlencode($API_Data['cancel']);
$bad = urlencode("MESS subscription");

// Add request-specific fields to the request string.
$nvpStr = "&CANCELURL=$cancelURL&REQCONFIRMSHIPPING=0&NOSHIPPING=1&PAYMENTREQUEST_0_AMT=$paymentAmount&PAYMENTREQUEST_0_ITEMAMT=$paymentAmount&PAYMENTREQUEST_0_TAXAMT=0&RETURNURL=$returnURL&L_BILLINGTYPE0=RecurringPayments&PAYMENTREQUEST_0_DESC=$bad&L_BILLINGAGREEMENTDESCRIPTION0=$bad&PAYMENTREQUEST_0_PAYMENTACTION=$paymentType&PAYMENTREQUEST_0_CURRENCYCODE=$currencyID";

// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = ExpressCheckout::PPHttpPost('SetExpressCheckout', $nvpStr);

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
    // Redirect to paypal.com.
    $token = urldecode($httpParsedResponseAr["TOKEN"]);
    $payPalURL = "https://www.paypal.com/webscr&cmd=_express-checkout&token=$token";
    if("sandbox" === $environment || "beta-sandbox" === $environment) {
        $payPalURL = "https://www.$environment.paypal.com/webscr&cmd=_express-checkout&token=$token";
    }
    //header("Location: $payPalURL"); //commented out to view token and parsed response
    return array($token, $httpParsedResponseAr);
} else  {
    return 'SetExpressCheckout failed: ' . print_r($httpParsedResponseAr, true);
}
}

}

My code above works correctly for retrieving the token (the response is ACK = ‘SUCCESS’) but when I redirect to paypal with the token i get the following error:

This transaction is invalid. Please return to the recipient’s website
to complete your transaction using their regular checkout flow.

I have tried several ways of doing this, searched online, still no luck for 3 days now. Can anyone see where I’m going wrong? Thanks in advance.

oh and this is called with: var_dump($token = ExpressCheckout::send($_SESSION['email']));
var dump() being used to see the token and response when header("Location: $payPalURL"); is commented out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:16:35+00:00Added an answer on June 9, 2026 at 1:16 pm

    I was trying to wrap the example code into a class and came up with the exact same issue. It turned out in my case that the token wasn’t being written into the redirect.

    Try using var_dump to get the token, then manually entering the url and parameters into your browser’s address bar.

    Another thought: It looks like $environment is initialized in the PPHttpPost() function but not for the send() function. That could be the problem if you are using the sandbox environment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class X { int i; public: X() { i = 0; } void set(int
class Test { public static void main(String[] args) throws Exception { Test t =
{ class Program { static void Main(string[] args) { int id = 0, stock
class Program { static void Main(string[] args) { Console.WriteLine(Fib 1: ); Console.ReadLine(); } long
class LinkedList{ private $first; public function Merge(LinkedList $ll){ //We can't access $ll->first for merging
Class A has a UIImage. Class B has a static reference to a class
class A{ public A(){ System.out.println(in A); } } public class SampleClass{ public static void
class A { String s4 = abc; static public void main(String[]args ) { String
class A(object): _all = set() def __new__(cls): obj = super(A,cls).__new__(cls) cls._all.add(obj) return obj class
class Employee{ // salary variable is a private static variable private static double salary;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.