Payum\Paypal\ProHosted\Nvp\Action\ConvertPaymentAction::execute PHP Method

execute() public method

{@inheritDoc}
public execute ( Payum\Core\Request\Convert $request )
$request Payum\Core\Request\Convert
    public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);
        /** @var PaymentInterface $payment */
        $payment = $request->getSource();
        $this->gateway->execute($currency = new GetCurrency($payment->getCurrencyCode()));
        $details = ArrayObject::ensureArrayObject($payment->getDetails());
        $details['INVNUM'] = $payment->getNumber();
        $details['AMT'] = (double) $payment->getTotalAmount();
        $details['CURRENCYCODE'] = $payment->getCurrencyCode();
        $request->setResult((array) $details);
    }

Usage Example

 /**
  * @test
  */
 public function shouldNotOverwriteAlreadySetExtraDetails()
 {
     $gatewayMock = $this->getMock('Payum\\Core\\GatewayInterface');
     $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\GetCurrency'))->willReturnCallback(function (GetCurrency $request) {
         $request->name = 'US Dollar';
         $request->alpha3 = 'USD';
         $request->numeric = 123;
         $request->exp = 2;
         $request->country = 'US';
     });
     $payment = new Payment();
     $payment->setCurrencyCode('USD');
     $payment->setTotalAmount(123);
     $payment->setDescription('the description');
     $payment->setDetails(array('foo' => 'fooVal'));
     $action = new ConvertPaymentAction();
     $action->setGateway($gatewayMock);
     $action->execute($convert = new Convert($payment, 'array'));
     $details = $convert->getResult();
     $this->assertNotEmpty($details);
     $this->assertArrayHasKey('foo', $details);
     $this->assertEquals('fooVal', $details['foo']);
 }
ConvertPaymentAction