1

paypalrecurring.php

private $test = false;
private $liveServer = 'https://api-3t.paypal.com/nvp'; # https://api.paypal.com/nvp
private $testServer = 'https://api-3t.sandbox.paypal.com/nvp'; # https://api.sandbox.paypal.com/nvp
private $methodName = 'CreateRecurringPaymentsProfile';

public function sendRequest()
{
    $nvpreq = '';

    foreach ($this->request as $fldname => $val)
        if($val != '') $nvpreq .= strtoupper($fldname) . "=" . urlencode($val) . "&";

    $url = ($this->test) ? $this->testServer : $this->liveServer;
    $post = "METHOD=" . $this->methodName . "&" . $nvpreq . "&VERSION=56.0";
    $retstr = $this->sendAPIRequest($url . "?" . $post);
    $retarrtmp = explode("&",$retstr);
    $retarr = array();

    for($i=0;$i<count($retarrtmp);$i++)
    {
        $sparr = explode("=",$retarrtmp[$i]);
        $txt = urldecode($sparr[0]);
        $val = urldecode($sparr[1]);
        $retarr[$txt] = $val;
    }

    return $retarr;
}

/**
 * True for test server. False for production.
 * @param bool $isTest
 */
public function setIsTest($isTest)
{
    $this->test = $isTest;
}

private function sendAPIRequest($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($ch);

    if(curl_errno($ch))
        $response = curl_error($ch);

    curl_close($ch);
    return $response;
}
}

Usageexample.php

<?php
require_once 'PaypalRecurring.php';

$pp = new PayPalRecurring();

$pp->setIsTest(true); // PayPal test sandbox or live server

// Your PayPal account credentials go here
$pp->request['user'] = 'xxx';
$pp->request['pwd'] = 'xxx';
$pp->request['signature'] = 'xxx';
// End PayPal account credentials

// User info
$pp->request['firstname'] = 'The users first name';
$pp->request['lastname'] = 'The users last name';
$pp->request['email'] = 'The users email address';

$pp->request['creditcardtype'] = 'Visa'; // Visa, Mastercard, Discover, Amex
$pp->request['acct'] = ''; // Credit card number
$pp->request['expdate'] = str_pad('8',2,'0', STR_PAD_LEFT)  .'2020'; // Expiration month and full year. Pad the month with 0. Month should be 1-12. This example is 8/2020.
// End user info

// Product info
$pp->request['countrycode'] = 'US';
$pp->request['billingperiod'] = 'Month'; // Bill per month
$pp->request['billingfrequency'] = 1; // How many times to bill per billing period.. This example is once per month
$pp->request['currencycode'] = 'USD';
$pp->request['amt'] = 9.95; // Amount to bill every month
$pp->request['initamt'] = 0.00; // Setup fee.. One time on account creation
$pp->request['taxamt'] = $pp->request['amt'] * .07; // Replace .07 with your tax percentage. 0 for no tax.
$pp->request['desc'] = 'Super Deluxe Package'; // The description of your product for reporting in your account
$pp->request['profilestartdate'] = gmdate('Y-m-d\TH:i:s\Z');
$pp->request['totalbillingcycles'] = '3'; // How many billing cycles. 0 for no expiration. This example is for 3 total months of billing.
$pp->request['payerstatus'] = 'verified';
// End product info

$ppResponse = $pp->sendRequest();

if(isset($ppResponse['L_ERRORCODE0']))
    echo "Error: {$ppResponse['L_LONGMESSAGE0']}";
else if(isset($ppResponse['ACK']) && $ppResponse['ACK'] == ('Success' || 'SuccessWithWarning'))
    echo "Success: {$ppResponse['ACK']}";
else
    print_r($ppResponse);

whenever i am trying to implement recurring payment in paypal always got error security header is not valid

Above example is from github

i need to integrate recurring payment in ecommerce site

I have two files paypalrecurring.php & usageExample.php

When i executed usageExample.php i got error security header is not valid

can anybody help me

  • Maybe this will help: http://stackoverflow.com/questions/1712685/express-checkout-error-message-security-header-is-not-valid – Serhat Akay Aug 14 '15 at 08:40

1 Answers1

0

This is because your API credentials in below codes is not correct.

$pp->request['user'] = 'xxx';
$pp->request['pwd'] = 'xxx';
$pp->request['signature'] = 'xxx';

You can follow up the steps below to find your API credentials:

For sandbox account:

Access https://developer.paypal.com/ and login, then access below URL:

https://developer.paypal.com/developer/accounts

Click the business account being used for your test, then click the "Profile" link under the account. Then click the "API Credentials" tab, you will find the API credentials.

For live account:

Login to www.paypal.com, go to Profile->Selling tools->API Access, click "Request API credentials" link, then select "Request API signature" and click "Agree and Submit". Then you can find your API username, API password and API signature in the final page.

PP_MTS_Frank
  • 379
  • 1
  • 2
  • As this error is generally due to incorrect credentials, have you double confirmed your sandbox credentials are correct? – PP_MTS_Frank Aug 17 '15 at 09:45
  • You may need to contact PayPal Merchant Tech Support:https://www.paypal-techsupport.com/ , Provide your account and all API request and response then we will investigate further. – PP_MTS_Frank Aug 18 '15 at 02:58