/** * {@inheritDoc} */ public function execute($request) { /** @var $request CreateAgreement */ RequestNotSupportedException::assertSupports($this, $request); $model = ArrayObject::ensureArrayObject($request->getModel()); if ($model['agreementRef']) { throw new LogicException('The agreement has already been created.'); } $model->validatedKeysSet(array('merchantRef', 'description', 'purchaseOperation', 'maxAmount', 'startDate', 'stopDate')); $model->validateNotEmpty(array('maxAmount', 'merchantRef', 'description')); $result = $this->api->create((array) $model); $model->replace($result); }
/** * @test */ public function shouldUseSoapClientOnCreateAgreementAndConvertItsResponse() { $response = new \stdClass(); $response->CreateAgreement3Result = '<foo>fooValue</foo>'; $soapClientMock = $this->getMock('SoapClient', array('CreateAgreement3'), array(), '', false); $soapClientMock->expects($this->once())->method('CreateAgreement3')->with($this->isType('array'))->will($this->returnValue($response)); $clientFactoryMock = $this->getMock('Payum\\Payex\\Api\\SoapClientFactory', array('createWsdlClient')); $clientFactoryMock->expects($this->atLeastOnce())->method('createWsdlClient')->will($this->returnValue($soapClientMock)); $agreementApi = new AgreementApi($clientFactoryMock, array('encryptionKey' => 'aKey', 'accountNumber' => 'aNumber', 'sandbox' => true)); $result = $agreementApi->create(array()); $this->assertEquals(array('fooValue'), $result); }