3

I am trying to run the example code here

But I am getting this error:

Payum\Core\Exception\InvalidArgumentException: A token with hash `RVpxpP1m3HnTWcj2oL19SQ38NWvCDIz5qeUwfr283kY` could not be found. in /var/www/test/vendor/payum/core/Payum/Core/Security/PlainHttpRequestVerifier.php on line 47

My code looks like this:

namespace Paypal\Model;

use Payum\Core\Model\ArrayObject;

class AgreementDetails extends ArrayObject {

}

namespace Paypal\Model;

use Payum\Core\Model\Token;

class PaymentSecurityToken extends Token
{
}

namespace Paypal\Model;

use Payum\Core\Model\ArrayObject;

class RecurringPaymentDetails extends  ArrayObject{

}

config.php

use Buzz\Client\Curl;
use Payum\Paypal\ExpressCheckout\Nvp\PaymentFactory;
use Payum\Paypal\ExpressCheckout\Nvp\Api;
use Payum\Core\Registry\SimpleRegistry;
use Payum\Core\Storage\FilesystemStorage;
use Payum\Core\Security\PlainHttpRequestVerifier;
use Payum\Core\Security\GenericTokenFactory;

$tokenStorage = new FilesystemStorage('/home/vagrant/tmp', 'Paypal\Model\PaymentSecurityToken');
$requestVerifier = new PlainHttpRequestVerifier($tokenStorage);

$agreementDetailsClass = 'Paypal\Model\AgreementDetails';
$recurringPaymentDetailsClass = 'Paypal\Model\RecurringPaymentDetails';
$storages = array(
    'paypal' => array(
        $agreementDetailsClass => new FilesystemStorage('/home/vagrant/tmp',$agreementDetailsClass),
        $recurringPaymentDetailsClass => new FilesystemStorage('/home/vagrant/tmp',$recurringPaymentDetailsClass)
    )
);

$payments = array(
    'paypal' => PaymentFactory::create(new Api(new Curl, array(
            'username' => 'REPLACE WITH YOURS',
            'password' => 'REPLACE WITH YOURS',
            'signature' => 'REPLACE WITH YOURS',
            'sandbox' => true
        )
    )));

$registry = new SimpleRegistry($payments, $storages, null, null);

$tokenFactory = new GenericTokenFactory(
    $tokenStorage,
    $registry,
    'https://'.$_SERVER['HTTP_HOST'],
    'capture.php',
    'notify.php'
);

prepare.php

use Payum\Paypal\ExpressCheckout\Nvp\Api;

include 'config.php';

$storage = $registry->getStorageForClass($agreementDetailsClass, 'paypal');

$agreementDetails = $storage->createModel();
$agreementDetails['PAYMENTREQUEST_0_AMT'] = 0;
$agreementDetails['L_BILLINGTYPE0'] = Api::BILLINGTYPE_RECURRING_PAYMENTS;
$agreementDetails['L_BILLINGAGREEMENTDESCRIPTION0'] = $subscription['description'];
$agreementDetails['NOSHIPPING'] = 1;
$storage->updateModel($agreementDetails);

$captureToken = $tokenFactory->createCaptureToken('paypal', $agreementDetails, 'create_recurring_payment.php');

$agreementDetails['RETURNURL'] = $captureToken->getTargetUrl();
$agreementDetails['CANCELURL'] = $captureToken->getTargetUrl();
$storage->updateModel($agreementDetails);

header("Location: ".$captureToken->getTargetUrl());

capture.php

use Payum\Core\Request\BinaryMaskStatusRequest;
use Payum\Core\Request\SecuredCaptureRequest;
use Payum\Core\Request\RedirectUrlInteractiveRequest;

include 'config.php';

$token = $requestVerifier->verify($_REQUEST);
$payment = $registry->getPayment($token->getPaymentName());

$payment->execute($status = new BinaryMaskStatusRequest($token));
if (false == $status->isNew()) {
    header('HTTP/1.1 400 Bad Request', true, 400);
    exit;
}

if ($interactiveRequest = $payment->execute(new SecuredCaptureRequest($token), true)) {
    if ($interactiveRequest instanceof RedirectUrlInteractiveRequest) {
        header("Location: ".$interactiveRequest->getUrl());
        die();
    }

    throw new \LogicException('Unsupported interactive request', null, $interactiveRequest);
}

$requestVerifier->invalidate($token);

header("Location: ".$token->getAfterUrl());

create_recurring_payment.php

same as here

I have confirmed that file storage class is able to write data to files, but on capture step it fails to verify the token.

Any sort of help is appreciated to get this code running.

sakhunzai
  • 13,900
  • 23
  • 98
  • 159

1 Answers1

1

Token storage is not configured correctly (not your fault the doc is wrong too). It has to use hash model field as id. Try:

<?php

$tokenStorage = new FilesystemStorage('/home/vagrant/tmp', 'Paypal\Model\PaymentSecurityToken', 'hash');

About the exception you've gotten. It tries to find token by id and uses for that token's hash. Ofcouce it is could not be found.

Maksim Kotlyar
  • 3,821
  • 27
  • 31
  • Let me try , do you suggest any reference/tutorial etc ..which I could follow ? – sakhunzai May 10 '14 at 10:37
  • I get this error after changes.`Catchable fatal error: Argument 1 passed to Payum\Payment::addExtension() must implement interface Payum\Extension\ExtensionInterface, instance of Payum\Core\Extension\StorageExtension given, called in /vagrant/pprp/vendor/payum/core/Payum/Core/Registry/SimpleRegistry.php on line 34 and defined in /vagrant/pprp/vendor/payum/payum/src/Payum/Payment.php on line 80` – sakhunzai May 10 '14 at 10:47
  • I guess you use an old version of payum. Are you using 0.8? – Maksim Kotlyar May 11 '14 at 16:24
  • yes its latest, e.g `php composer.phar require "payum/payum-bundle:*@stable"` http://payum.forma-dev.com/documentation/0.8/PayumBundle/get_it_started#installation. I installed through composer and I assume it should be latest – sakhunzai May 11 '14 at 17:11
  • Payum\Payment is not the correct namespace, should be Payum\Core\Payment. `Payum\Extension\XXX` too. That's why I suspect you install an old one, one before 0.7. Could you try to set version explicitly? Something liek 0.8.*. – Maksim Kotlyar May 13 '14 at 08:05
  • @Maskim its debug output , which is full path to source file echoed by xdebuger. see my code in question I never used Payum\Payum path. The other thing is I am using composer so It builds autoloader based on package configs, you know better thank me :) – sakhunzai May 13 '14 at 09:51