2014-05-09 59 views
3

我試圖運行示例代碼here令牌問題與Payum

但我收到此錯誤定期付款:

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 

我的代碼如下所示:

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

我已確認該文件存儲類是能夠將數據寫入文件,但捕獲步驟無法驗證令牌。

任何形式的幫助表示感謝,讓這個代碼運行。

回答

1

令牌存儲配置不正確(不是你的錯,該文件也是錯誤的)。它必須使用hash模型字段作爲id。試試:

<?php 

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

關於你得到的例外。它試圖通過id查找令牌並使用該令牌的散列。 Ofcouce是無法找到的。

+0

讓我試試看,你有什麼參考/教程等,我可以遵循嗎? – sakhunzai

+0

更改後出現此錯誤.'Catchable致命錯誤:傳遞給Payum \ Payment :: addExtension()的參數1必須實現接口Payum \ Extension \ ExtensionInterface,實例Payum \ Core \ Extension \ StorageExtension,在/ vagrant /第34行的pprp/vendor/payum/core/Payum/Core/Registry/SimpleRegistry.php,在80行中定義在/vagrant/pprp/vendor/payum/payum/src/Payum/Payment.php上。 – sakhunzai

+0

我想你會用舊版本的付款。你用的是0.8嗎? –