Payum - PaymentDetails object in done action where

2019-08-31 06:22发布

问题:

im on done aciton and dont know how to get paymentDetails object...

here is manual : http://payum.forma-dev.com/documentation/0.8/PayumBundle/purchase_done_action

i try get object PaymentDetails from step before http://payum.forma-dev.com/documentation/0.8/PayumBundle/simple_purchase_examples/paypal_express_checkout

UPDATE1

public function doneAction(){

    $request = $this->getRequest();

    /**
     * @var $token PayumSecurityToken
     */
    $token = $this->get('payum.security.http_request_verifier')->verify($request);

    /**
     * @var $details PaymentDetails
     */
    $details = $token->getDetails();


    var_dump($details);

give

object(Payum\Core\Model\Identificator)[345]
  protected 'class' => string 'ed\partnerBundle\Entity\PaymentDetails' (length=38)
  protected 'id' => int 1

UPDATE2

 $details = unserialize($token->getDetails());

ContextErrorException: Notice: unserialize(): Error at offset 0 of 40 bytes in /home/grek/public_html/edpartner/src/ed/partnerBundle/Controller/PaymentController.php line 110

回答1:

Payum\Core\Model\Identificator is expected result. There two ways to get details:

  1. Using storage:

    <?php
    $registry = $this->get('payum');
    $storage = $registry->getStorageForClass(
        $token->getDetails()->getClass(), 
        $token->getPaymentName()
    );
    
    $details = $storage->findModelByIdentificator($token->getDetails());
    
  2. Executing a request. Here StorageExtension will set it to the request.

    <?php
    $status = new BinaryMaskStatusRequest($token);
    
    $this->get('payum')->getPayment($token->getPaymentName())->execute($status);
    
    $details = $status->getModel();
    


回答2:

<?php
$registry = $this->get('payum');
$storage = $registry->getStorage(
    $token->getDetails()->getClass(), 
    $token->getPaymentName()
);

if you are using 0.13 then make sure to include the use Payum\Core\Request\GetHumanStatus; in order to get the human readable status. To do it in 0.13 use the code provided in the documentation

here is a code example

$token = $this->get('payum.security.http_request_verifier')->verify($request);
$payment = $this->get('payum')->getPayment($token->getPaymentName());
$status->getValue();