Payum\AuthorizeNet\Aim\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()));
        $divisor = pow(10, $currency->exp);
        $details = ArrayObject::ensureArrayObject($payment->getDetails());
        $details['amount'] = $payment->getTotalAmount() / $divisor;
        $details['invoice_num'] = $payment->getNumber();
        $details['description'] = $payment->getDescription();
        $details['email'] = $payment->getClientEmail();
        $details['cust_id'] = $payment->getClientId();
        $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'));
     $result = $convert->getResult();
     $this->assertNotEmpty($result);
     $this->assertArrayHasKey('foo', $result);
     $this->assertEquals('fooVal', $result['foo']);
 }
ConvertPaymentAction